fix teams api
All checks were successful
deploy / build-and-deploy (push) Successful in 15s

This commit is contained in:
2025-05-18 22:49:04 +02:00
parent af1424edc2
commit 9785a8c087
3 changed files with 27 additions and 48 deletions

View File

@ -9,27 +9,25 @@ export const GET: APIRoute = async ({ request }) => {
const teams = await db.getTeamsFull({});
const response = [];
const response = {} as Record<number, any>;
for (const team of teams) {
response.push({
name: team.team.name,
color: team.team.color,
lastJoined: team.team.lastJoined ? new Date(team.team.lastJoined).getTime() : null,
strikeWeight: team.strikeWeight ?? 0,
memberOne: team.memberOne
? {
uuid: team.memberOne.uuid,
dead: team.memberOneDeath != null
}
: null,
memberTwo: team.memberTwo
? {
uuid: team.memberTwo.uuid,
dead: team.memberTwoDeath != null
}
: null
});
if (response[team.team.id] === undefined) {
response[team.team.id] = {
name: team.team.name,
color: team.team.color,
lastJoined: team.team.lastJoined ? new Date(team.team.lastJoined).getTime() : null,
strikeWeight: team.strikeWeight ?? 0,
users: []
};
}
if (team.user) {
response[team.team.id].users.push({
uuid: team.user.uuid,
dead: team.death != null
});
}
}
return new Response(JSON.stringify(response));
return new Response(JSON.stringify(Object.values(response)));
};