This commit is contained in:
27
src/pages/api/feedback/index.ts
Normal file
27
src/pages/api/feedback/index.ts
Normal file
@@ -0,0 +1,27 @@
|
||||
import { externalApi } from '../_api.ts';
|
||||
import { z } from 'astro:schema';
|
||||
import { db } from '@db/database.ts';
|
||||
import { BASE_PATH } from 'astro:env/server';
|
||||
|
||||
export const POST = externalApi({
|
||||
input: z.object({
|
||||
event: z.string(),
|
||||
title: z.string(),
|
||||
uuids: z.array(z.string())
|
||||
}),
|
||||
auth: true,
|
||||
handler: async ({ input }) => {
|
||||
const feedbacks = await db.addUserFeedbacks({
|
||||
event: input.event,
|
||||
title: input.title,
|
||||
uuids: input.uuids
|
||||
});
|
||||
|
||||
const response = feedbacks.map((feedback) => ({
|
||||
uuid: feedback.uuid,
|
||||
url: `${BASE_PATH}/feedback/${feedback.urlHash}`
|
||||
}));
|
||||
|
||||
return new Response(JSON.stringify({ feedback: response }), { status: 200 });
|
||||
}
|
||||
});
|
||||
Reference in New Issue
Block a user