@voyant-travel/finance 0.119.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +201 -0
- package/README.md +192 -0
- package/dist/action-ledger-drift.d.ts +29 -0
- package/dist/action-ledger-drift.d.ts.map +1 -0
- package/dist/action-ledger-drift.js +166 -0
- package/dist/booking-tax.d.ts +124 -0
- package/dist/booking-tax.d.ts.map +1 -0
- package/dist/booking-tax.js +264 -0
- package/dist/checkout-routes.d.ts +1154 -0
- package/dist/checkout-routes.d.ts.map +1 -0
- package/dist/checkout-routes.js +116 -0
- package/dist/checkout-service-plan.d.ts +137 -0
- package/dist/checkout-service-plan.d.ts.map +1 -0
- package/dist/checkout-service-plan.js +119 -0
- package/dist/checkout-service.d.ts +9 -0
- package/dist/checkout-service.d.ts.map +1 -0
- package/dist/checkout-service.js +324 -0
- package/dist/checkout-validation.d.ts +1682 -0
- package/dist/checkout-validation.d.ts.map +1 -0
- package/dist/checkout-validation.js +228 -0
- package/dist/document-download.d.ts +3 -0
- package/dist/document-download.d.ts.map +1 -0
- package/dist/document-download.js +1 -0
- package/dist/fx-money.d.ts +17 -0
- package/dist/fx-money.d.ts.map +1 -0
- package/dist/fx-money.js +194 -0
- package/dist/index.d.ts +65 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +108 -0
- package/dist/invoice-fx.d.ts +134 -0
- package/dist/invoice-fx.d.ts.map +1 -0
- package/dist/invoice-fx.js +240 -0
- package/dist/invoice-number-errors.d.ts +2 -0
- package/dist/invoice-number-errors.d.ts.map +1 -0
- package/dist/invoice-number-errors.js +58 -0
- package/dist/markets-ref.d.ts +149 -0
- package/dist/markets-ref.d.ts.map +1 -0
- package/dist/markets-ref.js +17 -0
- package/dist/payment-link.d.ts +23 -0
- package/dist/payment-link.d.ts.map +1 -0
- package/dist/payment-link.js +30 -0
- package/dist/payment-policy.d.ts +113 -0
- package/dist/payment-policy.d.ts.map +1 -0
- package/dist/payment-policy.js +193 -0
- package/dist/route-runtime.d.ts +22 -0
- package/dist/route-runtime.d.ts.map +1 -0
- package/dist/route-runtime.js +18 -0
- package/dist/routes-action-ledger.d.ts +181 -0
- package/dist/routes-action-ledger.d.ts.map +1 -0
- package/dist/routes-action-ledger.js +142 -0
- package/dist/routes-booking-billing.d.ts +852 -0
- package/dist/routes-booking-billing.d.ts.map +1 -0
- package/dist/routes-booking-billing.js +223 -0
- package/dist/routes-booking-create.d.ts +3 -0
- package/dist/routes-booking-create.d.ts.map +1 -0
- package/dist/routes-booking-create.js +194 -0
- package/dist/routes-booking-reads.d.ts +46 -0
- package/dist/routes-booking-reads.d.ts.map +1 -0
- package/dist/routes-booking-reads.js +20 -0
- package/dist/routes-documents.d.ts +195 -0
- package/dist/routes-documents.d.ts.map +1 -0
- package/dist/routes-documents.js +93 -0
- package/dist/routes-invoice-core.d.ts +794 -0
- package/dist/routes-invoice-core.d.ts.map +1 -0
- package/dist/routes-invoice-core.js +238 -0
- package/dist/routes-invoice-documents.d.ts +401 -0
- package/dist/routes-invoice-documents.d.ts.map +1 -0
- package/dist/routes-invoice-documents.js +91 -0
- package/dist/routes-invoice-issue.d.ts +384 -0
- package/dist/routes-invoice-issue.d.ts.map +1 -0
- package/dist/routes-invoice-issue.js +208 -0
- package/dist/routes-payment-processing.d.ts +1193 -0
- package/dist/routes-payment-processing.d.ts.map +1 -0
- package/dist/routes-payment-processing.js +238 -0
- package/dist/routes-payments.d.ts +309 -0
- package/dist/routes-payments.d.ts.map +1 -0
- package/dist/routes-payments.js +94 -0
- package/dist/routes-public.d.ts +1948 -0
- package/dist/routes-public.d.ts.map +1 -0
- package/dist/routes-public.js +275 -0
- package/dist/routes-reference-data.d.ts +977 -0
- package/dist/routes-reference-data.d.ts.map +1 -0
- package/dist/routes-reference-data.js +191 -0
- package/dist/routes-reports.d.ts +344 -0
- package/dist/routes-reports.d.ts.map +1 -0
- package/dist/routes-reports.js +93 -0
- package/dist/routes-runtime.d.ts +71 -0
- package/dist/routes-runtime.d.ts.map +1 -0
- package/dist/routes-runtime.js +59 -0
- package/dist/routes-settlement.d.ts +67 -0
- package/dist/routes-settlement.d.ts.map +1 -0
- package/dist/routes-settlement.js +23 -0
- package/dist/routes-shared.d.ts +35 -0
- package/dist/routes-shared.d.ts.map +1 -0
- package/dist/routes-shared.js +10 -0
- package/dist/routes-supplier-invoices.d.ts +778 -0
- package/dist/routes-supplier-invoices.d.ts.map +1 -0
- package/dist/routes-supplier-invoices.js +159 -0
- package/dist/routes-vouchers.d.ts +228 -0
- package/dist/routes-vouchers.d.ts.map +1 -0
- package/dist/routes-vouchers.js +54 -0
- package/dist/routes.d.ts +5577 -0
- package/dist/routes.d.ts.map +1 -0
- package/dist/routes.js +44 -0
- package/dist/schema/booking-billing.d.ts +1006 -0
- package/dist/schema/booking-billing.d.ts.map +1 -0
- package/dist/schema/booking-billing.js +106 -0
- package/dist/schema/enums.d.ts +48 -0
- package/dist/schema/enums.d.ts.map +1 -0
- package/dist/schema/enums.js +237 -0
- package/dist/schema/invoice-documents.d.ts +1245 -0
- package/dist/schema/invoice-documents.d.ts.map +1 -0
- package/dist/schema/invoice-documents.js +140 -0
- package/dist/schema/payment-instruments.d.ts +418 -0
- package/dist/schema/payment-instruments.d.ts.map +1 -0
- package/dist/schema/payment-instruments.js +45 -0
- package/dist/schema/payment-processing.d.ts +563 -0
- package/dist/schema/payment-processing.d.ts.map +1 -0
- package/dist/schema/payment-processing.js +65 -0
- package/dist/schema/payment-sessions.d.ts +728 -0
- package/dist/schema/payment-sessions.d.ts.map +1 -0
- package/dist/schema/payment-sessions.js +79 -0
- package/dist/schema/receivables.d.ts +1474 -0
- package/dist/schema/receivables.d.ts.map +1 -0
- package/dist/schema/receivables.js +179 -0
- package/dist/schema/relations.d.ts +82 -0
- package/dist/schema/relations.d.ts.map +1 -0
- package/dist/schema/relations.js +144 -0
- package/dist/schema/supplier-invoices.d.ts +1619 -0
- package/dist/schema/supplier-invoices.d.ts.map +1 -0
- package/dist/schema/supplier-invoices.js +228 -0
- package/dist/schema/tax.d.ts +712 -0
- package/dist/schema/tax.d.ts.map +1 -0
- package/dist/schema/tax.js +98 -0
- package/dist/schema/vouchers.d.ts +444 -0
- package/dist/schema/vouchers.d.ts.map +1 -0
- package/dist/schema/vouchers.js +64 -0
- package/dist/schema.d.ts +12 -0
- package/dist/schema.d.ts.map +1 -0
- package/dist/schema.js +11 -0
- package/dist/service-accountant-shares.d.ts +106 -0
- package/dist/service-accountant-shares.d.ts.map +1 -0
- package/dist/service-accountant-shares.js +331 -0
- package/dist/service-action-ledger-accounting.d.ts +104 -0
- package/dist/service-action-ledger-accounting.d.ts.map +1 -0
- package/dist/service-action-ledger-accounting.js +386 -0
- package/dist/service-action-ledger-booking-payments.d.ts +48 -0
- package/dist/service-action-ledger-booking-payments.d.ts.map +1 -0
- package/dist/service-action-ledger-booking-payments.js +178 -0
- package/dist/service-action-ledger-bookings.d.ts +44 -0
- package/dist/service-action-ledger-bookings.d.ts.map +1 -0
- package/dist/service-action-ledger-bookings.js +81 -0
- package/dist/service-action-ledger-payment-authorizations.d.ts +48 -0
- package/dist/service-action-ledger-payment-authorizations.d.ts.map +1 -0
- package/dist/service-action-ledger-payment-authorizations.js +209 -0
- package/dist/service-action-ledger-payment-sessions.d.ts +83 -0
- package/dist/service-action-ledger-payment-sessions.d.ts.map +1 -0
- package/dist/service-action-ledger-payment-sessions.js +294 -0
- package/dist/service-action-ledger-supplier-invoices.d.ts +27 -0
- package/dist/service-action-ledger-supplier-invoices.d.ts.map +1 -0
- package/dist/service-action-ledger-supplier-invoices.js +111 -0
- package/dist/service-action-ledger-supplier-payments.d.ts +21 -0
- package/dist/service-action-ledger-supplier-payments.d.ts.map +1 -0
- package/dist/service-action-ledger-supplier-payments.js +97 -0
- package/dist/service-action-ledger.d.ts +7 -0
- package/dist/service-action-ledger.d.ts.map +1 -0
- package/dist/service-action-ledger.js +6 -0
- package/dist/service-aggregates.d.ts +96 -0
- package/dist/service-aggregates.d.ts.map +1 -0
- package/dist/service-aggregates.js +294 -0
- package/dist/service-booking-billing.d.ts +2322 -0
- package/dist/service-booking-billing.d.ts.map +1 -0
- package/dist/service-booking-billing.js +8 -0
- package/dist/service-booking-create.d.ts +410 -0
- package/dist/service-booking-create.d.ts.map +1 -0
- package/dist/service-booking-create.js +1256 -0
- package/dist/service-booking-guarantees.d.ts +725 -0
- package/dist/service-booking-guarantees.d.ts.map +1 -0
- package/dist/service-booking-guarantees.js +153 -0
- package/dist/service-booking-item-billing.d.ts +1062 -0
- package/dist/service-booking-item-billing.d.ts.map +1 -0
- package/dist/service-booking-item-billing.js +77 -0
- package/dist/service-booking-payment-schedules.d.ts +557 -0
- package/dist/service-booking-payment-schedules.d.ts.map +1 -0
- package/dist/service-booking-payment-schedules.js +372 -0
- package/dist/service-bookings-dual-create.d.ts +308 -0
- package/dist/service-bookings-dual-create.d.ts.map +1 -0
- package/dist/service-bookings-dual-create.js +131 -0
- package/dist/service-boundary-sql.d.ts +6 -0
- package/dist/service-boundary-sql.d.ts.map +1 -0
- package/dist/service-boundary-sql.js +15 -0
- package/dist/service-cost-categories.d.ts +26 -0
- package/dist/service-cost-categories.d.ts.map +1 -0
- package/dist/service-cost-categories.js +76 -0
- package/dist/service-documents.d.ts +80 -0
- package/dist/service-documents.d.ts.map +1 -0
- package/dist/service-documents.js +228 -0
- package/dist/service-invoice-artifacts.d.ts +246 -0
- package/dist/service-invoice-artifacts.d.ts.map +1 -0
- package/dist/service-invoice-artifacts.js +277 -0
- package/dist/service-invoice-core.d.ts +405 -0
- package/dist/service-invoice-core.d.ts.map +1 -0
- package/dist/service-invoice-core.js +290 -0
- package/dist/service-invoice-credit-notes.d.ts +973 -0
- package/dist/service-invoice-credit-notes.d.ts.map +1 -0
- package/dist/service-invoice-credit-notes.js +142 -0
- package/dist/service-invoice-from-booking.d.ts +41 -0
- package/dist/service-invoice-from-booking.d.ts.map +1 -0
- package/dist/service-invoice-from-booking.js +267 -0
- package/dist/service-invoice-line-items.d.ts +432 -0
- package/dist/service-invoice-line-items.d.ts.map +1 -0
- package/dist/service-invoice-line-items.js +102 -0
- package/dist/service-invoice-numbering.d.ts +227 -0
- package/dist/service-invoice-numbering.d.ts.map +1 -0
- package/dist/service-invoice-numbering.js +260 -0
- package/dist/service-invoice-payments.d.ts +673 -0
- package/dist/service-invoice-payments.d.ts.map +1 -0
- package/dist/service-invoice-payments.js +398 -0
- package/dist/service-invoices.d.ts +2501 -0
- package/dist/service-invoices.d.ts.map +1 -0
- package/dist/service-invoices.js +12 -0
- package/dist/service-issue.d.ts +207 -0
- package/dist/service-issue.d.ts.map +1 -0
- package/dist/service-issue.js +431 -0
- package/dist/service-payment-authorizations.d.ts +164 -0
- package/dist/service-payment-authorizations.d.ts.map +1 -0
- package/dist/service-payment-authorizations.js +227 -0
- package/dist/service-payment-instruments.d.ts +116 -0
- package/dist/service-payment-instruments.d.ts.map +1 -0
- package/dist/service-payment-instruments.js +99 -0
- package/dist/service-payment-processing.d.ts +676 -0
- package/dist/service-payment-processing.d.ts.map +1 -0
- package/dist/service-payment-processing.js +10 -0
- package/dist/service-payment-session-completion.d.ts +48 -0
- package/dist/service-payment-session-completion.d.ts.map +1 -0
- package/dist/service-payment-session-completion.js +238 -0
- package/dist/service-payment-sessions.d.ts +361 -0
- package/dist/service-payment-sessions.d.ts.map +1 -0
- package/dist/service-payment-sessions.js +280 -0
- package/dist/service-profitability.d.ts +114 -0
- package/dist/service-profitability.d.ts.map +1 -0
- package/dist/service-profitability.js +794 -0
- package/dist/service-public.d.ts +553 -0
- package/dist/service-public.d.ts.map +1 -0
- package/dist/service-public.js +583 -0
- package/dist/service-reference-data.d.ts +272 -0
- package/dist/service-reference-data.d.ts.map +1 -0
- package/dist/service-reference-data.js +280 -0
- package/dist/service-rendition-wait.d.ts +38 -0
- package/dist/service-rendition-wait.d.ts.map +1 -0
- package/dist/service-rendition-wait.js +67 -0
- package/dist/service-reports.d.ts +37 -0
- package/dist/service-reports.d.ts.map +1 -0
- package/dist/service-reports.js +62 -0
- package/dist/service-settlement.d.ts +46 -0
- package/dist/service-settlement.d.ts.map +1 -0
- package/dist/service-settlement.js +185 -0
- package/dist/service-shared.d.ts +541 -0
- package/dist/service-shared.d.ts.map +1 -0
- package/dist/service-shared.js +764 -0
- package/dist/service-supplier-invoices.d.ts +871 -0
- package/dist/service-supplier-invoices.d.ts.map +1 -0
- package/dist/service-supplier-invoices.js +744 -0
- package/dist/service-supplier-payments.d.ts +69 -0
- package/dist/service-supplier-payments.d.ts.map +1 -0
- package/dist/service-supplier-payments.js +136 -0
- package/dist/service-vouchers-migration.d.ts +44 -0
- package/dist/service-vouchers-migration.d.ts.map +1 -0
- package/dist/service-vouchers-migration.js +148 -0
- package/dist/service-vouchers.d.ts +157 -0
- package/dist/service-vouchers.d.ts.map +1 -0
- package/dist/service-vouchers.js +191 -0
- package/dist/service.d.ts +6490 -0
- package/dist/service.d.ts.map +1 -0
- package/dist/service.js +29 -0
- package/dist/validation-billing.d.ts +2 -0
- package/dist/validation-billing.d.ts.map +1 -0
- package/dist/validation-billing.js +1 -0
- package/dist/validation-payments.d.ts +2 -0
- package/dist/validation-payments.d.ts.map +1 -0
- package/dist/validation-payments.js +1 -0
- package/dist/validation-public.d.ts +2 -0
- package/dist/validation-public.d.ts.map +1 -0
- package/dist/validation-public.js +1 -0
- package/dist/validation-shared.d.ts +2 -0
- package/dist/validation-shared.d.ts.map +1 -0
- package/dist/validation-shared.js +1 -0
- package/dist/validation-vouchers.d.ts +2 -0
- package/dist/validation-vouchers.d.ts.map +1 -0
- package/dist/validation-vouchers.js +1 -0
- package/dist/validation.d.ts +2 -0
- package/dist/validation.d.ts.map +1 -0
- package/dist/validation.js +1 -0
- package/package.json +121 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"routes-supplier-invoices.d.ts","sourceRoot":"","sources":["../src/routes-supplier-invoices.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,oBAAoB,CAAA;AAoD7C,eAAO,MAAM,qBAAqB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;qDAsK9B,CAAA;AAEJ,MAAM,MAAM,qBAAqB,GAAG,OAAO,qBAAqB,CAAA"}
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
import { parseJsonBody, parseQuery } from "@voyant-travel/hono";
|
|
2
|
+
import { Hono } from "hono";
|
|
3
|
+
import { resolveStoredDocumentDownload } from "./document-download.js";
|
|
4
|
+
import { getActionLedgerRequestContext, getFinanceRouteRuntime } from "./routes-runtime.js";
|
|
5
|
+
import { financeService } from "./service.js";
|
|
6
|
+
import { SupplierInvoiceServiceError, supplierInvoicesService, } from "./service-supplier-invoices.js";
|
|
7
|
+
import { insertSupplierInvoiceAttachmentSchema, insertSupplierInvoiceSchema, insertSupplierPaymentSchema, setSupplierCostAllocationsSchema, setSupplierInvoiceLinesSchema, supplierInvoiceListQuerySchema, supplierPaymentListQuerySchema, updateSupplierInvoiceSchema, } from "./validation.js";
|
|
8
|
+
/**
|
|
9
|
+
* Map a SupplierInvoiceServiceError to HTTP. `not_found` → 404; the allocation
|
|
10
|
+
* invariant violations (§6.1) → 422. Anything else re-throws to the boundary.
|
|
11
|
+
*/
|
|
12
|
+
function handleSupplierInvoiceError(c, error) {
|
|
13
|
+
if (error instanceof SupplierInvoiceServiceError) {
|
|
14
|
+
const status = error.code === "supplier_invoice_not_found" ? 404 : 422;
|
|
15
|
+
return c.json({ error: error.message, code: error.code }, status);
|
|
16
|
+
}
|
|
17
|
+
throw error;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Action-ledger + FX runtime for the AP (supplier-invoice) service. The FX
|
|
21
|
+
* options (settings + exchange-rate resolver) let create/update/setLines snapshot
|
|
22
|
+
* each invoice's accounting-base value at the rate effective on its issue date.
|
|
23
|
+
*/
|
|
24
|
+
function apRuntime(c) {
|
|
25
|
+
const fx = getFinanceRouteRuntime(c);
|
|
26
|
+
return {
|
|
27
|
+
actionLedgerContext: getActionLedgerRequestContext(c),
|
|
28
|
+
actionLedgerAuthorizationSource: "finance.supplier_invoice.route",
|
|
29
|
+
...(fx?.invoiceFxSettings !== undefined ? { invoiceFxSettings: fx.invoiceFxSettings } : {}),
|
|
30
|
+
...(fx?.resolveInvoiceFxSettings
|
|
31
|
+
? { resolveInvoiceFxSettings: fx.resolveInvoiceFxSettings }
|
|
32
|
+
: {}),
|
|
33
|
+
...(fx?.resolveInvoiceExchangeRate
|
|
34
|
+
? { resolveInvoiceExchangeRate: fx.resolveInvoiceExchangeRate }
|
|
35
|
+
: {}),
|
|
36
|
+
...(fx?.onInvoiceFxResolutionError
|
|
37
|
+
? { onInvoiceFxResolutionError: fx.onInvoiceFxResolutionError }
|
|
38
|
+
: {}),
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
export const supplierInvoiceRoutes = new Hono()
|
|
42
|
+
.get("/supplier-invoices", async (c) => {
|
|
43
|
+
const query = parseQuery(c, supplierInvoiceListQuerySchema);
|
|
44
|
+
return c.json(await supplierInvoicesService.list(c.get("db"), query));
|
|
45
|
+
})
|
|
46
|
+
.post("/supplier-invoices", async (c) => {
|
|
47
|
+
try {
|
|
48
|
+
const row = await supplierInvoicesService.create(c.get("db"), await parseJsonBody(c, insertSupplierInvoiceSchema), apRuntime(c));
|
|
49
|
+
return c.json({ data: row }, 201);
|
|
50
|
+
}
|
|
51
|
+
catch (error) {
|
|
52
|
+
return handleSupplierInvoiceError(c, error);
|
|
53
|
+
}
|
|
54
|
+
})
|
|
55
|
+
.get("/supplier-invoices/:id", async (c) => {
|
|
56
|
+
const row = await supplierInvoicesService.getById(c.get("db"), c.req.param("id"));
|
|
57
|
+
if (!row)
|
|
58
|
+
return c.json({ error: "Supplier invoice not found" }, 404);
|
|
59
|
+
return c.json({ data: row });
|
|
60
|
+
})
|
|
61
|
+
.patch("/supplier-invoices/:id", async (c) => {
|
|
62
|
+
const row = await supplierInvoicesService.update(c.get("db"), c.req.param("id"), await parseJsonBody(c, updateSupplierInvoiceSchema), apRuntime(c));
|
|
63
|
+
if (!row)
|
|
64
|
+
return c.json({ error: "Supplier invoice not found" }, 404);
|
|
65
|
+
return c.json({ data: row });
|
|
66
|
+
})
|
|
67
|
+
.delete("/supplier-invoices/:id", async (c) => {
|
|
68
|
+
const result = await supplierInvoicesService.softDelete(c.get("db"), c.req.param("id"), apRuntime(c));
|
|
69
|
+
if (!result)
|
|
70
|
+
return c.json({ error: "Supplier invoice not found" }, 404);
|
|
71
|
+
return c.json({ data: result });
|
|
72
|
+
})
|
|
73
|
+
.put("/supplier-invoices/:id/lines", async (c) => {
|
|
74
|
+
try {
|
|
75
|
+
const row = await supplierInvoicesService.setLines(c.get("db"), c.req.param("id"), await parseJsonBody(c, setSupplierInvoiceLinesSchema), apRuntime(c));
|
|
76
|
+
if (!row)
|
|
77
|
+
return c.json({ error: "Supplier invoice not found" }, 404);
|
|
78
|
+
return c.json({ data: row });
|
|
79
|
+
}
|
|
80
|
+
catch (error) {
|
|
81
|
+
// setLines now rejects edits that would over-allocate surviving
|
|
82
|
+
// whole-invoice allocations (§6.1) → 422 via the shared mapper.
|
|
83
|
+
return handleSupplierInvoiceError(c, error);
|
|
84
|
+
}
|
|
85
|
+
})
|
|
86
|
+
.put("/supplier-invoices/:id/allocations", async (c) => {
|
|
87
|
+
try {
|
|
88
|
+
const row = await supplierInvoicesService.setAllocations(c.get("db"), c.req.param("id"), await parseJsonBody(c, setSupplierCostAllocationsSchema), apRuntime(c));
|
|
89
|
+
if (!row)
|
|
90
|
+
return c.json({ error: "Supplier invoice not found" }, 404);
|
|
91
|
+
return c.json({ data: row });
|
|
92
|
+
}
|
|
93
|
+
catch (error) {
|
|
94
|
+
return handleSupplierInvoiceError(c, error);
|
|
95
|
+
}
|
|
96
|
+
})
|
|
97
|
+
.get("/supplier-invoices/:id/document/download", async (c) => {
|
|
98
|
+
const invoice = await supplierInvoicesService.getById(c.get("db"), c.req.param("id"));
|
|
99
|
+
if (!invoice)
|
|
100
|
+
return c.json({ error: "Supplier invoice not found" }, 404);
|
|
101
|
+
if (!invoice.storageKey)
|
|
102
|
+
return c.json({ error: "No document attached" }, 404);
|
|
103
|
+
const runtime = getFinanceRouteRuntime(c);
|
|
104
|
+
const download = await resolveStoredDocumentDownload({ storageKey: invoice.storageKey }, { bindings: c.env, resolveDocumentDownloadUrl: runtime?.resolveDocumentDownloadUrl });
|
|
105
|
+
if (download.status === "resolver_not_configured") {
|
|
106
|
+
return c.json({ error: "Document download resolver is not configured" }, 501);
|
|
107
|
+
}
|
|
108
|
+
if (download.status !== "ready") {
|
|
109
|
+
return c.json({ error: "Supplier invoice document is not available" }, 404);
|
|
110
|
+
}
|
|
111
|
+
return c.redirect(download.download.url, 302);
|
|
112
|
+
})
|
|
113
|
+
.get("/supplier-invoices/:id/payments", async (c) => {
|
|
114
|
+
const query = parseQuery(c, supplierPaymentListQuerySchema);
|
|
115
|
+
return c.json(await financeService.listSupplierPayments(c.get("db"), {
|
|
116
|
+
...query,
|
|
117
|
+
supplierInvoiceId: c.req.param("id"),
|
|
118
|
+
}));
|
|
119
|
+
})
|
|
120
|
+
.post("/supplier-invoices/:id/payments", async (c) => {
|
|
121
|
+
const body = await parseJsonBody(c, insertSupplierPaymentSchema);
|
|
122
|
+
const row = await financeService.createSupplierPayment(c.get("db"), { ...body, supplierInvoiceId: c.req.param("id") }, {
|
|
123
|
+
...getFinanceRouteRuntime(c),
|
|
124
|
+
actionLedgerContext: getActionLedgerRequestContext(c),
|
|
125
|
+
actionLedgerAuthorizationSource: "finance.supplier_payment.route",
|
|
126
|
+
});
|
|
127
|
+
return c.json({ data: row }, 201);
|
|
128
|
+
})
|
|
129
|
+
.get("/supplier-invoices/:id/attachments", async (c) => {
|
|
130
|
+
return c.json({
|
|
131
|
+
data: await supplierInvoicesService.listAttachments(c.get("db"), c.req.param("id")),
|
|
132
|
+
});
|
|
133
|
+
})
|
|
134
|
+
.post("/supplier-invoices/:id/attachments", async (c) => {
|
|
135
|
+
const row = await supplierInvoicesService.createAttachment(c.get("db"), c.req.param("id"), await parseJsonBody(c, insertSupplierInvoiceAttachmentSchema));
|
|
136
|
+
if (!row)
|
|
137
|
+
return c.json({ error: "Supplier invoice not found" }, 404);
|
|
138
|
+
return c.json({ data: row }, 201);
|
|
139
|
+
})
|
|
140
|
+
.delete("/supplier-invoices/:id/attachments/:attachmentId", async (c) => {
|
|
141
|
+
const row = await supplierInvoicesService.deleteAttachment(c.get("db"), c.req.param("id"), c.req.param("attachmentId"));
|
|
142
|
+
if (!row)
|
|
143
|
+
return c.json({ error: "Attachment not found" }, 404);
|
|
144
|
+
return c.json({ success: true });
|
|
145
|
+
})
|
|
146
|
+
.get("/supplier-invoice-attachments/:id/download", async (c) => {
|
|
147
|
+
const attachment = await supplierInvoicesService.getAttachmentById(c.get("db"), c.req.param("id"));
|
|
148
|
+
if (!attachment?.storageKey)
|
|
149
|
+
return c.json({ error: "Attachment not found" }, 404);
|
|
150
|
+
const runtime = getFinanceRouteRuntime(c);
|
|
151
|
+
const download = await resolveStoredDocumentDownload({ storageKey: attachment.storageKey }, { bindings: c.env, resolveDocumentDownloadUrl: runtime?.resolveDocumentDownloadUrl });
|
|
152
|
+
if (download.status === "resolver_not_configured") {
|
|
153
|
+
return c.json({ error: "Document download resolver is not configured" }, 501);
|
|
154
|
+
}
|
|
155
|
+
if (download.status !== "ready") {
|
|
156
|
+
return c.json({ error: "Attachment file is not available" }, 404);
|
|
157
|
+
}
|
|
158
|
+
return c.redirect(download.download.url, 302);
|
|
159
|
+
});
|
|
@@ -0,0 +1,228 @@
|
|
|
1
|
+
import type { Env } from "./routes-shared.js";
|
|
2
|
+
export declare const financeVoucherRoutes: import("hono/hono-base").HonoBase<Env, {
|
|
3
|
+
"/vouchers": {
|
|
4
|
+
$get: {
|
|
5
|
+
input: {};
|
|
6
|
+
output: {
|
|
7
|
+
data: {
|
|
8
|
+
id: string;
|
|
9
|
+
code: string;
|
|
10
|
+
seriesCode: string | null;
|
|
11
|
+
status: "active" | "void" | "expired" | "redeemed";
|
|
12
|
+
currency: string;
|
|
13
|
+
initialAmountCents: number;
|
|
14
|
+
remainingAmountCents: number;
|
|
15
|
+
issuedToPersonId: string | null;
|
|
16
|
+
issuedToOrganizationId: string | null;
|
|
17
|
+
sourceType: "manual" | "refund" | "cancellation_credit" | "gift" | "promo";
|
|
18
|
+
sourceBookingId: string | null;
|
|
19
|
+
sourcePaymentId: string | null;
|
|
20
|
+
validFrom: string | null;
|
|
21
|
+
expiresAt: string | null;
|
|
22
|
+
notes: string | null;
|
|
23
|
+
issuedByUserId: string | null;
|
|
24
|
+
createdAt: string;
|
|
25
|
+
updatedAt: string;
|
|
26
|
+
}[];
|
|
27
|
+
total: number;
|
|
28
|
+
limit: number;
|
|
29
|
+
offset: number;
|
|
30
|
+
};
|
|
31
|
+
outputFormat: "json";
|
|
32
|
+
status: import("hono/utils/http-status").ContentfulStatusCode;
|
|
33
|
+
};
|
|
34
|
+
};
|
|
35
|
+
} & {
|
|
36
|
+
"/vouchers": {
|
|
37
|
+
$post: {
|
|
38
|
+
input: {};
|
|
39
|
+
output: {
|
|
40
|
+
data: {
|
|
41
|
+
currency: string;
|
|
42
|
+
id: string;
|
|
43
|
+
code: string;
|
|
44
|
+
createdAt: string;
|
|
45
|
+
updatedAt: string;
|
|
46
|
+
status: "active" | "void" | "expired" | "redeemed";
|
|
47
|
+
notes: string | null;
|
|
48
|
+
expiresAt: string | null;
|
|
49
|
+
sourceType: "manual" | "refund" | "cancellation_credit" | "gift" | "promo";
|
|
50
|
+
seriesCode: string | null;
|
|
51
|
+
issuedToPersonId: string | null;
|
|
52
|
+
issuedToOrganizationId: string | null;
|
|
53
|
+
sourceBookingId: string | null;
|
|
54
|
+
sourcePaymentId: string | null;
|
|
55
|
+
validFrom: string | null;
|
|
56
|
+
initialAmountCents: number;
|
|
57
|
+
remainingAmountCents: number;
|
|
58
|
+
issuedByUserId: string | null;
|
|
59
|
+
} | null;
|
|
60
|
+
};
|
|
61
|
+
outputFormat: "json";
|
|
62
|
+
status: 201;
|
|
63
|
+
} | {
|
|
64
|
+
input: {};
|
|
65
|
+
output: {
|
|
66
|
+
error: string;
|
|
67
|
+
};
|
|
68
|
+
outputFormat: "json";
|
|
69
|
+
status: 409;
|
|
70
|
+
};
|
|
71
|
+
};
|
|
72
|
+
} & {
|
|
73
|
+
"/vouchers/:id": {
|
|
74
|
+
$get: {
|
|
75
|
+
input: {
|
|
76
|
+
param: {
|
|
77
|
+
id: string;
|
|
78
|
+
};
|
|
79
|
+
};
|
|
80
|
+
output: {
|
|
81
|
+
error: string;
|
|
82
|
+
};
|
|
83
|
+
outputFormat: "json";
|
|
84
|
+
status: 404;
|
|
85
|
+
} | {
|
|
86
|
+
input: {
|
|
87
|
+
param: {
|
|
88
|
+
id: string;
|
|
89
|
+
};
|
|
90
|
+
};
|
|
91
|
+
output: {
|
|
92
|
+
data: {
|
|
93
|
+
redemptions: {
|
|
94
|
+
id: string;
|
|
95
|
+
voucherId: string;
|
|
96
|
+
bookingId: string;
|
|
97
|
+
paymentId: string | null;
|
|
98
|
+
amountCents: number;
|
|
99
|
+
createdAt: string;
|
|
100
|
+
createdByUserId: string | null;
|
|
101
|
+
}[];
|
|
102
|
+
id: string;
|
|
103
|
+
code: string;
|
|
104
|
+
seriesCode: string | null;
|
|
105
|
+
status: "active" | "void" | "expired" | "redeemed";
|
|
106
|
+
currency: string;
|
|
107
|
+
initialAmountCents: number;
|
|
108
|
+
remainingAmountCents: number;
|
|
109
|
+
issuedToPersonId: string | null;
|
|
110
|
+
issuedToOrganizationId: string | null;
|
|
111
|
+
sourceType: "manual" | "refund" | "cancellation_credit" | "gift" | "promo";
|
|
112
|
+
sourceBookingId: string | null;
|
|
113
|
+
sourcePaymentId: string | null;
|
|
114
|
+
validFrom: string | null;
|
|
115
|
+
expiresAt: string | null;
|
|
116
|
+
notes: string | null;
|
|
117
|
+
issuedByUserId: string | null;
|
|
118
|
+
createdAt: string;
|
|
119
|
+
updatedAt: string;
|
|
120
|
+
};
|
|
121
|
+
};
|
|
122
|
+
outputFormat: "json";
|
|
123
|
+
status: import("hono/utils/http-status").ContentfulStatusCode;
|
|
124
|
+
};
|
|
125
|
+
};
|
|
126
|
+
} & {
|
|
127
|
+
"/vouchers/:id": {
|
|
128
|
+
$patch: {
|
|
129
|
+
input: {
|
|
130
|
+
param: {
|
|
131
|
+
id: string;
|
|
132
|
+
};
|
|
133
|
+
};
|
|
134
|
+
output: {
|
|
135
|
+
error: string;
|
|
136
|
+
};
|
|
137
|
+
outputFormat: "json";
|
|
138
|
+
status: 404;
|
|
139
|
+
} | {
|
|
140
|
+
input: {
|
|
141
|
+
param: {
|
|
142
|
+
id: string;
|
|
143
|
+
};
|
|
144
|
+
};
|
|
145
|
+
output: {
|
|
146
|
+
data: {
|
|
147
|
+
id: string;
|
|
148
|
+
code: string;
|
|
149
|
+
seriesCode: string | null;
|
|
150
|
+
status: "active" | "void" | "expired" | "redeemed";
|
|
151
|
+
currency: string;
|
|
152
|
+
initialAmountCents: number;
|
|
153
|
+
remainingAmountCents: number;
|
|
154
|
+
issuedToPersonId: string | null;
|
|
155
|
+
issuedToOrganizationId: string | null;
|
|
156
|
+
sourceType: "manual" | "refund" | "cancellation_credit" | "gift" | "promo";
|
|
157
|
+
sourceBookingId: string | null;
|
|
158
|
+
sourcePaymentId: string | null;
|
|
159
|
+
validFrom: string | null;
|
|
160
|
+
expiresAt: string | null;
|
|
161
|
+
notes: string | null;
|
|
162
|
+
issuedByUserId: string | null;
|
|
163
|
+
createdAt: string;
|
|
164
|
+
updatedAt: string;
|
|
165
|
+
};
|
|
166
|
+
};
|
|
167
|
+
outputFormat: "json";
|
|
168
|
+
status: import("hono/utils/http-status").ContentfulStatusCode;
|
|
169
|
+
};
|
|
170
|
+
};
|
|
171
|
+
} & {
|
|
172
|
+
"/vouchers/:id/redeem": {
|
|
173
|
+
$post: {
|
|
174
|
+
input: {
|
|
175
|
+
param: {
|
|
176
|
+
id: string;
|
|
177
|
+
};
|
|
178
|
+
};
|
|
179
|
+
output: {
|
|
180
|
+
data: {
|
|
181
|
+
voucher: {
|
|
182
|
+
id: string;
|
|
183
|
+
code: string;
|
|
184
|
+
seriesCode: string | null;
|
|
185
|
+
status: "active" | "void" | "expired" | "redeemed";
|
|
186
|
+
currency: string;
|
|
187
|
+
initialAmountCents: number;
|
|
188
|
+
remainingAmountCents: number;
|
|
189
|
+
issuedToPersonId: string | null;
|
|
190
|
+
issuedToOrganizationId: string | null;
|
|
191
|
+
sourceType: "manual" | "refund" | "cancellation_credit" | "gift" | "promo";
|
|
192
|
+
sourceBookingId: string | null;
|
|
193
|
+
sourcePaymentId: string | null;
|
|
194
|
+
validFrom: string | null;
|
|
195
|
+
expiresAt: string | null;
|
|
196
|
+
notes: string | null;
|
|
197
|
+
issuedByUserId: string | null;
|
|
198
|
+
createdAt: string;
|
|
199
|
+
updatedAt: string;
|
|
200
|
+
};
|
|
201
|
+
redemption: {
|
|
202
|
+
id: string;
|
|
203
|
+
createdAt: string;
|
|
204
|
+
bookingId: string;
|
|
205
|
+
amountCents: number;
|
|
206
|
+
paymentId: string | null;
|
|
207
|
+
voucherId: string;
|
|
208
|
+
createdByUserId: string | null;
|
|
209
|
+
} | null;
|
|
210
|
+
};
|
|
211
|
+
};
|
|
212
|
+
outputFormat: "json";
|
|
213
|
+
status: 201;
|
|
214
|
+
} | {
|
|
215
|
+
input: {
|
|
216
|
+
param: {
|
|
217
|
+
id: string;
|
|
218
|
+
};
|
|
219
|
+
};
|
|
220
|
+
output: {
|
|
221
|
+
error: "code_in_use" | "voucher_not_found" | "voucher_inactive" | "voucher_not_started" | "voucher_expired" | "insufficient_balance";
|
|
222
|
+
};
|
|
223
|
+
outputFormat: "json";
|
|
224
|
+
status: 404 | 409 | 422;
|
|
225
|
+
};
|
|
226
|
+
};
|
|
227
|
+
}, "/", "/vouchers/:id/redeem">;
|
|
228
|
+
//# sourceMappingURL=routes-vouchers.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"routes-vouchers.d.ts","sourceRoot":"","sources":["../src/routes-vouchers.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,oBAAoB,CAAA;AAU7C,eAAO,MAAM,oBAAoB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;+BAgE7B,CAAA"}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { parseJsonBody, parseQuery } from "@voyant-travel/hono";
|
|
2
|
+
import { Hono } from "hono";
|
|
3
|
+
import { financeService } from "./service.js";
|
|
4
|
+
import { VoucherServiceError } from "./service-vouchers.js";
|
|
5
|
+
import { insertVoucherSchema, redeemVoucherSchema, updateVoucherSchema, voucherListQuerySchema, } from "./validation.js";
|
|
6
|
+
export const financeVoucherRoutes = new Hono()
|
|
7
|
+
// ========================================================================
|
|
8
|
+
// Vouchers — issuance, lookup, redemption
|
|
9
|
+
// ========================================================================
|
|
10
|
+
.get("/vouchers", async (c) => {
|
|
11
|
+
const query = parseQuery(c, voucherListQuerySchema);
|
|
12
|
+
return c.json(await financeService.vouchers.list(c.get("db"), query));
|
|
13
|
+
})
|
|
14
|
+
.post("/vouchers", async (c) => {
|
|
15
|
+
try {
|
|
16
|
+
const row = await financeService.vouchers.create(c.get("db"), await parseJsonBody(c, insertVoucherSchema), c.get("userId"));
|
|
17
|
+
return c.json({ data: row }, 201);
|
|
18
|
+
}
|
|
19
|
+
catch (error) {
|
|
20
|
+
if (error instanceof VoucherServiceError && error.code === "code_in_use") {
|
|
21
|
+
return c.json({ error: "Voucher code already in use" }, 409);
|
|
22
|
+
}
|
|
23
|
+
throw error;
|
|
24
|
+
}
|
|
25
|
+
})
|
|
26
|
+
.get("/vouchers/:id", async (c) => {
|
|
27
|
+
const row = await financeService.vouchers.getById(c.get("db"), c.req.param("id"));
|
|
28
|
+
if (!row)
|
|
29
|
+
return c.json({ error: "Voucher not found" }, 404);
|
|
30
|
+
return c.json({ data: row });
|
|
31
|
+
})
|
|
32
|
+
.patch("/vouchers/:id", async (c) => {
|
|
33
|
+
const row = await financeService.vouchers.update(c.get("db"), c.req.param("id"), await parseJsonBody(c, updateVoucherSchema));
|
|
34
|
+
if (!row)
|
|
35
|
+
return c.json({ error: "Voucher not found" }, 404);
|
|
36
|
+
return c.json({ data: row });
|
|
37
|
+
})
|
|
38
|
+
.post("/vouchers/:id/redeem", async (c) => {
|
|
39
|
+
try {
|
|
40
|
+
const result = await financeService.vouchers.redeem(c.get("db"), c.req.param("id"), await parseJsonBody(c, redeemVoucherSchema), c.get("userId"));
|
|
41
|
+
return c.json({ data: result }, 201);
|
|
42
|
+
}
|
|
43
|
+
catch (error) {
|
|
44
|
+
if (error instanceof VoucherServiceError) {
|
|
45
|
+
const status = error.code === "voucher_not_found"
|
|
46
|
+
? 404
|
|
47
|
+
: error.code === "insufficient_balance"
|
|
48
|
+
? 409
|
|
49
|
+
: 422;
|
|
50
|
+
return c.json({ error: error.code }, status);
|
|
51
|
+
}
|
|
52
|
+
throw error;
|
|
53
|
+
}
|
|
54
|
+
});
|