From 2d04e2081b12bff77e15cfce97b475fa1901df79 Mon Sep 17 00:00:00 2001 From: scott Date: Sun, 5 Apr 2026 10:21:15 -0700 Subject: [PATCH] fix: geocoding validation and emoji race condition - Add addressdetails=1 to Nominatim query so address fields are populated - Change emoji endpoint to server-side increment instead of client count - Remove client-provided count from emoji PATCH validation Co-Authored-By: Claude Opus 4.6 (1M context) --- backend/index.js | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/backend/index.js b/backend/index.js index a540cf6..b8b84c2 100644 --- a/backend/index.js +++ b/backend/index.js @@ -183,7 +183,7 @@ app.post('/awards', const userAgent = process.env.NOMINATIM_USER_AGENT || 'BestOfPBAwardsApp/1.0'; const resp = await fetch( - `${nominatimUrl}/search?format=json&q=${encodeURIComponent(address)}`, + `${nominatimUrl}/search?format=json&addressdetails=1&q=${encodeURIComponent(address)}`, { headers: { 'User-Agent': userAgent } } ); @@ -243,11 +243,10 @@ app.patch('/awards/:id/emojis', emojiLimiter, param('id').isInt().withMessage('Invalid award ID'), body('emoji').trim().isLength({ min: 1, max: 10 }).withMessage('Invalid emoji'), - body('count').isInt({ min: 0, max: 1000 }).withMessage('Count must be between 0 and 1000'), validate, (req, res) => { const { id } = req.params; - const { emoji, count } = req.body; + const { emoji } = req.body; db.get('SELECT * FROM awards WHERE id = ?', [id], (err, row) => { if (err || !row) { @@ -256,7 +255,7 @@ app.patch('/awards/:id/emojis', } let emojiTally = row.emoji_tally ? JSON.parse(row.emoji_tally) : {}; - emojiTally[emoji] = count; + emojiTally[emoji] = (emojiTally[emoji] || 0) + 1; db.run( 'UPDATE awards SET emoji_tally = ? WHERE id = ?',