This commit is contained in:
seb
2026-10-10 02:08:10 +02:00
parent d4e2b05cb0
commit 7f8661be3e
43 changed files with 3312 additions and 2339 deletions

View File

@@ -1,5 +1,7 @@
import * as db from '../../db/payment.js';
// #region Helpers
function requireSelectedCompany(req) {
const companyId = req.user?.selectedCompanyId;
if (companyId == null) {
@@ -25,6 +27,8 @@ function paymentErrorStatus(error) {
return 500;
}
// #endregion
/**
* Registers payment routes (payments belong to an order / manifest).
* @param {import('express').Application} app
@@ -78,6 +82,8 @@ export function register(app, basePath = '') {
* schema:
* $ref: '#/components/schemas/Error'
*/
// #region GET /order/:id/payment
app.get(`${basePath}/order/:id/payment`, async (req, res) => {
const selected = requireSelectedCompany(req);
if (selected.error) {
@@ -99,6 +105,8 @@ export function register(app, basePath = '') {
}
});
// #endregion
/**
* @openapi
* /order/{id}/payment:
@@ -164,6 +172,8 @@ export function register(app, basePath = '') {
* schema:
* $ref: '#/components/schemas/Error'
*/
// #region POST /order/:id/payment
app.post(`${basePath}/order/:id/payment`, async (req, res) => {
const selected = requireSelectedCompany(req);
if (selected.error) {
@@ -188,6 +198,8 @@ export function register(app, basePath = '') {
}
});
// #endregion
/**
* @openapi
* /payment/{id}:
@@ -226,6 +238,8 @@ export function register(app, basePath = '') {
* schema:
* $ref: '#/components/schemas/Error'
*/
// #region DELETE /payment/:id
app.delete(`${basePath}/payment/:id`, async (req, res) => {
const selected = requireSelectedCompany(req);
if (selected.error) {
@@ -246,4 +260,6 @@ export function register(app, basePath = '') {
res.status(status).json({ error: error.message });
}
});
// #endregion
}