Skip to content

Commit

Permalink
adjust logic
Browse files Browse the repository at this point in the history
  • Loading branch information
tiffanyvu committed Jan 16, 2025
1 parent 2e9a427 commit 83f8839
Showing 1 changed file with 34 additions and 32 deletions.
66 changes: 34 additions & 32 deletions lib/lambda/update/updatePackage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,39 +120,41 @@ const sendUpdateIdMessage = async ({
});
}
console.log("AFTER HERE");
// use event of current package to determine how ID should be formatted
const packageEvent = await getPackageType(currentPackage._id);
console.log(packageEvent, "PACKAGE EVENT?");
const packageSubmissionTypeSchema = events[packageEvent as keyof typeof events].baseSchema;
console.log(packageSubmissionTypeSchema, "SCHEMA???");

const idSchema = packageSubmissionTypeSchema.shape.id;
console.log(idSchema, "ID SCHEMA???");
const parsedId = idSchema.safeParse(updatedId);
console.log(parsedId, "PARSED IDDD");

if (!parsedId.success) {
return response({
statusCode: 400,
body: parsedId.error.message,
});
}
if (packageExists === undefined || !packageExists.found) {
// use event of current package to determine how ID should be formatted
const packageEvent = await getPackageType(currentPackage._id);
console.log(packageEvent, "PACKAGE EVENT?");
const packageSubmissionTypeSchema = events[packageEvent as keyof typeof events].baseSchema;
console.log(packageSubmissionTypeSchema, "SCHEMA???");

const idSchema = packageSubmissionTypeSchema.shape.id;
console.log(idSchema, "ID SCHEMA???");
const parsedId = idSchema.safeParse(updatedId);
console.log(parsedId, "PARSED IDDD");

if (!parsedId.success) {
return response({
statusCode: 400,
body: parsedId.error.message,
});
}

await sendDeleteMessage(currentPackage._id);
console.log("JUST DELETED");
await produceMessage(
topicName,
updatedId,
JSON.stringify({
id: updatedId,
idToBeUpdated: currentPackage._id,
...remainingFields,
origin: "OneMAC",
changeMade: "ID has been updated.",
isAdminChange: true,
adminChangeType: "update-id",
}),
);
await sendDeleteMessage(currentPackage._id);
console.log("JUST DELETED");
await produceMessage(
topicName,
updatedId,
JSON.stringify({
id: updatedId,
idToBeUpdated: currentPackage._id,
...remainingFields,
origin: "OneMAC",
changeMade: "ID has been updated.",
isAdminChange: true,
adminChangeType: "update-id",
}),
);
}

return response({
statusCode: 200,
Expand Down

0 comments on commit 83f8839

Please sign in to comment.