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 supplierErrorStatus(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 === 'Supplier not found') return 404;
|
||||
@@ -132,7 +133,7 @@ export function register(app, basePath = '') {
|
||||
}
|
||||
|
||||
try {
|
||||
const suppliers = await db.list(req.user.id, selected.companyId);
|
||||
const suppliers = await db.list(req.user.id);
|
||||
res.status(200).json({ suppliers });
|
||||
} catch (error) {
|
||||
const status = supplierErrorStatus(error);
|
||||
@@ -150,7 +151,7 @@ export function register(app, basePath = '') {
|
||||
const { name } = req.body ?? {};
|
||||
|
||||
try {
|
||||
const supplier = await db.create(req.user.id, selected.companyId, { name });
|
||||
const supplier = await db.create(req.user.id, { name });
|
||||
res.status(201).json({ supplier });
|
||||
} catch (error) {
|
||||
const status = supplierErrorStatus(error);
|
||||
@@ -278,7 +279,7 @@ export function register(app, basePath = '') {
|
||||
const { name } = req.body ?? {};
|
||||
|
||||
try {
|
||||
const supplier = await db.update(req.user.id, selected.companyId, id, { name });
|
||||
const supplier = await db.update(req.user.id, id, { name });
|
||||
res.status(200).json({ supplier });
|
||||
} catch (error) {
|
||||
const status = supplierErrorStatus(error);
|
||||
@@ -299,7 +300,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 = supplierErrorStatus(error);
|
||||
|
||||
Reference in New Issue
Block a user