Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rweb #211

Closed
wants to merge 24 commits into from
Closed

Rweb #211

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
8703769
feat(withdraw package):implement withdraw package functionality
Nov 15, 2023
53871cd
feat(merge master): merge master
Nov 15, 2023
c61ebbd
feat(merge master): merge master
Nov 15, 2023
ac42ea9
feat(withdraw package):implement withdraw package functionality
Nov 15, 2023
595f570
feat(withdraw package):implement withdraw package functionality
Nov 15, 2023
191c612
feat(withdraw package):implement withdraw package functionality
Nov 16, 2023
84efea3
feat(withdraw package):implement withdraw package functionality
Nov 16, 2023
1dc6c8d
feat(withdraw package):implement withdraw package functionality
Nov 16, 2023
319869f
feat(withdraw package):implement withdraw package functionality
Nov 16, 2023
d52ea5e
merging master
Nov 16, 2023
ff20b77
feat(withdraw package):implement withdraw package functionality
Nov 16, 2023
049c567
feat(withdraw package):implement withdraw package functionality
Nov 16, 2023
df9b9dc
Empty commit to re-deploy and fix back-end
Nov 17, 2023
97fd56a
go team... banner for no role case (#206)
Walesango2 Nov 20, 2023
41dbeca
Merge master
Nov 21, 2023
7bc0e0a
Fix deploy
Nov 21, 2023
f5f407a
Fix File not defined error
Nov 22, 2023
a7345e9
Fix deploy
Nov 22, 2023
e0f29c2
Re-export function
Nov 22, 2023
99a9530
Return action in getPackageActions
Nov 27, 2023
af608e3
feat(withdraw package):implement withdraw package functionality
Nov 29, 2023
f4ab601
feat(withdraw package):implement withdraw package functionality
Dec 1, 2023
3010c52
feat(withdraw package):implement withdraw package action
Dec 1, 2023
f2bb708
feat(withdraw package):implement withdraw package action
Dec 1, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions src/packages/shared-types/action-types/withdrawPackage.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { z, ZodArray } from "zod";
import { onemacAttachmentSchema } from "../onemac";

export const withdrawPackageSchema = (attachmentArrayType: ZodArray<any>) =>
z.object({
id: z.string(),
additionalInformation: z
.string()
.max(4000, "This field may only be up to 4000 characters.")
.optional(),
attachments: z.object({
supportingDocumentation: attachmentArrayType.optional(),
}),
});

export const withdrawPackageEventSchema = withdrawPackageSchema(
z.array(onemacAttachmentSchema)
);
export type WithdrawPackageEventSchema = z.infer<
typeof withdrawPackageEventSchema
>;
1 change: 1 addition & 0 deletions src/packages/shared-types/actions.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
export enum Action {
ENABLE_RAI_WITHDRAW = "enable-rai-withdraw",
WITHDRAW_PACKAGE = "withdraw-package",
DISABLE_RAI_WITHDRAW = "disable-rai-withdraw",
ISSUE_RAI = "issue-rai",
RESPOND_TO_RAI = "respond-to-rai",
Expand Down
1 change: 1 addition & 0 deletions src/packages/shared-types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ export * from "./actions";
export * from "./attachments";
export * from "./authority";
export * from "./action-types/withdraw-record";
export * from "./action-types/withdrawPackage";
2 changes: 1 addition & 1 deletion src/packages/shared-types/onemac.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { z } from "zod";
import { s3ParseUrl } from "shared-utils/s3-url-parser";

const onemacAttachmentSchema = z.object({
export const onemacAttachmentSchema = z.object({
s3Key: z.string().nullish(),
filename: z.string(),
title: z.string(),
Expand Down
4 changes: 4 additions & 0 deletions src/services/api/handlers/action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
issueRai,
respondToRai,
toggleRaiResponseWithdraw,
withdrawPackage
} from "./packageActions";

export const handler = async (event: APIGatewayEvent) => {
Expand Down Expand Up @@ -53,6 +54,9 @@ export const handler = async (event: APIGatewayEvent) => {

// Call package action
switch (actionType) {
case Action.WITHDRAW_PACKAGE:
await withdrawPackage(body);
break;
case Action.ISSUE_RAI:
await issueRai(body);
break;
Expand Down
5 changes: 1 addition & 4 deletions src/services/api/handlers/getPackageActions.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { APIGatewayEvent } from "aws-lambda";
import { Action, CognitoUserAttributes, ItemResult } from "shared-types";
import {
isCmsUser,

Check warning on line 4 in src/services/api/handlers/getPackageActions.ts

View workflow job for this annotation

GitHub Actions / lint

'isCmsUser' is defined but never used

Check warning on line 4 in src/services/api/handlers/getPackageActions.ts

View workflow job for this annotation

GitHub Actions / lint

'isCmsUser' is defined but never used
getActiveRai,
isCmsWriteUser,
isStateUser,
Expand Down Expand Up @@ -53,6 +53,7 @@
}
}
} else if (isStateUser(user)) {
actions.push(Action.WITHDRAW_PACKAGE);
switch (result._source.seatoolStatus) {
case SEATOOL_STATUS.PENDING_RAI:
if (activeRai) {
Expand All @@ -67,7 +68,6 @@
export const getPackageActions = async (event: APIGatewayEvent) => {
const body = JSON.parse(event.body) as GetPackageActionsBody;
try {
console.log(body);
const result = await getPackage(body.id);
const passedStateAuth = await isAuthorized(event, result._source.state);
if (!passedStateAuth)
Expand All @@ -80,13 +80,11 @@
statusCode: 404,
body: { message: "No record found for the given id" },
});

const authDetails = getAuthDetails(event);
const userAttr = await lookupUserAttributes(
authDetails.userId,
authDetails.poolId
);

return response({
statusCode: 200,
body: {
Expand All @@ -101,5 +99,4 @@
});
}
};

export const handler = getPackageActions;
57 changes: 55 additions & 2 deletions src/services/api/handlers/packageActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,15 @@
database: "SEA",
};

import { Action, raiSchema, RaiSchema } from "shared-types";
import {
Action,
raiSchema,
RaiSchema,
OneMacSink,

Check warning on line 19 in src/services/api/handlers/packageActions.ts

View workflow job for this annotation

GitHub Actions / lint

'OneMacSink' is defined but never used

Check warning on line 19 in src/services/api/handlers/packageActions.ts

View workflow job for this annotation

GitHub Actions / lint

'OneMacSink' is defined but never used
WithdrawPackageEventSchema,
transformOnemac,
withdrawPackageEventSchema,
} from "shared-types";
import { produceMessage } from "../libs/kafka";
import { response } from "../libs/handler";
import { SEATOOL_STATUS } from "shared-types/statusHelper";
Expand Down Expand Up @@ -140,8 +148,53 @@
console.log("heyo");
}

export async function withdrawPackage(id, timestamp) {
export async function withdrawPackage(body: WithdrawPackageEventSchema) {
console.log("State withdrawing a package.");
// Check incoming data
const result = withdrawPackageEventSchema.safeParse(body);
if (result.success === false) {
console.error(
"Withdraw Package event validation error. The following record failed to parse: ",
JSON.stringify(body),
"Because of the following Reason(s):",
result.error.message
);
return response({
statusCode: 400,
body: { message: "Withdraw Package event validation error" },
});
}
// Begin query (data is confirmed)
const pool = await sql.connect(config);
const transaction = new sql.Transaction(pool);
const query = `
UPDATE SEA.dbo.State_Plan
SET SPW_Status_ID = (Select SPW_Status_ID from SEA.dbo.SPW_Status where SPW_Status_DESC = '${SEATOOL_STATUS.WITHDRAWN}')
WHERE ID_Number = '${body.id}'
`;

try {
const txnResult = await transaction.request().query(query);
console.log(txnResult);
await produceMessage(
TOPIC_NAME,
body.id,
JSON.stringify({ ...result.data, actionType: Action.WITHDRAW_PACKAGE })
);
// Commit transaction
await transaction.commit();
} catch (err) {
// Rollback and log
await transaction.rollback();
console.error("Error executing query:", err);
return response({
statusCode: 500,
body: { message: err.message },
});
} finally {
// Close pool
await pool.close();
}
}

export async function toggleRaiResponseWithdraw(
Expand Down
2 changes: 0 additions & 2 deletions src/services/api/handlers/search.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ export const getSearchData = async (event: APIGatewayEvent) => {
if (event.body) {
query = JSON.parse(event.body);
}

query.query = query?.query || {};
query.query.bool = query.query?.bool || {};
query.query.bool.must = query.query.bool?.must || [];
Expand All @@ -30,7 +29,6 @@ export const getSearchData = async (event: APIGatewayEvent) => {
console.log(JSON.stringify(query, null, 2));

const results = await os.search(process.env.osDomain, "main", query);

return response<unknown>({
statusCode: 200,
body: results,
Expand Down
Loading
Loading