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:
@@ -18,6 +18,7 @@ function parsePositiveInt(value, field) {
|
||||
}
|
||||
|
||||
function posterminalErrorStatus(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 === 'Posterminal not found') return 404;
|
||||
@@ -86,7 +87,7 @@ export function register(app, basePath = '') {
|
||||
}
|
||||
|
||||
try {
|
||||
const posterminals = await db.list(req.user.id, selected.companyId);
|
||||
const posterminals = await db.list(req.user.id);
|
||||
res.status(200).json({ posterminals });
|
||||
} catch (error) {
|
||||
const status = posterminalErrorStatus(error);
|
||||
@@ -169,7 +170,7 @@ export function register(app, basePath = '') {
|
||||
const pairingpin = String(randomInt(100000, 999999));
|
||||
|
||||
try {
|
||||
const posterminal = await db.upsert(req.user.id, selected.companyId, {
|
||||
const posterminal = await db.upsert(req.user.id, {
|
||||
name: name.trim(),
|
||||
pairingpin,
|
||||
});
|
||||
@@ -237,7 +238,7 @@ export function register(app, basePath = '') {
|
||||
}
|
||||
|
||||
try {
|
||||
await db.remove(req.user.id, selected.companyId, parsed.id);
|
||||
await db.remove(req.user.id, parsed.id);
|
||||
res.sendStatus(204);
|
||||
} catch (error) {
|
||||
const status = posterminalErrorStatus(error);
|
||||
@@ -379,7 +380,7 @@ export function register(app, basePath = '') {
|
||||
}
|
||||
|
||||
try {
|
||||
const result = await db.setOn(req.user.id, selected.companyId, terminal.id, category.id);
|
||||
const result = await db.setOn(req.user.id, terminal.id, category.id);
|
||||
res.status(200).json(result);
|
||||
} catch (error) {
|
||||
const status = posterminalErrorStatus(error);
|
||||
@@ -405,7 +406,7 @@ export function register(app, basePath = '') {
|
||||
}
|
||||
|
||||
try {
|
||||
const result = await db.setOff(req.user.id, selected.companyId, terminal.id, category.id);
|
||||
const result = await db.setOff(req.user.id, terminal.id, category.id);
|
||||
res.status(200).json(result);
|
||||
} catch (error) {
|
||||
const status = posterminalErrorStatus(error);
|
||||
@@ -534,7 +535,7 @@ export function register(app, basePath = '') {
|
||||
}
|
||||
|
||||
try {
|
||||
const result = await db.setOnAll(req.user.id, selected.companyId, terminal.id);
|
||||
const result = await db.setOnAll(req.user.id, terminal.id);
|
||||
res.status(200).json(result);
|
||||
} catch (error) {
|
||||
const status = posterminalErrorStatus(error);
|
||||
@@ -555,7 +556,7 @@ export function register(app, basePath = '') {
|
||||
}
|
||||
|
||||
try {
|
||||
const result = await db.setOffAll(req.user.id, selected.companyId, terminal.id);
|
||||
const result = await db.setOffAll(req.user.id, terminal.id);
|
||||
res.status(200).json(result);
|
||||
} catch (error) {
|
||||
const status = posterminalErrorStatus(error);
|
||||
|
||||
Reference in New Issue
Block a user