Skip to content

Commit 07ef0ea

Browse files
authored
#3768 - CAS Supplier Updates Report - Saving Snapshot (#4011)
## Added Saving the Snapshot - [x] Created shared service to centralize the logic of extracting the snapshot from student data. - [x] Added saving snapshot when get supplier returns matching supplier and site. [cas-active-supplier-and-site-found-processor](https://github.com/bcgov/SIMS/blob/e8289820812b2c90258b8672124c5eee510569ea/sources/packages/backend/apps/queue-consumers/src/services/cas-supplier/cas-evaluation-result-processor/cas-active-supplier-and-site-found-processor.ts#L34) - [x] Added saving snapshot when no supplier found AND supplier and site created. [cas-active-supplier-not-found-processor](https://github.com/bcgov/SIMS/blob/e8289820812b2c90258b8672124c5eee510569ea/sources/packages/backend/apps/queue-consumers/src/services/cas-supplier/cas-evaluation-result-processor/cas-active-supplier-not-found-processor.ts#L95) - [x] Added saving snapshot when Active supplier found but site not found AND new site created. [cas-active-supplier-found-processor.ts](https://github.com/bcgov/SIMS/blob/f06eee1f706e2cc1498caa5a89be9fec91eb6ba2/sources/packages/backend/apps/queue-consumers/src/services/cas-supplier/cas-evaluation-result-processor/cas-active-supplier-found-processor.ts#L67) - [x] Added saving snapshot when ministry is manually adding a verified supplier. ![image](https://github.com/user-attachments/assets/2fdcdba4-7fe9-452d-b9d9-6eb4fdc58ce2)
1 parent adb0699 commit 07ef0ea

File tree

11 files changed

+106
-15
lines changed

11 files changed

+106
-15
lines changed

sources/packages/backend/apps/api/src/app.aest.module.ts

+2
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ import {
9696
RestrictionSharedService,
9797
MSFAANumberSharedService,
9898
AssessmentSequentialProcessingService,
99+
CASSupplierSharedService,
99100
} from "@sims/services";
100101
import { ECertIntegrationModule } from "@sims/integrations/esdc-integration";
101102

@@ -194,6 +195,7 @@ import { ECertIntegrationModule } from "@sims/integrations/esdc-integration";
194195
ApplicationRestrictionBypassService,
195196
CRAIncomeVerificationService,
196197
SupportingUserService,
198+
CASSupplierSharedService,
197199
],
198200
})
199201
export class AppAESTModule {}

sources/packages/backend/apps/api/src/constants/error-code.constants.ts

+4
Original file line numberDiff line numberDiff line change
@@ -239,3 +239,7 @@ export const APPLICATION_RESTRICTION_BYPASS_NOT_FOUND =
239239
*/
240240
export const APPLICATION_RESTRICTION_BYPASS_IS_NOT_ACTIVE =
241241
"APPLICATION_RESTRICTION_BYPASS_IS_NOT_ACTIVE";
242+
/**
243+
* Student not found error code.
244+
*/
245+
export const STUDENT_NOT_FOUND = "STUDENT_NOT_FOUND";

sources/packages/backend/apps/api/src/route-controllers/cas-supplier/cas-supplier.aest.controller.ts

