diff --git a/packages/functions/src/consumer.ts b/packages/functions/src/consumer.ts index 1c62b65..1dca685 100644 --- a/packages/functions/src/consumer.ts +++ b/packages/functions/src/consumer.ts @@ -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"; diff --git a/packages/functions/src/triggers/postConfirmation.ts b/packages/functions/src/triggers/postConfirmation.ts index 7e8a98e..8dbb4c8 100644 --- a/packages/functions/src/triggers/postConfirmation.ts +++ b/packages/functions/src/triggers/postConfirmation.ts @@ -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; @@ -16,3 +12,7 @@ export const handler = async (event: any) => { return event; }; + +export const handler = middy(postHandler).use([ + connectDatabase(Config.POSTGRES_URL), +]);