Align store calls with selected-company scoping and add entity numbers.
Drop companyId from company-scoped store wrappers and routes, add GET /entity/next-number plus optional number on entity create/update, and document dashdbschema API.md lookup in sibling-repos.
This commit is contained in:
@@ -9,6 +9,7 @@ function requireSelectedCompany(req) {
|
||||
}
|
||||
|
||||
function addressErrorStatus(error) {
|
||||
if (error.message === 'No company selected') return 400;
|
||||
if (error.message === 'Not authorized') return 403;
|
||||
if (error.message === 'Company not found') return 404;
|
||||
if (error.message === 'Entity not found') return 404;
|
||||
@@ -183,7 +184,7 @@ export function register(app, basePath = '') {
|
||||
}
|
||||
|
||||
try {
|
||||
const addresses = await db.list(req.user.id, selected.companyId, entityId);
|
||||
const addresses = await db.list(req.user.id, entityId);
|
||||
res.status(200).json({ addresses });
|
||||
} catch (error) {
|
||||
const status = addressErrorStatus(error);
|
||||
@@ -212,7 +213,7 @@ export function register(app, basePath = '') {
|
||||
}
|
||||
|
||||
try {
|
||||
const address = await db.create(req.user.id, selected.companyId, entityId, data);
|
||||
const address = await db.create(req.user.id, entityId, data);
|
||||
res.status(201).json({ address });
|
||||
} catch (error) {
|
||||
const status = addressErrorStatus(error);
|
||||
@@ -379,7 +380,7 @@ export function register(app, basePath = '') {
|
||||
}
|
||||
|
||||
try {
|
||||
const address = await db.update(req.user.id, selected.companyId, entityId, id, patch);
|
||||
const address = await db.update(req.user.id, entityId, id, patch);
|
||||
res.status(200).json({ address });
|
||||
} catch (error) {
|
||||
const status = addressErrorStatus(error);
|
||||
@@ -404,7 +405,7 @@ export function register(app, basePath = '') {
|
||||
}
|
||||
|
||||
try {
|
||||
await db.remove(req.user.id, selected.companyId, entityId, id);
|
||||
await db.remove(req.user.id, entityId, id);
|
||||
res.sendStatus(204);
|
||||
} catch (error) {
|
||||
const status = addressErrorStatus(error);
|
||||
|
||||
Reference in New Issue
Block a user