-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into hcd-design-changes
- Loading branch information
Showing
42 changed files
with
711 additions
and
1,036 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 appK = async (event: APIGatewayEvent) => { | ||
if (!event.body) return; | ||
|
||
const parsedResult = events["app-k"].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"; | ||
} | ||
|
||
// This is the backend check for the item already existing | ||
if (await itemExists({ id: parsedResult.data.id })) { | ||
throw "Item Already Exists"; | ||
} | ||
|
||
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["app-k"].schema.parse({ | ||
...parsedResult.data, | ||
submitterName, | ||
submitterEmail, | ||
timestamp: Date.now(), | ||
}); | ||
|
||
return transformedData; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.