Skip to content

Commit 9b9f90d

Browse files
committed
Merge branch 'main' of https://github.com/uwblueprint/website-bp-be into INTW26-create-firebase-file-model
2 parents 301c6b3 + d7cfc20 commit 9b9f90d

File tree

4 files changed

+107
-10
lines changed

4 files changed

+107
-10
lines changed

backend/typescript/graphql/resolvers/reviewPageResolvers.ts

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
import { ApplicationDTO, ReviewedApplicantsDTO } from "../../types";
1+
import {
2+
ApplicationDTO,
3+
ReviewedApplicantRecordDTO,
4+
ReviewedApplicantsDTO,
5+
} from "../../types";
26
import ReviewPageService from "../../services/implementations/reviewPageService";
37
import { getErrorMessage } from "../../utilities/errorUtils";
48

@@ -29,6 +33,21 @@ const reviewPageResolvers = {
2933
}
3034
},
3135
},
36+
Mutation: {
37+
reportReviewConflict: async (
38+
_parent: undefined,
39+
args: { applicantRecordId: string; reviewerId: number },
40+
): Promise<ReviewedApplicantRecordDTO> => {
41+
try {
42+
return await reviewPageService.reportReviewConflict(
43+
args.applicantRecordId,
44+
args.reviewerId,
45+
);
46+
} catch (error) {
47+
throw new Error(getErrorMessage(error));
48+
}
49+
},
50+
},
3251
};
3352

3453
export default reviewPageResolvers;

