-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwalletRecharge.ts
44 lines (38 loc) · 1.14 KB
/
walletRecharge.ts
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
43
44
import fetch from "node-fetch";
import { Review, User } from "../models";
import { response } from "../utils/helper";
import WalletRecharge from "../models/WalletRecharge";
export const handler = async (event: any) => {
let body: any = event.body;
const { sub } = event?.requestContext?.authorizer?.claims;
let { customer_email, customer_mobile, amount, medium_payment_id, mode, medium } = JSON.parse(body);
const user = await User.findOne({
where: {
uuid: sub
}
});
console.log({
customer_uuid: sub,
customer_email,
customer_mobile,
amount,
medium_payment_id,
mode,
medium
});
if (mode === 'CREDIT' && amount) {
await user?.increment('wallet_balance', { by: parseFloat(amount) }).then(() => {
})
await WalletRecharge.create({
customer_uuid: sub,
customer_email,
customer_mobile,
amount,
medium_payment_id,
mode,
medium,
status: 'INITIATED'
}).then((res) => console.log(res))
}
return response(200, {});
}