Skip to content
This repository was archived by the owner on May 20, 2025. It is now read-only.

Commit 8ed23bf

Browse files
committed
swap code around to avoid syntax errors
1 parent bfd85d5 commit 8ed23bf

File tree

1 file changed

+27
-27
lines changed

1 file changed

+27
-27
lines changed

docs/guides/nodejs/survey-application.mdx

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -138,33 +138,7 @@ formApi.post('/forms/:formId', async (ctx) => {
138138

139139
## Step 3: Generate PDF Receipts
140140

141-
Listen for submitted events and generate a formatted PDF receipt from the stored data.
142-
143-
```ts title:services/pdfs.ts
144-
import { receipts, submissions, output } from '../resources/resources'
145-
import { buildReceipt } from '../form/receipt'
146-
147-
receipts.subscribe(async (ctx) => {
148-
const { id, formId } = ctx.req.json()
149-
const submission = await submissions.get(id)
150-
151-
if (!submission) {
152-
console.error(`No submission found for ID: ${id}`)
153-
return
154-
}
155-
156-
// Build the PDF buffer from the submission data
157-
const buffer = await buildReceipt(submission, formId)
158-
159-
// Store the PDF file in the bucket
160-
const file = output.file(`${id}.pdf`)
161-
await file.write(buffer)
162-
163-
console.log(`Receipt stored for ${id}`)
164-
})
165-
```
166-
167-
### Build the PDF Receipt
141+
Build a PDF receipt from the submission data using `pdfkit`.
168142

169143
```ts title:form/receipt.ts
170144
import PDFDocument from 'pdfkit'
@@ -235,6 +209,32 @@ Guests: ${guests}`,
235209
}
236210
```
237211

212+
Listen for submitted events and generate a formatted PDF receipt from the stored data.
213+
214+
```ts title:services/pdfs.ts
215+
import { receipts, submissions, output } from '../resources/resources'
216+
import { buildReceipt } from '../form/receipt'
217+
218+
receipts.subscribe(async (ctx) => {
219+
const { id, formId } = ctx.req.json()
220+
const submission = await submissions.get(id)
221+
222+
if (!submission) {
223+
console.error(`No submission found for ID: ${id}`)
224+
return
225+
}
226+
227+
// Build the PDF buffer from the submission data
228+
const buffer = await buildReceipt(submission, formId)
229+
230+
// Store the PDF file in the bucket
231+
const file = output.file(`${id}.pdf`)
232+
await file.write(buffer)
233+
234+
console.log(`Receipt stored for ${id}`)
235+
})
236+
```
237+
238238
This PDF output is fairly plain, you can enhance it further using layout templates or branding.
239239

240240
## Step 4: Delivery Logic

0 commit comments

Comments
 (0)