Skip to content

Commit 50d34ef

Browse files
authored
#4390 - CAS Manual Intervention: Add CASInvoiceStatusUpdatedBy Column (#4467)
### As a part of this PR, the following have been completed: - Added the migration for the `CASInvoiceStatusUpdatedBy` column. **Rollback Screenshot:** <img width="815" alt="image" src="https://github.com/user-attachments/assets/43a2d311-ab3e-43b1-9c65-0124a6e0dff7" />
1 parent e0e7184 commit 50d34ef

File tree

6 files changed

+60
-1
lines changed

6 files changed

+60
-1
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import { MigrationInterface, QueryRunner } from "typeorm";
2+
import { getSQLFileData } from "../utilities/sqlLoader";
3+
4+
export class AddCASInvoiceStatusUpdatedByColumn1741646122852
5+
implements MigrationInterface
6+
{
7+
public async up(queryRunner: QueryRunner): Promise<void> {
8+
await queryRunner.query(
9+
getSQLFileData(
10+
"Add-cas-invoice-status-updated-by-column.sql",
11+
"CASInvoices",
12+
),
13+
);
14+
}
15+
16+
public async down(queryRunner: QueryRunner): Promise<void> {
17+
await queryRunner.query(
18+
getSQLFileData(
19+
"Rollback-add-cas-invoice-status-updated-by-column.sql",
20+
"CASInvoices",
21+
),
22+
);
23+
}
24+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
ALTER TABLE
2+
sims.cas_invoices
3+
ADD
4+
COLUMN invoice_status_updated_by INT REFERENCES sims.users(id);
5+
6+
COMMENT ON COLUMN sims.cas_invoices.invoice_status_updated_by IS 'User who updated the invoice status.';
7+
8+
-- Update the existing records with the creator.
9+
UPDATE
10+
sims.cas_invoices
11+
SET
12+
invoice_status_updated_by = creator;
13+
14+
-- Update the column to NOT NULL.
15+
ALTER TABLE
16+
sims.cas_invoices
17+
ALTER COLUMN
18+
invoice_status_updated_by
19+
SET
20+
NOT NULL;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
ALTER TABLE
2+
sims.cas_invoices DROP COLUMN invoice_status_updated_by;

sources/packages/backend/apps/queue-consumers/src/services/cas-invoice-batch/cas-invoice-batch.service.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@ export class CASInvoiceBatchService {
133133
): CASInvoice[] {
134134
const casInvoices: CASInvoice[] = [];
135135
const invoicesSummary = new ProcessSummary();
136+
const systemUser = this.systemUsersService.systemUser;
136137
parentProcessSummary.children(invoicesSummary);
137138
// Start processing the invoices for each pending receipt.
138139
for (const receipt of pendingReceipts) {
@@ -152,7 +153,8 @@ export class CASInvoiceBatchService {
152153
}`;
153154
newInvoice.invoiceStatus = CASInvoiceStatus.Pending;
154155
newInvoice.invoiceStatusUpdatedOn = referenceDate;
155-
newInvoice.creator = this.systemUsersService.systemUser;
156+
newInvoice.creator = systemUser;
157+
newInvoice.invoiceStatusUpdatedBy = systemUser;
156158
newInvoice.createdAt = referenceDate;
157159
newInvoice.updatedAt = referenceDate;
158160
// Create invoice details.

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

+10
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import {
1414
CASSupplier,
1515
CASInvoiceStatus,
1616
CASInvoiceDetail,
17+
User,
1718
} from ".";
1819

1920
/**
@@ -79,6 +80,15 @@ export class CASInvoice extends RecordDataModel {
7980
type: "timestamptz",
8081
})
8182
invoiceStatusUpdatedOn: Date;
83+
/**
84+
* User that changed the status last time.
85+
*/
86+
@ManyToOne(() => User, { nullable: false })
87+
@JoinColumn({
88+
name: "invoice_status_updated_by",
89+
referencedColumnName: ColumnNames.ID,
90+
})
91+
invoiceStatusUpdatedBy: User;
8292
/**
8393
* Invoice details.
8494
*/

sources/packages/backend/libs/test-utils/src/factories/cas-invoice.ts

+1
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ export function createFakeCASInvoice(relations: {
3535
casInvoice.invoiceStatus = CASInvoiceStatus.Pending;
3636
casInvoice.invoiceStatusUpdatedOn = now;
3737
casInvoice.creator = relations.creator;
38+
casInvoice.invoiceStatusUpdatedBy = relations.creator;
3839
return casInvoice;
3940
}
4041

0 commit comments

Comments
 (0)