Skip to content

Commit

Permalink
add middy
Browse files Browse the repository at this point in the history
  • Loading branch information
tranlehaiquan committed Dec 17, 2023
1 parent fe93996 commit 48c8dc5
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 8 deletions.
1 change: 0 additions & 1 deletion packages/functions/src/consumer.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { SQSEvent } from "aws-lambda";
import { connectDB } from "./data-source";
import { Config } from "sst/node/config";
import { Capture } from "@website-capture/core/entity/Capture";

Expand Down
14 changes: 7 additions & 7 deletions packages/functions/src/triggers/postConfirmation.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
import { User } from "@website-capture/core/entity/User";
import { connectDB } from "../data-source";
import { Config } from "sst/node/config";
import middy from "@middy/core";
import { connectDatabase } from "@website-capture/core/middlewares";

export const handler = async (event: any) => {
// get config
const POSTGRES_URL = Config.POSTGRES_URL;
// connect db
await connectDB(POSTGRES_URL);

const postHandler = async (event: any) => {
const user = new User();
user.username = event.request.userAttributes.email;
user.cognitoId = event.userName;
Expand All @@ -16,3 +12,7 @@ export const handler = async (event: any) => {

return event;
};

export const handler = middy(postHandler).use([
connectDatabase(Config.POSTGRES_URL),
]);

0 comments on commit 48c8dc5

Please sign in to comment.