u
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
import * as db from '../../db/entityaddress.js';
|
||||
|
||||
// #region Helpers
|
||||
|
||||
function requireSelectedCompany(req) {
|
||||
const companyId = req.user.selectedCompanyId;
|
||||
if (companyId == null) {
|
||||
@@ -29,6 +31,8 @@ const ADDRESS_FIELDS = [
|
||||
'county',
|
||||
];
|
||||
|
||||
// #endregion
|
||||
|
||||
/**
|
||||
* Registers entity address routes nested under `/entity/:entityId/address`.
|
||||
* @param {import('express').Application} app
|
||||
@@ -172,6 +176,8 @@ export function register(app, basePath = '') {
|
||||
* schema:
|
||||
* $ref: '#/components/schemas/Error'
|
||||
*/
|
||||
// #region GET /entity/:entityId/address
|
||||
|
||||
app.get(`${basePath}/entity/:entityId/address`, async (req, res) => {
|
||||
const selected = requireSelectedCompany(req);
|
||||
if (selected.error) {
|
||||
@@ -193,6 +199,10 @@ export function register(app, basePath = '') {
|
||||
}
|
||||
});
|
||||
|
||||
// #endregion
|
||||
|
||||
// #region POST /entity/:entityId/address
|
||||
|
||||
app.post(`${basePath}/entity/:entityId/address`, async (req, res) => {
|
||||
const selected = requireSelectedCompany(req);
|
||||
if (selected.error) {
|
||||
@@ -222,6 +232,8 @@ export function register(app, basePath = '') {
|
||||
}
|
||||
});
|
||||
|
||||
// #endregion
|
||||
|
||||
/**
|
||||
* @openapi
|
||||
* /entity/{entityId}/address/{id}:
|
||||
@@ -356,6 +368,8 @@ export function register(app, basePath = '') {
|
||||
* schema:
|
||||
* $ref: '#/components/schemas/Error'
|
||||
*/
|
||||
// #region PATCH /entity/:entityId/address/:id
|
||||
|
||||
app.patch(`${basePath}/entity/:entityId/address/:id`, async (req, res) => {
|
||||
const selected = requireSelectedCompany(req);
|
||||
if (selected.error) {
|
||||
@@ -389,6 +403,10 @@ export function register(app, basePath = '') {
|
||||
}
|
||||
});
|
||||
|
||||
// #endregion
|
||||
|
||||
// #region DELETE /entity/:entityId/address/:id
|
||||
|
||||
app.delete(`${basePath}/entity/:entityId/address/:id`, async (req, res) => {
|
||||
const selected = requireSelectedCompany(req);
|
||||
if (selected.error) {
|
||||
@@ -413,4 +431,6 @@ export function register(app, basePath = '') {
|
||||
res.status(status).json({ error: error.message });
|
||||
}
|
||||
});
|
||||
|
||||
// #endregion
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user