11import { Design_Review_Status , User } from '@prisma/client' ;
2- import { DesignReview , WbsNumber , isAdmin , isLeadership , isNotLeadership } from 'shared' ;
2+ import { DesignReview , TeamType , WbsNumber , isAdmin , isLeadership , isNotLeadership } from 'shared' ;
33import prisma from '../prisma/prisma' ;
44import {
55 NotFoundException ,
@@ -10,7 +10,7 @@ import {
1010 AccessDeniedException
1111} from '../utils/errors.utils' ;
1212import { getUsers , getPrismaQueryUserIds } from '../utils/users.utils' ;
13- import { validateMeetingTimes } from '../utils/design-reviews.utils' ;
13+ import { isUserOnDesignReview , validateMeetingTimes } from '../utils/design-reviews.utils' ;
1414import designReviewQueryArgs from '../prisma-query-args/design-reviews.query-args' ;
1515import { designReviewTransformer } from '../transformers/design-reviews.transformer' ;
1616import { sendSlackDesignReviewNotification } from '../utils/slack.utils' ;
@@ -27,6 +27,11 @@ export default class DesignReviewsService {
2727 return designReviews . map ( designReviewTransformer ) ;
2828 }
2929
30+ static async getAllTeamTypes ( ) : Promise < TeamType [ ] > {
31+ const teamTypes = await prisma . teamType . findMany ( ) ;
32+ return teamTypes ;
33+ }
34+
3035 /**
3136 * Deletes a design review
3237 * @param submitter the user who deleted the design review
@@ -55,34 +60,24 @@ export default class DesignReviewsService {
5560 }
5661
5762 /**
58- * Creates a design review
59- * @param submitter user who submitted the design review
63+ * Create a design review
64+ * @param submitter User submitting the design review
6065 * @param dateScheduled when the design review is scheduled for
61- * @param teamTypeId team type id of the design review
62- * @param requiredMemberIds ids of the required members to attend the design review
63- * @param optionalMemberIds ids of the optional members to attend the design reivew
64- * @param isOnline if design review is online
65- * @param isInPerson if design review is in person
66- * @param docTemplateLink link to the doc template
67- * @param wbsNum wbs number for the design review
68- * @param meetingTimes the meeting times for the design review
69- * @param zoomLink link for the zoom if design review is online
70- * @param location location of the design review if in person
71- * @returns a design review
66+ * @param teamTypeId team type id
67+ * @param requiredMemberIds ids of members who are required to go
68+ * @param optionalMemberIds ids of members who do not have to go
69+ * @param wbsNum wbs num related to the design review
70+ * @param meetingTimes meeting times of the design review
71+ * @returns a new design review
7272 */
7373 static async createDesignReview (
7474 submitter : User ,
7575 dateScheduled : Date ,
7676 teamTypeId : string ,
7777 requiredMemberIds : number [ ] ,
7878 optionalMemberIds : number [ ] ,
79- isOnline : boolean ,
80- isInPerson : boolean ,
81- docTemplateLink : string ,
8279 wbsNum : WbsNumber ,
83- meetingTimes : number [ ] ,
84- zoomLink ?: string ,
85- location ?: string
80+ meetingTimes : number [ ]
8681 ) : Promise < DesignReview > {
8782 if ( ! isLeadership ( submitter . role ) ) throw new AccessDeniedException ( 'create design review' ) ;
8883
@@ -125,14 +120,6 @@ export default class DesignReviewsService {
125120 }
126121 }
127122
128- if ( isOnline && ! zoomLink ) {
129- throw new HttpException ( 400 , 'If the design review is online then there needs to be a zoom link' ) ;
130- }
131-
132- if ( isInPerson && ! location ) {
133- throw new HttpException ( 400 , 'If the design review is in person then there needs to be a location' ) ;
134- }
135-
136123 if ( dateScheduled . valueOf ( ) < new Date ( ) . valueOf ( ) ) {
137124 throw new HttpException ( 400 , 'Design review cannot be scheduled for a past day' ) ;
138125 }
@@ -142,11 +129,8 @@ export default class DesignReviewsService {
142129 dateScheduled,
143130 dateCreated : new Date ( ) ,
144131 status : Design_Review_Status . UNCONFIRMED ,
145- location,
146- isOnline,
147- isInPerson,
148- zoomLink,
149- docTemplateLink,
132+ isOnline : false ,
133+ isInPerson : false ,
150134 userCreated : { connect : { userId : submitter . userId } } ,
151135 teamType : { connect : { teamTypeId : teamType . teamTypeId } } ,
152136 requiredMembers : { connect : requiredMemberIds . map ( ( memberId ) => ( { userId : memberId } ) ) } ,
@@ -178,7 +162,11 @@ export default class DesignReviewsService {
178162 for ( const memberUserSetting of memberUserSettings ) {
179163 if ( memberUserSetting . slackId ) {
180164 try {
181- await sendSlackDesignReviewNotification ( memberUserSetting . slackId , designReview . designReviewId ) ;
165+ await sendSlackDesignReviewNotification (
166+ memberUserSetting . slackId ,
167+ designReview . designReviewId ,
168+ designReview . wbsElement . name
169+ ) ;
182170 } catch ( err : unknown ) {
183171 if ( err instanceof Error ) {
184172 throw new HttpException ( 500 , `Failed to send slack notification: ${ err . message } ` ) ;
@@ -316,4 +304,76 @@ export default class DesignReviewsService {
316304 } ) ;
317305 return designReviewTransformer ( updateDesignReview ) ;
318306 }
307+
308+ /**
309+ * Edits a design review by confirming a given user's availability and also updating their schedule settings with the given availability
310+ * @param submitter the member that is being confirmed
311+ * @param designReviewId the id of the design review
312+ * @param availability the given member's availabilities
313+ * @returns the modified design review with its updated confirmedMembers
314+ */
315+ static async markUserConfirmed ( designReviewId : string , availability : number [ ] , submitter : User ) : Promise < DesignReview > {
316+ const designReview = await prisma . design_Review . findUnique ( {
317+ where : { designReviewId } ,
318+ ...designReviewQueryArgs
319+ } ) ;
320+
321+ if ( ! designReview ) throw new NotFoundException ( 'Design Review' , designReviewId ) ;
322+
323+ if ( designReview . dateDeleted ) throw new DeletedException ( 'Design Review' , designReviewId ) ;
324+
325+ if ( ! isUserOnDesignReview ( submitter , designReviewTransformer ( designReview ) ) )
326+ throw new HttpException ( 400 , 'Current user is not in the list of this design reviews members' ) ;
327+
328+ availability . forEach ( ( time ) => {
329+ if ( time < 0 || time > 83 ) {
330+ throw new HttpException ( 400 , 'Availability times have to be in range 0-83' ) ;
331+ }
332+ } ) ;
333+
334+ await prisma . schedule_Settings . upsert ( {
335+ where : { userId : submitter . userId } ,
336+ update : {
337+ availability
338+ } ,
339+ create : {
340+ userId : submitter . userId ,
341+ personalGmail : '' ,
342+ personalZoomLink : '' ,
343+ availability
344+ }
345+ } ) ;
346+
347+ // set submitter as confirmed if they're not already
348+ if ( ! designReview . confirmedMembers . map ( ( user ) => user . userId ) . includes ( submitter . userId ) ) {
349+ const updatedDesignReview = await prisma . design_Review . update ( {
350+ where : { designReviewId } ,
351+ ...designReviewQueryArgs ,
352+ data : {
353+ confirmedMembers : {
354+ connect : {
355+ userId : submitter . userId
356+ }
357+ }
358+ }
359+ } ) ;
360+
361+ // If all requested attendees have confirmed their schedule, mark design review as confirmed
362+ if (
363+ updatedDesignReview . confirmedMembers . length ===
364+ designReview . requiredMembers . length + designReview . optionalMembers . length
365+ ) {
366+ await prisma . design_Review . update ( {
367+ where : { designReviewId } ,
368+ ...designReviewQueryArgs ,
369+ data : {
370+ status : Design_Review_Status . CONFIRMED
371+ }
372+ } ) ;
373+ }
374+
375+ return designReviewTransformer ( updatedDesignReview ) ;
376+ }
377+ return designReviewTransformer ( designReview ) ;
378+ }
319379}
0 commit comments