From 31e7968689b8287e2a0e7422986cc03959e49c0d Mon Sep 17 00:00:00 2001 From: Andie Swift Date: Thu, 20 Feb 2025 15:27:37 -0600 Subject: [PATCH] fix(lambda): Split Spa & NOSO timestamp bugs (#1165) * added type for statusDate & also changed NOSO timestamp to use same time as others --------- Co-authored-by: tiffanyvu --- lib/lambda/sinkChangelog.test.ts | 28 ++++++++++++++++++ lib/lambda/sinkMainProcessors.test.ts | 24 ++++++++++++++++ lib/lambda/submit/submitSplitSPA.ts | 14 ++++----- lib/lambda/update/adminChangeSchemas.ts | 21 +++++++++++--- lib/lambda/update/submitNOSO.ts | 32 +++++++++------------ lib/lambda/update/updatePackage.ts | 38 +++++++++++++++++++++++++ 6 files changed, 125 insertions(+), 32 deletions(-) diff --git a/lib/lambda/sinkChangelog.test.ts b/lib/lambda/sinkChangelog.test.ts index 4813300a62..6a2d090384 100644 --- a/lib/lambda/sinkChangelog.test.ts +++ b/lib/lambda/sinkChangelog.test.ts @@ -172,6 +172,9 @@ describe("syncing Changelog events", () => { isAdminChange: true, adminChangeType: "update-id", idToBeUpdated: TEST_ITEM_ID, + makoChangedDate: TIMESTAMP, + changedDate: TIMESTAMP, + statusDate: TIMESTAMP, timestamp: TIMESTAMP, }), offset: 3, @@ -208,6 +211,9 @@ describe("syncing Changelog events", () => { isAdminChange: true, adminChangeType: "update-values", additionalInformation: "changed additional information", + makoChangedDate: TIMESTAMP, + changedDate: TIMESTAMP, + statusDate: TIMESTAMP, timestamp: TIMESTAMP, }), offset: 3, @@ -230,6 +236,9 @@ describe("syncing Changelog events", () => { submitterName: "George Harrison", submitterEmail: "george@example.com", additionalInformation: "changed additional information", + makoChangedDate: expect.any(Number), + changedDate: expect.any(Number), + statusDate: expect.any(Number), timestamp: expect.any(Number), }, ]); @@ -249,6 +258,9 @@ describe("syncing Changelog events", () => { isAdminChange: true, adminChangeType: "update-values", additionalInformation: "changed additional information", + makoChangedDate: TIMESTAMP, + changedDate: TIMESTAMP, + statusDate: TIMESTAMP, timestamp: TIMESTAMP, }), offset: 3, @@ -264,6 +276,9 @@ describe("syncing Changelog events", () => { isAdminChange: true, adminChangeType: "update-id", idToBeUpdated: TEST_ITEM_ID, + makoChangedDate: TIMESTAMP, + changedDate: TIMESTAMP, + statusDate: TIMESTAMP, timestamp: TIMESTAMP, }), offset: 3, @@ -293,6 +308,9 @@ describe("syncing Changelog events", () => { submitterName: "George Harrison", submitterEmail: "george@example.com", additionalInformation: "changed additional information", + makoChangedDate: expect.any(Number), + changedDate: expect.any(Number), + statusDate: expect.any(Number), timestamp: expect.any(Number), }, { @@ -306,6 +324,9 @@ describe("syncing Changelog events", () => { submitterName: "George Harrison", submitterEmail: "george@example.com", additionalInformation: "changed additional information", + makoChangedDate: expect.any(Number), + changedDate: expect.any(Number), + statusDate: expect.any(Number), timestamp: expect.any(Number), }, ...expectedChangelogs, @@ -359,6 +380,10 @@ describe("syncing Changelog events", () => { deleted: false, submitterName: "George Harrison", submitterEmail: "george@example.com", + makoChangedDate: TIMESTAMP, + changedDate: TIMESTAMP, + statusDate: TIMESTAMP, + timestamp: TIMESTAMP, }), offset: 3, }), @@ -383,6 +408,9 @@ describe("syncing Changelog events", () => { packageId: TEST_ITEM_ID, submitterName: "George Harrison", submitterEmail: "george@example.com", + makoChangedDate: expect.any(Number), + changedDate: expect.any(Number), + statusDate: expect.any(Number), timestamp: expect.any(Number), }, ]); diff --git a/lib/lambda/sinkMainProcessors.test.ts b/lib/lambda/sinkMainProcessors.test.ts index 11d5b93565..d3bb26e0af 100644 --- a/lib/lambda/sinkMainProcessors.test.ts +++ b/lib/lambda/sinkMainProcessors.test.ts @@ -312,6 +312,10 @@ describe("insertOneMacRecordsFromKafkaIntoMako", () => { changeMade: "ID has been updated.", submitterName: "George Harrison", submitterEmail: "george@example.com", + makoChangedDate: TIMESTAMP, + changedDate: TIMESTAMP, + statusDate: TIMESTAMP, + timestamp: TIMESTAMP, }), }), ], @@ -327,6 +331,10 @@ describe("insertOneMacRecordsFromKafkaIntoMako", () => { changeMade: "ID has been updated.", submitterName: "George Harrison", submitterEmail: "george@example.com", + makoChangedDate: TIMESTAMP, + changedDate: TIMESTAMP, + statusDate: TIMESTAMP, + timestamp: TIMESTAMP, }, ]); }); @@ -345,6 +353,10 @@ describe("insertOneMacRecordsFromKafkaIntoMako", () => { changeMade: "title has been updated.", submitterName: "George Harrison", submitterEmail: "george@example.com", + makoChangedDate: TIMESTAMP, + changedDate: TIMESTAMP, + statusDate: TIMESTAMP, + timestamp: TIMESTAMP, }), }), ], @@ -360,6 +372,10 @@ describe("insertOneMacRecordsFromKafkaIntoMako", () => { changeMade: "title has been updated.", submitterName: "George Harrison", submitterEmail: "george@example.com", + makoChangedDate: TIMESTAMP, + changedDate: TIMESTAMP, + statusDate: TIMESTAMP, + timestamp: TIMESTAMP, }, ]); }); @@ -377,6 +393,10 @@ describe("insertOneMacRecordsFromKafkaIntoMako", () => { deleted: false, submitterName: "George Harrison", submitterEmail: "george@example.com", + makoChangedDate: TIMESTAMP, + changedDate: TIMESTAMP, + statusDate: TIMESTAMP, + timestamp: TIMESTAMP, }), }), ], @@ -391,6 +411,10 @@ describe("insertOneMacRecordsFromKafkaIntoMako", () => { deleted: false, submitterName: "George Harrison", submitterEmail: "george@example.com", + makoChangedDate: TIMESTAMP, + changedDate: TIMESTAMP, + statusDate: TIMESTAMP, + timestamp: TIMESTAMP, }, ]); }); diff --git a/lib/lambda/submit/submitSplitSPA.ts b/lib/lambda/submit/submitSplitSPA.ts index fc73ef484a..f0b9f46710 100644 --- a/lib/lambda/submit/submitSplitSPA.ts +++ b/lib/lambda/submit/submitSplitSPA.ts @@ -7,15 +7,10 @@ import { events } from "shared-types/events"; import { getNextSplitSPAId } from "./getNextSplitSPAId"; import { z } from "zod"; -/* -EXAMPLE EVENT JSON: -{ - "body": { - "packageId": "MD-25-9999" - } -} -*/ - +/** @typedef {object} json + * @property {object} body + * @property {string} body.packageId + */ const sendSubmitSplitSPAMessage = async (currentPackage: ItemResult) => { const topicName = process.env.topicName as string; if (!topicName) { @@ -46,6 +41,7 @@ const sendSubmitSplitSPAMessage = async (currentPackage: ItemResult) => { makoChangedDate: currentTime, changedDate: currentTime, timestamp: currentTime, + statusDate: currentTime, origin: "OneMAC", changeMade: "OneMAC Admin has added a package to OneMAC.", changeReason: "Per request from CMS, this package was added to OneMAC.", diff --git a/lib/lambda/update/adminChangeSchemas.ts b/lib/lambda/update/adminChangeSchemas.ts index b3956627d5..9c920aafbb 100644 --- a/lib/lambda/update/adminChangeSchemas.ts +++ b/lib/lambda/update/adminChangeSchemas.ts @@ -5,6 +5,10 @@ export const deleteAdminChangeSchema = z id: z.string(), deleted: z.boolean(), adminChangeType: z.literal("delete"), + makoChangedDate: z.number(), + changedDate: z.number(), + statusDate: z.number(), + timestamp: z.number(), }) .and(z.record(z.string(), z.any())); @@ -12,6 +16,10 @@ export const updateValuesAdminChangeSchema = z .object({ id: z.string(), adminChangeType: z.literal("update-values"), + makoChangedDate: z.number(), + changedDate: z.number(), + statusDate: z.number(), + timestamp: z.number(), }) .and(z.record(z.string(), z.any())); @@ -20,6 +28,10 @@ export const updateIdAdminChangeSchema = z id: z.string(), adminChangeType: z.literal("update-id"), idToBeUpdated: z.string(), + makoChangedDate: z.number(), + changedDate: z.number(), + statusDate: z.number(), + timestamp: z.number(), }) .and(z.record(z.string(), z.any())); @@ -28,6 +40,10 @@ export const splitSPAAdminChangeSchema = z id: z.string(), adminChangeType: z.literal("split-spa"), idToBeUpdated: z.string(), + makoChangedDate: z.number(), + changedDate: z.number(), + statusDate: z.number(), + timestamp: z.number(), }) .and(z.record(z.string(), z.any())); @@ -37,7 +53,6 @@ export const transformDeleteSchema = (offset: number) => event: "delete", packageId: data.id, id: `${data.id}-${offset}`, - timestamp: Date.now(), })); export const transformUpdateValuesSchema = (offset: number) => @@ -46,7 +61,6 @@ export const transformUpdateValuesSchema = (offset: number) => event: "update-values", packageId: data.id, id: `${data.id}-${offset}`, - timestamp: Date.now(), })); export const transformedUpdateIdSchema = updateIdAdminChangeSchema.transform((data) => ({ @@ -54,7 +68,6 @@ export const transformedUpdateIdSchema = updateIdAdminChangeSchema.transform((da event: "update-id", packageId: data.id, id: `${data.id}`, - timestamp: Date.now(), })); export const transformedSplitSPASchema = splitSPAAdminChangeSchema.transform((data) => ({ @@ -82,6 +95,7 @@ export const extendSubmitNOSOAdminSchema = submitNOSOAdminSchema.extend({ makoChangedDate: z.number(), changedDate: z.number(), statusDate: z.number(), + timestamp: z.number(), isAdminChange: z.boolean(), state: z.string(), event: z.string(), @@ -95,5 +109,4 @@ export const transformSubmitValuesSchema = extendSubmitNOSOAdminSchema.transform event: "NOSO", id: data.id, packageId: data.id, - timestamp: Date.now(), })); diff --git a/lib/lambda/update/submitNOSO.ts b/lib/lambda/update/submitNOSO.ts index 9eaf66762a..24b4f1f201 100644 --- a/lib/lambda/update/submitNOSO.ts +++ b/lib/lambda/update/submitNOSO.ts @@ -8,25 +8,18 @@ import { z } from "zod"; import { getStatus } from "shared-types"; -/* -EXAMPLE EVENT JSON: - -{ - "body": { - "id": "CO-34304.R00.01", - "authority": "1915(c)", - "status": "Submitted", - "submitterEmail": "george@example.com", - "submitterName": "George Harrison", - "adminChangeType": "NOSO", - "mockEvent": "app-k", //needed for future actions - "changeMade": "CO-34304.R00.01 added to OneMAC.Package not originally submitted in OneMAC. Contact your CPOC to verify the initial submission documents.", - "changeReason": "Per request from CMS, this package was added to OneMAC." - } -} - -*/ - +/** @typedef {object} json + * @property {object} body + * @property {string} body.id + * @property {string} body.authority + * @property {string} body.status + * @property {string} body.submitterEmail + * @property {string} body.submitterName + * @property {string} body.adminChangeType + * @property {string} body.mockEvent + * @property {string} body.changeMade + * @property {string} body.changeReason + */ interface submitMessageType { id: string; authority: string; @@ -61,6 +54,7 @@ const sendSubmitMessage = async (item: submitMessageType) => { makoChangedDate: currentTime, changedDate: currentTime, statusDate: currentTime, + timestamp: currentTime, }), ); diff --git a/lib/lambda/update/updatePackage.ts b/lib/lambda/update/updatePackage.ts index 038ba8760a..edb7577a82 100644 --- a/lib/lambda/update/updatePackage.ts +++ b/lib/lambda/update/updatePackage.ts @@ -7,11 +7,19 @@ import { getPackageType } from "./getPackageType"; import { events } from "shared-types"; import { z } from "zod"; +/** @typedef {object} json + * @property {object} body + * @property {string} body.packageId + * @property {string} body.action + */ const sendDeleteMessage = async (packageId: string) => { const topicName = process.env.topicName as string; if (!topicName) { throw new Error("Topic name is not defined"); } + + const currentTime = Date.now(); + await produceMessage( topicName, packageId, @@ -20,6 +28,10 @@ const sendDeleteMessage = async (packageId: string) => { deleted: true, isAdminChange: true, adminChangeType: "delete", + makoChangedDate: currentTime, + changedDate: currentTime, + statusDate: currentTime, + timestamp: currentTime, }), ); @@ -29,6 +41,14 @@ const sendDeleteMessage = async (packageId: string) => { }); }; +/** @typedef {object} json + * @property {object} body + * @property {string} body.packageId + * @property {string} body.action + * @property {object} body.updatedFields + * @property {string} body.updatedFields.title + */ + const sendUpdateValuesMessage = async ({ currentPackage, updatedFields, @@ -64,6 +84,8 @@ const sendUpdateValuesMessage = async ({ Object.keys(updatedFields).length > 1 ? "have" : "has" } been updated`; + const currentTime = Date.now(); + await produceMessage( topicName, currentPackage._id, @@ -74,6 +96,10 @@ const sendUpdateValuesMessage = async ({ adminChangeType: "update-values", changeMade: changeMadeText, changeReason, + makoChangedDate: currentTime, + changedDate: currentTime, + statusDate: currentTime, + timestamp: currentTime, }), ); @@ -83,6 +109,12 @@ const sendUpdateValuesMessage = async ({ }); }; +/** @typedef {object} json + * @property {object} body + * @property {string} body.packageId + * @property {string} body.action + * @property {string} body.updatedId + */ const sendUpdateIdMessage = async ({ currentPackage, updatedId, @@ -131,6 +163,8 @@ const sendUpdateIdMessage = async ({ await sendDeleteMessage(currentPackage._id); + const currentTime = Date.now(); + await produceMessage( topicName, updatedId, @@ -142,6 +176,10 @@ const sendUpdateIdMessage = async ({ changeMade: "ID has been updated.", isAdminChange: true, adminChangeType: "update-id", + makoChangedDate: currentTime, + changedDate: currentTime, + statusDate: currentTime, + timestamp: currentTime, }), );