|
| 1 | +import ConfirmCommand from "@Transaction/Application/Confirm/Command"; |
| 2 | +import FailCommand from "@Transaction/Application/Fail/Command"; |
| 3 | +import RefundCommand from "@Transaction/Application/Refund/Command"; |
| 4 | +import type {FastifyReply, FastifyRequest} from "fastify"; |
| 5 | +import { Application } from "hollywood-js"; |
| 6 | +import { IRoute } from "../index"; |
| 7 | + |
| 8 | +export function confirm(app: Application.App): IRoute { |
| 9 | + return { |
| 10 | + action: async (req: FastifyRequest, res: FastifyReply) => { |
| 11 | + const { uuid } = req.params as any; |
| 12 | + await app.handle(new ConfirmCommand(uuid)); |
| 13 | + res.status(204).send(); |
| 14 | + }, |
| 15 | + method: "patch", |
| 16 | + options: { |
| 17 | + schema: { |
| 18 | + params: { |
| 19 | + properties: { uuid: { type: "string" } }, |
| 20 | + type: "object", |
| 21 | + }, |
| 22 | + response: { 204: {}, 404: {}, 409: {} }, |
| 23 | + tags: ["Transactions"], |
| 24 | + }, |
| 25 | + }, |
| 26 | + path: "/transaction/:uuid/confirm", |
| 27 | + }; |
| 28 | +} |
| 29 | + |
| 30 | +export function fail(app: Application.App): IRoute { |
| 31 | + return { |
| 32 | + action: async (req: FastifyRequest, res: FastifyReply) => { |
| 33 | + const { uuid } = req.params as any; |
| 34 | + const { reason } = req.body as any; |
| 35 | + await app.handle(new FailCommand(uuid, reason ?? "")); |
| 36 | + res.status(204).send(); |
| 37 | + }, |
| 38 | + method: "patch", |
| 39 | + options: { |
| 40 | + schema: { |
| 41 | + body: { |
| 42 | + properties: { reason: { type: "string" } }, |
| 43 | + type: "object", |
| 44 | + }, |
| 45 | + params: { |
| 46 | + properties: { uuid: { type: "string" } }, |
| 47 | + type: "object", |
| 48 | + }, |
| 49 | + response: { 204: {}, 404: {}, 409: {} }, |
| 50 | + tags: ["Transactions"], |
| 51 | + }, |
| 52 | + }, |
| 53 | + path: "/transaction/:uuid/fail", |
| 54 | + }; |
| 55 | +} |
| 56 | + |
| 57 | +export function refund(app: Application.App): IRoute { |
| 58 | + return { |
| 59 | + action: async (req: FastifyRequest, res: FastifyReply) => { |
| 60 | + const { uuid } = req.params as any; |
| 61 | + await app.handle(new RefundCommand(uuid)); |
| 62 | + res.status(204).send(); |
| 63 | + }, |
| 64 | + method: "patch", |
| 65 | + options: { |
| 66 | + schema: { |
| 67 | + params: { |
| 68 | + properties: { uuid: { type: "string" } }, |
| 69 | + type: "object", |
| 70 | + }, |
| 71 | + response: { 204: {}, 404: {}, 409: {} }, |
| 72 | + tags: ["Transactions"], |
| 73 | + }, |
| 74 | + }, |
| 75 | + path: "/transaction/:uuid/refund", |
| 76 | + }; |
| 77 | +} |
0 commit comments