Skip to content

Commit 4f47313

Browse files
committed
Add an override flag for the post-dated business logic, for testing later
1 parent 4c65bd4 commit 4f47313

1 file changed

Lines changed: 21 additions & 0 deletions

File tree

packages/postDatedLambda/src/businessLogic.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ import {Logger} from "@aws-lambda-powertools/logger"
22

33
import {PostDatedSQSMessageWithExistingRecords} from "./types"
44

5+
const POST_DATED_OVERRIDE = process.env.POST_DATED_OVERRIDE === "true"
6+
const POST_DATED_OVERRIDE_VALUE = process.env.POST_DATED_OVERRIDE_VALUE === "true"
7+
58
/**
69
* Process a single post-dated prescription message.
710
* This is a placeholder function that I'll implement properly later.
@@ -20,6 +23,12 @@ export async function processMessage(
2023
existingRecordsCount: message.existingRecords.length,
2124
existingRecordTaskIds: message.existingRecords.map((r) => r.TaskID)
2225
})
26+
if (POST_DATED_OVERRIDE) {
27+
logger.info("Post-dated override is enabled, returning override value", {
28+
overrideValue: POST_DATED_OVERRIDE_VALUE
29+
})
30+
return POST_DATED_OVERRIDE_VALUE
31+
}
2332

2433
// TODO: Implement actual business logic for post-dated prescription processing
2534
// The existingRecords array contains all records from the DynamoDB table
@@ -28,5 +37,17 @@ export async function processMessage(
2837
// NOTE: It is technically possible for the array to be empty if no existing records are found
2938
// This SHOULD never happen in practice, but the code should handle it gracefully just in case
3039

40+
const mostRecentRecord = message.existingRecords.reduce((latest, record) => {
41+
return new Date(record.LastModified) > new Date(latest.LastModified) ? record : latest
42+
}, message.existingRecords[0])
43+
const mostRecentLastModified = new Date(mostRecentRecord.LastModified)
44+
const desiredTransitionTime = new Date(mostRecentRecord.PostDatedLastModifiedSetAt as string)
45+
const currentTime = new Date()
46+
logger.info("Post-dated prescription timing details", {
47+
mostRecentLastModified: mostRecentLastModified.toISOString(),
48+
desiredTransitionTime: desiredTransitionTime.toISOString(),
49+
currentTime: currentTime.toISOString()
50+
})
51+
3152
return true
3253
}

0 commit comments

Comments
 (0)