+18-10
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ import {
2323
import { CASSupplierService, StudentService } from "../../services";
2424
import { ClientTypeBaseRoute } from "../../types";
2525
import { PrimaryIdentifierAPIOutDTO } from "../models/primary.identifier.dto";
26+
import { STUDENT_NOT_FOUND } from "../../constants";
27+
import { CustomNamedError } from "@sims/utilities";
2628

2729
/**
2830
* CAS supplier controller.
@@ -87,16 +89,22 @@ export class CASSupplierAESTController extends BaseController {
8789
@Param("studentId", ParseIntPipe) studentId: number,
8890
@UserToken() userToken: IUserToken,
8991
): Promise<PrimaryIdentifierAPIOutDTO> {
90-
const studentExist = await this.studentService.studentExists(studentId);
91-
if (!studentExist) {
92-
throw new NotFoundException("Student not found.");
92+
try {
93+
const casSupplier = await this.casSupplierService.addCASSupplier(
94+
studentId,
95+
payload.supplierNumber,
96+
payload.supplierSiteCode,
97+
userToken.userId,
98+
);
99+
return { id: casSupplier.id };
100+
} catch (error: unknown) {
101+
if (
102+
error instanceof CustomNamedError &&
103+
error.name === STUDENT_NOT_FOUND
104+
) {
105+
throw new NotFoundException(error.message);
106+
}
107+
throw error;
93108
}
94-
const casSupplier = await this.casSupplierService.addCASSupplier(
95-
studentId,
96-
payload.supplierNumber,
97-
payload.supplierSiteCode,
98-
userToken.userId,
99-
);
100-
return { id: casSupplier.id };
101109
}
102110
}

sources/packages/backend/apps/api/src/services/cas-supplier/cas-supplier.service.ts

+17-1
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
11
import { Injectable } from "@nestjs/common";
22
import { InjectRepository } from "@nestjs/typeorm";
3+
import { StudentService } from "../../services";
34
import {
45
CASSupplier,
56
Student,
67
SupplierAddress,
78
SupplierStatus,
89
User,
910
} from "@sims/sims-db";
11+
import { CustomNamedError } from "@sims/utilities";
12+
import { STUDENT_NOT_FOUND } from "../../constants";
1013
import { Repository } from "typeorm";
14+
import { CASSupplierSharedService } from "@sims/services";
1115

1216
Injectable();
1317
export class CASSupplierService {
@@ -16,6 +20,8 @@ export class CASSupplierService {
1620
private readonly casSupplierRepo: Repository<CASSupplier>,
1721
@InjectRepository(Student)
1822
private readonly studentRepo: Repository<Student>,
23+
private readonly studentService: StudentService,
24+
private readonly casSupplierSharedService: CASSupplierSharedService,
1925
) {}
2026

2127
/**
@@ -56,9 +62,12 @@ export class CASSupplierService {
5662
supplierSiteCode: string,
5763
auditUserId: number,
5864
): Promise<CASSupplier> {
65+
const student = await this.studentService.getStudentById(studentId);
66+
if (!student) {
67+
throw new CustomNamedError("Student not found.", STUDENT_NOT_FOUND);
68+
}
5969
const now = new Date();
6070
const auditUser = { id: auditUserId } as User;
61-
const student = { id: studentId } as Student;
6271

6372
// Create manual verified CAS Supplier.
6473
const manualVerifiedSupplier = new CASSupplier();
@@ -73,6 +82,13 @@ export class CASSupplierService {
7382
manualVerifiedSupplier.isValid = true;
7483
manualVerifiedSupplier.createdAt = now;
7584
manualVerifiedSupplier.creator = auditUser;
85+
manualVerifiedSupplier.studentProfileSnapshot =
86+
this.casSupplierSharedService.getStudentProfileSnapshot(
87+
student.user.firstName,
88+
student.user.lastName,
89+
student.sinValidation.sin,
90+
student.contactInfo.address,
91+
);
7692

7793
// Set manual verified CAS Supplier for the student.
7894
student.casSupplier = manualVerifiedSupplier;

sources/packages/backend/apps/queue-consumers/src/queue-consumers.module.ts

+2
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ import {
4343
GlobalHttpModule,
4444
AssessmentSequentialProcessingService,
4545
ClamAVService,
46+
CASSupplierSharedService,
4647
} from "@sims/services";
4748
import { DatabaseModule } from "@sims/sims-db";
4849
import { IER12IntegrationModule } from "@sims/integrations/institution-integration/ier12-integration";
@@ -160,6 +161,7 @@ import { BullBoardQueuesModule } from "./bull-board/bull-board-queues.module";
160161
CASPreValidationsProcessor,
161162
CASActiveSupplierFoundProcessor,
162163
CASActiveSupplierAndSiteFoundProcessor,
164+
CASSupplierSharedService,
163165
],
164166
controllers: [HealthController],
165167
})

sources/packages/backend/apps/queue-consumers/src/services/cas-supplier/cas-evaluation-result-processor/cas-active-supplier-and-site-found-processor.ts

+10-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { Injectable } from "@nestjs/common";
22
import { InjectRepository } from "@nestjs/typeorm";
3-
import { SystemUsersService } from "@sims/services";
3+
import { CASSupplierSharedService, SystemUsersService } from "@sims/services";
44
import { CASSupplier, SupplierStatus } from "@sims/sims-db";
55
import { ProcessSummary } from "@sims/utilities/logger";
66
import {
@@ -20,6 +20,7 @@ export class CASActiveSupplierAndSiteFoundProcessor extends CASEvaluationResultP
2020
private readonly systemUsersService: SystemUsersService,
2121
@InjectRepository(CASSupplier)
2222
private readonly casSupplierRepo: Repository<CASSupplier>,
23+
private readonly casSupplierSharedService: CASSupplierSharedService,
2324
) {
2425
super();
2526
}
@@ -56,6 +57,13 @@ export class CASActiveSupplierAndSiteFoundProcessor extends CASEvaluationResultP
5657
siteProtected: address.siteprotected,
5758
lastUpdated: new Date(address.lastupdated),
5859
};
60+
const studentProfileSnapshot =
61+
this.casSupplierSharedService.getStudentProfileSnapshot(
62+
studentSupplier.firstName,
63+
studentSupplier.lastName,
64+
studentSupplier.sin,
65+
studentSupplier.address,
66+
);
5967
const now = new Date();
6068
const systemUser = this.systemUsersService.systemUser;
6169
const supplierToUpdate = evaluationResult.activeSupplier;
@@ -71,6 +79,7 @@ export class CASActiveSupplierAndSiteFoundProcessor extends CASEvaluationResultP
7179
lastUpdated: new Date(supplierToUpdate.lastupdated),
7280
supplierAddress: supplierAddressToUpdate,
7381
supplierStatus: SupplierStatus.Verified,
82+
studentProfileSnapshot,
7483
supplierStatusUpdatedOn: now,
7584
isValid: true,
7685
updatedAt: now,

sources/packages/backend/apps/queue-consumers/src/services/cas-supplier/cas-evaluation-result-processor/cas-active-supplier-found-processor.ts

+10-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { Injectable } from "@nestjs/common";
22
import { InjectRepository } from "@nestjs/typeorm";
3-
import { SystemUsersService } from "@sims/services";
3+
import { CASSupplierSharedService, SystemUsersService } from "@sims/services";
44
import { CASSupplier, SupplierAddress, SupplierStatus } from "@sims/sims-db";
55
import { ProcessSummary } from "@sims/utilities/logger";
66
import {
@@ -25,6 +25,7 @@ export class CASActiveSupplierFoundProcessor extends CASEvaluationResultProcesso
2525
@InjectRepository(CASSupplier)
2626
private readonly casSupplierRepo: Repository<CASSupplier>,
2727
private readonly casService: CASService,
28+
private readonly casSupplierSharedService: CASSupplierSharedService,
2829
) {
2930
super();
3031
}
@@ -78,6 +79,13 @@ export class CASActiveSupplierFoundProcessor extends CASEvaluationResultProcesso
7879
status: "ACTIVE",
7980
lastUpdated: now,
8081
};
82+
const studentProfileSnapshot =
83+
this.casSupplierSharedService.getStudentProfileSnapshot(
84+
studentSupplier.firstName,
85+
studentSupplier.lastName,
86+
studentSupplier.sin,
87+
studentSupplier.address,
88+
);
8189
const updateResult = await this.casSupplierRepo.update(
8290
{
8391
id: studentSupplier.casSupplierID,
@@ -90,6 +98,7 @@ export class CASActiveSupplierFoundProcessor extends CASEvaluationResultProcesso
9098
lastUpdated: new Date(supplierToUpdate.lastupdated),
9199
supplierAddress: supplierAddressToUpdate,
92100
supplierStatus: SupplierStatus.Verified,
101+
studentProfileSnapshot,
93102
supplierStatusUpdatedOn: now,
94103
isValid: true,
95104
updatedAt: now,

sources/packages/backend/apps/queue-consumers/src/services/cas-supplier/cas-evaluation-result-processor/cas-active-supplier-not-found-processor.ts

+10-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { Injectable } from "@nestjs/common";
22
import { InjectRepository } from "@nestjs/typeorm";
3-
import { SystemUsersService } from "@sims/services";
3+
import { CASSupplierSharedService, SystemUsersService } from "@sims/services";
44
import { CASSupplier, SupplierStatus } from "@sims/sims-db";
55
import { ProcessSummary } from "@sims/utilities/logger";
66
import {
@@ -25,6 +25,7 @@ export class CASActiveSupplierNotFoundProcessor extends CASEvaluationResultProce
2525
private readonly systemUsersService: SystemUsersService,
2626
@InjectRepository(CASSupplier)
2727
private readonly casSupplierRepo: Repository<CASSupplier>,
28+
private readonly casSupplierSharedService: CASSupplierSharedService,
2829
) {
2930
super();
3031
}
@@ -71,6 +72,13 @@ export class CASActiveSupplierNotFoundProcessor extends CASEvaluationResultProce
7172
const [submittedAddress] = result.submittedData.SupplierAddress;
7273
const now = new Date();
7374
const systemUser = this.systemUsersService.systemUser;
75+
const studentProfileSnapshot =
76+
this.casSupplierSharedService.getStudentProfileSnapshot(
77+
studentSupplier.firstName,
78+
studentSupplier.lastName,
79+
studentSupplier.sin,
80+
studentSupplier.address,
81+
);
7482
const updateResult = await this.casSupplierRepo.update(
7583
{
7684
id: studentSupplier.casSupplierID,
@@ -91,6 +99,7 @@ export class CASActiveSupplierNotFoundProcessor extends CASEvaluationResultProce
9199
lastUpdated: now,
92100
},
93101
supplierStatus: SupplierStatus.Verified,
102+
studentProfileSnapshot,
94103
supplierStatusUpdatedOn: now,
95104
isValid: true,
96105
updatedAt: now,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import { Injectable } from "@nestjs/common";
2+
import { AddressInfo, StudentProfileSnapshot } from "@sims/sims-db";
3+
4+
Injectable();
5+
export class CASSupplierSharedService {
6+
/**
7+
* Get a snapshot of the student profile.
8+
* @param firstName student first name.
9+
* @param lastName student last name.
10+
* @param sin student sin.
11+
* @param addressInfo student address.
12+
* @returns student profile snapshot.
13+
*/
14+
getStudentProfileSnapshot(
15+
firstName: string,
16+
lastName: string,
17+
sin: string,
18+
addressInfo: AddressInfo,
19+
): StudentProfileSnapshot {
20+
return {
21+
firstName: firstName,
22+
lastName: lastName,
23+
sin: sin,
24+
addressLine1: addressInfo.addressLine1,
25+
city: addressInfo.city,
26+
province: addressInfo.provinceState,
27+
postalCode: addressInfo.postalCode,
28+
country: addressInfo.country,
29+
};
30+
}
31+
}

sources/packages/backend/libs/services/src/index.ts

+1
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,4 @@ export * from "./student-loan-balance/student-loan-balance-shared.service";
3636
export * from "./clamav/services/clamav.service";
3737
export * from "./clamav/models/clamav.models";
3838
export * from "./clamav/clam-antivirus.module";
39+
export * from "./cas-supplier/cas-supplier.shared.service";

sources/packages/backend/libs/sims-db/src/entities/cas-supplier.model.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ export interface SupplierAddress {
163163
/**
164164
* Student profile snapshot information.
165165
*/
166-
interface StudentProfileSnapshot {
166+
export interface StudentProfileSnapshot {
167167
firstName: string;
168168
lastName: string;
169169
sin: string;

0 commit comments

Comments
 (0)