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 quoteErrorStatus(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 === 'Quote not found') return 404;
@@ -157,7 +158,7 @@ export function register(app, basePath = '') {
}
try {
const quotes = await db.list(req.user.id, selected.companyId);
const quotes = await db.list(req.user.id);
res.status(200).json({ quotes });
} catch (error) {
const status = quoteErrorStatus(error);
@@ -175,7 +176,7 @@ export function register(app, basePath = '') {
const { number, date, entityId, lines } = req.body ?? {};
try {
const quote = await db.create(req.user.id, selected.companyId, {
const quote = await db.create(req.user.id, {
number,
date,
entityId,
@@ -365,7 +366,7 @@ export function register(app, basePath = '') {
}
try {
const quote = await db.getById(req.user.id, selected.companyId, id);
const quote = await db.getById(req.user.id, id);
res.status(200).json({ quote });
} catch (error) {
const status = quoteErrorStatus(error);
@@ -401,7 +402,7 @@ export function register(app, basePath = '') {
}
try {
const quote = await db.update(req.user.id, selected.companyId, id, patch);
const quote = await db.update(req.user.id, id, patch);
res.status(200).json({ quote });
} catch (error) {
const status = quoteErrorStatus(error);
@@ -422,7 +423,7 @@ export function register(app, basePath = '') {
}
try {
await db.remove(req.user.id, selected.companyId, id);
await db.remove(req.user.id, id);
res.sendStatus(204);
} catch (error) {
const status = quoteErrorStatus(error);