Skip to content

Commit

Permalink
add route, and middleware for public event
Browse files Browse the repository at this point in the history
  • Loading branch information
prakashchoudhary07 committed Nov 10, 2023
1 parent e81c764 commit acf3f29
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
10 changes: 10 additions & 0 deletions middlewares/validators/zod-schemas/events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ const postEventSchema = z.object({
endTime: z.number(),
calendarId: z.number(),
attendees: z.array(z.string()).optional(),
isPrivate: z.boolean(),
// TODO: Recuring event to be added
})
.strict(),
Expand All @@ -32,6 +33,7 @@ const patchEventSchema = z.object({
endTime: z.number().optional(),
calendarId: z.number().optional(),
attendees: z.array(z.string()).optional(),
isPrivate: z.boolean(),
// TODO: Recuring event to be added
})
.strict(),
Expand All @@ -53,9 +55,17 @@ const getCalenderEventSchema = z.object({
}),
});

const getPublicEventSchema = z.object({
query: z.object({
startTime: z.preprocess((a) => Number(a), z.number().positive()).optional(),
endTime: z.preprocess((a) => Number(a), z.number().positive()).optional(),
}),
});

export {
postEventSchema,
patchEventSchema,
getEventSchema,
getCalenderEventSchema,
getPublicEventSchema,
};
4 changes: 4 additions & 0 deletions routes/events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
getEvents,
postEvent,
patchEvent,
getPublicEvents,
} from '../controllers/events';
import authenticate from '../middlewares/authenticate';
import { validate } from '../middlewares/validators/validator';
Expand All @@ -12,6 +13,7 @@ import {
getEventSchema,
postEventSchema,
patchEventSchema,
getPublicEventSchema,
} from '../middlewares/validators/zod-schemas/events';
import {
calendarBelongsToUser,
Expand All @@ -21,6 +23,7 @@ import {
const router = Router();

/* eslint-disable @typescript-eslint/no-misused-promises */
router.get('/', authenticate, validate(getPublicEventSchema), getPublicEvents);
router.post(
'/',
authenticate,
Expand Down Expand Up @@ -49,6 +52,7 @@ router.get(
calendarBelongsToUser,
getCalendarEvents
);

/* eslint-disable @typescript-eslint/no-misused-promises */

export default router;

0 comments on commit acf3f29

Please sign in to comment.