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 unitErrorStatus(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 === 'Unit not found') return 404;
|
||||
@@ -190,7 +191,7 @@ export function register(app, basePath = '') {
|
||||
}
|
||||
|
||||
try {
|
||||
const units = await db.list(req.user.id, selected.companyId);
|
||||
const units = await db.list(req.user.id);
|
||||
res.status(200).json({ units });
|
||||
} catch (error) {
|
||||
const status = unitErrorStatus(error);
|
||||
@@ -208,7 +209,7 @@ export function register(app, basePath = '') {
|
||||
const { si, basesi, basesifactor, symbol, name } = req.body ?? {};
|
||||
|
||||
try {
|
||||
const unit = await db.upsert(req.user.id, selected.companyId, {
|
||||
const unit = await db.upsert(req.user.id, {
|
||||
si,
|
||||
basesi,
|
||||
basesifactor,
|
||||
@@ -235,7 +236,7 @@ export function register(app, basePath = '') {
|
||||
}
|
||||
|
||||
try {
|
||||
await db.remove(req.user.id, selected.companyId, si);
|
||||
await db.remove(req.user.id, si);
|
||||
res.sendStatus(204);
|
||||
} catch (error) {
|
||||
const status = unitErrorStatus(error);
|
||||
|
||||
Reference in New Issue
Block a user