Skip to content
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
merged 2 commits into from
Nov 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the fix ❤️

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;
Copy link
Collaborator

Choose a reason for hiding this comment

The 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;
}
}
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;
}

/**
Copy link
Collaborator

Choose a reason for hiding this comment

The 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;
}