-
Notifications
You must be signed in to change notification settings - Fork 1
[INTF25] Build Mutator to Create Reviewed Applicant Record #84
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 5 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
b8b9a8f
current draft
ff42da4
debugging
isabellehuangg a060abe
cleanup
isabellehuangg 3fd0746
data migration for createdAt and updatedAt
isabellehuangg f9e0422
Merge branch 'main' into application-status-mutator
isabellehuangg 3b70eeb
use Review type in graphQL schema
isabellehuangg 490d79a
DTO type name change
isabellehuangg b341617
type change
isabellehuangg db7354b
linter
isabellehuangg e4bc1ef
linting: obj destructuring
isabellehuangg 68036aa
lint
isabellehuangg 1f954df
ran lint and wrapped service function in try catch
cfeb96d
resolve merge conflict
3345c6e
logger messages
isabellehuangg File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
63 changes: 63 additions & 0 deletions
63
backend/typescript/graphql/resolvers/reviewedApplicantRecordResolver.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,63 @@ | ||
| import ReviewedApplicantRecordService from "../../services/implementations/reviewedApplicantRecordService"; | ||
| import { | ||
| ReviewedApplicantRecordDTO, | ||
| CreateReviewedApplicantRecordDTO, | ||
| DeleteReviewedApplicantRecord | ||
| } from "../../types"; | ||
| import { getErrorMessage } from "../../utilities/errorUtils"; | ||
|
|
||
| const reviewedApplicantRecordService = new ReviewedApplicantRecordService(); | ||
|
|
||
| const reviewedApplicantRecordResolvers = { | ||
| Mutation: { | ||
| createReviewedApplicantRecord: async ( | ||
| _parent: undefined, | ||
| args: { input: CreateReviewedApplicantRecordDTO }, | ||
| ): Promise<ReviewedApplicantRecordDTO> => { | ||
| try { | ||
| return await reviewedApplicantRecordService.createReviewedApplicantRecord(args.input); | ||
| } catch (error) { | ||
| throw new Error(getErrorMessage(error)); | ||
| } | ||
| }, | ||
|
|
||
| bulkCreateReviewedApplicantRecord: async ( | ||
| _parent: undefined, | ||
| args: { inputs: CreateReviewedApplicantRecordDTO[] }, | ||
| ): Promise<ReviewedApplicantRecordDTO[]> => { | ||
| try { | ||
| return await reviewedApplicantRecordService.bulkCreateReviewedApplicantRecord(args.inputs); | ||
| } catch (error) { | ||
| throw new Error(getErrorMessage(error)); | ||
| } | ||
| }, | ||
|
|
||
| deleteReviewedApplicantRecord: async ( | ||
| _parent: undefined, | ||
| args: { input: DeleteReviewedApplicantRecord }, | ||
| ): Promise<ReviewedApplicantRecordDTO> => { | ||
| try { | ||
| return await reviewedApplicantRecordService.deleteReviewedApplicantRecord( | ||
| args.input | ||
| ); | ||
| } catch (error) { | ||
| throw new Error(getErrorMessage(error)); | ||
| } | ||
| }, | ||
|
|
||
| bulkDeleteReviewedApplicantRecord: async ( | ||
| _parent: undefined, | ||
| args: { inputs: DeleteReviewedApplicantRecord[] }, | ||
| ): Promise<ReviewedApplicantRecordDTO[]> => { | ||
| try { | ||
| return await reviewedApplicantRecordService.bulkDeleteReviewedApplicantRecord( | ||
| args.inputs | ||
| ); | ||
| } catch (error) { | ||
| throw new Error(getErrorMessage(error)); | ||
| } | ||
| }, | ||
| }, | ||
| }; | ||
|
|
||
| export default reviewedApplicantRecordResolvers; |
44 changes: 44 additions & 0 deletions
44
backend/typescript/graphql/types/reviewedApplicantRecordTypes.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| import { gql } from "apollo-server-express"; | ||
|
|
||
| const reviewedApplicantRecordTypes = gql` | ||
| type ReviewedApplicantRecord { | ||
| applicantRecordId: ID! | ||
| reviewerId: Int! | ||
| review: JSON | ||
| status: String | ||
| score: Int | ||
| reviewerHasConflict: Boolean | ||
| } | ||
|
|
||
| input CreateReviewedApplicantRecordInput { | ||
| applicantRecordId: ID! | ||
| reviewerId: Int! | ||
| review: JSON | ||
| status: String | ||
| } | ||
|
|
||
| input DeleteReviewedApplicantRecord { | ||
| applicantRecordId: ID! | ||
| reviewerId: Int! | ||
| } | ||
|
|
||
| extend type Mutation { | ||
| createReviewedApplicantRecord( | ||
| input: CreateReviewedApplicantRecordInput! | ||
| ): ReviewedApplicantRecord! | ||
|
|
||
| bulkCreateReviewedApplicantRecord( | ||
| inputs: [CreateReviewedApplicantRecordInput!]! | ||
| ): [ReviewedApplicantRecord!]! | ||
|
|
||
| deleteReviewedApplicantRecord( | ||
| input: DeleteReviewedApplicantRecord! | ||
| ): ReviewedApplicantRecord! | ||
|
|
||
| bulkDeleteReviewedApplicantRecord( | ||
| inputs: [DeleteReviewedApplicantRecord!]! | ||
| ): [ReviewedApplicantRecord!]! | ||
| } | ||
| `; | ||
|
|
||
| export default reviewedApplicantRecordTypes; |
23 changes: 23 additions & 0 deletions
23
...d/typescript/migrations/20251112023004-add-createdat-updatedat-to-reviewed-application.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| import { DataType } from "sequelize-typescript"; | ||
| import { Migration } from "../umzug"; | ||
|
|
||
| const TABLE_NAME = "reviewed_applicant_records"; | ||
|
|
||
| export const up: Migration = async ({ context: sequelize }) => { | ||
| await sequelize.getQueryInterface().addColumn(TABLE_NAME, "createdAt", { | ||
| type: DataType.DATE, | ||
| allowNull: false, | ||
| defaultValue: DataType.NOW | ||
| }) | ||
|
|
||
| await sequelize.getQueryInterface().addColumn(TABLE_NAME, "updatedAt", { | ||
| type: DataType.DATE, | ||
| allowNull: false, | ||
| defaultValue: DataType.NOW | ||
| }) | ||
| }; | ||
|
|
||
| export const down: Migration = async ({ context: sequelize }) => { | ||
| await sequelize.getQueryInterface().removeColumn(TABLE_NAME, "createdAt"); | ||
| await sequelize.getQueryInterface().removeColumn(TABLE_NAME, "updatedAt"); | ||
| }; |
74 changes: 74 additions & 0 deletions
74
backend/typescript/services/implementations/reviewedApplicantRecordService.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,74 @@ | ||
| import { sequelize } from "../../models"; | ||
| import ReviewedApplicantRecord from "../../models/reviewedApplicantRecord.model"; | ||
| import { | ||
| ReviewedApplicantRecordDTO, | ||
| CreateReviewedApplicantRecordDTO, | ||
| DeleteReviewedApplicantRecord | ||
| } from "../../types"; | ||
|
|
||
| import IReviewApplicantRecordService from "../interfaces/IReviewedApplicantRecordService"; | ||
|
|
||
| class ReviewedApplicantRecordService implements IReviewApplicantRecordService { | ||
|
|
||
| async createReviewedApplicantRecord( | ||
| dto: CreateReviewedApplicantRecordDTO | ||
| ): Promise<ReviewedApplicantRecordDTO> { | ||
| const record = await ReviewedApplicantRecord.create(dto); | ||
| return record.toJSON() as ReviewedApplicantRecordDTO; | ||
| } | ||
|
|
||
| async bulkCreateReviewedApplicantRecord( | ||
| createReviewedApplicantRecordDTOs: CreateReviewedApplicantRecordDTO[] | ||
| ): Promise<ReviewedApplicantRecordDTO[]> { | ||
| const reviewedApplicantRecords = await sequelize.transaction(async (t) => { | ||
| const records = await ReviewedApplicantRecord.bulkCreate( | ||
| createReviewedApplicantRecordDTOs, | ||
| { transaction: t } | ||
| ); | ||
| return records; | ||
| }); | ||
|
|
||
| return reviewedApplicantRecords.map((record) => | ||
| record.toJSON() as ReviewedApplicantRecordDTO | ||
| ); | ||
| } | ||
|
|
||
| async deleteReviewedApplicantRecord(deleteReviewedApplicantRecord: DeleteReviewedApplicantRecord): Promise<ReviewedApplicantRecordDTO> { | ||
| const applicantRecordId = deleteReviewedApplicantRecord.applicantRecordId; | ||
| const reviewerId = deleteReviewedApplicantRecord.reviewerId; | ||
| const record = await ReviewedApplicantRecord.findOne({ where: { applicantRecordId, reviewerId } }); | ||
|
|
||
| if (!record) { | ||
| throw new Error("ReviewedApplicantRecord not found, delete failed"); | ||
| } | ||
|
|
||
| await record.destroy(); | ||
| return record.toJSON() as ReviewedApplicantRecordDTO; | ||
| } | ||
|
|
||
| async bulkDeleteReviewedApplicantRecord(deleteReviewedApplicantRecords: DeleteReviewedApplicantRecord[]): Promise<ReviewedApplicantRecordDTO[]> { | ||
| const deletedRecords = await sequelize.transaction(async (t) => { | ||
| const records = await Promise.all( | ||
| deleteReviewedApplicantRecords.map(({ applicantRecordId, reviewerId }) => | ||
| ReviewedApplicantRecord.findOne({ | ||
| where: { applicantRecordId, reviewerId }, | ||
| transaction: t, | ||
| }) | ||
| ) | ||
| ); | ||
|
|
||
| if (records.some((r) => !r)) { | ||
| throw new Error("Not all records were found, bulk delete failed"); | ||
| } | ||
|
|
||
| const existingRecords = records as ReviewedApplicantRecord[]; | ||
| await Promise.all(existingRecords.map((r) => r.destroy({ transaction: t }))); | ||
|
|
||
| return existingRecords; | ||
| }); | ||
|
|
||
| return deletedRecords.map((r) => r.toJSON() as ReviewedApplicantRecordDTO); | ||
| } | ||
| } | ||
|
|
||
| export default ReviewedApplicantRecordService; |
42 changes: 42 additions & 0 deletions
42
backend/typescript/services/interfaces/IReviewedApplicantRecordService.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| import { | ||
| ReviewedApplicantRecordDTO, | ||
| CreateReviewedApplicantRecordDTO, | ||
| DeleteReviewedApplicantRecord | ||
| } from "../../types"; | ||
|
|
||
| interface IReviewApplicantRecordService { | ||
| /** | ||
| * Creates a single reviewed applicant record entry | ||
| * @Param createReviewedApplicantRecordDTO data to create reviewed applicant record | ||
| */ | ||
| createReviewedApplicantRecord( | ||
| createReviewedApplicantRecordDTO: CreateReviewedApplicantRecordDTO | ||
| ): Promise<ReviewedApplicantRecordDTO>; | ||
|
|
||
| /** | ||
| * Creates multiple reviewed applicant record entries in bulk | ||
| * @Param createReviewedApplicantRecordDTOs array of data to create reviewed applicant records | ||
| */ | ||
| bulkCreateReviewedApplicantRecord( | ||
| createReviewedApplicantRecordDTOs: CreateReviewedApplicantRecordDTO[] | ||
| ): Promise<ReviewedApplicantRecordDTO[]>; | ||
|
|
||
| /** | ||
| * Deletes a single reviewed applicant record entry | ||
| * @Param applicantRecordId the ID of applicant record to delete | ||
| * @Param reviewerId the ID of the reviewer | ||
| */ | ||
| deleteReviewedApplicantRecord( | ||
| deleteReviewedApplicantRecord: DeleteReviewedApplicantRecord | ||
| ): Promise<ReviewedApplicantRecordDTO>; | ||
|
|
||
| /** | ||
| * Deletes multiple reviewed applicant record entries in bulk | ||
| * @Param deleteReviewedApplicantRecord array of data to delete reviewed applicant records | ||
| */ | ||
| bulkDeleteReviewedApplicantRecord( | ||
| deleteReviewedApplicantRecords: DeleteReviewedApplicantRecord[] | ||
| ): Promise<ReviewedApplicantRecordDTO[]>; | ||
| } | ||
|
|
||
| export default IReviewApplicantRecordService; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -208,6 +208,17 @@ export type ReviewedApplicantRecordDTO = { | |
| reviewerHasConflict: boolean; | ||
| }; | ||
|
|
||
| export type CreateReviewedApplicantRecordDTO = { | ||
| applicantRecordId: string; | ||
| reviewerId: number; | ||
| review?: Review; | ||
| reviewerHasConflict?: boolean; | ||
| } | ||
|
|
||
| export type DeleteReviewedApplicantRecord = { | ||
| applicantRecordId: string; | ||
| reviewerId: number; | ||
| } | ||
|
||
| export type AdminCommentDTO = { | ||
| id: string; | ||
| userId: number; | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is legacy code I deleted in another PR... would you mind merging to main to get rid of this LOL, sorry I forgot everyone to pull main when I merged that PR in