|
| 1 | +import { NextFunction, Request, Response } from 'express'; |
| 2 | +import DesignReviewsService from '../services/design-reviews.services'; |
| 3 | +import { getCurrentUser } from '../utils/auth.utils'; |
| 4 | +import { User } from '@prisma/client'; |
| 5 | + |
| 6 | +export default class DesignReviewsController { |
| 7 | + static async getAllDesignReviews(_req: Request, res: Response, next: NextFunction) { |
| 8 | + try { |
| 9 | + const designReviews = await DesignReviewsService.getAllDesignReviews(); |
| 10 | + return res.status(200).json(designReviews); |
| 11 | + } catch (error: unknown) { |
| 12 | + next(error); |
| 13 | + } |
| 14 | + } |
| 15 | + |
| 16 | + static async deleteDesignReview(req: Request, res: Response, next: NextFunction) { |
| 17 | + try { |
| 18 | + const drId: string = req.params.designReviewId; |
| 19 | + const user: User = await getCurrentUser(res); |
| 20 | + const deletedDesignReview = await DesignReviewsService.deleteDesignReview(user, drId); |
| 21 | + return res.status(200).json(deletedDesignReview); |
| 22 | + } catch (error: unknown) { |
| 23 | + next(error); |
| 24 | + } |
| 25 | + } |
| 26 | + |
| 27 | + static async createDesignReview(req: Request, res: Response, next: NextFunction) { |
| 28 | + try { |
| 29 | + const submitter: User = await getCurrentUser(res); |
| 30 | + const { |
| 31 | + dateScheduled, |
| 32 | + teamTypeId, |
| 33 | + requiredMemberIds, |
| 34 | + optionalMemberIds, |
| 35 | + location, |
| 36 | + isOnline, |
| 37 | + isInPerson, |
| 38 | + zoomLink, |
| 39 | + docTemplateLink, |
| 40 | + wbsNum, |
| 41 | + meetingTimes |
| 42 | + } = req.body; |
| 43 | + |
| 44 | + const createdDesignReview = await DesignReviewsService.createDesignReview( |
| 45 | + submitter, |
| 46 | + dateScheduled, |
| 47 | + teamTypeId, |
| 48 | + requiredMemberIds, |
| 49 | + optionalMemberIds, |
| 50 | + isOnline, |
| 51 | + isInPerson, |
| 52 | + docTemplateLink, |
| 53 | + wbsNum, |
| 54 | + meetingTimes, |
| 55 | + zoomLink, |
| 56 | + location |
| 57 | + ); |
| 58 | + return res.status(200).json(createdDesignReview); |
| 59 | + } catch (error: unknown) { |
| 60 | + next(error); |
| 61 | + } |
| 62 | + } |
| 63 | + |
| 64 | + static async getSingleDesignReview(req: Request, res: Response, next: NextFunction) { |
| 65 | + try { |
| 66 | + const drId: string = req.params.designReviewId; |
| 67 | + const user: User = await getCurrentUser(res); |
| 68 | + const designReview = await DesignReviewsService.getSingleDesignReview(user, drId); |
| 69 | + return res.status(200).json(designReview); |
| 70 | + } catch (error: unknown) { |
| 71 | + next(error); |
| 72 | + } |
| 73 | + } |
| 74 | + |
| 75 | + // Edit a work package to the given specifications |
| 76 | + static async editDesignReviews(req: Request, res: Response, next: NextFunction) { |
| 77 | + try { |
| 78 | + const { |
| 79 | + dateScheduled, |
| 80 | + teamType, |
| 81 | + requiredMembers, |
| 82 | + optionalMembers, |
| 83 | + isOnline, |
| 84 | + isInPerson, |
| 85 | + zoomLink, |
| 86 | + location, |
| 87 | + docTemplateLink, |
| 88 | + status, |
| 89 | + attendees, |
| 90 | + meetingTimes |
| 91 | + } = req.body; |
| 92 | + |
| 93 | + const { designReviewId } = req.params; |
| 94 | + |
| 95 | + // get the user from the submitter |
| 96 | + const user = await getCurrentUser(res); |
| 97 | + |
| 98 | + await DesignReviewsService.editDesignReview( |
| 99 | + user, |
| 100 | + designReviewId, |
| 101 | + dateScheduled, |
| 102 | + teamType.teamTypeId, |
| 103 | + requiredMembers, |
| 104 | + optionalMembers, |
| 105 | + isOnline, |
| 106 | + isInPerson, |
| 107 | + zoomLink, |
| 108 | + location, |
| 109 | + docTemplateLink, |
| 110 | + status, |
| 111 | + attendees, |
| 112 | + meetingTimes |
| 113 | + ); |
| 114 | + return res.status(200).json({ message: 'Design Review updated successfully' }); |
| 115 | + } catch (error: unknown) { |
| 116 | + next(error); |
| 117 | + } |
| 118 | + } |
| 119 | +} |
0 commit comments