PacktPublishing / Accelerating-Server-Side-Development-with-Fastify

Accelerate Web Development with Fastify, published by Packt
MIT License
128 stars 37 forks source link

Invalid column name in csv parser (Chapter 8) #53

Closed doichev-kostia closed 1 year ago

doichev-kostia commented 1 year ago

In the following snippet, the author uses the updatedAt property as one of the CSV headers. However, we actually use the modifiedAt field:

fastify.route({
    method: 'GET',
    url: '/export',
    schema: {
      querystring: fastify.getSchema('schema:todo:list:export')
    },
    handler: async function listTodo (request, reply) {
      const { title } = request.query

      // We manage the cursor as the data could be huge
      const cursor = await request.todosDataSource.listTodos({
        filter: { title },
        skip: 0,
        limit: undefined,
        asStream: true
      })

      reply.header('Content-Disposition', 'attachment; filename="todo-list.csv"')
      reply.type('text/csv')

      return cursor.pipe(csvStringify({
        quoted_string: true,
        header: true,
        columns: ['title', 'done', 'createdAt', 'updatedAt', 'id'],
        cast: {
          boolean: (value) => value ? 'true' : 'false',
          date: (value) => value.toISOString()
        }
      }))
    }
  })

Path: Chapter 8/routes/todos/files/routes.js Chapter: 8 Section: Managing uploads and downloads

Eomm commented 1 year ago

Thanks for reporting and providing the PR!

I will look into it