u
This commit is contained in:
22
README.md
22
README.md
@@ -27,23 +27,11 @@ SQL lives in `src/sql/<table>.js`. Schema DDL: `src/schema.js` / `import 'libdas
|
|||||||
|
|
||||||
| Method | Signature | Returns |
|
| Method | Signature | Returns |
|
||||||
| --- | --- | --- |
|
| --- | --- | --- |
|
||||||
| `create` | `({ iso639, name, taxrate, reducedtaxrate })` | result |
|
| `create` | `({ iso639, name, taxrate, reducedtaxrate })` | `{ id, root_category_id, language_id, taxrate_id, reducedtaxrate_id, taxfreerate_id }` |
|
||||||
| `update` | `(id, { iso639, name, taxrate, reducedtaxrate })` | result |
|
| `update` | `(id, { iso639, name, taxrate, reducedtaxrate })` | `{ id, root_category_id, language_id, taxrate_id, reducedtaxrate_id, taxfreerate_id }` |
|
||||||
| `delete` | `(companyId)` | `void` |
|
| `delete` | `(companyId)` | `void` |
|
||||||
| `list` | `()` | `result[]` |
|
| `list` | `()` | `{ id, root_category_id, language_id, taxrate_id, reducedtaxrate_id, taxfreerate_id }[]` |
|
||||||
|
|
||||||
### result (`create` / `update` / `list` items)
|
|
||||||
|
|
||||||
```ts
|
|
||||||
{
|
|
||||||
id: number // company id
|
|
||||||
root_category_id: number
|
|
||||||
language_id: number // language.id for iso639
|
|
||||||
taxrate: number // tax.id
|
|
||||||
reducedtaxrate: number // tax.id
|
|
||||||
taxfreerate: number // tax.id (rate 0; unchanged on update)
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
### `create` (transaction)
|
### `create` (transaction)
|
||||||
|
|
||||||
@@ -51,7 +39,7 @@ For `POST /api/company`:
|
|||||||
|
|
||||||
1. Fails if `name` is taken (`Company name not available`)
|
1. Fails if `name` is taken (`Company name not available`)
|
||||||
2. Ensures language by `iso639` (get or create)
|
2. Ensures language by `iso639` (get or create)
|
||||||
3. Ensures tax rows for `taxrate`, `reducedtaxrate`, and `0` → `taxfreerate`
|
3. Ensures tax rows for `taxrate`, `reducedtaxrate`, and `0` → `taxfreerate_id`
|
||||||
4. Creates root category (`parent_id = null`)
|
4. Creates root category (`parent_id = null`)
|
||||||
5. Inserts company with all FKs set
|
5. Inserts company with all FKs set
|
||||||
|
|
||||||
@@ -62,7 +50,7 @@ For `PATCH /api/company/:id`:
|
|||||||
1. Fails if company missing / name taken by another company
|
1. Fails if company missing / name taken by another company
|
||||||
2. Ensures lang + tax rates
|
2. Ensures lang + tax rates
|
||||||
3. Updates `name`, `default_language_id`, `taxrate`, `reducedtaxrate`
|
3. Updates `name`, `default_language_id`, `taxrate`, `reducedtaxrate`
|
||||||
(`taxfreerate` / root category unchanged)
|
(`taxfreerate_id` / root category unchanged)
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
|
|||||||
@@ -45,9 +45,9 @@ SELECT
|
|||||||
id,
|
id,
|
||||||
root_category_id,
|
root_category_id,
|
||||||
default_language_id AS language_id,
|
default_language_id AS language_id,
|
||||||
taxrate,
|
taxrate AS taxrate_id,
|
||||||
reducedtaxrate,
|
reducedtaxrate AS reducedtaxrate_id,
|
||||||
taxfreerate
|
taxfreerate AS taxfreerate_id
|
||||||
FROM company
|
FROM company
|
||||||
`;
|
`;
|
||||||
|
|
||||||
|
|||||||
@@ -48,9 +48,9 @@ export default function create(pool) {
|
|||||||
id: result.recordset[0].id,
|
id: result.recordset[0].id,
|
||||||
root_category_id: rootCategoryId,
|
root_category_id: rootCategoryId,
|
||||||
language_id: languageId,
|
language_id: languageId,
|
||||||
taxrate: taxrateId,
|
taxrate_id: taxrateId,
|
||||||
reducedtaxrate: reducedtaxrateId,
|
reducedtaxrate_id: reducedtaxrateId,
|
||||||
taxfreerate: taxfreerateId,
|
taxfreerate_id: taxfreerateId,
|
||||||
};
|
};
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
try {
|
try {
|
||||||
|
|||||||
@@ -47,9 +47,9 @@ export default function update(pool) {
|
|||||||
id,
|
id,
|
||||||
root_category_id: company.root_category_id,
|
root_category_id: company.root_category_id,
|
||||||
language_id: languageId,
|
language_id: languageId,
|
||||||
taxrate: taxrateId,
|
taxrate_id: taxrateId,
|
||||||
reducedtaxrate: reducedtaxrateId,
|
reducedtaxrate_id: reducedtaxrateId,
|
||||||
taxfreerate: company.taxfreerate,
|
taxfreerate_id: company.taxfreerate,
|
||||||
};
|
};
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
try {
|
try {
|
||||||
|
|||||||
Reference in New Issue
Block a user