From 83caf44a16a665ed090e7b485b8c4cf48e970e1a Mon Sep 17 00:00:00 2001 From: Jeff Emmett Date: Tue, 7 Apr 2026 10:26:58 -0400 Subject: [PATCH] fix: lookup/update uses latest application per email Add ORDER BY submitted_at DESC LIMIT 1 to all email-based queries so returning users always get their most recent application data. Co-Authored-By: Claude Opus 4.6 --- api/application.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/api/application.js b/api/application.js index cd16826..0631621 100644 --- a/api/application.js +++ b/api/application.js @@ -223,7 +223,7 @@ module.exports = async function handler(req, res) { // Check for duplicate application const existing = await pool.query( - 'SELECT id FROM applications WHERE email = $1', + 'SELECT id FROM applications WHERE email = $1 ORDER BY submitted_at DESC LIMIT 1', [data.email.toLowerCase().trim()] ); @@ -484,7 +484,7 @@ module.exports = async function handler(req, res) { // Find existing application by email const existing = await pool.query( - 'SELECT id, payment_status, submitted_at, status FROM applications WHERE email = $1', + 'SELECT id, payment_status, submitted_at, status FROM applications WHERE email = $1 ORDER BY submitted_at DESC LIMIT 1', [data.email.toLowerCase().trim()] ); @@ -662,7 +662,8 @@ module.exports.lookup = async function lookupHandler(req, res) { accommodation_type, selected_weeks, top_themes, belief_update, volunteer_interest, coupon_code, food_preference, accessibility_needs, payment_status, submitted_at - FROM applications WHERE email = $1`, + FROM applications WHERE email = $1 + ORDER BY submitted_at DESC LIMIT 1`, [email] );