Fix: Using bigint and added backend testing

This commit is contained in:
aronmal 2024-03-10 17:12:50 +01:00
parent ed6195e1e2
commit 89507f8412
Signed by: aronmal
GPG key ID: 816B7707426FC612
20 changed files with 830 additions and 292 deletions

View file

@ -5,7 +5,7 @@ import { guilds, matches } from "~/drizzle/schema";
import { BasicAuth } from "~/lib/auth";
import { buildMatches } from "~/lib/responseBuilders";
import { ErrorResponse, Res } from "~/lib/responses";
import { zodId, zodMatch } from "~/lib/zod";
import { zodBigIntId, zodMatch } from "~/lib/zod";
import { APIResponse, RequestBody } from "~/types/backend";
type Path = "/api/{guildId}/matches";
@ -22,9 +22,9 @@ export const GET = async (
return ErrorResponse("UNAUTHORIZED");
}
let guildId: number;
let guildId: bigint;
try {
guildId = zodId.parse(event.params.guildId);
guildId = zodBigIntId.parse(event.params.guildId);
} catch (e) {
return ErrorResponse("BAD_REQUEST", JSON.stringify(e));
}
@ -60,9 +60,9 @@ export const POST = async (
return ErrorResponse("UNAUTHORIZED");
}
let guildId: number;
let guildId: bigint;
try {
guildId = zodId.parse(event.params.guildId);
guildId = zodBigIntId.parse(event.params.guildId);
} catch (e) {
return ErrorResponse("BAD_REQUEST", JSON.stringify(e));
}
@ -94,8 +94,13 @@ export const POST = async (
);
await db.insert(matches).values({
...body.match,
guildId: guild.id,
channelId: BigInt(body.match.channelId),
roleId: BigInt(body.match.roleId),
createrId: BigInt(body.match.createrId),
messageId: BigInt(body.match.messageId),
matchType: body.match.matchType,
opponentName: body.match.opponentName,
utc_ts: new Date(body.match.utc_ts),
});