u
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
import * as db from '../../db/entitycontact.js';
|
||||
|
||||
// #region Helpers
|
||||
|
||||
function requireSelectedCompany(req) {
|
||||
const companyId = req.user.selectedCompanyId;
|
||||
if (companyId == null) {
|
||||
@@ -18,6 +20,8 @@ function contactErrorStatus(error) {
|
||||
return 500;
|
||||
}
|
||||
|
||||
// #endregion
|
||||
|
||||
/**
|
||||
* Registers entity contact routes nested under `/entity/:entityId/contact`.
|
||||
* @param {import('express').Application} app
|
||||
@@ -140,6 +144,8 @@ export function register(app, basePath = '') {
|
||||
* schema:
|
||||
* $ref: '#/components/schemas/Error'
|
||||
*/
|
||||
// #region GET /entity/:entityId/contact
|
||||
|
||||
app.get(`${basePath}/entity/:entityId/contact`, async (req, res) => {
|
||||
const selected = requireSelectedCompany(req);
|
||||
if (selected.error) {
|
||||
@@ -161,6 +167,10 @@ export function register(app, basePath = '') {
|
||||
}
|
||||
});
|
||||
|
||||
// #endregion
|
||||
|
||||
// #region POST /entity/:entityId/contact
|
||||
|
||||
app.post(`${basePath}/entity/:entityId/contact`, async (req, res) => {
|
||||
const selected = requireSelectedCompany(req);
|
||||
if (selected.error) {
|
||||
@@ -187,6 +197,8 @@ export function register(app, basePath = '') {
|
||||
}
|
||||
});
|
||||
|
||||
// #endregion
|
||||
|
||||
/**
|
||||
* @openapi
|
||||
* /entity/{entityId}/contact/{id}:
|
||||
@@ -301,6 +313,8 @@ export function register(app, basePath = '') {
|
||||
* schema:
|
||||
* $ref: '#/components/schemas/Error'
|
||||
*/
|
||||
// #region PATCH /entity/:entityId/contact/:id
|
||||
|
||||
app.patch(`${basePath}/entity/:entityId/contact/:id`, async (req, res) => {
|
||||
const selected = requireSelectedCompany(req);
|
||||
if (selected.error) {
|
||||
@@ -335,6 +349,10 @@ export function register(app, basePath = '') {
|
||||
}
|
||||
});
|
||||
|
||||
// #endregion
|
||||
|
||||
// #region DELETE /entity/:entityId/contact/:id
|
||||
|
||||
app.delete(`${basePath}/entity/:entityId/contact/:id`, async (req, res) => {
|
||||
const selected = requireSelectedCompany(req);
|
||||
if (selected.error) {
|
||||
@@ -359,4 +377,6 @@ export function register(app, basePath = '') {
|
||||
res.status(status).json({ error: error.message });
|
||||
}
|
||||
});
|
||||
|
||||
// #endregion
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user