Skip to content

Commit db4f866

Browse files
committed
add event delete
1 parent e58786a commit db4f866

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

src/routes/events.ts

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { z } from "zod";
44
import { zodToJsonSchema } from "zod-to-json-schema";
55
import { OrganizationList } from "../orgs.js";
66
import {
7+
DeleteItemCommand,
78
DynamoDBClient,
89
PutItemCommand,
910
ScanCommand,
@@ -151,6 +152,44 @@ const eventsPlugin: FastifyPluginAsync = async (fastify, _options) => {
151152
}
152153
},
153154
);
155+
type EventDeleteRequest = {
156+
Params: { id: string };
157+
Querystring: undefined;
158+
Body: undefined;
159+
};
160+
fastify.delete<EventDeleteRequest>(
161+
"/:id",
162+
{
163+
schema: {
164+
response: { 200: responseJsonSchema },
165+
},
166+
onRequest: async (request, reply) => {
167+
await fastify.authorize(request, reply, [AppRoles.MANAGER]);
168+
},
169+
},
170+
async (request: FastifyRequest<EventDeleteRequest>, reply) => {
171+
const id = request.params.id;
172+
try {
173+
await dynamoClient.send(
174+
new DeleteItemCommand({
175+
TableName: genericConfig.DynamoTableName,
176+
Key: marshall({ id }),
177+
}),
178+
);
179+
reply.send({
180+
id,
181+
resource: `/api/v1/event/${id}`,
182+
});
183+
} catch (e: unknown) {
184+
if (e instanceof Error) {
185+
request.log.error("Failed to delete from DynamoDB: " + e.toString());
186+
}
187+
throw new DatabaseInsertError({
188+
message: "Failed to delete event from Dynamo table.",
189+
});
190+
}
191+
},
192+
);
154193
type EventsGetRequest = {
155194
Body: undefined;
156195
Querystring?: EventsGetQueryParams;

0 commit comments

Comments
 (0)