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/account.js';
// #region Helpers
function requireSelectedCompany(req) {
const companyId = req.user?.selectedCompanyId;
if (companyId == null) {
@@ -24,6 +26,8 @@ function accountErrorStatus(error) {
return 500;
}
// #endregion
/**
* Registers account routes for the authenticated user's selected company.
* @param {import('express').Application} app
@@ -64,6 +68,8 @@ export function register(app, basePath = '') {
* schema:
* $ref: '#/components/schemas/Error'
*/
// #region GET /account
app.get(`${basePath}/account`, async (req, res) => {
const selected = requireSelectedCompany(req);
if (selected.error) {
@@ -80,6 +86,8 @@ export function register(app, basePath = '') {
}
});
// #endregion
/**
* @openapi
* /account:
@@ -130,6 +138,8 @@ export function register(app, basePath = '') {
* schema:
* $ref: '#/components/schemas/Error'
*/
// #region POST /account
app.post(`${basePath}/account`, async (req, res) => {
const selected = requireSelectedCompany(req);
if (selected.error) {
@@ -146,6 +156,8 @@ export function register(app, basePath = '') {
}
});
// #endregion
/**
* @openapi
* /account/{id}:
@@ -190,6 +202,8 @@ export function register(app, basePath = '') {
* schema:
* $ref: '#/components/schemas/Error'
*/
// #region DELETE /account/:id
app.delete(`${basePath}/account/:id`, async (req, res) => {
const selected = requireSelectedCompany(req);
if (selected.error) {
@@ -210,4 +224,6 @@ export function register(app, basePath = '') {
res.status(status).json({ error: error.message });
}
});
// #endregion
}