@@ -57,8 +57,8 @@ const getEventSchema = requestSchema.extend({
57
57
id : z . string ( ) ,
58
58
} ) ;
59
59
60
- // export type EventGetResponse = z.infer<typeof getEventSchema>;
61
- // const getEventJsonSchema = zodToJsonSchema(getEventSchema);
60
+ export type EventGetResponse = z . infer < typeof getEventSchema > ;
61
+ const getEventJsonSchema = zodToJsonSchema ( getEventSchema ) ;
62
62
63
63
const getEventsSchema = z . array ( getEventSchema ) ;
64
64
export type EventsGetResponse = z . infer < typeof getEventsSchema > ;
@@ -111,6 +111,46 @@ const eventsPlugin: FastifyPluginAsync = async (fastify, _options) => {
111
111
}
112
112
} ,
113
113
) ;
114
+ type EventGetRequest = {
115
+ Params : { id : string } ;
116
+ Querystring : undefined ;
117
+ Body : undefined ;
118
+ } ;
119
+ fastify . get < EventGetRequest > (
120
+ "/:id" ,
121
+ {
122
+ schema : {
123
+ response : { 200 : getEventJsonSchema } ,
124
+ } ,
125
+ } ,
126
+ async ( request : FastifyRequest < EventGetRequest > , reply ) => {
127
+ const id = request . params . id ;
128
+ try {
129
+ const response = await dynamoClient . send (
130
+ new ScanCommand ( {
131
+ TableName : genericConfig . DynamoTableName ,
132
+ FilterExpression : "#id = :id" ,
133
+ ExpressionAttributeNames : {
134
+ "#id" : "id" ,
135
+ } ,
136
+ ExpressionAttributeValues : marshall ( { ":id" : id } ) ,
137
+ } ) ,
138
+ ) ;
139
+ const items = response . Items ?. map ( ( item ) => unmarshall ( item ) ) ;
140
+ if ( items ?. length !== 1 ) {
141
+ throw new Error ( "Event not found" ) ;
142
+ }
143
+ reply . send ( items [ 0 ] ) ;
144
+ } catch ( e : unknown ) {
145
+ if ( e instanceof Error ) {
146
+ request . log . error ( "Failed to get from DynamoDB: " + e . toString ( ) ) ;
147
+ }
148
+ throw new DatabaseFetchError ( {
149
+ message : "Failed to get event from Dynamo table." ,
150
+ } ) ;
151
+ }
152
+ } ,
153
+ ) ;
114
154
type EventsGetRequest = {
115
155
Body : undefined ;
116
156
Querystring ?: EventsGetQueryParams ;
0 commit comments