feat: update payment views
This commit is contained in:
@@ -1,31 +1,29 @@
|
||||
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`
|
||||
export default route.access("public").handle(async ({ params: { id: tenantId } }) => {
|
||||
return db.schema(DashboardSchema).many`
|
||||
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
|
||||
COALESCE(
|
||||
NEST_MANY(
|
||||
SELECT
|
||||
pl.*,
|
||||
pl._system_from AS "createdAt"
|
||||
FROM
|
||||
payment.ledger pl
|
||||
WHERE
|
||||
pl."beneficiaryId" = pb._id
|
||||
ORDER BY
|
||||
pl._id
|
||||
),
|
||||
[] -- default to empty array
|
||||
) AS ledgers
|
||||
FROM
|
||||
payment.beneficiary pb
|
||||
WHERE
|
||||
pb._id = ${id}
|
||||
pb."tenantId" = ${tenantId}
|
||||
`;
|
||||
if (dashboard === undefined) {
|
||||
return new NotFoundError("Beneficiary not found");
|
||||
}
|
||||
return dashboard;
|
||||
});
|
||||
|
||||
@@ -12,5 +12,5 @@ export const DashboardSchema = z.strictObject({
|
||||
|
||||
export default route
|
||||
.get("/api/v1/payment/dashboard/:id")
|
||||
.params({ id: BeneficiarySchema.shape._id })
|
||||
.response(DashboardSchema);
|
||||
.params({ id: BeneficiarySchema.shape.tenantId })
|
||||
.response(z.array(DashboardSchema));
|
||||
|
||||
Reference in New Issue
Block a user