feat: add payment module
This commit is contained in:
31
modules/payment/routes/dashboard/handle.ts
Normal file
31
modules/payment/routes/dashboard/handle.ts
Normal 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;
|
||||
});
|
||||
16
modules/payment/routes/dashboard/spec.ts
Normal file
16
modules/payment/routes/dashboard/spec.ts
Normal 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);
|
||||
Reference in New Issue
Block a user