backend/typescript/graphql/types/reviewPageType.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,22 @@ const reviewPageType = gql`
3232
applicantLastName: String!
3333
}
3434
35+
type ReviewedApplicantRecordDTO {
36+
applicantRecordId: String!
37+
reviewerId: Int!
38+
review: Review!
39+
status: String!
40+
score: Int
41+
reviewerHasConflict: Boolean!
42+
}
43+
44+
extend type Mutation {
45+
reportReviewConflict(
46+
applicantRecordId: String!
47+
reviewerId: Int!
48+
): ReviewedApplicantRecordDTO!
49+
}
50+
3551
extend type Query {
3652
reviewApplicantPage(applicantRecordId: String!): ApplicationDTO!
3753
getReviewedApplicantsByUserId(userId: Int!): [ReviewedApplicantsDTO!]!

backend/typescript/services/implementations/reviewPageService.ts

Lines changed: 56 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
1-
import { ApplicationDTO, ReviewedApplicantsDTO } from "../../types";
1+
import {
2+
ApplicationDTO,
3+
ReviewedApplicantRecordDTO,
4+
ReviewedApplicantsDTO,
5+
} from "../../types";
26
import IReviewPageService from "../interfaces/IReviewPageService";
37
import { getErrorMessage } from "../../utilities/errorUtils";
48
import logger from "../../utilities/logger";
59
import ApplicantRecord from "../../models/applicantRecord.model";
6-
import type ReviewedApplicantRecord from "../../models/reviewedApplicantRecord.model";
10+
import ReviewedApplicantRecord from "../../models/reviewedApplicantRecord.model";
711
import Applicant from "../../models/applicant.model";
812
import User from "../../models/user.model";
913

@@ -39,7 +43,7 @@ function toApplicationDTO(model: Applicant): ApplicationDTO {
3943
};
4044
}
4145

42-
function toReviewedApplicantRecordDTO(
46+
function toReviewedApplicantsDTO(
4347
model: ReviewedApplicantRecord,
4448
): ReviewedApplicantsDTO {
4549
/* eslint-disable @typescript-eslint/no-non-null-assertion */
@@ -51,6 +55,18 @@ function toReviewedApplicantRecordDTO(
5155
};
5256
}
5357

58+
function toReviewedApplicantRecordDTO(
59+
model: ReviewedApplicantRecord,
60+
): ReviewedApplicantRecordDTO {
61+
return {
62+
applicantRecordId: model.applicantRecordId,
63+
reviewerId: model.reviewerId,
64+
review: model.review,
65+
status: model.status,
66+
reviewerHasConflict: model.reviewerHasConflict,
67+
};
68+
}
69+
5470
class ReviewPageService implements IReviewPageService {
5571
/* eslint-disable class-methods-use-this */
5672
async getReviewPage(applicantRecordId: string): Promise<ApplicationDTO> {
@@ -60,8 +76,9 @@ class ReviewPageService implements IReviewPageService {
6076
where: { id: applicantRecordId },
6177
attributes: { exclude: ["createdAt", "updatedAt"] },
6278
});
63-
if (!applicantRecord)
79+
if (!applicantRecord) {
6480
throw new Error(`Database integrity has been violated`);
81+
}
6582

6683
const applicant: Applicant | null = await Applicant.findOne({
6784
where: { id: applicantRecord.applicantId },
@@ -73,7 +90,9 @@ class ReviewPageService implements IReviewPageService {
7390
},
7491
],
7592
});
76-
if (!applicant) throw new Error(`Database integrity has been violated`);
93+
if (!applicant) {
94+
throw new Error(`Database integrity has been violated`);
95+
}
7796

7897
return toApplicationDTO(applicant);
7998
} catch (error: unknown) {
@@ -108,14 +127,43 @@ class ReviewPageService implements IReviewPageService {
108127
},
109128
],
110129
});
111-
if (!user) throw new Error(`No user with ${userId} found.`);
112-
if (!user.reviewedApplicantRecords) return [];
113-
return user.reviewedApplicantRecords.map(toReviewedApplicantRecordDTO);
130+
if (!user) {
131+
throw new Error(`No user with ${userId} found.`);
132+
}
133+
if (!user.reviewedApplicantRecords) {
134+
return [];
135+
}
136+
return user.reviewedApplicantRecords.map(toReviewedApplicantsDTO);
114137
} catch (error: unknown) {
115138
Logger.error(`Failed to fetch. Reason = ${getErrorMessage(error)}`);
116139
throw error;
117140
}
118141
}
142+
143+
async reportReviewConflict(
144+
applicantRecordId: string,
145+
reviewerId: number,
146+
): Promise<ReviewedApplicantRecordDTO> {
147+
try {
148+
const reviewedApplicantRecord: ReviewedApplicantRecord | null =
149+
await ReviewedApplicantRecord.findOne({
150+
where: { applicantRecordId, reviewerId },
151+
});
152+
if (!reviewedApplicantRecord) {
153+
throw new Error(
154+
`No reviewed applicant record with ${applicantRecordId} and ${reviewerId} found.`,
155+
);
156+
}
157+
reviewedApplicantRecord.reviewerHasConflict = true;
158+
await reviewedApplicantRecord.save();
159+
return toReviewedApplicantRecordDTO(reviewedApplicantRecord);
160+
} catch (error: unknown) {
161+
Logger.error(
162+
`Failed to report conflict. Reason = ${getErrorMessage(error)}`,
163+
);
164+
throw error;
165+
}
166+
}
119167
}
120168

121169
export default ReviewPageService;

backend/typescript/services/interfaces/IReviewPageService.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
import { ApplicationDTO, ReviewedApplicantsDTO } from "../../types";
1+
import {
2+
ApplicationDTO,
3+
ReviewedApplicantRecordDTO,
4+
ReviewedApplicantsDTO,
5+
} from "../../types";
26

37
interface IReviewPageService {
48
/**
@@ -14,6 +18,16 @@ interface IReviewPageService {
1418
getReviewedApplicantsByUserId(
1519
userId: number,
1620
): Promise<ReviewedApplicantsDTO[]>;
21+
22+
/**
23+
* Update the reviewerHasConflict column of a ReviewedApplicantRecord entry to indicate a conflict.
24+
* @param applicantRecordId the id of the applicant record that the reviewer is interested in
25+
* @param reviewerId the id of the reviewer that is reporting the conflict
26+
*/
27+
reportReviewConflict(
28+
applicantRecordId: string,
29+
reviewerId: number,
30+
): Promise<ReviewedApplicantRecordDTO>;
1731
}
1832

1933
export default IReviewPageService;

0 commit comments

Comments
 (0)