Hebrew group names + multilingual API + cleanup mock data
- task_groups.names JSONB with cs/he/ru/ua translations - GET /groups?lang=he returns Hebrew names - Removed 14 test users, cleaned orphan data - 6 real users, 2 real tasks remain Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -1,16 +1,28 @@
|
|||||||
// Task Team — Groups CRUD — 2026-03-29
|
// Task Team — Groups CRUD — 2026-03-29
|
||||||
async function groupRoutes(app) {
|
async function groupRoutes(app) {
|
||||||
app.get('/groups', async (req) => {
|
app.get('/groups', async (req) => {
|
||||||
|
const lang = req.query.lang;
|
||||||
const { rows } = await app.db.query(
|
const { rows } = await app.db.query(
|
||||||
'SELECT * FROM task_groups ORDER BY order_index ASC'
|
'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) => {
|
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]);
|
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' };
|
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) => {
|
app.post('/groups', async (req) => {
|
||||||
@@ -64,7 +76,6 @@ async function groupRoutes(app) {
|
|||||||
if (!Array.isArray(time_zones)) {
|
if (!Array.isArray(time_zones)) {
|
||||||
throw { statusCode: 400, message: 'time_zones must be an array of [{days, from, to}]' };
|
throw { statusCode: 400, message: 'time_zones must be an array of [{days, from, to}]' };
|
||||||
}
|
}
|
||||||
// Validate each timezone entry
|
|
||||||
for (const tz of time_zones) {
|
for (const tz of time_zones) {
|
||||||
if (!Array.isArray(tz.days) || !tz.from || !tz.to) {
|
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)' };
|
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)) {
|
if (!Array.isArray(locations)) {
|
||||||
throw { statusCode: 400, message: 'locations must be an array of [{name, lat, lng, radius_m}]' };
|
throw { statusCode: 400, message: 'locations must be an array of [{name, lat, lng, radius_m}]' };
|
||||||
}
|
}
|
||||||
// Validate each location entry
|
|
||||||
for (const loc of locations) {
|
for (const loc of locations) {
|
||||||
if (!loc.name || loc.lat === undefined || loc.lng === undefined) {
|
if (!loc.name || loc.lat === undefined || loc.lng === undefined) {
|
||||||
throw { statusCode: 400, message: 'Each location must have name, lat, lng' };
|
throw { statusCode: 400, message: 'Each location must have name, lat, lng' };
|
||||||
|
|||||||
Reference in New Issue
Block a user