-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
39 lines (38 loc) · 1.13 KB
/
index.js
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
var aws = require("aws-sdk");
const { Book, Order, OrderItem, User, BookRent } = require("./db");
const db = require("./db/connection");
const BuildOrderEmail = require("./EmailTemplates/orderConfirmation");
const {
orderReceipt,
forgotPassword,
resendPayment,
} = require("./EventHandlers");
const EventTypes = require("./EventTypes");
aws.config.update({ region: "ap-south-1" });
var ses = new aws.SES({ apiVersion: "2010-12-01" });
exports.handler = async function (event, context, callback) {
try {
console.log("connecting to db");
await db.authenticate();
console.log("connected");
} catch (err) {
console.error(err);
}
console.log(event.type);
switch (event.type) {
case EventTypes.ORDER_RECEIPT:
await orderReceipt(event, callback, ses);
break;
case EventTypes.FORGOT_PASSWORD:
await forgotPassword(event, callback, ses);
break;
case EventTypes.RESEND_PAYMENT_LINK:
await resendPayment(event, callback, ses);
break;
default:
callback(null, {
statusCode: 400,
body: JSON.stringify({ code: 0, message: "invalid event type" }),
});
}
};