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:
@@ -32,13 +32,17 @@ Wenn ein Vertrag unklar oder fehlt: **nicht weiterwursteln**. Human fragen, Vors
|
||||
| **dieses** | `docs/api/README.md` | HTTP-Routen, Auth, CORS |
|
||||
| **dieses** | `docs/api/routes/` | eine Markdown-Datei pro Endpoint |
|
||||
| **dieses** | `docs/api/openapi.json` | maschinenlesbare Spec |
|
||||
| dashdbschema | `../dashdbschema/README.md` | Store-Methoden, Signaturen, Returns |
|
||||
| dashdbschema | `../dashdbschema/README.md` | Store-Übersicht, Konventionen, HTTP-Mapping |
|
||||
| dashdbschema | `../dashdbschema/API.md` | Store-API-Index (TOC → `API.<modul>.md`) |
|
||||
| dashdbschema | `../dashdbschema/API.<modul>.md` | pro Namespace (`entity`, `article`, …): Methoden, Signaturen, JSDoc-Beispiele |
|
||||
| dashdbschema | `../dashdbschema/src/store/` | Implementierung (wenn Doku unklar) |
|
||||
| dashfront | `../dashfront/README.md`, `../dashfront/src/api/index.js` | Client-Spiegel; erwartet unsere API-Docs |
|
||||
|
||||
API-Docs hier regenerieren: `npm run docs:api` (aus `@openapi` an den Handlern).
|
||||
API-Docs hier regenerieren: `npm run docs:api` (aus `@openapi` an den Handlern).
|
||||
Store-API-Docs in dashdbschema: `npm run api-doc` (aus JSDoc in `src/store/` → `API.md` + `API.<modul>.md`).
|
||||
|
||||
## Was der Human / die anderen von dir erwarten
|
||||
|
||||
1. **Vor Frontend-Arbeit:** Route in `docs/api/` aktuell halten (nach Code-Änderung `docs:api` laufen lassen).
|
||||
2. **Vor Store-Nutzung:** `../dashdbschema/README.md` und ggf. dessen Git-Log lesen — fehlende Store-Methode dem Human melden, nicht erfinden.
|
||||
2. **Vor Store-Nutzung:** `../dashdbschema/API.md` / `API.<modul>.md` für Signaturen und Beispiele; `README.md` für Konventionen und HTTP-Mapping; ggf. Git-Log lesen — fehlende Store-Methode dem Human melden, nicht erfinden.
|
||||
3. Frontend-Verträge nur über dokumentierte HTTP-Shapes; keine stillen Breaking Changes ohne Doku-Update.
|
||||
|
||||
@@ -77,6 +77,7 @@ Generated from `@openapi` annotations in [`src/api/routes/`](../../src/api/route
|
||||
| [`routes/delivery/update.md`](routes/delivery/update.md) | `PATCH /delivery/{id}` |
|
||||
| [`routes/entity/list.md`](routes/entity/list.md) | `GET /entity` |
|
||||
| [`routes/entity/create.md`](routes/entity/create.md) | `POST /entity` |
|
||||
| [`routes/entity/next-number.md`](routes/entity/next-number.md) | `GET /entity/next-number` |
|
||||
| [`routes/entity/address/list.md`](routes/entity/address/list.md) | `GET /entity/{entityId}/address` |
|
||||
| [`routes/entity/address/create.md`](routes/entity/address/create.md) | `POST /entity/{entityId}/address` |
|
||||
| [`routes/entity/address/delete.md`](routes/entity/address/delete.md) | `DELETE /entity/{entityId}/address/{id}` |
|
||||
|
||||
@@ -3299,7 +3299,7 @@
|
||||
"Entity"
|
||||
],
|
||||
"summary": "List entities",
|
||||
"description": "Lists entities for the selected company. Optional `customergroupId`\nquery filters to one group (must belong to the company).\n",
|
||||
"description": "Lists entities for the selected company. Optional `customergroupId`\nfilters to one group. Optional `role=customer` excludes Lieferanten/POS\ngroups (for quote/order pickers). `role` wins when both are set.\n",
|
||||
"security": [
|
||||
{
|
||||
"cookieAuth": []
|
||||
@@ -3314,6 +3314,17 @@
|
||||
"schema": {
|
||||
"type": "integer"
|
||||
}
|
||||
},
|
||||
{
|
||||
"in": "query",
|
||||
"name": "role",
|
||||
"required": false,
|
||||
"schema": {
|
||||
"type": "string",
|
||||
"enum": [
|
||||
"customer"
|
||||
]
|
||||
}
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
@@ -3336,7 +3347,7 @@
|
||||
}
|
||||
},
|
||||
"400": {
|
||||
"description": "No company selected or invalid customergroupId",
|
||||
"description": "No company selected, invalid customergroupId, or invalid role",
|
||||
"content": {
|
||||
"application/json": {
|
||||
"schema": {
|
||||
@@ -3382,7 +3393,7 @@
|
||||
"Entity"
|
||||
],
|
||||
"summary": "Create entity",
|
||||
"description": "Creates an entity in a company customer group and writes `entityhistory` (`Erstellt`).\n",
|
||||
"description": "Creates an entity in a company customer group and writes `entityhistory` (`Erstellt`).\nOptional `number`: omit to allocate the next customer number (`type` entity).\n",
|
||||
"security": [
|
||||
{
|
||||
"cookieAuth": []
|
||||
@@ -3409,12 +3420,17 @@
|
||||
"firstName": {
|
||||
"type": "string",
|
||||
"nullable": true
|
||||
},
|
||||
"number": {
|
||||
"type": "string",
|
||||
"description": "Customer number; omit to auto-allocate"
|
||||
}
|
||||
},
|
||||
"example": {
|
||||
"customergroupId": 1,
|
||||
"name": "Müller",
|
||||
"firstName": "Anna"
|
||||
"firstName": "Anna",
|
||||
"number": "10042"
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -3437,7 +3453,7 @@
|
||||
}
|
||||
},
|
||||
"400": {
|
||||
"description": "Name required or no company selected",
|
||||
"description": "Name/number required or no company selected",
|
||||
"content": {
|
||||
"application/json": {
|
||||
"schema": {
|
||||
@@ -3475,6 +3491,94 @@
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"409": {
|
||||
"description": "Number already in use",
|
||||
"content": {
|
||||
"application/json": {
|
||||
"schema": {
|
||||
"$ref": "#/components/schemas/Error"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"/entity/next-number": {
|
||||
"get": {
|
||||
"tags": [
|
||||
"Entity"
|
||||
],
|
||||
"summary": "Peek next customer number",
|
||||
"description": "Returns the next customer number that would be allocated (`type` entity)\nwithout consuming it. Use on the customer add form.\n",
|
||||
"security": [
|
||||
{
|
||||
"cookieAuth": []
|
||||
}
|
||||
],
|
||||
"x-markdown": "entity/next-number.md",
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "Next number",
|
||||
"content": {
|
||||
"application/json": {
|
||||
"schema": {
|
||||
"type": "object",
|
||||
"required": [
|
||||
"number"
|
||||
],
|
||||
"properties": {
|
||||
"number": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
},
|
||||
"example": {
|
||||
"number": "1"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"400": {
|
||||
"description": "No company selected",
|
||||
"content": {
|
||||
"application/json": {
|
||||
"schema": {
|
||||
"$ref": "#/components/schemas/Error"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"401": {
|
||||
"description": "Unauthorized",
|
||||
"content": {
|
||||
"application/json": {
|
||||
"schema": {
|
||||
"$ref": "#/components/schemas/Error"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"403": {
|
||||
"description": "Not authorized",
|
||||
"content": {
|
||||
"application/json": {
|
||||
"schema": {
|
||||
"$ref": "#/components/schemas/Error"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"404": {
|
||||
"description": "Company not found",
|
||||
"content": {
|
||||
"application/json": {
|
||||
"schema": {
|
||||
"$ref": "#/components/schemas/Error"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -3565,7 +3669,7 @@
|
||||
"Entity"
|
||||
],
|
||||
"summary": "Update entity",
|
||||
"description": "Patches `name` and/or `firstName`. Writes `entityhistory` when values change.\n",
|
||||
"description": "Patches fields that are present (`name`, `firstName`, `number`).\n`number` is only changed when the key is present (no auto-allocate).\nWrites `entityhistory` when values change.\n",
|
||||
"security": [
|
||||
{
|
||||
"cookieAuth": []
|
||||
@@ -3595,11 +3699,16 @@
|
||||
"firstName": {
|
||||
"type": "string",
|
||||
"nullable": true
|
||||
},
|
||||
"number": {
|
||||
"type": "string",
|
||||
"nullable": true
|
||||
}
|
||||
},
|
||||
"example": {
|
||||
"name": "Müller",
|
||||
"firstName": "Anna"
|
||||
"firstName": "Anna",
|
||||
"number": "10042"
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -3622,7 +3731,7 @@
|
||||
}
|
||||
},
|
||||
"400": {
|
||||
"description": "Name required, invalid id, or no company selected",
|
||||
"description": "Name/number required, invalid id, or no company selected",
|
||||
"content": {
|
||||
"application/json": {
|
||||
"schema": {
|
||||
@@ -3660,6 +3769,16 @@
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"409": {
|
||||
"description": "Number already in use",
|
||||
"content": {
|
||||
"application/json": {
|
||||
"schema": {
|
||||
"$ref": "#/components/schemas/Error"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
@@ -8070,6 +8189,7 @@
|
||||
"customergroupId",
|
||||
"firstName",
|
||||
"name",
|
||||
"number",
|
||||
"createdAt",
|
||||
"updatedAt"
|
||||
],
|
||||
@@ -8087,6 +8207,11 @@
|
||||
"name": {
|
||||
"type": "string"
|
||||
},
|
||||
"number": {
|
||||
"type": "string",
|
||||
"nullable": true,
|
||||
"description": "Customer number (null for suppliers)"
|
||||
},
|
||||
"createdAt": {
|
||||
"type": "string",
|
||||
"format": "date-time"
|
||||
|
||||
@@ -5,6 +5,7 @@ Protected. Requires a valid session cookie (`credentials: 'include'`).
|
||||
Create entity
|
||||
|
||||
Creates an entity in a company customer group and writes `entityhistory` (`Erstellt`).
|
||||
Optional `number`: omit to allocate the next customer number (`type` entity).
|
||||
|
||||
|
||||
## Body (JSON)
|
||||
@@ -13,7 +14,8 @@ Creates an entity in a company customer group and writes `entityhistory` (`Erste
|
||||
{
|
||||
"customergroupId": 1,
|
||||
"name": "Müller",
|
||||
"firstName": "Anna"
|
||||
"firstName": "Anna",
|
||||
"number": "10042"
|
||||
}
|
||||
```
|
||||
|
||||
@@ -28,6 +30,7 @@ Created entity
|
||||
"customergroupId": 1,
|
||||
"firstName": "…",
|
||||
"name": "…",
|
||||
"number": "…",
|
||||
"createdAt": "2026-08-10T00:00:00.000Z",
|
||||
"updatedAt": "2026-08-10T00:00:00.000Z"
|
||||
}
|
||||
@@ -38,10 +41,11 @@ Created entity
|
||||
|
||||
| Status | Description |
|
||||
|--------|-------------|
|
||||
| 400 | Name required or no company selected — `{"error":"…"}` |
|
||||
| 400 | Name/number required or no company selected — `{"error":"…"}` |
|
||||
| 401 | Unauthorized — `{"error":"…"}` |
|
||||
| 403 | Not authorized — `{"error":"…"}` |
|
||||
| 404 | Company or customer group not found — `{"error":"…"}` |
|
||||
| 409 | Number already in use — `{"error":"…"}` |
|
||||
|
||||
---
|
||||
|
||||
|
||||
@@ -23,6 +23,7 @@ Entity
|
||||
"customergroupId": 1,
|
||||
"firstName": "…",
|
||||
"name": "…",
|
||||
"number": "…",
|
||||
"createdAt": "2026-08-10T00:00:00.000Z",
|
||||
"updatedAt": "2026-08-10T00:00:00.000Z"
|
||||
}
|
||||
|
||||
@@ -5,7 +5,8 @@ Protected. Requires a valid session cookie (`credentials: 'include'`).
|
||||
List entities
|
||||
|
||||
Lists entities for the selected company. Optional `customergroupId`
|
||||
query filters to one group (must belong to the company).
|
||||
filters to one group. Optional `role=customer` excludes Lieferanten/POS
|
||||
groups (for quote/order pickers). `role` wins when both are set.
|
||||
|
||||
|
||||
## Query parameters
|
||||
@@ -13,6 +14,7 @@ query filters to one group (must belong to the company).
|
||||
| Param | Required | Type | Description |
|
||||
|-------|----------|------|-------------|
|
||||
| `customergroupId` | no | integer | |
|
||||
| `role` | no | string | |
|
||||
|
||||
## Response `200`
|
||||
|
||||
@@ -26,6 +28,7 @@ Entity list
|
||||
"customergroupId": 1,
|
||||
"firstName": "…",
|
||||
"name": "…",
|
||||
"number": "…",
|
||||
"createdAt": "2026-08-10T00:00:00.000Z",
|
||||
"updatedAt": "2026-08-10T00:00:00.000Z"
|
||||
}
|
||||
@@ -37,7 +40,7 @@ Entity list
|
||||
|
||||
| Status | Description |
|
||||
|--------|-------------|
|
||||
| 400 | No company selected or invalid customergroupId — `{"error":"…"}` |
|
||||
| 400 | No company selected, invalid customergroupId, or invalid role — `{"error":"…"}` |
|
||||
| 401 | Unauthorized — `{"error":"…"}` |
|
||||
| 403 | Not authorized — `{"error":"…"}` |
|
||||
| 404 | Company or customer group not found — `{"error":"…"}` |
|
||||
|
||||
32
docs/api/routes/entity/next-number.md
Normal file
32
docs/api/routes/entity/next-number.md
Normal file
@@ -0,0 +1,32 @@
|
||||
# `GET /entity/next-number`
|
||||
|
||||
Protected. Requires a valid session cookie (`credentials: 'include'`).
|
||||
|
||||
Peek next customer number
|
||||
|
||||
Returns the next customer number that would be allocated (`type` entity)
|
||||
without consuming it. Use on the customer add form.
|
||||
|
||||
|
||||
## Response `200`
|
||||
|
||||
Next number
|
||||
|
||||
```json
|
||||
{
|
||||
"number": "…"
|
||||
}
|
||||
```
|
||||
|
||||
## Errors
|
||||
|
||||
| Status | Description |
|
||||
|--------|-------------|
|
||||
| 400 | No company selected — `{"error":"…"}` |
|
||||
| 401 | Unauthorized — `{"error":"…"}` |
|
||||
| 403 | Not authorized — `{"error":"…"}` |
|
||||
| 404 | Company not found — `{"error":"…"}` |
|
||||
|
||||
---
|
||||
|
||||
_Generated from `@openapi` JSDoc. Do not edit by hand — run `npm run docs:api`._
|
||||
@@ -4,7 +4,9 @@ Protected. Requires a valid session cookie (`credentials: 'include'`).
|
||||
|
||||
Update entity
|
||||
|
||||
Patches `name` and/or `firstName`. Writes `entityhistory` when values change.
|
||||
Patches fields that are present (`name`, `firstName`, `number`).
|
||||
`number` is only changed when the key is present (no auto-allocate).
|
||||
Writes `entityhistory` when values change.
|
||||
|
||||
|
||||
## Path parameters
|
||||
@@ -18,7 +20,8 @@ Patches `name` and/or `firstName`. Writes `entityhistory` when values change.
|
||||
```json
|
||||
{
|
||||
"name": "Müller",
|
||||
"firstName": "Anna"
|
||||
"firstName": "Anna",
|
||||
"number": "10042"
|
||||
}
|
||||
```
|
||||
|
||||
@@ -33,6 +36,7 @@ Updated entity
|
||||
"customergroupId": 1,
|
||||
"firstName": "…",
|
||||
"name": "…",
|
||||
"number": "…",
|
||||
"createdAt": "2026-08-10T00:00:00.000Z",
|
||||
"updatedAt": "2026-08-10T00:00:00.000Z"
|
||||
}
|
||||
@@ -43,10 +47,11 @@ Updated entity
|
||||
|
||||
| Status | Description |
|
||||
|--------|-------------|
|
||||
| 400 | Name required, invalid id, or no company selected — `{"error":"…"}` |
|
||||
| 400 | Name/number required, invalid id, or no company selected — `{"error":"…"}` |
|
||||
| 401 | Unauthorized — `{"error":"…"}` |
|
||||
| 403 | Not authorized — `{"error":"…"}` |
|
||||
| 404 | Entity or company not found — `{"error":"…"}` |
|
||||
| 409 | Number already in use — `{"error":"…"}` |
|
||||
|
||||
---
|
||||
|
||||
|
||||
@@ -148,7 +148,7 @@
|
||||
* `PUT /customergroup/order`.
|
||||
* Entity:
|
||||
* type: object
|
||||
* required: [id, customergroupId, firstName, name, createdAt, updatedAt]
|
||||
* required: [id, customergroupId, firstName, name, number, createdAt, updatedAt]
|
||||
* properties:
|
||||
* id:
|
||||
* type: integer
|
||||
@@ -159,6 +159,10 @@
|
||||
* nullable: true
|
||||
* name:
|
||||
* type: string
|
||||
* number:
|
||||
* type: string
|
||||
* nullable: true
|
||||
* description: Customer number (null for suppliers)
|
||||
* createdAt:
|
||||
* type: string
|
||||
* format: date-time
|
||||
|
||||
@@ -45,6 +45,7 @@ function parseFullHash(value) {
|
||||
}
|
||||
|
||||
function articleErrorStatus(error) {
|
||||
if (error.message === 'No company selected') return 400;
|
||||
if (error.message === 'Not authorized') return 403;
|
||||
if (error.message === 'Parent not found') return 404;
|
||||
if (error.message === 'Article not found') return 404;
|
||||
@@ -230,7 +231,7 @@ export function register(app, basePath = '') {
|
||||
}
|
||||
|
||||
try {
|
||||
const rows = await db.listExport(req.user.id, companyId, categoryId);
|
||||
const rows = await db.listExport(req.user.id, categoryId);
|
||||
|
||||
const csv = buildArtikelCsv(rows);
|
||||
|
||||
@@ -1376,7 +1377,7 @@ export function register(app, basePath = '') {
|
||||
}
|
||||
|
||||
try {
|
||||
const articles = await db.listSearchIndex(req.user.id, companyId);
|
||||
const articles = await db.listSearchIndex(req.user.id);
|
||||
res.status(200).json({ articles });
|
||||
} catch (error) {
|
||||
const status = articleErrorStatus(error);
|
||||
|
||||
@@ -9,6 +9,7 @@ function requireSelectedCompany(req) {
|
||||
}
|
||||
|
||||
function brandErrorStatus(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 === 'Brand not found') return 404;
|
||||
@@ -134,7 +135,7 @@ export function register(app, basePath = '') {
|
||||
}
|
||||
|
||||
try {
|
||||
const brands = await db.list(req.user.id, selected.companyId);
|
||||
const brands = await db.list(req.user.id);
|
||||
res.status(200).json({ brands });
|
||||
} catch (error) {
|
||||
const status = brandErrorStatus(error);
|
||||
@@ -152,7 +153,7 @@ export function register(app, basePath = '') {
|
||||
const { name, gsprpinfo } = req.body ?? {};
|
||||
|
||||
try {
|
||||
const brand = await db.upsert(req.user.id, selected.companyId, {
|
||||
const brand = await db.upsert(req.user.id, {
|
||||
name,
|
||||
gsprpinfo,
|
||||
});
|
||||
@@ -228,7 +229,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 = brandErrorStatus(error);
|
||||
|
||||
@@ -23,6 +23,7 @@ function parsePositiveInt(value, field) {
|
||||
}
|
||||
|
||||
function categoryErrorStatus(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 === 'Parent not found') return 404;
|
||||
@@ -103,7 +104,7 @@ export function register(app, basePath = '') {
|
||||
}
|
||||
|
||||
try {
|
||||
const result = await db.getTreeForCompany(req.user.id, companyId);
|
||||
const result = await db.getTreeForCompany(req.user.id);
|
||||
res.status(200).json(result);
|
||||
} catch (error) {
|
||||
const status = categoryErrorStatus(error);
|
||||
@@ -166,7 +167,7 @@ export function register(app, basePath = '') {
|
||||
}
|
||||
|
||||
try {
|
||||
const { tree } = await db.getTreeForCompany(req.user.id, companyId);
|
||||
const { tree } = await db.getTreeForCompany(req.user.id);
|
||||
|
||||
const csv = buildKategorienCsv(tree, tree.find((n) => n.parentId == null)?.id ?? null);
|
||||
|
||||
|
||||
@@ -12,6 +12,7 @@ function requireSelectedCompany(req) {
|
||||
}
|
||||
|
||||
function customergroupErrorStatus(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 === 'Customer group not found') return 404;
|
||||
@@ -149,7 +150,7 @@ export function register(app, basePath = '') {
|
||||
}
|
||||
|
||||
try {
|
||||
const rows = await db.list(req.user.id, selected.companyId);
|
||||
const rows = await db.list(req.user.id);
|
||||
res.status(200).json({ customergroups: rows.map(withEditable) });
|
||||
} catch (error) {
|
||||
const status = customergroupErrorStatus(error);
|
||||
@@ -167,7 +168,7 @@ export function register(app, basePath = '') {
|
||||
const { name } = req.body ?? {};
|
||||
|
||||
try {
|
||||
const customergroup = await db.create(req.user.id, selected.companyId, { name });
|
||||
const customergroup = await db.create(req.user.id, { name });
|
||||
res.status(201).json({ customergroup });
|
||||
} catch (error) {
|
||||
const status = customergroupErrorStatus(error);
|
||||
@@ -260,7 +261,7 @@ export function register(app, basePath = '') {
|
||||
}
|
||||
|
||||
try {
|
||||
const result = await db.order(req.user.id, selected.companyId, { customergroupIds });
|
||||
const result = await db.order(req.user.id, { customergroupIds });
|
||||
res.status(200).json(result);
|
||||
} catch (error) {
|
||||
const status = customergroupErrorStatus(error);
|
||||
@@ -396,7 +397,7 @@ export function register(app, basePath = '') {
|
||||
const { name } = req.body ?? {};
|
||||
|
||||
try {
|
||||
const customergroup = await db.update(req.user.id, selected.companyId, id, { name });
|
||||
const customergroup = await db.update(req.user.id, id, { name });
|
||||
res.status(200).json({ customergroup });
|
||||
} catch (error) {
|
||||
const status = customergroupErrorStatus(error);
|
||||
@@ -417,7 +418,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 = customergroupErrorStatus(error);
|
||||
|
||||
@@ -9,6 +9,7 @@ function requireSelectedCompany(req) {
|
||||
}
|
||||
|
||||
function deliveryErrorStatus(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 === 'Delivery not found') return 404;
|
||||
@@ -154,7 +155,7 @@ export function register(app, basePath = '') {
|
||||
}
|
||||
|
||||
try {
|
||||
const deliveries = await db.list(req.user.id, selected.companyId);
|
||||
const deliveries = await db.list(req.user.id);
|
||||
res.status(200).json({ deliveries });
|
||||
} catch (error) {
|
||||
const status = deliveryErrorStatus(error);
|
||||
@@ -172,7 +173,7 @@ export function register(app, basePath = '') {
|
||||
const { number, date, supplierId, lines } = req.body ?? {};
|
||||
|
||||
try {
|
||||
const delivery = await db.create(req.user.id, selected.companyId, {
|
||||
const delivery = await db.create(req.user.id, {
|
||||
number,
|
||||
date,
|
||||
supplierId,
|
||||
@@ -361,7 +362,7 @@ export function register(app, basePath = '') {
|
||||
}
|
||||
|
||||
try {
|
||||
const delivery = await db.getById(req.user.id, selected.companyId, id);
|
||||
const delivery = await db.getById(req.user.id, id);
|
||||
res.status(200).json({ delivery });
|
||||
} catch (error) {
|
||||
const status = deliveryErrorStatus(error);
|
||||
@@ -397,7 +398,7 @@ export function register(app, basePath = '') {
|
||||
}
|
||||
|
||||
try {
|
||||
const delivery = await db.update(req.user.id, selected.companyId, id, patch);
|
||||
const delivery = await db.update(req.user.id, id, patch);
|
||||
res.status(200).json({ delivery });
|
||||
} catch (error) {
|
||||
const status = deliveryErrorStatus(error);
|
||||
@@ -418,7 +419,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 = deliveryErrorStatus(error);
|
||||
|
||||
@@ -9,11 +9,15 @@ function requireSelectedCompany(req) {
|
||||
}
|
||||
|
||||
function entityErrorStatus(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 === 'Entity not found') return 404;
|
||||
if (error.message === 'Customer group not found') return 404;
|
||||
if (error.message === 'Name required') return 400;
|
||||
if (error.message === 'Number required') return 400;
|
||||
if (error.message === 'Number already in use') return 409;
|
||||
if (error.message === 'Invalid role') return 400;
|
||||
return 500;
|
||||
}
|
||||
|
||||
@@ -31,7 +35,8 @@ export function register(app, basePath = '') {
|
||||
* summary: List entities
|
||||
* description: |
|
||||
* Lists entities for the selected company. Optional `customergroupId`
|
||||
* query filters to one group (must belong to the company).
|
||||
* filters to one group. Optional `role=customer` excludes Lieferanten/POS
|
||||
* groups (for quote/order pickers). `role` wins when both are set.
|
||||
* security:
|
||||
* - cookieAuth: []
|
||||
* x-markdown: entity/list.md
|
||||
@@ -41,6 +46,12 @@ export function register(app, basePath = '') {
|
||||
* required: false
|
||||
* schema:
|
||||
* type: integer
|
||||
* - in: query
|
||||
* name: role
|
||||
* required: false
|
||||
* schema:
|
||||
* type: string
|
||||
* enum: [customer]
|
||||
* responses:
|
||||
* 200:
|
||||
* description: Entity list
|
||||
@@ -54,7 +65,7 @@ export function register(app, basePath = '') {
|
||||
* items:
|
||||
* $ref: '#/components/schemas/Entity'
|
||||
* 400:
|
||||
* description: No company selected or invalid customergroupId
|
||||
* description: No company selected, invalid customergroupId, or invalid role
|
||||
* content:
|
||||
* application/json:
|
||||
* schema:
|
||||
@@ -82,6 +93,7 @@ export function register(app, basePath = '') {
|
||||
* summary: Create entity
|
||||
* description: |
|
||||
* Creates an entity in a company customer group and writes `entityhistory` (`Erstellt`).
|
||||
* Optional `number`: omit to allocate the next customer number (`type` entity).
|
||||
* security:
|
||||
* - cookieAuth: []
|
||||
* x-markdown: entity/create.md
|
||||
@@ -100,10 +112,14 @@ export function register(app, basePath = '') {
|
||||
* firstName:
|
||||
* type: string
|
||||
* nullable: true
|
||||
* number:
|
||||
* type: string
|
||||
* description: Customer number; omit to auto-allocate
|
||||
* example:
|
||||
* customergroupId: 1
|
||||
* name: Müller
|
||||
* firstName: Anna
|
||||
* number: '10042'
|
||||
* responses:
|
||||
* 201:
|
||||
* description: Created entity
|
||||
@@ -115,7 +131,7 @@ export function register(app, basePath = '') {
|
||||
* entity:
|
||||
* $ref: '#/components/schemas/Entity'
|
||||
* 400:
|
||||
* description: Name required or no company selected
|
||||
* description: Name/number required or no company selected
|
||||
* content:
|
||||
* application/json:
|
||||
* schema:
|
||||
@@ -138,6 +154,12 @@ export function register(app, basePath = '') {
|
||||
* application/json:
|
||||
* schema:
|
||||
* $ref: '#/components/schemas/Error'
|
||||
* 409:
|
||||
* description: Number already in use
|
||||
* content:
|
||||
* application/json:
|
||||
* schema:
|
||||
* $ref: '#/components/schemas/Error'
|
||||
*/
|
||||
app.get(`${basePath}/entity`, async (req, res) => {
|
||||
const selected = requireSelectedCompany(req);
|
||||
@@ -153,9 +175,12 @@ export function register(app, basePath = '') {
|
||||
}
|
||||
options.customergroupId = customergroupId;
|
||||
}
|
||||
if (Object.prototype.hasOwnProperty.call(req.query, 'role')) {
|
||||
options.role = req.query.role;
|
||||
}
|
||||
|
||||
try {
|
||||
const entities = await db.list(req.user.id, selected.companyId, options);
|
||||
const entities = await db.list(req.user.id, options);
|
||||
res.status(200).json({ entities });
|
||||
} catch (error) {
|
||||
const status = entityErrorStatus(error);
|
||||
@@ -170,14 +195,18 @@ export function register(app, basePath = '') {
|
||||
return res.status(400).json({ error: selected.error });
|
||||
}
|
||||
|
||||
const { customergroupId, name, firstName } = req.body ?? {};
|
||||
const body = req.body ?? {};
|
||||
const data = {
|
||||
customergroupId: body.customergroupId,
|
||||
name: body.name,
|
||||
firstName: body.firstName,
|
||||
};
|
||||
if (Object.prototype.hasOwnProperty.call(body, 'number')) {
|
||||
data.number = body.number;
|
||||
}
|
||||
|
||||
try {
|
||||
const entity = await db.create(req.user.id, selected.companyId, {
|
||||
customergroupId,
|
||||
name,
|
||||
firstName,
|
||||
});
|
||||
const entity = await db.create(req.user.id, data);
|
||||
res.status(201).json({ entity });
|
||||
} catch (error) {
|
||||
const status = entityErrorStatus(error);
|
||||
@@ -186,6 +215,72 @@ export function register(app, basePath = '') {
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* @openapi
|
||||
* /entity/next-number:
|
||||
* get:
|
||||
* tags: [Entity]
|
||||
* summary: Peek next customer number
|
||||
* description: |
|
||||
* Returns the next customer number that would be allocated (`type` entity)
|
||||
* without consuming it. Use on the customer add form.
|
||||
* security:
|
||||
* - cookieAuth: []
|
||||
* x-markdown: entity/next-number.md
|
||||
* responses:
|
||||
* 200:
|
||||
* description: Next number
|
||||
* content:
|
||||
* application/json:
|
||||
* schema:
|
||||
* type: object
|
||||
* required: [number]
|
||||
* properties:
|
||||
* number:
|
||||
* type: string
|
||||
* example:
|
||||
* number: '1'
|
||||
* 400:
|
||||
* description: No company selected
|
||||
* content:
|
||||
* application/json:
|
||||
* schema:
|
||||
* $ref: '#/components/schemas/Error'
|
||||
* 401:
|
||||
* description: Unauthorized
|
||||
* content:
|
||||
* application/json:
|
||||
* schema:
|
||||
* $ref: '#/components/schemas/Error'
|
||||
* 403:
|
||||
* description: Not authorized
|
||||
* content:
|
||||
* application/json:
|
||||
* schema:
|
||||
* $ref: '#/components/schemas/Error'
|
||||
* 404:
|
||||
* description: Company not found
|
||||
* content:
|
||||
* application/json:
|
||||
* schema:
|
||||
* $ref: '#/components/schemas/Error'
|
||||
*/
|
||||
app.get(`${basePath}/entity/next-number`, async (req, res) => {
|
||||
const selected = requireSelectedCompany(req);
|
||||
if (selected.error) {
|
||||
return res.status(400).json({ error: selected.error });
|
||||
}
|
||||
|
||||
try {
|
||||
const number = await db.peekNextNumber(req.user.id);
|
||||
res.status(200).json({ number });
|
||||
} catch (error) {
|
||||
const status = entityErrorStatus(error);
|
||||
if (status === 500) console.error('Peek next entity number failed:', error);
|
||||
res.status(status).json({ error: error.message });
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* @openapi
|
||||
* /entity/{id}:
|
||||
@@ -240,7 +335,9 @@ export function register(app, basePath = '') {
|
||||
* tags: [Entity]
|
||||
* summary: Update entity
|
||||
* description: |
|
||||
* Patches `name` and/or `firstName`. Writes `entityhistory` when values change.
|
||||
* Patches fields that are present (`name`, `firstName`, `number`).
|
||||
* `number` is only changed when the key is present (no auto-allocate).
|
||||
* Writes `entityhistory` when values change.
|
||||
* security:
|
||||
* - cookieAuth: []
|
||||
* x-markdown: entity/update.md
|
||||
@@ -262,9 +359,13 @@ export function register(app, basePath = '') {
|
||||
* firstName:
|
||||
* type: string
|
||||
* nullable: true
|
||||
* number:
|
||||
* type: string
|
||||
* nullable: true
|
||||
* example:
|
||||
* name: Müller
|
||||
* firstName: Anna
|
||||
* number: '10042'
|
||||
* responses:
|
||||
* 200:
|
||||
* description: Updated entity
|
||||
@@ -276,7 +377,7 @@ export function register(app, basePath = '') {
|
||||
* entity:
|
||||
* $ref: '#/components/schemas/Entity'
|
||||
* 400:
|
||||
* description: Name required, invalid id, or no company selected
|
||||
* description: Name/number required, invalid id, or no company selected
|
||||
* content:
|
||||
* application/json:
|
||||
* schema:
|
||||
@@ -299,6 +400,12 @@ export function register(app, basePath = '') {
|
||||
* application/json:
|
||||
* schema:
|
||||
* $ref: '#/components/schemas/Error'
|
||||
* 409:
|
||||
* description: Number already in use
|
||||
* content:
|
||||
* application/json:
|
||||
* schema:
|
||||
* $ref: '#/components/schemas/Error'
|
||||
* delete:
|
||||
* tags: [Entity]
|
||||
* summary: Delete entity
|
||||
@@ -352,7 +459,7 @@ export function register(app, basePath = '') {
|
||||
}
|
||||
|
||||
try {
|
||||
const entity = await db.getById(req.user.id, selected.companyId, id);
|
||||
const entity = await db.getById(req.user.id, id);
|
||||
res.status(200).json({ entity });
|
||||
} catch (error) {
|
||||
const status = entityErrorStatus(error);
|
||||
@@ -380,9 +487,12 @@ export function register(app, basePath = '') {
|
||||
if (Object.prototype.hasOwnProperty.call(body, 'firstName')) {
|
||||
patch.firstName = body.firstName;
|
||||
}
|
||||
if (Object.prototype.hasOwnProperty.call(body, 'number')) {
|
||||
patch.number = body.number;
|
||||
}
|
||||
|
||||
try {
|
||||
const entity = await db.update(req.user.id, selected.companyId, id, patch);
|
||||
const entity = await db.update(req.user.id, id, patch);
|
||||
res.status(200).json({ entity });
|
||||
} catch (error) {
|
||||
const status = entityErrorStatus(error);
|
||||
@@ -403,7 +513,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 = entityErrorStatus(error);
|
||||
|
||||
@@ -9,6 +9,7 @@ function requireSelectedCompany(req) {
|
||||
}
|
||||
|
||||
function addressErrorStatus(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 === 'Entity not found') return 404;
|
||||
@@ -183,7 +184,7 @@ export function register(app, basePath = '') {
|
||||
}
|
||||
|
||||
try {
|
||||
const addresses = await db.list(req.user.id, selected.companyId, entityId);
|
||||
const addresses = await db.list(req.user.id, entityId);
|
||||
res.status(200).json({ addresses });
|
||||
} catch (error) {
|
||||
const status = addressErrorStatus(error);
|
||||
@@ -212,7 +213,7 @@ export function register(app, basePath = '') {
|
||||
}
|
||||
|
||||
try {
|
||||
const address = await db.create(req.user.id, selected.companyId, entityId, data);
|
||||
const address = await db.create(req.user.id, entityId, data);
|
||||
res.status(201).json({ address });
|
||||
} catch (error) {
|
||||
const status = addressErrorStatus(error);
|
||||
@@ -379,7 +380,7 @@ export function register(app, basePath = '') {
|
||||
}
|
||||
|
||||
try {
|
||||
const address = await db.update(req.user.id, selected.companyId, entityId, id, patch);
|
||||
const address = await db.update(req.user.id, entityId, id, patch);
|
||||
res.status(200).json({ address });
|
||||
} catch (error) {
|
||||
const status = addressErrorStatus(error);
|
||||
@@ -404,7 +405,7 @@ export function register(app, basePath = '') {
|
||||
}
|
||||
|
||||
try {
|
||||
await db.remove(req.user.id, selected.companyId, entityId, id);
|
||||
await db.remove(req.user.id, entityId, id);
|
||||
res.sendStatus(204);
|
||||
} catch (error) {
|
||||
const status = addressErrorStatus(error);
|
||||
|
||||
@@ -9,6 +9,7 @@ function requireSelectedCompany(req) {
|
||||
}
|
||||
|
||||
function contactErrorStatus(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 === 'Entity not found') return 404;
|
||||
@@ -151,7 +152,7 @@ export function register(app, basePath = '') {
|
||||
}
|
||||
|
||||
try {
|
||||
const contacts = await db.list(req.user.id, selected.companyId, entityId);
|
||||
const contacts = await db.list(req.user.id, entityId);
|
||||
res.status(200).json({ contacts });
|
||||
} catch (error) {
|
||||
const status = contactErrorStatus(error);
|
||||
@@ -174,7 +175,7 @@ export function register(app, basePath = '') {
|
||||
const { contactType, contact } = req.body ?? {};
|
||||
|
||||
try {
|
||||
const row = await db.create(req.user.id, selected.companyId, entityId, {
|
||||
const row = await db.create(req.user.id, entityId, {
|
||||
contactType,
|
||||
contact,
|
||||
});
|
||||
@@ -325,7 +326,7 @@ export function register(app, basePath = '') {
|
||||
}
|
||||
|
||||
try {
|
||||
const row = await db.update(req.user.id, selected.companyId, entityId, id, patch);
|
||||
const row = await db.update(req.user.id, entityId, id, patch);
|
||||
res.status(200).json({ contact: row });
|
||||
} catch (error) {
|
||||
const status = contactErrorStatus(error);
|
||||
@@ -350,7 +351,7 @@ export function register(app, basePath = '') {
|
||||
}
|
||||
|
||||
try {
|
||||
await db.remove(req.user.id, selected.companyId, entityId, id);
|
||||
await db.remove(req.user.id, entityId, id);
|
||||
res.sendStatus(204);
|
||||
} catch (error) {
|
||||
const status = contactErrorStatus(error);
|
||||
|
||||
@@ -9,6 +9,7 @@ function requireSelectedCompany(req) {
|
||||
}
|
||||
|
||||
function orderErrorStatus(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 === 'Order not found') return 404;
|
||||
@@ -157,7 +158,7 @@ export function register(app, basePath = '') {
|
||||
}
|
||||
|
||||
try {
|
||||
const orders = await db.list(req.user.id, selected.companyId);
|
||||
const orders = await db.list(req.user.id);
|
||||
res.status(200).json({ orders });
|
||||
} catch (error) {
|
||||
const status = orderErrorStatus(error);
|
||||
@@ -175,7 +176,7 @@ export function register(app, basePath = '') {
|
||||
const { number, date, entityId, lines } = req.body ?? {};
|
||||
|
||||
try {
|
||||
const order = await db.create(req.user.id, selected.companyId, {
|
||||
const order = await db.create(req.user.id, {
|
||||
number,
|
||||
date,
|
||||
entityId,
|
||||
@@ -365,7 +366,7 @@ export function register(app, basePath = '') {
|
||||
}
|
||||
|
||||
try {
|
||||
const order = await db.getById(req.user.id, selected.companyId, id);
|
||||
const order = await db.getById(req.user.id, id);
|
||||
res.status(200).json({ order });
|
||||
} catch (error) {
|
||||
const status = orderErrorStatus(error);
|
||||
@@ -401,7 +402,7 @@ export function register(app, basePath = '') {
|
||||
}
|
||||
|
||||
try {
|
||||
const order = await db.update(req.user.id, selected.companyId, id, patch);
|
||||
const order = await db.update(req.user.id, id, patch);
|
||||
res.status(200).json({ order });
|
||||
} catch (error) {
|
||||
const status = orderErrorStatus(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 = orderErrorStatus(error);
|
||||
|
||||
@@ -13,6 +13,7 @@ function parseFullHash(value) {
|
||||
}
|
||||
|
||||
function picErrorStatus(error) {
|
||||
if (error.message === 'No company selected') return 400;
|
||||
if (error.message === 'Not authorized') return 403;
|
||||
if (error.message === 'Image not found') return 404;
|
||||
return 500;
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -65,12 +65,12 @@ export async function setCategoryIdsBySku(googleAuthId, sku, categoryIds) {
|
||||
return store.article.setCategoryIdsBySku(googleAuthId, sku, categoryIds);
|
||||
}
|
||||
|
||||
export async function listSearchIndex(googleAuthId, companyId) {
|
||||
export async function listSearchIndex(googleAuthId) {
|
||||
const store = await getStore();
|
||||
return store.article.listSearchIndex(googleAuthId, companyId);
|
||||
return store.article.listSearchIndex(googleAuthId);
|
||||
}
|
||||
|
||||
export async function listExport(googleAuthId, companyId, categoryId) {
|
||||
export async function listExport(googleAuthId, categoryId) {
|
||||
const store = await getStore();
|
||||
return store.article.listExport(googleAuthId, companyId, categoryId);
|
||||
return store.article.listExport(googleAuthId, categoryId);
|
||||
}
|
||||
|
||||
@@ -1,16 +1,16 @@
|
||||
import { getStore } from './store.js';
|
||||
|
||||
export async function list(googleAuthId, companyId) {
|
||||
export async function list(googleAuthId) {
|
||||
const store = await getStore();
|
||||
return store.brand.list(googleAuthId, companyId);
|
||||
return store.brand.list(googleAuthId);
|
||||
}
|
||||
|
||||
export async function upsert(googleAuthId, companyId, data) {
|
||||
export async function upsert(googleAuthId, data) {
|
||||
const store = await getStore();
|
||||
return store.brand.upsert(googleAuthId, companyId, data);
|
||||
return store.brand.upsert(googleAuthId, data);
|
||||
}
|
||||
|
||||
export async function remove(googleAuthId, companyId, id) {
|
||||
export async function remove(googleAuthId, id) {
|
||||
const store = await getStore();
|
||||
return store.brand.delete(googleAuthId, companyId, id);
|
||||
return store.brand.delete(googleAuthId, id);
|
||||
}
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import { getStore } from './store.js';
|
||||
|
||||
export async function getTreeForCompany(googleAuthId, companyId) {
|
||||
export async function getTreeForCompany(googleAuthId) {
|
||||
const store = await getStore();
|
||||
return store.category.getTreeForCompany(googleAuthId, companyId);
|
||||
return store.category.getTreeForCompany(googleAuthId);
|
||||
}
|
||||
|
||||
export async function createUnderParent({ googleAuthId, parentId, name }) {
|
||||
|
||||
@@ -1,26 +1,26 @@
|
||||
import { getStore } from './store.js';
|
||||
|
||||
export async function list(googleAuthId, companyId) {
|
||||
export async function list(googleAuthId) {
|
||||
const store = await getStore();
|
||||
return store.customergroup.list(googleAuthId, companyId);
|
||||
return store.customergroup.list(googleAuthId);
|
||||
}
|
||||
|
||||
export async function create(googleAuthId, companyId, data) {
|
||||
export async function create(googleAuthId, data) {
|
||||
const store = await getStore();
|
||||
return store.customergroup.create(googleAuthId, companyId, data);
|
||||
return store.customergroup.create(googleAuthId, data);
|
||||
}
|
||||
|
||||
export async function update(googleAuthId, companyId, id, data) {
|
||||
export async function update(googleAuthId, id, data) {
|
||||
const store = await getStore();
|
||||
return store.customergroup.update(googleAuthId, companyId, id, data);
|
||||
return store.customergroup.update(googleAuthId, id, data);
|
||||
}
|
||||
|
||||
export async function order(googleAuthId, companyId, data) {
|
||||
export async function order(googleAuthId, data) {
|
||||
const store = await getStore();
|
||||
return store.customergroup.order(googleAuthId, companyId, data);
|
||||
return store.customergroup.order(googleAuthId, data);
|
||||
}
|
||||
|
||||
export async function remove(googleAuthId, companyId, id) {
|
||||
export async function remove(googleAuthId, id) {
|
||||
const store = await getStore();
|
||||
return store.customergroup.delete(googleAuthId, companyId, id);
|
||||
return store.customergroup.delete(googleAuthId, id);
|
||||
}
|
||||
|
||||
@@ -1,26 +1,26 @@
|
||||
import { getStore } from './store.js';
|
||||
|
||||
export async function list(googleAuthId, companyId) {
|
||||
export async function list(googleAuthId) {
|
||||
const store = await getStore();
|
||||
return store.delivery.list(googleAuthId, companyId);
|
||||
return store.delivery.list(googleAuthId);
|
||||
}
|
||||
|
||||
export async function getById(googleAuthId, companyId, id) {
|
||||
export async function getById(googleAuthId, id) {
|
||||
const store = await getStore();
|
||||
return store.delivery.getById(googleAuthId, companyId, id);
|
||||
return store.delivery.getById(googleAuthId, id);
|
||||
}
|
||||
|
||||
export async function create(googleAuthId, companyId, data) {
|
||||
export async function create(googleAuthId, data) {
|
||||
const store = await getStore();
|
||||
return store.delivery.create(googleAuthId, companyId, data);
|
||||
return store.delivery.create(googleAuthId, data);
|
||||
}
|
||||
|
||||
export async function update(googleAuthId, companyId, id, data) {
|
||||
export async function update(googleAuthId, id, data) {
|
||||
const store = await getStore();
|
||||
return store.delivery.update(googleAuthId, companyId, id, data);
|
||||
return store.delivery.update(googleAuthId, id, data);
|
||||
}
|
||||
|
||||
export async function remove(googleAuthId, companyId, id) {
|
||||
export async function remove(googleAuthId, id) {
|
||||
const store = await getStore();
|
||||
return store.delivery.delete(googleAuthId, companyId, id);
|
||||
return store.delivery.delete(googleAuthId, id);
|
||||
}
|
||||
|
||||
@@ -1,26 +1,31 @@
|
||||
import { getStore } from './store.js';
|
||||
|
||||
export async function list(googleAuthId, companyId, options) {
|
||||
export async function list(googleAuthId, options) {
|
||||
const store = await getStore();
|
||||
return store.entity.list(googleAuthId, companyId, options);
|
||||
return store.entity.list(googleAuthId, options);
|
||||
}
|
||||
|
||||
export async function getById(googleAuthId, companyId, id) {
|
||||
export async function getById(googleAuthId, id) {
|
||||
const store = await getStore();
|
||||
return store.entity.getById(googleAuthId, companyId, id);
|
||||
return store.entity.getById(googleAuthId, id);
|
||||
}
|
||||
|
||||
export async function create(googleAuthId, companyId, data) {
|
||||
export async function create(googleAuthId, data) {
|
||||
const store = await getStore();
|
||||
return store.entity.create(googleAuthId, companyId, data);
|
||||
return store.entity.create(googleAuthId, data);
|
||||
}
|
||||
|
||||
export async function update(googleAuthId, companyId, id, data) {
|
||||
export async function update(googleAuthId, id, data) {
|
||||
const store = await getStore();
|
||||
return store.entity.update(googleAuthId, companyId, id, data);
|
||||
return store.entity.update(googleAuthId, id, data);
|
||||
}
|
||||
|
||||
export async function remove(googleAuthId, companyId, id) {
|
||||
export async function remove(googleAuthId, id) {
|
||||
const store = await getStore();
|
||||
return store.entity.delete(googleAuthId, companyId, id);
|
||||
return store.entity.delete(googleAuthId, id);
|
||||
}
|
||||
|
||||
export async function peekNextNumber(googleAuthId) {
|
||||
const store = await getStore();
|
||||
return store.entity.peekNextNumber(googleAuthId);
|
||||
}
|
||||
|
||||
@@ -1,21 +1,21 @@
|
||||
import { getStore } from './store.js';
|
||||
|
||||
export async function list(googleAuthId, companyId, entityId) {
|
||||
export async function list(googleAuthId, entityId) {
|
||||
const store = await getStore();
|
||||
return store.entityaddress.list(googleAuthId, companyId, entityId);
|
||||
return store.entityaddress.list(googleAuthId, entityId);
|
||||
}
|
||||
|
||||
export async function create(googleAuthId, companyId, entityId, data) {
|
||||
export async function create(googleAuthId, entityId, data) {
|
||||
const store = await getStore();
|
||||
return store.entityaddress.create(googleAuthId, companyId, entityId, data);
|
||||
return store.entityaddress.create(googleAuthId, entityId, data);
|
||||
}
|
||||
|
||||
export async function update(googleAuthId, companyId, entityId, id, data) {
|
||||
export async function update(googleAuthId, entityId, id, data) {
|
||||
const store = await getStore();
|
||||
return store.entityaddress.update(googleAuthId, companyId, entityId, id, data);
|
||||
return store.entityaddress.update(googleAuthId, entityId, id, data);
|
||||
}
|
||||
|
||||
export async function remove(googleAuthId, companyId, entityId, id) {
|
||||
export async function remove(googleAuthId, entityId, id) {
|
||||
const store = await getStore();
|
||||
return store.entityaddress.delete(googleAuthId, companyId, entityId, id);
|
||||
return store.entityaddress.delete(googleAuthId, entityId, id);
|
||||
}
|
||||
|
||||
@@ -1,21 +1,21 @@
|
||||
import { getStore } from './store.js';
|
||||
|
||||
export async function list(googleAuthId, companyId, entityId) {
|
||||
export async function list(googleAuthId, entityId) {
|
||||
const store = await getStore();
|
||||
return store.entitycontact.list(googleAuthId, companyId, entityId);
|
||||
return store.entitycontact.list(googleAuthId, entityId);
|
||||
}
|
||||
|
||||
export async function create(googleAuthId, companyId, entityId, data) {
|
||||
export async function create(googleAuthId, entityId, data) {
|
||||
const store = await getStore();
|
||||
return store.entitycontact.create(googleAuthId, companyId, entityId, data);
|
||||
return store.entitycontact.create(googleAuthId, entityId, data);
|
||||
}
|
||||
|
||||
export async function update(googleAuthId, companyId, entityId, id, data) {
|
||||
export async function update(googleAuthId, entityId, id, data) {
|
||||
const store = await getStore();
|
||||
return store.entitycontact.update(googleAuthId, companyId, entityId, id, data);
|
||||
return store.entitycontact.update(googleAuthId, entityId, id, data);
|
||||
}
|
||||
|
||||
export async function remove(googleAuthId, companyId, entityId, id) {
|
||||
export async function remove(googleAuthId, entityId, id) {
|
||||
const store = await getStore();
|
||||
return store.entitycontact.delete(googleAuthId, companyId, entityId, id);
|
||||
return store.entitycontact.delete(googleAuthId, entityId, id);
|
||||
}
|
||||
|
||||
@@ -1,26 +1,26 @@
|
||||
import { getStore } from './store.js';
|
||||
|
||||
export async function list(googleAuthId, companyId) {
|
||||
export async function list(googleAuthId) {
|
||||
const store = await getStore();
|
||||
return store.order.list(googleAuthId, companyId);
|
||||
return store.order.list(googleAuthId);
|
||||
}
|
||||
|
||||
export async function getById(googleAuthId, companyId, id) {
|
||||
export async function getById(googleAuthId, id) {
|
||||
const store = await getStore();
|
||||
return store.order.getById(googleAuthId, companyId, id);
|
||||
return store.order.getById(googleAuthId, id);
|
||||
}
|
||||
|
||||
export async function create(googleAuthId, companyId, data) {
|
||||
export async function create(googleAuthId, data) {
|
||||
const store = await getStore();
|
||||
return store.order.create(googleAuthId, companyId, data);
|
||||
return store.order.create(googleAuthId, data);
|
||||
}
|
||||
|
||||
export async function update(googleAuthId, companyId, id, data) {
|
||||
export async function update(googleAuthId, id, data) {
|
||||
const store = await getStore();
|
||||
return store.order.update(googleAuthId, companyId, id, data);
|
||||
return store.order.update(googleAuthId, id, data);
|
||||
}
|
||||
|
||||
export async function remove(googleAuthId, companyId, id) {
|
||||
export async function remove(googleAuthId, id) {
|
||||
const store = await getStore();
|
||||
return store.order.delete(googleAuthId, companyId, id);
|
||||
return store.order.delete(googleAuthId, id);
|
||||
}
|
||||
|
||||
@@ -1,36 +1,36 @@
|
||||
import { getStore } from './store.js';
|
||||
|
||||
export async function list(googleAuthId, companyId) {
|
||||
export async function list(googleAuthId) {
|
||||
const store = await getStore();
|
||||
return store.posterminal.list(googleAuthId, companyId);
|
||||
return store.posterminal.list(googleAuthId);
|
||||
}
|
||||
|
||||
export async function upsert(googleAuthId, companyId, data) {
|
||||
export async function upsert(googleAuthId, data) {
|
||||
const store = await getStore();
|
||||
return store.posterminal.upsert(googleAuthId, companyId, data);
|
||||
return store.posterminal.upsert(googleAuthId, data);
|
||||
}
|
||||
|
||||
export async function remove(googleAuthId, companyId, id) {
|
||||
export async function remove(googleAuthId, id) {
|
||||
const store = await getStore();
|
||||
return store.posterminal.delete(googleAuthId, companyId, id);
|
||||
return store.posterminal.delete(googleAuthId, id);
|
||||
}
|
||||
|
||||
export async function setOn(googleAuthId, companyId, posterminalId, categoryId) {
|
||||
export async function setOn(googleAuthId, posterminalId, categoryId) {
|
||||
const store = await getStore();
|
||||
return store.posterminal.setOn(googleAuthId, companyId, posterminalId, categoryId);
|
||||
return store.posterminal.setOn(googleAuthId, posterminalId, categoryId);
|
||||
}
|
||||
|
||||
export async function setOff(googleAuthId, companyId, posterminalId, categoryId) {
|
||||
export async function setOff(googleAuthId, posterminalId, categoryId) {
|
||||
const store = await getStore();
|
||||
return store.posterminal.setOff(googleAuthId, companyId, posterminalId, categoryId);
|
||||
return store.posterminal.setOff(googleAuthId, posterminalId, categoryId);
|
||||
}
|
||||
|
||||
export async function setOnAll(googleAuthId, companyId, posterminalId) {
|
||||
export async function setOnAll(googleAuthId, posterminalId) {
|
||||
const store = await getStore();
|
||||
return store.posterminal.setOnAll(googleAuthId, companyId, posterminalId);
|
||||
return store.posterminal.setOnAll(googleAuthId, posterminalId);
|
||||
}
|
||||
|
||||
export async function setOffAll(googleAuthId, companyId, posterminalId) {
|
||||
export async function setOffAll(googleAuthId, posterminalId) {
|
||||
const store = await getStore();
|
||||
return store.posterminal.setOffAll(googleAuthId, companyId, posterminalId);
|
||||
return store.posterminal.setOffAll(googleAuthId, posterminalId);
|
||||
}
|
||||
|
||||
@@ -1,26 +1,26 @@
|
||||
import { getStore } from './store.js';
|
||||
|
||||
export async function list(googleAuthId, companyId) {
|
||||
export async function list(googleAuthId) {
|
||||
const store = await getStore();
|
||||
return store.quote.list(googleAuthId, companyId);
|
||||
return store.quote.list(googleAuthId);
|
||||
}
|
||||
|
||||
export async function getById(googleAuthId, companyId, id) {
|
||||
export async function getById(googleAuthId, id) {
|
||||
const store = await getStore();
|
||||
return store.quote.getById(googleAuthId, companyId, id);
|
||||
return store.quote.getById(googleAuthId, id);
|
||||
}
|
||||
|
||||
export async function create(googleAuthId, companyId, data) {
|
||||
export async function create(googleAuthId, data) {
|
||||
const store = await getStore();
|
||||
return store.quote.create(googleAuthId, companyId, data);
|
||||
return store.quote.create(googleAuthId, data);
|
||||
}
|
||||
|
||||
export async function update(googleAuthId, companyId, id, data) {
|
||||
export async function update(googleAuthId, id, data) {
|
||||
const store = await getStore();
|
||||
return store.quote.update(googleAuthId, companyId, id, data);
|
||||
return store.quote.update(googleAuthId, id, data);
|
||||
}
|
||||
|
||||
export async function remove(googleAuthId, companyId, id) {
|
||||
export async function remove(googleAuthId, id) {
|
||||
const store = await getStore();
|
||||
return store.quote.delete(googleAuthId, companyId, id);
|
||||
return store.quote.delete(googleAuthId, id);
|
||||
}
|
||||
|
||||
@@ -1,21 +1,21 @@
|
||||
import { getStore } from './store.js';
|
||||
|
||||
export async function list(googleAuthId, companyId) {
|
||||
export async function list(googleAuthId) {
|
||||
const store = await getStore();
|
||||
return store.supplier.list(googleAuthId, companyId);
|
||||
return store.supplier.list(googleAuthId);
|
||||
}
|
||||
|
||||
export async function create(googleAuthId, companyId, data) {
|
||||
export async function create(googleAuthId, data) {
|
||||
const store = await getStore();
|
||||
return store.supplier.create(googleAuthId, companyId, data);
|
||||
return store.supplier.create(googleAuthId, data);
|
||||
}
|
||||
|
||||
export async function update(googleAuthId, companyId, id, data) {
|
||||
export async function update(googleAuthId, id, data) {
|
||||
const store = await getStore();
|
||||
return store.supplier.update(googleAuthId, companyId, id, data);
|
||||
return store.supplier.update(googleAuthId, id, data);
|
||||
}
|
||||
|
||||
export async function remove(googleAuthId, companyId, id) {
|
||||
export async function remove(googleAuthId, id) {
|
||||
const store = await getStore();
|
||||
return store.supplier.delete(googleAuthId, companyId, id);
|
||||
return store.supplier.delete(googleAuthId, id);
|
||||
}
|
||||
|
||||
@@ -1,16 +1,16 @@
|
||||
import { getStore } from './store.js';
|
||||
|
||||
export async function list(googleAuthId, companyId) {
|
||||
export async function list(googleAuthId) {
|
||||
const store = await getStore();
|
||||
return store.unit.list(googleAuthId, companyId);
|
||||
return store.unit.list(googleAuthId);
|
||||
}
|
||||
|
||||
export async function upsert(googleAuthId, companyId, data) {
|
||||
export async function upsert(googleAuthId, data) {
|
||||
const store = await getStore();
|
||||
return store.unit.upsert(googleAuthId, companyId, data);
|
||||
return store.unit.upsert(googleAuthId, data);
|
||||
}
|
||||
|
||||
export async function remove(googleAuthId, companyId, si) {
|
||||
export async function remove(googleAuthId, si) {
|
||||
const store = await getStore();
|
||||
return store.unit.delete(googleAuthId, companyId, si);
|
||||
return store.unit.delete(googleAuthId, si);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user