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) <noreply@anthropic.com>
This commit is contained in:
@@ -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 = ?',
|
||||
|
||||
Reference in New Issue
Block a user