@@ -4,6 +4,7 @@ import { z } from "zod";
4
4
import { zodToJsonSchema } from "zod-to-json-schema" ;
5
5
import { OrganizationList } from "../orgs.js" ;
6
6
import {
7
+ DeleteItemCommand ,
7
8
DynamoDBClient ,
8
9
PutItemCommand ,
9
10
ScanCommand ,
@@ -151,6 +152,44 @@ const eventsPlugin: FastifyPluginAsync = async (fastify, _options) => {
151
152
}
152
153
} ,
153
154
) ;
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
+ ) ;
154
193
type EventsGetRequest = {
155
194
Body : undefined ;
156
195
Querystring ?: EventsGetQueryParams ;
0 commit comments