1- import { ApplicationDTO , ReviewedApplicantsDTO } from "../../types" ;
1+ import { ApplicationDTO , ReviewedApplicantRecordDTO , ReviewedApplicantsDTO } from "../../types" ;
22import IReviewPageService from "../interfaces/IReviewPageService" ;
33import { getErrorMessage } from "../../utilities/errorUtils" ;
44import logger from "../../utilities/logger" ;
55import ApplicantRecord from "../../models/applicantRecord.model" ;
6- import type ReviewedApplicantRecord from "../../models/reviewedApplicantRecord.model" ;
6+ import ReviewedApplicantRecord from "../../models/reviewedApplicantRecord.model" ;
77import Applicant from "../../models/applicant.model" ;
88import User from "../../models/user.model" ;
99
@@ -39,7 +39,7 @@ function toApplicationDTO(model: Applicant): ApplicationDTO {
3939 } ;
4040}
4141
42- function toReviewedApplicantRecordDTO (
42+ function toReviewedApplicantsDTO (
4343 model : ReviewedApplicantRecord ,
4444) : ReviewedApplicantsDTO {
4545 /* eslint-disable @typescript-eslint/no-non-null-assertion */
@@ -51,6 +51,18 @@ function toReviewedApplicantRecordDTO(
5151 } ;
5252}
5353
54+ function toReviewedApplicantRecordDTO (
55+ model : ReviewedApplicantRecord ,
56+ ) : ReviewedApplicantRecordDTO {
57+ return {
58+ applicantRecordId : model . applicantRecordId ,
59+ reviewerId : model . reviewerId ,
60+ review : model . review ,
61+ status : model . status ,
62+ reviewerHasConflict : model . reviewerHasConflict ,
63+ } ;
64+ }
65+
5466class ReviewPageService implements IReviewPageService {
5567 /* eslint-disable class-methods-use-this */
5668 async getReviewPage ( applicantRecordId : string ) : Promise < ApplicationDTO > {
@@ -110,12 +122,28 @@ class ReviewPageService implements IReviewPageService {
110122 } ) ;
111123 if ( ! user ) throw new Error ( `No user with ${ userId } found.` ) ;
112124 if ( ! user . reviewedApplicantRecords ) return [ ] ;
113- return user . reviewedApplicantRecords . map ( toReviewedApplicantRecordDTO ) ;
125+ return user . reviewedApplicantRecords . map ( toReviewedApplicantsDTO ) ;
114126 } catch ( error : unknown ) {
115127 Logger . error ( `Failed to fetch. Reason = ${ getErrorMessage ( error ) } ` ) ;
116128 throw error ;
117129 }
118130 }
131+
132+ async reportReviewConflict ( applicantRecordId : string , reviewerId : number ) : Promise < ReviewedApplicantRecordDTO > {
133+ try {
134+ const reviewedApplicantRecord : ReviewedApplicantRecord | null = await ReviewedApplicantRecord . findOne ( {
135+ where : { applicantRecordId, reviewerId } ,
136+ } ) ;
137+ if ( ! reviewedApplicantRecord ) throw new Error ( `No reviewed applicant record with ${ applicantRecordId } and ${ reviewerId } found.` ) ;
138+ reviewedApplicantRecord . reviewerHasConflict = true ;
139+ await reviewedApplicantRecord . save ( ) ;
140+ return toReviewedApplicantRecordDTO ( reviewedApplicantRecord ) ;
141+ }
142+ catch ( error : unknown ) {
143+ Logger . error ( `Failed to report conflict. Reason = ${ getErrorMessage ( error ) } ` ) ;
144+ throw error ;
145+ }
146+ }
119147}
120148
121149export default ReviewPageService ;
0 commit comments