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:
seb
2026-08-07 06:22:13 +02:00
parent 2767568f5a
commit e6c24654dd
36 changed files with 496 additions and 189 deletions

View File

@@ -9,6 +9,7 @@ function requireSelectedCompany(req) {
}
function contactErrorStatus(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;
@@ -151,7 +152,7 @@ export function register(app, basePath = '') {
}
try {
const contacts = await db.list(req.user.id, selected.companyId, entityId);
const contacts = await db.list(req.user.id, entityId);
res.status(200).json({ contacts });
} catch (error) {
const status = contactErrorStatus(error);
@@ -174,7 +175,7 @@ export function register(app, basePath = '') {
const { contactType, contact } = req.body ?? {};
try {
const row = await db.create(req.user.id, selected.companyId, entityId, {
const row = await db.create(req.user.id, entityId, {
contactType,
contact,
});
@@ -325,7 +326,7 @@ export function register(app, basePath = '') {
}
try {
const row = await db.update(req.user.id, selected.companyId, entityId, id, patch);
const row = await db.update(req.user.id, entityId, id, patch);
res.status(200).json({ contact: row });
} catch (error) {
const status = contactErrorStatus(error);
@@ -350,7 +351,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 = contactErrorStatus(error);