Fix: use intergers for discord ids

This commit is contained in:
aronmal 2024-02-28 21:58:57 +01:00
parent ffaf8d989e
commit 95fee833a1
Signed by: aronmal
GPG key ID: 816B7707426FC612
9 changed files with 151 additions and 181 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 { zodMatch } from "~/lib/zod";
import { zodId, zodMatch } from "~/lib/zod";
import { APIResponse, RequestBody } from "~/types/backend";
type Path = "/api/{guildId}/matches";
@ -22,17 +22,22 @@ export const GET = async (
return ErrorResponse("UNAUTHORIZED");
}
let guildId: number;
try {
guildId = zodId.parse(event.params.guildId);
} catch (e) {
return ErrorResponse("BAD_REQUEST", JSON.stringify(e));
}
const guild = await db.query.guilds
.findFirst({
where: eq(guilds.id, event.params.guildId),
where: eq(guilds.id, guildId),
with: {
matches: true,
},
})
.execute();
console.log(event.params.guildId, guild);
if (!guild) return ErrorResponse("NOT_FOUND");
if (guild.matches.length < 1) return Res("NO_CONTENT", null);
@ -55,17 +60,22 @@ export const POST = async (
return ErrorResponse("UNAUTHORIZED");
}
let guildId: number;
try {
guildId = zodId.parse(event.params.guildId);
} catch (e) {
return ErrorResponse("BAD_REQUEST", JSON.stringify(e));
}
const guild = await db.query.guilds
.findFirst({
where: eq(guilds.id, event.params.guildId),
where: eq(guilds.id, guildId),
with: {
matches: true,
},
})
.execute();
console.log(event.params.guildId, guild);
if (!guild) return ErrorResponse("NOT_FOUND");
const unparsedBody = await new Response(event.request.body).json();