Template
1
0

feat: add payment module

This commit is contained in:
2025-12-05 01:56:42 +01:00
parent a818f3135a
commit be9b8e9e55
160 changed files with 8615 additions and 1158 deletions

View File

@@ -0,0 +1,4 @@
import { createAccount } from "../../../repositories/account.ts";
import route from "./spec.ts";
export default route.access("public").handle(async ({ body }) => createAccount(body));

View File

@@ -0,0 +1,6 @@
import { route } from "@platform/relay";
import z from "zod";
import { AccountInsertSchema } from "../../../schemas/account.ts";
export default route.post("/api/v1/payment/accounts").body(AccountInsertSchema).response(z.uuid());

View File

@@ -0,0 +1,12 @@
import { NotFoundError } from "@platform/relay";
import { getBeneficiaryById } from "../../../repositories/beneficiary.ts";
import route from "./spec.ts";
export default route.access("public").handle(async ({ params: { id } }) => {
const beneficiary = await getBeneficiaryById(id);
if (beneficiary === undefined) {
return new NotFoundError();
}
return beneficiary;
});

View File

@@ -0,0 +1,8 @@
import { route } from "@platform/relay";
import { BeneficiarySchema } from "../../../schemas/beneficiary.ts";
export default route
.get("/api/v1/payment/beneficiaries/:id")
.params({ id: BeneficiarySchema.shape._id })
.response(BeneficiarySchema);

View File

@@ -0,0 +1,4 @@
import { createBeneficiary } from "../../../repositories/beneficiary.ts";
import route from "./spec.ts";
export default route.access("public").handle(async ({ body }) => createBeneficiary(body));

View File

@@ -0,0 +1,5 @@
import { route } from "@platform/relay";
import { BeneficiaryInsertSchema, BeneficiarySchema } from "../../../schemas/beneficiary.ts";
export default route.post("/api/v1/payment/beneficiaries").body(BeneficiaryInsertSchema).response(BeneficiarySchema);

View File

@@ -0,0 +1,4 @@
import { getLedgersByBeneficiary } from "../../../repositories/ledger.ts";
import route from "./spec.ts";
export default route.access("public").handle(async ({ params: { id } }) => getLedgersByBeneficiary(id));

View File

@@ -0,0 +1,9 @@
import { route } from "@platform/relay";
import z from "zod";
import { LedgerSchema } from "../../../schemas/ledger.ts";
export default route
.get("/api/v1/payment/beneficiaries/:id/ledgers")
.params({ id: z.uuid() })
.response(z.array(LedgerSchema));

View File

@@ -0,0 +1,4 @@
import { getBeneficiaries } from "../../../repositories/beneficiary.ts";
import route from "./spec.ts";
export default route.access("public").handle(async () => getBeneficiaries());

View File

@@ -0,0 +1,6 @@
import { route } from "@platform/relay";
import z from "zod";
import { BeneficiarySchema } from "../../../schemas/beneficiary.ts";
export default route.get("/api/v1/payment/beneficiaries").response(z.array(BeneficiarySchema));

View File

@@ -0,0 +1,31 @@
import { db } from "@platform/database";
import { NotFoundError } from "@platform/relay";
import route, { DashboardSchema } from "./spec.ts";
export default route.access("public").handle(async ({ params: { id } }) => {
const dashboard = await db.schema(DashboardSchema).one`
SELECT
pb.*,
pb._system_from AS "createdAt",
NEST_MANY(
SELECT
pl.*,
pl._system_from AS "createdAt",
FROM
payment.ledger pl
WHERE
pl."beneficiaryId" = pb._id
ORDER BY
pl._id
) AS ledgers
FROM
payment.beneficiary pb
WHERE
pb._id = ${id}
`;
if (dashboard === undefined) {
return new NotFoundError("Beneficiary not found");
}
return dashboard;
});

View File

@@ -0,0 +1,16 @@
import { nestMany } from "@platform/parse";
import { route } from "@platform/relay";
import z from "zod";
import { BeneficiarySchema } from "../../schemas/beneficiary.ts";
import { LedgerSchema } from "../../schemas/ledger.ts";
export const DashboardSchema = z.strictObject({
...BeneficiarySchema.shape,
ledgers: nestMany(LedgerSchema),
});
export default route
.get("/api/v1/payment/dashboard/:id")
.params({ id: BeneficiarySchema.shape._id })
.response(DashboardSchema);

View File

@@ -0,0 +1,4 @@
import { createLedger } from "../../../repositories/ledger.ts";
import route from "./spec.ts";
export default route.access("public").handle(async ({ body }) => createLedger(body));

View File

@@ -0,0 +1,6 @@
import { route } from "@platform/relay";
import z from "zod";
import { LedgerInsertSchema } from "../../../schemas/ledger.ts";
export default route.post("/api/v1/payment/ledgers").body(LedgerInsertSchema).response(z.uuid());

View File

@@ -0,0 +1,4 @@
import { getWalletsByLedgerId } from "../../../repositories/wallet.ts";
import route from "./spec.ts";
export default route.access("public").handle(async ({ params: { id } }) => getWalletsByLedgerId(id));

View File

@@ -0,0 +1,9 @@
import { route } from "@platform/relay";
import z from "zod";
import { WalletSchema } from "../../../schemas/wallet.ts";
export default route
.get("/api/v1/payment/ledgers/:id/wallets")
.params({ id: z.uuid() })
.response(z.array(WalletSchema));

View File

@@ -0,0 +1,4 @@
import { getAccountsByWalletId } from "../../../repositories/account.ts";
import route from "./spec.ts";
export default route.access("public").handle(async ({ params: { id } }) => getAccountsByWalletId(id));

View File

@@ -0,0 +1,9 @@
import { route } from "@platform/relay";
import z from "zod";
import { AccountSchema } from "../../../schemas/account.ts";
export default route
.get("/api/v1/payment/wallets/:id/accounts")
.params({ id: z.uuid() })
.response(z.array(AccountSchema));

View File

@@ -0,0 +1,4 @@
import { createWallet } from "../../../repositories/wallet.ts";
import route from "./spec.ts";
export default route.access("public").handle(async ({ body }) => createWallet(body));

View File

@@ -0,0 +1,6 @@
import { route } from "@platform/relay";
import z from "zod";
import { WalletInsertSchema } from "../../../schemas/wallet.ts";
export default route.post("/api/v1/payment/wallets").body(WalletInsertSchema).response(z.uuid());