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

feat(package-actions): remove withdraw rai writes from seatool #800

Open
wants to merge 47 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 35 commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
c4e85b3
wip fix backend
Sep 30, 2024
8ecdc5d
add withdraw rai to submission playloads
Sep 30, 2024
690bc33
add logs
Oct 1, 2024
7f8e197
add more logs
Oct 1, 2024
d3d4c91
more logs
Oct 1, 2024
8ce69d8
remove item exists check
Oct 1, 2024
1c82bda
fix schema extend
Oct 1, 2024
82de788
in sink main
Oct 1, 2024
3fb231e
add withdraw-rai to transforms
Oct 1, 2024
5fec41c
log record
Oct 1, 2024
be90811
fix schema transform
Oct 1, 2024
e8c1c10
test withdraw rai submission
Oct 3, 2024
01dc7e2
add requestedRaidate
Oct 3, 2024
b16b6b9
remove extra base schema field
Oct 3, 2024
ee242cd
add locked field
Oct 3, 2024
61b68d2
update changelog transforms
Oct 9, 2024
02768d2
add withdraw-rai in opensearch changelog index
Oct 9, 2024
d22e6de
Merge branch 'main' into feat-rm-withdraw-rai-seatool
Oct 9, 2024
5196acb
fix package activity description
Oct 9, 2024
df567e8
fix package activity description
Oct 9, 2024
5d35d18
remove locked ui
Oct 9, 2024
e255dcf
add routing
13bfrancis Oct 9, 2024
c856346
Merge branch 'feat-rm-withdraw-rai-seatool' of https://github.com/Ent…
13bfrancis Oct 9, 2024
0dfa83f
Merge branch 'main' into feat-rm-withdraw-rai-seatool
Oct 10, 2024
872d2db
add routing changes and enable withdraw rai response
Oct 10, 2024
dcf7b19
fix elipsis hyperlink
Oct 10, 2024
0dd1c17
add enable and disable withdraw rai forms
Oct 11, 2024
f9d20fe
maybe fix everything for the backend maybe
Oct 11, 2024
b7b9578
fix imports
Oct 11, 2024
1ce22ce
not again
Oct 11, 2024
2338c15
event
Oct 11, 2024
acd1ac9
fix changelog
Oct 11, 2024
6bc09f5
remove console logs
Oct 15, 2024
ca23384
refactor actionForm additional information utilities
Oct 15, 2024
38d6c98
add additionalinfo check
Oct 15, 2024
f9f1b6a
Update lib/packages/shared-types/events/toggle-withdraw-rai.ts
tiffanyvu Oct 15, 2024
08e786f
Update react-app/src/features/package/package-activity/index.tsx
tiffanyvu Oct 15, 2024
5c467bd
fix rules
Oct 15, 2024
fa89784
magic??
Oct 16, 2024
4365d58
fix eslint
Oct 17, 2024
013de4d
fix error in test
Oct 17, 2024
8d14159
take out unused code
Oct 17, 2024
9355c39
change test to it
Oct 17, 2024
bca2975
make fields optional (fix #5 and #7)
13bfrancis Oct 18, 2024
44bc6fc
add additional info schema rules
tiffanyvu Oct 18, 2024
7dd4725
fix redirect on cms user
tiffanyvu Oct 22, 2024
bbb5c14
add locked property to not allow repeating action
tiffanyvu Oct 22, 2024
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ cdk.context.json
build_run
.build_run
DS_Store
.DS_Store

# legacy ignores
.serverless
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { toggleRaiResponseWithdraw } from "./toggle-rai-response-withdraw";
import { vi, describe, it, expect } from "vitest";
import { Action, toggleWithdrawRaiEnabledSchema } from "shared-types";
import { Action, events } from "shared-types";
import { generateMock } from "@anatine/zod-mock";
import * as packageActionWriteService from "../services/package-action-write-service";

Expand All @@ -25,7 +25,7 @@ describe("toggleRaiResponseWithdraw", async () => {
"toggleRaiResponseWithdrawAction",
);

const mockData = generateMock(toggleWithdrawRaiEnabledSchema);
const mockData = generateMock(events["toggle-withdraw-rai"].baseSchema);
const toggleRaiWithdraw = await toggleRaiResponseWithdraw(mockData);

expect(packageWriteSpy).toHaveBeenCalledOnce();
Expand All @@ -38,7 +38,7 @@ describe("toggleRaiResponseWithdraw", async () => {
"toggleRaiResponseWithdrawAction",
);

const mockData = generateMock(toggleWithdrawRaiEnabledSchema);
const mockData = generateMock(events["toggle-withdraw-rai"].baseSchema);
await toggleRaiResponseWithdraw({ ...mockData, toggle: true });

expect(packageWriteSpy).toHaveBeenCalledWith(
Expand All @@ -49,7 +49,7 @@ describe("toggleRaiResponseWithdraw", async () => {
});

it("calls package write service with action set to Disable RAI when toggle set to false", async () => {
const mockData = generateMock(toggleWithdrawRaiEnabledSchema);
const mockData = generateMock(events["toggle-withdraw-rai"].baseSchema);
await toggleRaiResponseWithdraw(mockData);
});
});
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { toggleWithdrawRaiEnabledSchema, Action } from "shared-types";
import { Action, events } from "shared-types";
import { response } from "../../../libs/handler-lib";
import { TOPIC_NAME } from "../consts";
import { toggleRaiResponseWithdrawAction } from "../services/package-action-write-service";
Expand All @@ -8,7 +8,7 @@ export async function toggleRaiResponseWithdraw({
...body
}: Record<string, unknown> & { toggle?: boolean }) {
const now = new Date().getTime();
const result = toggleWithdrawRaiEnabledSchema.safeParse({
const result = events["toggle-withdraw-rai"].baseSchema.safeParse({
...body,
raiWithdrawEnabled: toggle,
});
Expand Down
91 changes: 0 additions & 91 deletions lib/lambda/package-actions/withdraw-rai/withdraw-rai.test.ts

This file was deleted.

4 changes: 2 additions & 2 deletions lib/lambda/package-actions/withdraw-rai/withdraw-rai.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { raiWithdrawSchema, SEATOOL_STATUS, Action } from "shared-types";
import { events, SEATOOL_STATUS, Action } from "shared-types";
import { seaToolFriendlyTimestamp } from "shared-utils";
import { response } from "../../../libs/handler-lib";
import { TOPIC_NAME } from "../consts";
Expand Down Expand Up @@ -28,7 +28,7 @@ export async function withdrawRai(
const now = new Date().getTime();
const today = seaToolFriendlyTimestamp();

const result = raiWithdrawSchema.safeParse({
const result = events["withdraw-rai"].baseSchema.safeParse({
...body,
requestedDate: raiToWithdraw,
withdrawnDate: today,
Expand Down
3 changes: 0 additions & 3 deletions lib/lambda/sinkMain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,6 @@ const processAndIndex = async ({
}

// If the event is a supported event, transform and push to docs array for indexing
console.log("event below");
console.log(record.event);

if (record.event in transforms) {
const transformForEvent =
transforms[record.event as keyof typeof transforms];
Expand Down
4 changes: 4 additions & 0 deletions lib/lambda/submit/submissionPayloads/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import { contractingAmendment } from "./contracting-amendment";
import { contractingInitial } from "./contracting-initial";
import { contractingRenewal } from "./contracting-renewal";
import { temporaryExtension } from "./temporary-extension";
import { withdrawRai } from "./withdraw-rai";
import { toggleWithdrawRai } from "./toggle-withdraw-rai";

export const submissionPayloads = {
"capitated-amendment": capitatedAmendment,
Expand All @@ -18,4 +20,6 @@ export const submissionPayloads = {
"new-chip-submission": newChipSubmission,
"new-medicaid-submission": newMedicaidSubmission,
"temporary-extension": temporaryExtension,
"withdraw-rai": withdrawRai,
"toggle-withdraw-rai": toggleWithdrawRai,
};
46 changes: 46 additions & 0 deletions lib/lambda/submit/submissionPayloads/toggle-withdraw-rai.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import { events } from "shared-types/events";
import {
isAuthorized,
getAuthDetails,
lookupUserAttributes,
} from "../../../libs/api/auth/user";
import { type APIGatewayEvent } from "aws-lambda";
import { itemExists } from "libs/api/package";

export const toggleWithdrawRai = async (event: APIGatewayEvent) => {
if (!event.body) return;

const parsedResult = events["toggle-withdraw-rai"].baseSchema.safeParse(
JSON.parse(event.body),
);

if (!parsedResult.success) {
throw parsedResult.error;
}

// This is the backend check for auth
if (!(await isAuthorized(event, parsedResult.data.id.slice(0, 2)))) {
throw "Unauthorized";
}

if (!(await itemExists({ id: parsedResult.data.id }))) {
throw "Item Does Not Exist";
}

const authDetails = getAuthDetails(event);
const userAttr = await lookupUserAttributes(
authDetails.userId,
authDetails.poolId,
);
const submitterEmail = userAttr.email;
const submitterName = `${userAttr.given_name} ${userAttr.family_name}`;

const transformedData = events["toggle-withdraw-rai"].schema.parse({
...parsedResult.data,
submitterName,
submitterEmail,
timestamp: Date.now(),
});

return transformedData;
};
46 changes: 46 additions & 0 deletions lib/lambda/submit/submissionPayloads/withdraw-rai.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import { events } from "shared-types/events";
import {
isAuthorized,
getAuthDetails,
lookupUserAttributes,
} from "../../../libs/api/auth/user";
import { type APIGatewayEvent } from "aws-lambda";
import { itemExists } from "libs/api/package";

export const withdrawRai = async (event: APIGatewayEvent) => {
if (!event.body) return;

const parsedResult = events["withdraw-rai"].baseSchema.safeParse(
JSON.parse(event.body),
);

if (!parsedResult.success) {
throw parsedResult.error;
}

// This is the backend check for auth
if (!(await isAuthorized(event, parsedResult.data.id.slice(0, 2)))) {
throw "Unauthorized";
}

if (!(await itemExists({ id: parsedResult.data.id }))) {
throw "Item Does Not Exist";
}

const authDetails = getAuthDetails(event);
const userAttr = await lookupUserAttributes(
authDetails.userId,
authDetails.poolId,
);
const submitterEmail = userAttr.email;
const submitterName = `${userAttr.given_name} ${userAttr.family_name}`;

const transformedData = events["withdraw-rai"].schema.parse({
...parsedResult.data,
submitterName,
submitterEmail,
timestamp: Date.now(),
});

return transformedData;
};
3 changes: 0 additions & 3 deletions lib/lambda/submit/submit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ export const submit = async (event: APIGatewayEvent) => {

const body: BaseSchemas = JSON.parse(event.body);

console.log(body);

// If there's no event, we reject
if (!body.event) {
return response({
Expand All @@ -35,7 +33,6 @@ export const submit = async (event: APIGatewayEvent) => {

try {
const eventBody = await submissionPayloads[body.event](event);

await produceMessage(
process.env.topicName as string,
body.id,
Expand Down
5 changes: 4 additions & 1 deletion lib/packages/shared-types/events/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@ import * as contractingAmendment from "./contracting-amendment";
import * as contractingInitial from "./contracting-initial";
import * as contractingRenewal from "./contracting-renewal";
import * as temporaryExtension from "./temporary-extension";
import * as withdrawRai from "./withdraw-rai";
import * as toggleWithdrawRai from "./toggle-withdraw-rai";

export * from "./toggle-withdraw-rai-enabled";
export * from "./issue-rai";
export * from "./respond-to-rai";
export * from "./withdraw-rai";
Expand All @@ -32,6 +33,8 @@ export const events = {
"new-chip-submission": newChipSubmission,
"new-medicaid-submission": newMedicaidSubmission,
"temporary-extension": temporaryExtension,
"withdraw-rai": withdrawRai,
"toggle-withdraw-rai": toggleWithdrawRai,
};

export type BaseSchemas = z.infer<typeof newMedicaidSubmission.baseSchema>;
14 changes: 0 additions & 14 deletions lib/packages/shared-types/events/toggle-withdraw-rai-enabled.ts

This file was deleted.

28 changes: 28 additions & 0 deletions lib/packages/shared-types/events/toggle-withdraw-rai.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { z } from "zod";

// export const toggleWithdrawRaiEnabledSchema = z.object({
// id: z.string(),
// authority: z.string(),
// origin: z.string(),
// raiWithdrawEnabled: z.boolean(),
// submitterName: z.string(),
// submitterEmail: z.string(),
// timestamp: z.number().optional(),
// });
// export type ToggleWithdrawRaiEnabled = z.infer<
// typeof toggleWithdrawRaiEnabledSchema
// >;
tiffanyvu marked this conversation as resolved.
Show resolved Hide resolved

export const baseSchema = z.object({
event: z.literal("toggle-withdraw-rai").default("toggle-withdraw-rai"),
id: z.string(),
authority: z.string(),
raiWithdrawEnabled: z.boolean(),
});

export const schema = baseSchema.extend({
origin: z.literal("mako").default("mako"),
submitterName: z.string(),
submitterEmail: z.string().email(),
timestamp: z.number().optional(),
});
Loading
Loading