From c4251d9f51efa53b3a91532afbe303c4d2fa7210 Mon Sep 17 00:00:00 2001 From: aronmal Date: Mon, 12 Feb 2024 11:08:34 +0100 Subject: [PATCH] fix: Added unfinished api routes to backend --- src/routes/api/[guildId]/config.ts | 48 +++++++++++++++++++ .../matches/[channelId]/[matchMessageId].ts | 24 ++++++++++ .../[guildId]/matches/[channelId]/index.ts | 24 ++++++++++ src/routes/api/[guildId]/matches/index.ts | 24 ++++++++++ src/routes/api/[guildId]/tp_messages.ts | 28 +++++++++++ src/routes/api/boot/config.ts | 14 ++++++ 6 files changed, 162 insertions(+) create mode 100644 src/routes/api/[guildId]/config.ts create mode 100644 src/routes/api/[guildId]/matches/[channelId]/[matchMessageId].ts create mode 100644 src/routes/api/[guildId]/matches/[channelId]/index.ts create mode 100644 src/routes/api/[guildId]/matches/index.ts create mode 100644 src/routes/api/[guildId]/tp_messages.ts create mode 100644 src/routes/api/boot/config.ts diff --git a/src/routes/api/[guildId]/config.ts b/src/routes/api/[guildId]/config.ts new file mode 100644 index 0000000..25fdaf9 --- /dev/null +++ b/src/routes/api/[guildId]/config.ts @@ -0,0 +1,48 @@ +import { APIEvent } from "@solidjs/start/server/types"; +import { eq } from "drizzle-orm"; +import db from "~/drizzle"; +import { guilds } from "~/drizzle/schema"; + +export const GET = async ({ params }: APIEvent) => { + const guild = await db.query.guilds + .findFirst({ + where: eq(guilds.id, params.guildId), + with: { + timePlanning: { with: { messages: true } }, + matches: true, + }, + }) + .execute(); + + if (!guild) + return new Response(JSON.stringify({ error: "No such guild found." }), { + status: 404, + }); + + return guild; +}; + +export const DELETE = async ({ params }: APIEvent) => { + const guildQuery = await db.query.guilds + .findFirst({ + where: eq(guilds.id, params.guildId), + with: { + timePlanning: { with: { messages: true } }, + matches: true, + }, + }) + .execute(); + + if (!guildQuery) + return new Response(JSON.stringify({ error: "No such guild found." }), { + status: 404, + }); + + const guild = await db + .delete(guilds) + .where(eq(guilds.id, params.guildId)) + .returning() + .execute(); + + return guild; +}; diff --git a/src/routes/api/[guildId]/matches/[channelId]/[matchMessageId].ts b/src/routes/api/[guildId]/matches/[channelId]/[matchMessageId].ts new file mode 100644 index 0000000..c701f81 --- /dev/null +++ b/src/routes/api/[guildId]/matches/[channelId]/[matchMessageId].ts @@ -0,0 +1,24 @@ +import { APIEvent } from "@solidjs/start/server/types"; +import { eq } from "drizzle-orm"; +import db from "~/drizzle"; +import { guilds } from "~/drizzle/schema"; + +export const PUT = async ({ params }: APIEvent) => { + const guild = await db.query.guilds + .findFirst({ + where: eq(guilds.id, params.guildId), + with: { + timePlanning: { with: { messages: true } }, + matches: true, + }, + }) + .execute(); + + if (!guild) + return new Response(JSON.stringify({ error: "No such guild found." }), { + status: 404, + }); + + return "TODO"; + // return guild.timePlanning; +}; diff --git a/src/routes/api/[guildId]/matches/[channelId]/index.ts b/src/routes/api/[guildId]/matches/[channelId]/index.ts new file mode 100644 index 0000000..bf84d60 --- /dev/null +++ b/src/routes/api/[guildId]/matches/[channelId]/index.ts @@ -0,0 +1,24 @@ +import { APIEvent } from "@solidjs/start/server/types"; +import { eq } from "drizzle-orm"; +import db from "~/drizzle"; +import { guilds } from "~/drizzle/schema"; + +export const POST = async ({ params }: APIEvent) => { + const guild = await db.query.guilds + .findFirst({ + where: eq(guilds.id, params.guildId), + with: { + timePlanning: { with: { messages: true } }, + matches: true, + }, + }) + .execute(); + + if (!guild) + return new Response(JSON.stringify({ error: "No such guild found." }), { + status: 404, + }); + + return "TODO"; + // return guild.timePlanning; +}; diff --git a/src/routes/api/[guildId]/matches/index.ts b/src/routes/api/[guildId]/matches/index.ts new file mode 100644 index 0000000..403aab3 --- /dev/null +++ b/src/routes/api/[guildId]/matches/index.ts @@ -0,0 +1,24 @@ +import { APIEvent } from "@solidjs/start/server/types"; +import { eq } from "drizzle-orm"; +import db from "~/drizzle"; +import { guilds } from "~/drizzle/schema"; + +export const GET = async ({ params }: APIEvent) => { + const guild = await db.query.guilds + .findFirst({ + where: eq(guilds.id, params.guildId), + with: { + timePlanning: { with: { messages: true } }, + matches: true, + }, + }) + .execute(); + + if (!guild) + return new Response(JSON.stringify({ error: "No such guild found." }), { + status: 404, + }); + + return "TODO"; + // return guild.timePlanning; +}; diff --git a/src/routes/api/[guildId]/tp_messages.ts b/src/routes/api/[guildId]/tp_messages.ts new file mode 100644 index 0000000..8ede1ed --- /dev/null +++ b/src/routes/api/[guildId]/tp_messages.ts @@ -0,0 +1,28 @@ +import { APIEvent } from "@solidjs/start/server/types"; +import { eq } from "drizzle-orm"; +import db from "~/drizzle"; +import { guilds } from "~/drizzle/schema"; + +export const GET = async ({ params }: APIEvent) => { + const guild = await db.query.guilds + .findFirst({ + where: eq(guilds.id, params.guildId), + with: { + timePlanning: { with: { messages: true } }, + matches: true, + }, + }) + .execute(); + + if (!guild) + return new Response(JSON.stringify({ error: "No such guild found." }), { + status: 404, + }); + + return "TODO"; + // return guild.timePlanning; +}; + +export const PUT = async () => { + return "TODO"; +}; diff --git a/src/routes/api/boot/config.ts b/src/routes/api/boot/config.ts new file mode 100644 index 0000000..c93810c --- /dev/null +++ b/src/routes/api/boot/config.ts @@ -0,0 +1,14 @@ +import db from "~/drizzle"; + +export const GET = async () => { + const guilds = await db.query.guilds + .findMany({ + with: { + timePlanning: { with: { messages: true } }, + matches: true, + }, + }) + .execute(); + + return { guilds }; +};