Fix users without weapon pool having one "null weapon"

This commit is contained in:
Kalle 2023-06-17 21:50:52 +03:00
parent af7c4db4f4
commit 68dac83f4f
2 changed files with 6 additions and 4 deletions

View File

@ -6,7 +6,7 @@ import type {
UserWeapon,
UserWithPlusTier,
} from "../../types";
import { parseDBArray } from "~/utils/sql";
import { parseDBJsonArray } from "~/utils/sql";
import { dateToDatabaseTimestamp } from "~/utils/dates";
import addPatronDataSql from "./addPatronData.sql";
@ -144,7 +144,7 @@ export function findByIdentifier(identifier: string | number) {
return {
...row,
css: css ? JSON.parse(css) : undefined,
weapons: parseDBArray(weapons),
weapons: parseDBJsonArray(weapons),
team: teamName
? {
name: teamName,

View File

@ -7,8 +7,10 @@ export function parseDBJsonArray(value: any) {
// If the returned array of JSON objects from DB is empty
// it will be returned as object with all values being null
// this is a workaround for that
return parsed.filter((item: any) => Object.values(item).some(Boolean));
// this is a (hacky) workaround for that
return parsed.filter((item: any) =>
Object.values(item).some((val) => val !== null)
);
}
export function parseDBArray(value: any) {