diff --git a/src/pages/api/report/index.ts b/src/pages/api/report/index.ts index fe55371..dc41bee 100644 --- a/src/pages/api/report/index.ts +++ b/src/pages/api/report/index.ts @@ -2,6 +2,7 @@ import type { APIRoute } from 'astro'; import { z } from 'astro:schema'; import { API_SECRET } from 'astro:env/server'; import { db } from '@db/database.ts'; +import { sendWebhook, WebhookAction } from '@util/webhook.ts'; const postSchema = z.object({ reporter: z.string(), @@ -92,5 +93,14 @@ export const PUT: APIRoute = async ({ request }) => { }); }); + const strikes = await db.getStrikesByTeamId({ teamId: reportedTeam.team.id }); + const teamMembers = await db.getTeamMembersByTeamId({ teamId: reportedTeam.team.id }); + + // send webhook in background + sendWebhook(WebhookAction.Strike, { + users: teamMembers.map((tm) => tm.user.uuid!), + totalWeight: strikes.map((strike) => strike.reason.weight).reduce((a, b) => a + b, 0) + }); + return new Response(null, { status: 200 }); };