Skip to content

Commit

Permalink
feat(status memo): Write onemac activity to the Status Memo field (#352)
Browse files Browse the repository at this point in the history
  • Loading branch information
mdial89f authored Feb 1, 2024
1 parent 3941458 commit e0c9db0
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 0 deletions.
20 changes: 20 additions & 0 deletions src/services/api/handlers/packageActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import { produceMessage } from "../libs/kafka";
import { response } from "../libs/handler";
import { SEATOOL_STATUS } from "shared-types/statusHelper";
import { seaToolFriendlyTimestamp } from "shared-utils";
import { buildStatusMemoQuery } from "../libs/statusMemo";

const TOPIC_NAME = process.env.topicName as string;

Expand Down Expand Up @@ -59,6 +60,11 @@ export async function issueRai(body: RaiIssue) {
const result2 = await transaction.request().query(query2);
console.log(result2);

const statusMemoUpdate = await transaction
.request()
.query(buildStatusMemoQuery(body.id, "RAI Issued"));
console.log(statusMemoUpdate);

// write to kafka here
const result = raiIssueSchema.safeParse({ ...body, requestedDate: today });
if (result.success === false) {
Expand Down Expand Up @@ -133,6 +139,11 @@ export async function withdrawRai(body: RaiWithdraw, document: any) {
const result2 = await transaction.request().query(query2);
console.log(result2);

const statusMemoUpdate = await transaction
.request()
.query(buildStatusMemoQuery(result.data.id, "RAI Response Withdrawn"));
console.log(statusMemoUpdate);

// write to kafka here
await produceMessage(
TOPIC_NAME,
Expand Down Expand Up @@ -196,6 +207,11 @@ export async function respondToRai(body: RaiResponse, document: any) {
const result2 = await transaction.request().query(query2);
console.log(result2);

const statusMemoUpdate = await transaction
.request()
.query(buildStatusMemoQuery(body.id, "RAI Response Received"));
console.log(statusMemoUpdate);

// // write to kafka here
const result = raiResponseSchema.safeParse({
...body,
Expand Down Expand Up @@ -267,6 +283,10 @@ export async function withdrawPackage(body: WithdrawPackage) {
await transaction.begin();
const txnResult = await transaction.request().query(query);
console.log(txnResult);
const statusMemoUpdate = await transaction
.request()
.query(buildStatusMemoQuery(result.data.id, "Package Withdrawn"));
console.log(statusMemoUpdate);
await produceMessage(
TOPIC_NAME,
body.id,
Expand Down
6 changes: 6 additions & 0 deletions src/services/api/handlers/submit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ const config = {
import { Kafka, Message } from "kafkajs";
import { PlanType, onemacSchema, transformOnemac } from "shared-types";
import { seaToolFriendlyTimestamp } from "shared-utils";
import { buildStatusMemoQuery } from "../libs/statusMemo";

const kafka = new Kafka({
clientId: "submit",
Expand Down Expand Up @@ -80,6 +81,11 @@ export const submit = async (event: APIGatewayEvent) => {
const result = await sql.query(query);
console.log(result);

const statusMemoUpdate = await sql.query(
buildStatusMemoQuery(body.id, "Package Submitted")
);
console.log(statusMemoUpdate);

await pool.close();

const eventBody = onemacSchema.safeParse(body);
Expand Down
8 changes: 8 additions & 0 deletions src/services/api/libs/statusMemo.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
export function buildStatusMemoQuery(id: string, msg: string) {
return `
UPDATE SEA.dbo.State_Plan
SET
Status_Memo = '- OneMAC Activity: ' + FORMAT(DATEADD(SECOND, CAST('${Date.now()}' AS BIGINT) / 1000, '1970-01-01'), 'MM/dd/yyyy HH:mm') + ' - ' + '${msg} ' + '\r' + CAST(ISNULL(Status_Memo, '') AS VARCHAR(MAX))
WHERE ID_Number = '${id}'
`;
}

0 comments on commit e0c9db0

Please sign in to comment.