Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 | 3x 2x 2x 2x 2x 1x 1x 1x 1x 1x 1x 1x 1x | import { APIGatewayEvent } from "aws-lambda";
import { getAuthDetails, lookupUserAttributes } from "libs/api/auth/user";
import { itemExists } from "libs/api/package";
import { events } from "shared-types";
import { getUserByEmail } from "../../user-management/userManagementService";
export const uploadSubsequentDocuments = async (event: APIGatewayEvent) => {
Iif (event.body === null) return;
const parsedResult = events["upload-subsequent-documents"].baseSchema.safeParse(
JSON.parse(event.body),
);
Iif (parsedResult.success === false) {
throw parsedResult.error;
}
if ((await itemExists({ id: parsedResult.data.id })) === false) {
throw "Item Doesn't Exist";
}
const authDetails = getAuthDetails(event);
const userAttr = await lookupUserAttributes(authDetails.userId, authDetails.poolId);
const submitterEmail = userAttr.email;
const user = await getUserByEmail(submitterEmail);
Iif (!user) {
throw new Error("User does not exist in User OpenSearch Index");
}
const transformedData = events["upload-subsequent-documents"].schema.parse({
...parsedResult.data,
submitterName: user.fullName,
submitterEmail: user.email,
timestamp: Date.now(),
});
return transformedData;
};
|