-
Notifications
You must be signed in to change notification settings - Fork 8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add functionality to update acknowledgement with path request #87
base: develop
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,10 @@ | ||
import { z } from 'zod'; | ||
import { Event, EventType } from '@prisma/client'; | ||
import { Request, Response } from 'express'; | ||
import Boom from '@hapi/boom'; | ||
import prisma from '../prisma/prisma'; | ||
import { findEvent, findEventFromCalendar } from '../services/eventsService'; | ||
import { getAcknowledgementSchema } from '../middlewares/validators/zod-schemas/events'; | ||
|
||
/** | ||
* Route used to post event | ||
|
@@ -99,7 +101,10 @@ const getEvents = async (req: Request, res: Response): Promise<any> => { | |
* @param req {Object} - Express request object | ||
* @param res {Object} - Express response object | ||
*/ | ||
const getCalendarEvents = async (req: Request, res: Response): Promise<any> => { | ||
const getCalendarEvents = async ( | ||
req: Request, | ||
res: Response | ||
): Promise<Response> => { | ||
try { | ||
const { calendarId } = req.params; | ||
const { startTime, endTime } = req.query; | ||
|
@@ -120,4 +125,40 @@ const getCalendarEvents = async (req: Request, res: Response): Promise<any> => { | |
} | ||
}; | ||
|
||
export { postEvent, getEvents, getCalendarEvents }; | ||
type TAcknowledgementStatusReq = z.infer<typeof getAcknowledgementSchema>; | ||
|
||
const getAcknowledgementStatus = async ( | ||
req: Request, | ||
res: Response | ||
): Promise<Response> => { | ||
const { eventId, attendeeId } = req.params; | ||
const { status } = req.body as TAcknowledgementStatusReq['body']; | ||
|
||
const attendeeData = await prisma.attendees.findFirst({ | ||
where: { | ||
eventId: Number(eventId), | ||
attendeeId: Number(attendeeId), | ||
}, | ||
}); | ||
|
||
if (attendeeData === null) { | ||
return res.boom(Boom.badRequest('Attendee not found')); | ||
} | ||
|
||
const updatedData = await prisma.attendees.update({ | ||
where: { | ||
id: attendeeData.id, | ||
}, | ||
data: { | ||
acknowledgement: status, | ||
}, | ||
}); | ||
|
||
if (updatedData && updatedData.acknowledgement === status) { | ||
isVivek99 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return res.json({ message: 'Acknowledgement status updated' }); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we move messages to constant files. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As the message is specifically used for this controller will this change be required? |
||
} else { | ||
return res.boom(Boom.internal('Something went wrong')); | ||
} | ||
}; | ||
|
||
export { postEvent, getEvents, getCalendarEvents, getAcknowledgementStatus }; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,6 +24,16 @@ const getEventSchema = z.object({ | |
}), | ||
}); | ||
|
||
const getAcknowledgementSchema = z.object({ | ||
params: z.object({ | ||
eventId: z.preprocess((a) => Number(a), z.number().positive()), | ||
attendeeId: z.preprocess((a) => Number(a), z.number().positive()), | ||
}), | ||
body: z.object({ | ||
status: z.enum(['ACCEPTED', 'DECLINED', 'TENTATIVE']), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Here too. Let us keep it in constants |
||
}), | ||
}); | ||
|
||
const getCalenderEventSchema = z.object({ | ||
params: z.object({ | ||
calendarId: z.preprocess((a) => Number(a), z.number().positive()), | ||
|
@@ -34,4 +44,9 @@ const getCalenderEventSchema = z.object({ | |
}), | ||
}); | ||
|
||
export { postEventSchema, getEventSchema, getCalenderEventSchema }; | ||
export { | ||
postEventSchema, | ||
getEventSchema, | ||
getCalenderEventSchema, | ||
getAcknowledgementSchema, | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can ignore this file as it is to fix the typescript eslint issue and got caught in this PR.