Fix: use intergers for discord ids
This commit is contained in:
parent
ffaf8d989e
commit
95fee833a1
9 changed files with 151 additions and 181 deletions
|
@ -22,15 +22,16 @@ export const GET = async (
|
|||
return ErrorResponse("UNAUTHORIZED");
|
||||
}
|
||||
|
||||
let guildId: number;
|
||||
try {
|
||||
zodId.parse(event.params.guildId);
|
||||
guildId = zodId.parse(event.params.guildId);
|
||||
} catch (e) {
|
||||
return ErrorResponse("BAD_REQUEST", JSON.stringify(e));
|
||||
}
|
||||
|
||||
const guildQuery = await db.query.guilds
|
||||
.findFirst({
|
||||
where: eq(guilds.id, event.params.guildId),
|
||||
where: eq(guilds.id, guildId),
|
||||
with: { tpMessages: true, matches: true },
|
||||
})
|
||||
.execute();
|
||||
|
@ -52,22 +53,23 @@ export const DELETE = async (
|
|||
return ErrorResponse("UNAUTHORIZED");
|
||||
}
|
||||
|
||||
let guildId: number;
|
||||
try {
|
||||
zodId.parse(event.params.guildId);
|
||||
guildId = zodId.parse(event.params.guildId);
|
||||
} catch (e) {
|
||||
return ErrorResponse("BAD_REQUEST", JSON.stringify(e));
|
||||
}
|
||||
|
||||
const guildQuery = await db.query.guilds
|
||||
.findFirst({
|
||||
where: eq(guilds.id, event.params.guildId),
|
||||
where: eq(guilds.id, guildId),
|
||||
with: { tpMessages: true, matches: true },
|
||||
})
|
||||
.execute();
|
||||
|
||||
if (!guildQuery) return ErrorResponse("NOT_FOUND");
|
||||
|
||||
await db.delete(guilds).where(eq(guilds.id, event.params.guildId)).execute();
|
||||
await db.delete(guilds).where(eq(guilds.id, guildId)).execute();
|
||||
|
||||
return Res("NO_CONTENT", null);
|
||||
};
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -4,14 +4,14 @@ import db from "~/drizzle";
|
|||
import { guilds, tpMessages } from "~/drizzle/schema";
|
||||
import { BasicAuth } from "~/lib/auth";
|
||||
import { ErrorResponse, Res } from "~/lib/responses";
|
||||
import { zodTpMessages } from "~/lib/zod";
|
||||
import { zodId, zodTpMessages } from "~/lib/zod";
|
||||
import { APIResponse, RequestBody } from "~/types/backend";
|
||||
|
||||
type Path = "/api/{guildId}/tp_messages";
|
||||
|
||||
const DayKeys = ["0", "1", "2", "3", "4", "5", "6"] as const;
|
||||
type DayKeys = (typeof DayKeys)[number];
|
||||
type Messages = Record<DayKeys, string | null>;
|
||||
type Messages = Record<DayKeys, number | null>;
|
||||
|
||||
export const GET = async (
|
||||
event: APIEvent,
|
||||
|
@ -25,8 +25,15 @@ 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: {
|
||||
tpMessages: true,
|
||||
},
|
||||
|
@ -72,9 +79,16 @@ export const PUT = 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: { tpMessages: true },
|
||||
})
|
||||
.execute();
|
||||
|
|
|
@ -5,6 +5,7 @@ import { guilds } from "~/drizzle/schema";
|
|||
import { BasicAuth } from "~/lib/auth";
|
||||
import { buildConfig } from "~/lib/responseBuilders";
|
||||
import { ErrorResponse, Res } from "~/lib/responses";
|
||||
import { zodId } from "~/lib/zod";
|
||||
import { APIResponse } from "~/types/backend";
|
||||
|
||||
type Path = "/api/boot";
|
||||
|
@ -21,9 +22,16 @@ 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 guildQuery = await db.query.guilds
|
||||
.findMany({
|
||||
where: eq(guilds.id, event.params.guildId),
|
||||
where: eq(guilds.id, guildId),
|
||||
with: { tpMessages: true, matches: true },
|
||||
})
|
||||
.execute();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue