This commit is contained in:
Stan
2026-04-19 21:14:16 +02:00
parent 0c74a75126
commit 28d167f11f
42 changed files with 5681 additions and 55 deletions
+30 -1
View File
@@ -2,26 +2,55 @@ import { Router } from 'express';
import { getLookup, listLookups } from '../services/lookupService.js';
import { asyncHandler } from '../utils/asyncHandler.js';
import { validateParam } from '../middleware/validateParams.js';
import { lookupCache } from '../services/cacheService.js';
const router = Router();
router.get(
'/',
asyncHandler(async (_req, res) => {
/*
* The bulk lookup endpoint is convenient for client startup because dropdown
* lists are small and reused across many dynamic fields. Fetching them in one
* call keeps the frontend startup sequence short.
*/
const cached = lookupCache.get('all-lookups');
if (cached) {
return res.json(cached);
}
const lookups = await listLookups();
res.json({ items: lookups });
const payload = { items: lookups };
lookupCache.set('all-lookups', payload);
return res.json(payload);
})
);
router.get(
'/:lookupCode',
validateParam('lookupCode'),
asyncHandler(async (req, res) => {
/*
* The single-lookup endpoint is still useful for debugging and for possible
* future optimization if the number of lookup sets grows and startup payloads
* need to become more selective.
*/
const cacheKey = `lookup-${req.params.lookupCode}`;
const cached = lookupCache.get(cacheKey);
if (cached) {
return res.json(cached);
}
const lookup = await getLookup(req.params.lookupCode);
if (!lookup) {
return res.status(404).json({ message: 'Lookup not found.' });
}
lookupCache.set(cacheKey, lookup);
return res.json(lookup);
})
);