Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 14 additions & 14 deletions api/src/repositories/characters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -326,19 +326,19 @@ function toRankingCharacterResponse(
character: RankingCharacterRecord,
): RankingCharacterResponse {
return {
id: character.id,
name: character.name,
level: character.level,
exp: character.exp,
expNextLevel: character.exp_next_level,
kills: character.count_killed,
idClase: character.id_clase,
idRaza: character.id_raza,
id: String(character.id ?? ""),
name: String(character.name ?? ""),
level: Number(character.level ?? 1),
exp: Number(character.exp ?? 0),
expNextLevel: Number(character.exp_next_level ?? 0),
kills: Number(character.count_killed ?? 0),
idClase: Number(character.id_clase ?? 0),
idRaza: Number(character.id_raza ?? 0),
criminal: Boolean(character.criminal),
faction: character.faction,
faction: String(character.faction ?? "none"),
Comment thread
gitar-bot[bot] marked this conversation as resolved.
Outdated
clanName: character.clan_name ?? null,
headId: character.id_head,
bodyId: character.id_body,
headId: Number(character.id_head ?? 0),
bodyId: Number(character.id_body ?? 0),
updatedAt: character.updated_at,
};
}
Expand Down Expand Up @@ -477,14 +477,14 @@ export async function listCharacterRanking(options?: {
c.level,
c.exp,
c.exp_next_level,
(c.ciudadanos_matados + c.criminales_matados) AS count_killed,
(COALESCE(c.ciudadanos_matados, 0) + COALESCE(c.criminales_matados, 0)) AS count_killed,
c.id_clase,
c.id_raza,
COALESCE(c.criminal, FALSE) AS criminal,
COALESCE(c.faction, 'none') AS faction,
cl.name AS clan_name,
CASE
WHEN (c.dead = TRUE OR c.muerto = TRUE OR c.navegando = TRUE) AND c.id_last_head > 0 THEN c.id_last_head
WHEN (c.dead = TRUE OR c.muerto = TRUE OR c.navegando = TRUE) AND COALESCE(c.id_last_head, 0) > 0 THEN c.id_last_head
ELSE c.id_head
END AS id_head,
c.id_body,
Expand All @@ -502,7 +502,7 @@ export async function listCharacterRanking(options?: {
);

return {
characters: result.rows.map(toRankingCharacterResponse),
characters: (result.rows || []).map(toRankingCharacterResponse),
};
}

Expand Down
1 change: 1 addition & 0 deletions api/src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,7 @@ app.get("/ranking", async (request, response) => {
const result = await listCharacterRanking({ sort, classId });
response.json(result);
} catch (error) {
console.error("Error in /ranking handler:", error);
response.status(500).json({
error: error instanceof Error ? error.message : "Unexpected error",
});
Expand Down