diff --git a/README.md b/README.md index d6d5820..a37d1f3 100644 --- a/README.md +++ b/README.md @@ -101,6 +101,8 @@ } ``` +##### Response Codes + | http code | beschreibung | | --------- | ----------------------------------------------------------------- | | 200 | / | @@ -115,17 +117,19 @@
-GET /api/player (Status eines Spielers) +POST /api/player (Status eines Spielers) ##### Request Body ``` { // UUID eines Spielers - "user": string + "uuid": string } ``` +##### Response Codes + | http code | beschreibung | | --------- | ------------------------------------------ | | 200 | / | @@ -161,8 +165,8 @@ Das Webhook wir so oft gesendet, bis der angegebene Webhook Endpoint eine Respon Alle Webhooks: -| Beschreibung | HTTP Header | Body | -| ------------------------------------- | ----------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -| Ein neuer Nutzer hat sich registriert |
x-webhook-action: signup
|
{
  // Vorname des Nutzers
  firstname: string,
  // Nachname des Nutzers
  lastname: string,
  //Geburtstag des Nutzers im YYYY-MM-DD format
  birthday: string,
  // Telefonnummer des Nutzers. `null` wenn keine angegeben wurde
  telephone: string \| null,
  // Spielername des Nutzers
  username: string,
  // Minecraft-Edition des Nutzers
  edition: 'java' \| 'bedrock'
| -| Ein neuer Report wurde erstellt |
x-webhook-action: report
|
{
  // Username des Reporters. `null` wenn der Report vom System gemacht wurde
  reporter: string \| null,
  // Username des reporteten Spielers. `null` wenn Spieler unbekannt ist
  reported: string \| null,
  // Grund des Reports
  reason: string
}
| -| Ein neuer Strike wurde erstellt |
x-webhook-action: strike
|
{
  // UUID des Spielers, der gestriked wurde
  user: string
}
| +| Beschreibung | HTTP Header | Body | +| ------------------------------------- | ----------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | +| Ein neuer Nutzer hat sich registriert |
x-webhook-action: signup
|
{
  // Vorname des Nutzers
  firstname: string,
  // Nachname des Nutzers
  lastname: string,
  //Geburtstag des Nutzers im YYYY-MM-DD format
  birthday: string,
  // Telefonnummer des Nutzers. `null` wenn keine angegeben wurde
  telephone: string \| null,
  // Spielername des Nutzers
  username: string,
  // Minecraft-Edition des Nutzers
  edition: 'java' \| 'bedrock'
  //UUID des Nutzers. null wenn keine UUID ermittelt werden konnte
  uuid: string \| null
}
| +| Ein neuer Report wurde erstellt |
x-webhook-action: report
|
{
  // Username des Reporters. `null` wenn der Report vom System gemacht wurde
  reporter: string \| null,
  // Username des reporteten Spielers. `null` wenn Spieler unbekannt ist
  reported: string \| null,
  // Grund des Reports
  reason: string
}
| +| Ein neuer Strike wurde erstellt |
x-webhook-action: strike
|
{
  // UUID des Spielers, der gestriked wurde
  uuid: string
}
| diff --git a/src/actions/report.ts b/src/actions/report.ts index bedd252..1b146c2 100644 --- a/src/actions/report.ts +++ b/src/actions/report.ts @@ -120,8 +120,8 @@ export const report = { } sendWebhook(WebhookAction.Report, { - reporter: report.reporter.username, - reported: report.reported?.username ?? null, + reporter: report.reporter.uuid, + reported: report.reported?.uuid ?? null, reason: input.reason }); }, @@ -211,7 +211,7 @@ export const report = { // send webhook in background sendWebhook(WebhookAction.Strike, { - user: user!.uuid! + uuid: user!.uuid! }); } } diff --git a/src/actions/signup.ts b/src/actions/signup.ts index a2b697c..a7d4754 100644 --- a/src/actions/signup.ts +++ b/src/actions/signup.ts @@ -73,7 +73,8 @@ export const signup = { birthday: new Date(input.birthday).toISOString().slice(0, 10), telephone: input.phone, username: input.username, - edition: input.edition + edition: input.edition, + uuid: uuid }); } }) diff --git a/src/pages/api/feedback.ts b/src/pages/api/feedback.ts index 47f1c4b..061f617 100644 --- a/src/pages/api/feedback.ts +++ b/src/pages/api/feedback.ts @@ -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) => ({ diff --git a/src/pages/api/player.ts b/src/pages/api/player.ts index d94479d..7bddc3a 100644 --- a/src/pages/api/player.ts +++ b/src/pages/api/player.ts @@ -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 }); diff --git a/src/util/webhook.ts b/src/util/webhook.ts index a56ed47..f2ef546 100644 --- a/src/util/webhook.ts +++ b/src/util/webhook.ts @@ -16,6 +16,7 @@ export type WebhookActionType = { telephone: string | null; username: string; edition: 'java' | 'bedrock'; + uuid: string | null; }; [WebhookAction.Report]: { reporter: string | null; @@ -23,7 +24,7 @@ export type WebhookActionType = { reason: string; }; [WebhookAction.Strike]: { - user: string; + uuid: string; }; }[T];