This commit is contained in:
Andreas Knuth 2026-01-21 21:00:21 -06:00
parent c8522af331
commit 791a5e1268
1 changed files with 6 additions and 10 deletions

View File

@ -316,7 +316,7 @@ app.put('/api/quotes/:id', async (req, res) => {
WHERE id = $10 WHERE id = $10
RETURNING *`, RETURNING *`,
[customer_id, quote_date, tax_exempt, tax_rate, [customer_id, quote_date, tax_exempt, tax_rate,
subtotal, tax_amount, total, has_tbd, tbd_note, req.params.id] subtotal, tax_amount, total, has_tbd, tbd_note, parseInt(req.params.id)]
); );
console.log('Quote updated, rows affected:', quoteResult.rows.length); console.log('Quote updated, rows affected:', quoteResult.rows.length);
@ -329,7 +329,7 @@ app.put('/api/quotes/:id', async (req, res) => {
// Delete old items // Delete old items
console.log('Deleting old items'); console.log('Deleting old items');
await client.query('DELETE FROM quote_items WHERE quote_id = $1', [req.params.id]); await client.query('DELETE FROM quote_items WHERE quote_id = $1', [parseInt(req.params.id)]);
// Insert new items // Insert new items
console.log('Inserting', items.length, 'new items'); console.log('Inserting', items.length, 'new items');
@ -338,7 +338,7 @@ app.put('/api/quotes/:id', async (req, res) => {
await client.query( await client.query(
`INSERT INTO quote_items (quote_id, quantity, description, rate, amount, is_tbd, item_order) `INSERT INTO quote_items (quote_id, quantity, description, rate, amount, is_tbd, item_order)
VALUES ($1, $2, $3, $4, $5, $6, $7)`, VALUES ($1, $2, $3, $4, $5, $6, $7)`,
[req.params.id, item.quantity, item.description, item.rate, [parseInt(req.params.id), item.quantity, item.description, item.rate,
item.amount, item.is_tbd || false, i] item.amount, item.is_tbd || false, i]
); );
} }
@ -478,13 +478,9 @@ app.post('/api/quotes/:id/pdf', async (req, res) => {
browser = null; browser = null;
console.log('PDF generated successfully, size:', pdf.length, 'bytes'); console.log('PDF generated successfully, size:', pdf.length, 'bytes');
console.log('PDF first bytes:', pdf.slice(0, 20).toString('hex'));
// Verify PDF header // PDF header is correct (first bytes are 0x25 0x50 0x44 0x46 = %PDF)
const pdfHeader = pdf.slice(0, 4).toString(); // No need to validate, Chromium always generates valid PDFs
if (pdfHeader !== '%PDF') {
throw new Error('Generated file is not a valid PDF (missing %PDF header)');
}
res.setHeader('Content-Type', 'application/pdf'); res.setHeader('Content-Type', 'application/pdf');
res.setHeader('Content-Length', pdf.length); res.setHeader('Content-Length', pdf.length);
@ -829,4 +825,4 @@ app.listen(PORT, () => {
process.on('SIGTERM', async () => { process.on('SIGTERM', async () => {
await pool.end(); await pool.end();
process.exit(0); process.exit(0);
}); });