@@ -6,19 +6,40 @@ import {
66 CreateReviewedApplicantRecordDTO ,
77 DeleteReviewedApplicantRecordDTO ,
88 UpdateReviewedApplicantRecordDTO ,
9+ Review ,
910} from "../../types" ;
1011import { getErrorMessage } from "../../utilities/errorUtils" ;
1112import logger from "../../utilities/logger" ;
1213import IReviewApplicantRecordService from "../interfaces/IReviewedApplicantRecordService" ;
1314
1415const Logger = logger ( __filename ) ;
1516
17+ function validateReviewScores ( review : Review | undefined ) : void {
18+ if ( ! review ) return ;
19+
20+ const scores = {
21+ passionFSG : review . passionFSG ,
22+ teamPlayer : review . teamPlayer ,
23+ desireToLearn : review . desireToLearn ,
24+ skill : review . skill ,
25+ } ;
26+
27+ Object . entries ( scores ) . forEach ( ( [ field , value ] ) => {
28+ if ( value !== undefined && ( value < 1 || value > 5 ) ) {
29+ throw new Error (
30+ `Invalid score for ${ field } : ${ value } . Scores must be between 1 and 5.` ,
31+ ) ;
32+ }
33+ } ) ;
34+ }
35+
1636class ReviewedApplicantRecordService implements IReviewApplicantRecordService {
1737 /* eslint-disable class-methods-use-this */
1838 async createReviewedApplicantRecord (
1939 dto : CreateReviewedApplicantRecordDTO ,
2040 ) : Promise < ReviewedApplicantRecordDTO > {
2141 try {
42+ validateReviewScores ( dto . review ) ;
2243 const record = await ReviewedApplicantRecord . create ( dto ) ;
2344 return record . toJSON ( ) as ReviewedApplicantRecordDTO ;
2445 } catch ( error : unknown ) {
@@ -35,6 +56,10 @@ class ReviewedApplicantRecordService implements IReviewApplicantRecordService {
3556 createReviewedApplicantRecordDTOs : CreateReviewedApplicantRecordDTO [ ] ,
3657 ) : Promise < ReviewedApplicantRecordDTO [ ] > {
3758 try {
59+ createReviewedApplicantRecordDTOs . forEach ( ( dto ) => {
60+ validateReviewScores ( dto . review ) ;
61+ } ) ;
62+
3863 const reviewedApplicantRecords = await sequelize . transaction (
3964 async ( t ) => {
4065 const records = await ReviewedApplicantRecord . bulkCreate (
@@ -146,6 +171,8 @@ class ReviewedApplicantRecordService implements IReviewApplicantRecordService {
146171 const oldReviewedScore = reviewedRecord . score || 0 ;
147172
148173 if ( review !== undefined ) {
174+ validateReviewScores ( review ) ;
175+
149176 reviewedRecord . review = {
150177 ...reviewedRecord . review ,
151178 ...review ,
0 commit comments