Skip to content

Commit

Permalink
#3768 - CAS Supplier Maintenance Updates Part 1 (#4002)
Browse files Browse the repository at this point in the history
## Added New Column

- [x] Added new column `student_profile_snapshot` to
`sims.cas_suppliers`
- [x] Updated the entity model.


## Bug Fix

- [x] Fixed the bug that does not associate the latest CAS SUPPLIER
created to `sims.students` while adding manually the CAS SUPPLIER NUMBER
and SITE CODE by ministry user.


## Rollback Evidence


![image](https://github.com/user-attachments/assets/ff8806ce-6cd0-40c3-807c-fe2f39949b98)
  • Loading branch information
dheepak-aot authored Nov 27, 2024
1 parent 99df144 commit 3225526
Show file tree
Hide file tree
Showing 5 changed files with 90 additions and 16 deletions.
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>,
) {}

/**
Expand Down Expand Up @@ -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;
student.updatedAt = now;
student.modifier = auditUser;

// Save student with manual verified CAS Supplier.
await this.studentRepo.save(student);

return student.casSupplier;
}
}
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",
),
);
}
}
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.';
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
ALTER TABLE
sims.cas_suppliers DROP COLUMN student_profile_snapshot;
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -148,3 +159,17 @@ export interface SupplierAddress {
siteProtected?: string;
lastUpdated: Date;
}

/**
* Student profile snapshot information.
*/
interface StudentProfileSnapshot {
firstName: string;
lastName: string;
sin: string;
addressLine1: string;
city: string;
province: string;
postalCode: string;
country: string;
}

0 comments on commit 3225526

Please sign in to comment.