This commit is contained in:
seb
2026-07-31 05:57:23 +02:00
parent b99c3a9ec7
commit 02bca8e236
14 changed files with 93 additions and 132 deletions

View File

@@ -12,6 +12,8 @@ const client = await new LibDashStore(pool); // runs initialize() (ensure schema
SQL lives in `src/sql/<table>.js`. Schema DDL: `src/schema.js` / `import 'libdashstore/schema'`.
ID fields in the JS API use camelCase `…Id` (DB columns stay snake_case).
---
## Schema
@@ -27,11 +29,10 @@ SQL lives in `src/sql/<table>.js`. Schema DDL: `src/schema.js` / `import 'libdas
| Method | Signature | Returns |
| --- | --- | --- |
| `create` | `({ iso639, name, taxrate, reducedtaxrate })` | `{ id, root_category_id, language_id, taxrate_id, reducedtaxrate_id, taxfreerate_id }` |
| `update` | `(id, { iso639, name, taxrate, reducedtaxrate })` | `{ id, root_category_id, language_id, taxrate_id, reducedtaxrate_id, taxfreerate_id }` |
| `create` | `({ iso639, name, taxrate, reducedtaxrate })` | `{ id, rootCategoryId, languageId, taxrateId, reducedtaxrateId, taxfreerateId }` |
| `update` | `(id, { iso639, name, taxrate, reducedtaxrate })` | `{ id, rootCategoryId, languageId, taxrateId, reducedtaxrateId, taxfreerateId }` |
| `delete` | `(companyId)` | `void` |
| `list` | `()` | `{ id, root_category_id, language_id, taxrate_id, reducedtaxrate_id, taxfreerate_id }[]` |
| `list` | `()` | `{ id, rootCategoryId, languageId, taxrateId, reducedtaxrateId, taxfreerateId }[]` |
### `create` (transaction)
@@ -39,8 +40,8 @@ For `POST /api/company`:
1. Fails if `name` is taken (`Company name not available`)
2. Ensures language by `iso639` (get or create)
3. Ensures tax rows for `taxrate`, `reducedtaxrate`, and `0` → `taxfreerate_id`
4. Creates root category (`parent_id = null`)
3. Ensures tax rows for `taxrate`, `reducedtaxrate`, and `0` → `taxfreerateId`
4. Creates root category (`parentId = null`)
5. Inserts company with all FKs set
### `update` (transaction)
@@ -50,7 +51,7 @@ For `PATCH /api/company/:id`:
1. Fails if company missing / name taken by another company
2. Ensures lang + tax rates
3. Updates `name`, `default_language_id`, `taxrate`, `reducedtaxrate`
(`taxfreerate_id` / root category unchanged)
(`taxfreerateId` / root category unchanged)
---
@@ -58,28 +59,16 @@ For `PATCH /api/company/:id`:
| Method | Signature | Returns |
| --- | --- | --- |
| `add` | `(email)` | `number` (auth id) |
| `getById` | `(id)` | `row \| undefined` |
| `getByEmail` | `(email)` | `row \| undefined` |
| `add` | `(email)` | `id` |
| `getByEmail` | `(email)` | `{ id, email, createdAt, selectedCompanyId } \| undefined` |
| `listAllowedEmails` | `()` | `{ id, email, createdAt, selectedCompanyId }[]` |
| `removeAllowedEmail` | `(email)` | `void` |
| `setSelectedCompany` | `(authId, companyId)` | `void` |
| `list` | `()` | `row[]` |
| `del` | `(id)` | `void` |
### Row shape
```ts
{
id: number
email: string
created_at: Date
selected_company: number | null
}
```
Backend mapping:
- Login: `getByEmail(email)` ← `getAllowedEmail`
- Auth middleware: `getById(id)` ← `getAllowedEmailById`
- Login: `getByEmail(email)`
- CLI user manager: `listAllowedEmails()` / `removeAllowedEmail(email)` / `add(email)`
- `PUT /api/auth/selected-company`: `setSelectedCompany(authId, companyId)`
---
@@ -88,8 +77,8 @@ Backend mapping:
| Method | Signature | Returns |
| --- | --- | --- |
| `add` | `(companyId, authId)` | `number` (companyuser id) |
| `getByEmail` | `(email)` | `number[]` (companyuser ids) |
| `add` | `(companyId, authId)` | `id` |
| `getByEmail` | `(email)` | `id[]` |
| `delete` | `(id)` | `void` |
---
@@ -98,9 +87,9 @@ Backend mapping:
| Method | Signature | Returns |
| --- | --- | --- |
| `create` | `(iso639)` | `number` |
| `create` | `(iso639)` | `id` |
| `getByIso639` | `(iso639)` | `{ id, iso639 } \| undefined` |
| `ensure` | `(iso639, tx?)` | `number` (existing or new id) |
| `ensure` | `(iso639, tx?)` | `id` |
| `list` | `()` | `{ id, iso639 }[]` |
| `delete` | `(id)` | `void` |
@@ -110,9 +99,9 @@ Backend mapping:
| Method | Signature | Returns |
| --- | --- | --- |
| `create` | `(rate)` | `number` |
| `create` | `(rate)` | `id` |
| `getByRate` | `(rate)` | `{ id, rate } \| undefined` |
| `ensure` | `(rate, tx?)` | `number` (existing or new id) |
| `ensure` | `(rate, tx?)` | `id` |
| `list` | `()` | `{ id, rate }[]` |
---
@@ -121,10 +110,10 @@ Backend mapping:
| Method | Signature | Returns |
| --- | --- | --- |
| `create` | `({ parent_id, sort })` | `number` |
| `create` | `({ parentId, sort })` | `id` |
| `updateParentId` | `(id, parentId)` | `void` |
| `delete` | `(id)` | `void` |
| `getTree` | `(rootId)` | `{ id, parent_id, sort }[]` (flat CTE result) |
| `getTree` | `(rootId)` | `{ id, parentId, sort }[]` |
---