diff --git a/api/src/routes/groups.js b/api/src/routes/groups.js index a2ea4c4..7008a3c 100644 --- a/api/src/routes/groups.js +++ b/api/src/routes/groups.js @@ -1,16 +1,28 @@ // Task Team — Groups CRUD — 2026-03-29 async function groupRoutes(app) { app.get('/groups', async (req) => { + const lang = req.query.lang; const { rows } = await app.db.query( 'SELECT * FROM task_groups ORDER BY order_index ASC' ); - return { data: rows }; + const data = rows.map(row => { + if (lang && row.names && row.names[lang]) { + return { ...row, name: row.names[lang] }; + } + return row; + }); + return { data }; }); app.get('/groups/:id', async (req) => { + const lang = req.query.lang; const { rows } = await app.db.query('SELECT * FROM task_groups WHERE id = $1', [req.params.id]); if (!rows.length) throw { statusCode: 404, message: 'Group not found' }; - return { data: rows[0] }; + const row = rows[0]; + if (lang && row.names && row.names[lang]) { + row.name = row.names[lang]; + } + return { data: row }; }); app.post('/groups', async (req) => { @@ -64,7 +76,6 @@ async function groupRoutes(app) { if (!Array.isArray(time_zones)) { throw { statusCode: 400, message: 'time_zones must be an array of [{days, from, to}]' }; } - // Validate each timezone entry for (const tz of time_zones) { if (!Array.isArray(tz.days) || !tz.from || !tz.to) { throw { statusCode: 400, message: 'Each timezone must have days (array), from (HH:MM), to (HH:MM)' }; @@ -84,7 +95,6 @@ async function groupRoutes(app) { if (!Array.isArray(locations)) { throw { statusCode: 400, message: 'locations must be an array of [{name, lat, lng, radius_m}]' }; } - // Validate each location entry for (const loc of locations) { if (!loc.name || loc.lat === undefined || loc.lng === undefined) { throw { statusCode: 400, message: 'Each location must have name, lat, lng' };