Skip to content

Commit

Permalink
renamed admin function files; fixed test error
Browse files Browse the repository at this point in the history
  • Loading branch information
andieswift committed Jan 21, 2025
1 parent abc05f1 commit 419cad2
Show file tree
Hide file tree
Showing 10 changed files with 30 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,22 @@ export const transformedUpdateIdSchema = updateIdAdminChangeSchema.transform((da
id: `${data.id}`,
timestamp: Date.now(),
}));

export const submitNOSOAdminSchema = z
.object({
packageId: z.string(),
event: z.literal("NOSO"),
adminChangeType: z.literal("NOSO"),
copyAttachmentsFrom: z.string().optional(),
})
.and(z.record(z.string(), z.any()));

export const transformSubmitValuesSchema = submitNOSOAdminSchema.transform((data) => ({
...data,
adminChangeType: "NOSO",
event: "NOSO",
id: data.packageId,
packageId: data.packageId,
timestamp: Date.now(),
copyAttachmentsFromId: z.string().optional(),
}));
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,8 @@ import { APIGatewayEvent } from "aws-lambda";
import { produceMessage } from "libs/api/kafka";
import { getPackage } from "libs/api/package";
import { getPackageChangelog } from "libs/api/package";
import { z } from "zod";
import { ItemResult } from "shared-types/opensearch/main";

// create admin schemas
export const submitNOSOAdminSchema = z
.object({
packageId: z.string(),
event: z.literal("NOSO"),
adminChangeType: z.literal("NOSO"),
copyAttachmentsFrom: z.string().optional(),
})
.and(z.record(z.string(), z.any()));

export const transformSubmitValuesSchema = submitNOSOAdminSchema.transform((data) => ({
...data,
adminChangeType: "NOSO",
event: "NOSO",
id: data.packageId,
packageId: data.packageId,
timestamp: Date.now(),
copyAttachmentsFromId: z.string().optional(),
}));
import { submitNOSOAdminSchema } from "./adminSchemas";

export const copyAttachments = async (data: any) => {
//ANDIE: change type not any
Expand Down Expand Up @@ -126,7 +106,7 @@ export const handler = async (event: APIGatewayEvent) => {
const { packageId, action, copyAttachmentsFromId } = submitNOSOAdminSchema.parse(
event.body === "string" ? JSON.parse(event.body) : event.body,
);
let currentPackage: ItemResult | undefined = await getPackage(packageId);
const currentPackage: ItemResult | undefined = await getPackage(packageId);

// currentpackage should have been entered in seaTool
if (!currentPackage || currentPackage.found == false) {
Expand Down
File renamed without changes.
File renamed without changes.
9 changes: 5 additions & 4 deletions lib/lambda/sinkChangelog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ import {
transformUpdateValuesSchema,
transformDeleteSchema,
transformedUpdateIdSchema,
} from "./update/adminChangeSchemas";
import { transformSubmitValuesSchema } from "./submit/submitNOSO";
import { getPackageChangelog } from "lib/libs/api/package";
import { copyAttachments } from "./submit/submitNOSO";
} from "./adminActions/adminSchemas";
import { transformSubmitValuesSchema } from "./adminActions/adminSchemas";
import { copyAttachments } from "./adminActions/submitNOSO";
import { getPackageChangelog } from "libs/api/package";

// One notable difference between this handler and sinkMain's...
// The order in which records are processed for the changelog doesn't matter.
Expand Down Expand Up @@ -90,6 +90,7 @@ const processAndIndex = async ({
});
});

//@ts-ignore
const packageChangelogs = await getPackageChangelog(result.data.idToBeUpdated);

packageChangelogs.hits.hits.forEach((log) => {
Expand Down
4 changes: 2 additions & 2 deletions lib/lambda/sinkMainProcessors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import {
deleteAdminChangeSchema,
updateValuesAdminChangeSchema,
updateIdAdminChangeSchema,
} from "./update/adminChangeSchemas";
import { submitNOSOAdminSchema } from "./submit/submitNOSO";
} from "./adminActions/adminSchemas";
import { submitNOSOAdminSchema } from "./adminActions/submitNOSO";

const removeDoubleQuotesSurroundingString = (str: string) => str.replace(/^"|"$/g, "");
const adminRecordSchema = deleteAdminChangeSchema
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import { TEST_ITEM_ID, WITHDRAWN_CHANGELOG_ITEM_ID } from "mocks";
import items from "mocks/data/items";
import { describe, expect, it } from "vitest";
import { getPackageChangelog } from "./changelog";
import { getPackageChangelog } from "./getPackageChangelog";

describe("getPackageChangelog", () => {
it("should throw an error if osDomain is not defined", async () => {
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion lib/libs/api/package/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export * from "./changelog";
export * from "./getPackageChangelog";
export * from "./getPackage";
export * from "./appk";
export * from "./itemExists";

0 comments on commit 419cad2

Please sign in to comment.