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 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);
|
||||
|
||||
Reference in New Issue
Block a user