update api
All checks were successful
deploy / build-and-deploy (push) Successful in 13s

This commit is contained in:
2025-10-15 13:40:31 +02:00
parent d3af1cedfd
commit 4fee3a721a
6 changed files with 25 additions and 19 deletions

View File

@@ -7,7 +7,7 @@ import { checkApiBasicAuth } from '@util/auth.ts';
const postSchema = z.object({
event: z.string(),
title: z.string(),
users: z.array(z.string())
uuids: z.array(z.string())
});
export const POST: APIRoute = async ({ request }) => {
@@ -25,7 +25,7 @@ export const POST: APIRoute = async ({ request }) => {
const feedbacks = await db.addUserFeedbacks({
event: parsed.event,
title: parsed.title,
uuids: parsed.users
uuids: parsed.uuids
});
const response = feedbacks.map((feedback) => ({

View File

@@ -3,23 +3,23 @@ import type { APIRoute } from 'astro';
import { db } from '@db/database.ts';
import { checkApiBasicAuth } from '@util/auth.ts';
const getSchema = z.object({
user: z.string()
const postSchema = z.object({
uuid: z.string()
});
export const GET: APIRoute = async ({ request }) => {
export const POST: APIRoute = async ({ request }) => {
if (!checkApiBasicAuth(request.headers)) {
return new Response(null, { status: 401 });
}
let parsed;
try {
parsed = await getSchema.parseAsync(await request.json());
parsed = await postSchema.parseAsync(await request.json());
} catch (_) {
return new Response(null, { status: 400 });
}
const user = await db.getUserByUuid({ uuid: parsed.user });
const user = await db.getUserByUuid({ uuid: parsed.uuid });
if (!user) return new Response(null, { status: 404 });
const strikes = await db.getStrikesByUserId({ userId: user.id });