-
Notifications
You must be signed in to change notification settings - Fork 14
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
#3768 - CAS Supplier Maintenance Updates Part 1 #4002
Merged
dheepak-aot
merged 2 commits into
main
from
feature/#3768-cas-supplier-maintenance-updates-1
Nov 27, 2024
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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 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 |
---|---|---|
@@ -1,13 +1,21 @@ | ||
import { Injectable } from "@nestjs/common"; | ||
import { InjectRepository } from "@nestjs/typeorm"; | ||
import { CASSupplier, SupplierStatus } from "@sims/sims-db"; | ||
import { | ||
CASSupplier, | ||
Student, | ||
SupplierAddress, | ||
SupplierStatus, | ||
User, | ||
} from "@sims/sims-db"; | ||
import { Repository } from "typeorm"; | ||
|
||
Injectable(); | ||
export class CASSupplierService { | ||
constructor( | ||
@InjectRepository(CASSupplier) | ||
private readonly casSupplierRepo: Repository<CASSupplier>, | ||
@InjectRepository(Student) | ||
private readonly studentRepo: Repository<Student>, | ||
) {} | ||
|
||
/** | ||
|
@@ -39,28 +47,41 @@ export class CASSupplierService { | |
* @param studentId student id for the CAS supplier information. | ||
* @param supplierNumber supplier number. | ||
* @param supplierSiteCode supplier site code. | ||
* @param creatorUserId user id for the record creation. | ||
* @param auditUserId user id for the record creation. | ||
* @returns the saved CAS supplier. | ||
*/ | ||
async addCASSupplier( | ||
studentId: number, | ||
supplierNumber: string, | ||
supplierSiteCode: string, | ||
creatorUserId: number, | ||
auditUserId: number, | ||
): Promise<CASSupplier> { | ||
const now = new Date(); | ||
return this.casSupplierRepo.save({ | ||
student: { id: studentId }, | ||
supplierNumber: supplierNumber, | ||
lastUpdated: now, | ||
supplierAddress: { | ||
supplierSiteCode: supplierSiteCode, | ||
}, | ||
supplierStatus: SupplierStatus.VerifiedManually, | ||
supplierStatusUpdatedOn: now, | ||
isValid: true, | ||
createdAt: now, | ||
creator: { id: creatorUserId }, | ||
}); | ||
const auditUser = { id: auditUserId } as User; | ||
const student = { id: studentId } as Student; | ||
|
||
// Create manual verified CAS Supplier. | ||
const manualVerifiedSupplier = new CASSupplier(); | ||
manualVerifiedSupplier.student = student; | ||
manualVerifiedSupplier.supplierNumber = supplierNumber; | ||
manualVerifiedSupplier.lastUpdated = now; | ||
manualVerifiedSupplier.supplierAddress = { | ||
supplierSiteCode, | ||
} as SupplierAddress; | ||
manualVerifiedSupplier.supplierStatus = SupplierStatus.VerifiedManually; | ||
manualVerifiedSupplier.supplierStatusUpdatedOn = now; | ||
manualVerifiedSupplier.isValid = true; | ||
manualVerifiedSupplier.createdAt = now; | ||
manualVerifiedSupplier.creator = auditUser; | ||
|
||
// Set manual verified CAS Supplier for the student. | ||
student.casSupplier = manualVerifiedSupplier; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
||
student.updatedAt = now; | ||
student.modifier = auditUser; | ||
|
||
// Save student with manual verified CAS Supplier. | ||
await this.studentRepo.save(student); | ||
|
||
return student.casSupplier; | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
...apps/db-migrations/src/migrations/1732666324256-AddStudentProfileSnapshotToCASSupplier.ts
This file contains 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,20 @@ | ||
import { MigrationInterface, QueryRunner } from "typeorm"; | ||
import { getSQLFileData } from "../utilities/sqlLoader"; | ||
export class AddStudentProfileSnapshotToCASSupplier1732666324256 | ||
implements MigrationInterface | ||
{ | ||
public async up(queryRunner: QueryRunner): Promise<void> { | ||
await queryRunner.query( | ||
getSQLFileData("Add-student-profile-snapshot-column.sql", "CASSuppliers"), | ||
); | ||
} | ||
|
||
public async down(queryRunner: QueryRunner): Promise<void> { | ||
await queryRunner.query( | ||
getSQLFileData( | ||
"Rollback-add-student-profile-snapshot-column.sql", | ||
"CASSuppliers", | ||
), | ||
); | ||
} | ||
} |
6 changes: 6 additions & 0 deletions
6
...s/backend/apps/db-migrations/src/sql/CASSuppliers/Add-student-profile-snapshot-column.sql
This file contains 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,6 @@ | ||
ALTER TABLE | ||
sims.cas_suppliers | ||
ADD | ||
COLUMN student_profile_snapshot jsonb; | ||
|
||
COMMENT ON COLUMN sims.cas_suppliers.student_profile_snapshot IS 'Snapshot of the student profile details which is captured when the CAS supplier is set to be valid.'; |
2 changes: 2 additions & 0 deletions
2
.../apps/db-migrations/src/sql/CASSuppliers/Rollback-add-student-profile-snapshot-column.sql
This file contains 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,2 @@ | ||
ALTER TABLE | ||
sims.cas_suppliers DROP COLUMN student_profile_snapshot; |
This file contains 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 |
---|---|---|
|
@@ -132,6 +132,17 @@ export class CASSupplier extends RecordDataModel { | |
type: "varchar", | ||
}) | ||
errors?: string[]; | ||
|
||
/** | ||
* Snapshot of the student profile details which is captured | ||
* when the CAS supplier is set to be active. | ||
*/ | ||
@Column({ | ||
name: "student_profile_snapshot", | ||
type: "jsonb", | ||
nullable: true, | ||
}) | ||
studentProfileSnapshot?: StudentProfileSnapshot; | ||
} | ||
|
||
export type CASSupplierRecordStatus = "ACTIVE" | "INACTIVE"; | ||
|
@@ -148,3 +159,17 @@ export interface SupplierAddress { | |
siteProtected?: string; | ||
lastUpdated: Date; | ||
} | ||
|
||
/** | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Minor, please add a blank line. |
||
* Student profile snapshot information. | ||
*/ | ||
interface StudentProfileSnapshot { | ||
firstName: string; | ||
lastName: string; | ||
sin: string; | ||
addressLine1: string; | ||
city: string; | ||
province: string; | ||
postalCode: string; | ||
country: string; | ||
} |
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.
Thanks for the fix ❤️