@@ -18,7 +18,7 @@ import moment from "moment-timezone";
18
18
19
19
const repeatOptions = [ "weekly" , "biweekly" ] as const ;
20
20
21
- const baseBodySchema = z . object ( {
21
+ const baseSchema = z . object ( {
22
22
title : z . string ( ) . min ( 1 ) ,
23
23
description : z . string ( ) . min ( 1 ) ,
24
24
start : z . string ( ) ,
@@ -30,16 +30,20 @@ const baseBodySchema = z.object({
30
30
paidEventId : z . optional ( z . string ( ) . min ( 1 ) ) ,
31
31
} ) ;
32
32
33
- const requestBodySchema = baseBodySchema
34
- . extend ( {
35
- repeats : z . optional ( z . enum ( repeatOptions ) ) ,
36
- repeatEnds : z . string ( ) . optional ( ) ,
37
- } )
38
- . refine ( ( data ) => ( data . repeatEnds ? data . repeats !== undefined : true ) , {
33
+ const requestSchema = baseSchema . extend ( {
34
+ repeats : z . optional ( z . enum ( repeatOptions ) ) ,
35
+ repeatEnds : z . string ( ) . optional ( ) ,
36
+ } ) ;
37
+
38
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
39
+ const postRequestSchema = requestSchema . refine (
40
+ ( data ) => ( data . repeatEnds ? data . repeats !== undefined : true ) ,
41
+ {
39
42
message : "repeats is required when repeatEnds is defined" ,
40
- } ) ;
43
+ } ,
44
+ ) ;
41
45
42
- type EventPostRequest = z . infer < typeof requestBodySchema > ;
46
+ type EventPostRequest = z . infer < typeof postRequestSchema > ;
43
47
44
48
const responseJsonSchema = zodToJsonSchema (
45
49
z . object ( {
@@ -49,9 +53,15 @@ const responseJsonSchema = zodToJsonSchema(
49
53
) ;
50
54
51
55
// GET
52
- const getResponseBodySchema = z . array ( requestBodySchema ) ;
53
- const getResponseJsonSchema = zodToJsonSchema ( getResponseBodySchema ) ;
54
- export type EventGetResponse = z . infer < typeof getResponseBodySchema > ;
56
+ const getEventSchema = requestSchema . extend ( {
57
+ id : z . string ( ) ,
58
+ } ) ;
59
+
60
+ // export type EventGetResponse = z.infer<typeof getEventSchema>;
61
+ // const getEventJsonSchema = zodToJsonSchema(getEventSchema);
62
+
63
+ const getEventsSchema = z . array ( getEventSchema ) ;
64
+ export type EventsGetResponse = z . infer < typeof getEventsSchema > ;
55
65
type EventsGetQueryParams = { upcomingOnly ?: boolean } ;
56
66
57
67
const dynamoClient = new DynamoDBClient ( {
@@ -66,7 +76,7 @@ const eventsPlugin: FastifyPluginAsync = async (fastify, _options) => {
66
76
response : { 200 : responseJsonSchema } ,
67
77
} ,
68
78
preValidation : async ( request , reply ) => {
69
- await fastify . zodValidateBody ( request , reply , requestBodySchema ) ;
79
+ await fastify . zodValidateBody ( request , reply , requestSchema ) ;
70
80
} ,
71
81
onRequest : async ( request , reply ) => {
72
82
await fastify . authorize ( request , reply , [ AppRoles . MANAGER ] ) ;
@@ -112,7 +122,7 @@ const eventsPlugin: FastifyPluginAsync = async (fastify, _options) => {
112
122
querystring : {
113
123
upcomingOnly : { type : "boolean" } ,
114
124
} ,
115
- response : { 200 : getResponseJsonSchema } ,
125
+ response : { 200 : getEventsSchema } ,
116
126
} ,
117
127
} ,
118
128
async ( request : FastifyRequest < EventsGetRequest > , reply ) => {
@@ -123,7 +133,7 @@ const eventsPlugin: FastifyPluginAsync = async (fastify, _options) => {
123
133
) ;
124
134
const items = response . Items ?. map ( ( item ) => unmarshall ( item ) ) ;
125
135
const currentTimeChicago = moment ( ) . tz ( "America/Chicago" ) ;
126
- let parsedItems = getResponseBodySchema . parse ( items ) ;
136
+ let parsedItems = getEventsSchema . parse ( items ) ;
127
137
if ( upcomingOnly ) {
128
138
parsedItems = parsedItems . filter ( ( item ) => {
129
139
try {
0 commit comments