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 <noreply@anthropic.com>
This commit is contained in:
Jeff Emmett 2026-04-07 10:26:58 -04:00
parent b8823e32ec
commit 83caf44a16
1 changed files with 4 additions and 3 deletions

View File

@ -223,7 +223,7 @@ module.exports = async function handler(req, res) {
// Check for duplicate application // Check for duplicate application
const existing = await pool.query( 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()] [data.email.toLowerCase().trim()]
); );
@ -484,7 +484,7 @@ module.exports = async function handler(req, res) {
// Find existing application by email // Find existing application by email
const existing = await pool.query( 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()] [data.email.toLowerCase().trim()]
); );
@ -662,7 +662,8 @@ module.exports.lookup = async function lookupHandler(req, res) {
accommodation_type, selected_weeks, top_themes, belief_update, accommodation_type, selected_weeks, top_themes, belief_update,
volunteer_interest, coupon_code, food_preference, accessibility_needs, volunteer_interest, coupon_code, food_preference, accessibility_needs,
payment_status, submitted_at payment_status, submitted_at
FROM applications WHERE email = $1`, FROM applications WHERE email = $1
ORDER BY submitted_at DESC LIMIT 1`,
[email] [email]
); );