Skip to content

Commit 1fefa5a

Browse files
committed
implemented resolve conflict service
1 parent 0a944f4 commit 1fefa5a

File tree

4 files changed

+82
-0
lines changed

4 files changed

+82
-0
lines changed

backend/typescript/graphql/resolvers/reviewedApplicantRecordResolver.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,25 @@ const reviewedApplicantRecordResolvers = {
6161
throw new Error(getErrorMessage(error));
6262
}
6363
},
64+
65+
reassignReviewedApplicantRecord: async (
66+
_parent: undefined,
67+
args: {
68+
applicantRecordId: string;
69+
oldReviewerId: number;
70+
newReviewerId: number;
71+
},
72+
): Promise<ReviewedApplicantRecordDTO> => {
73+
try {
74+
return await reviewedApplicantRecordService.reassignReviewedApplicantRecord(
75+
args.applicantRecordId,
76+
args.oldReviewerId,
77+
args.newReviewerId,
78+
);
79+
} catch (error) {
80+
throw new Error(getErrorMessage(error));
81+
}
82+
},
6483
},
6584
};
6685

backend/typescript/graphql/types/reviewedApplicantRecordTypes.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,12 @@ const reviewedApplicantRecordTypes = gql`
6060
bulkDeleteReviewedApplicantRecord(
6161
inputs: [DeleteReviewedApplicantRecord!]!
6262
): [ReviewedApplicantRecord!]!
63+
64+
reassignReviewedApplicantRecord(
65+
applicantRecordId: ID!
66+
oldReviewerId: Int!
67+
newReviewerId: Int!
68+
): ReviewedApplicantRecord!
6369
}
6470
`;
6571

backend/typescript/services/implementations/reviewedApplicantRecordService.ts

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,51 @@ class ReviewedApplicantRecordService implements IReviewApplicantRecordService {
121121
throw error;
122122
}
123123
}
124+
125+
async reassignReviewedApplicantRecord(
126+
applicantRecordId: string,
127+
oldReviewerId: number,
128+
newReviewerId: number,
129+
): Promise<ReviewedApplicantRecordDTO> {
130+
try {
131+
return await sequelize.transaction(async (t) => {
132+
const oldRecord = await ReviewedApplicantRecord.findOne({
133+
where: { applicantRecordId, reviewerId: oldReviewerId },
134+
transaction: t,
135+
});
136+
137+
if (!oldRecord) {
138+
throw new Error(
139+
`ReviewedApplicantRecord not found for applicantRecordId: ${applicantRecordId} and reviewerId: ${oldReviewerId}`,
140+
);
141+
}
142+
143+
const oldRecordData = oldRecord.toJSON() as ReviewedApplicantRecordDTO;
144+
145+
await oldRecord.destroy({ transaction: t });
146+
147+
const newRecord = await ReviewedApplicantRecord.create(
148+
{
149+
applicantRecordId,
150+
reviewerId: newReviewerId,
151+
review: oldRecordData.review,
152+
status: oldRecordData.status,
153+
reviewerHasConflict: false,
154+
},
155+
{ transaction: t },
156+
);
157+
158+
return newRecord.toJSON() as ReviewedApplicantRecordDTO;
159+
});
160+
} catch (error: unknown) {
161+
Logger.error(
162+
`Failed to reassign reviewed applicant record. Reason = ${getErrorMessage(
163+
error,
164+
)}`,
165+
);
166+
throw error;
167+
}
168+
}
124169
}
125170

126171
export default ReviewedApplicantRecordService;

backend/typescript/services/interfaces/IReviewedApplicantRecordService.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,18 @@ interface IReviewApplicantRecordService {
3737
bulkDeleteReviewedApplicantRecord(
3838
deleteReviewedApplicantRecords: DeleteReviewedApplicantRecordDTO[],
3939
): Promise<ReviewedApplicantRecordDTO[]>;
40+
41+
/**
42+
* Reassigns a reviewed applicant record from one reviewer to another
43+
* @Param applicantRecordId the ID of applicant record to reassign
44+
* @Param oldReviewerId the ID of the current reviewer
45+
* @Param newReviewerId the ID of the new reviewer
46+
*/
47+
reassignReviewedApplicantRecord(
48+
applicantRecordId: string,
49+
oldReviewerId: number,
50+
newReviewerId: number,
51+
): Promise<ReviewedApplicantRecordDTO>;
4052
}
4153

4254
export default IReviewApplicantRecordService;

0 commit comments

Comments
 (0)