forked from Lilly-Protocol/lily-backend
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpayments.controller.ts
More file actions
57 lines (49 loc) · 1.57 KB
/
Copy pathpayments.controller.ts
File metadata and controls
57 lines (49 loc) · 1.57 KB
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
45
46
47
48
49
50
51
52
53
54
55
56
57
import type { Request, Response } from "express";
import { asyncHandler } from "../../common/http/async-handler";
import type { ApiSuccessResponse } from "../../common/types/api-response";
import { paymentsService } from "./payments.service";
import type { ExecutePaymentInput } from "./payments.types";
interface CreateQuoteBody {
sourceAsset: string;
destinationAsset: string;
sourceAmount: string;
}
export const createQuote = asyncHandler(
async (
request: Request,
response: Response<
ApiSuccessResponse<ReturnType<typeof paymentsService.createQuote>>
>,
) => {
const body = request.body as CreateQuoteBody;
const result = paymentsService.createQuote({
sourceAsset: body.sourceAsset,
destinationAsset: body.destinationAsset,
sourceAmount: body.sourceAmount,
});
response.status(201).json({ success: true, data: result });
},
);
export const getQuote = asyncHandler(
async (
request: Request,
response: Response<
ApiSuccessResponse<ReturnType<typeof paymentsService.getQuoteById>>
>,
) => {
const result = paymentsService.getQuoteById(request.params.id);
response.status(200).json({ success: true, data: result });
},
);
export const executePayment = asyncHandler(
async (
request: Request,
response: Response<
ApiSuccessResponse<ReturnType<typeof paymentsService.executePayment>>
>,
) => {
const body = request.body as ExecutePaymentInput;
const result = paymentsService.executePayment(body);
response.status(200).json({ success: true, data: result });
},
);