send webhook on finished api report
This commit is contained in:
@ -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 });
|
||||
};
|
||||
|
Reference in New Issue
Block a user