Add customergroup and entity HTTP APIs with address and contact routes.

Expose store-backed CRUD for customer groups, entities, nested addresses, and contacts, matching the documented dashdbschema contracts.
This commit is contained in:
seb
2026-08-06 07:38:05 +02:00
parent 1860f38640
commit 74269cd3ef
30 changed files with 4166 additions and 0 deletions

View File

@@ -0,0 +1,59 @@
# `POST /entity/{entityId}/address`
Protected. Requires a valid session cookie (`credentials: 'include'`).
Create entity address
Creates an address for the entity. `addressType` is required.
## Path parameters
| Param | Required | Type | Description |
|-------|----------|------|-------------|
| `entityId` | yes | integer | |
## Body (JSON)
```json
{
"addressType": "billing",
"street": "Hauptstraße",
"streetNumber": "12",
"zip": "10115",
"city": "Berlin"
}
```
## Response `201`
Created address
```json
{
"address": {
"id": 1,
"entityId": 1,
"firstName": "…",
"name": "…",
"street": "…",
"streetNumber": "…",
"zip": "…",
"city": "…",
"county": "…",
"addressType": "…"
}
}
```
## Errors
| Status | Description |
|--------|-------------|
| 400 | Address type required, invalid entityId, or no company selected — `{"error":"…"}` |
| 401 | Unauthorized — `{"error":"…"}` |
| 403 | Not authorized — `{"error":"…"}` |
| 404 | Entity or company not found — `{"error":"…"}` |
---
_Generated from `@openapi` JSDoc. Do not edit by hand — run `npm run docs:api`._

View File

@@ -0,0 +1,33 @@
# `DELETE /entity/{entityId}/address/{id}`
Protected. Requires a valid session cookie (`credentials: 'include'`).
Delete entity address
Deletes one address of the entity.
## Path parameters
| Param | Required | Type | Description |
|-------|----------|------|-------------|
| `entityId` | yes | integer | |
| `id` | yes | integer | |
## Response `204`
Deleted
_No content_
## Errors
| Status | Description |
|--------|-------------|
| 400 | No company selected or invalid ids — `{"error":"…"}` |
| 401 | Unauthorized — `{"error":"…"}` |
| 403 | Not authorized — `{"error":"…"}` |
| 404 | Address or entity not found — `{"error":"…"}` |
---
_Generated from `@openapi` JSDoc. Do not edit by hand — run `npm run docs:api`._

View File

@@ -0,0 +1,49 @@
# `GET /entity/{entityId}/address`
Protected. Requires a valid session cookie (`credentials: 'include'`).
List entity addresses
Lists addresses for an entity of the selected company.
## Path parameters
| Param | Required | Type | Description |
|-------|----------|------|-------------|
| `entityId` | yes | integer | |
## Response `200`
Address list
```json
{
"addresses": [
{
"id": 1,
"entityId": 1,
"firstName": "…",
"name": "…",
"street": "…",
"streetNumber": "…",
"zip": "…",
"city": "…",
"county": "…",
"addressType": "…"
}
]
}
```
## Errors
| Status | Description |
|--------|-------------|
| 400 | No company selected or invalid entityId — `{"error":"…"}` |
| 401 | Unauthorized — `{"error":"…"}` |
| 403 | Not authorized — `{"error":"…"}` |
| 404 | Entity or company not found — `{"error":"…"}` |
---
_Generated from `@openapi` JSDoc. Do not edit by hand — run `npm run docs:api`._

View File

@@ -0,0 +1,57 @@
# `PATCH /entity/{entityId}/address/{id}`
Protected. Requires a valid session cookie (`credentials: 'include'`).
Update entity address
Patches address fields that are present.
## Path parameters
| Param | Required | Type | Description |
|-------|----------|------|-------------|
| `entityId` | yes | integer | |
| `id` | yes | integer | |
## Body (JSON)
```json
{
"city": "München",
"zip": "80331"
}
```
## Response `200`
Updated address
```json
{
"address": {
"id": 1,
"entityId": 1,
"firstName": "…",
"name": "…",
"street": "…",
"streetNumber": "…",
"zip": "…",
"city": "…",
"county": "…",
"addressType": "…"
}
}
```
## Errors
| Status | Description |
|--------|-------------|
| 400 | Address type required, invalid ids, or no company selected — `{"error":"…"}` |
| 401 | Unauthorized — `{"error":"…"}` |
| 403 | Not authorized — `{"error":"…"}` |
| 404 | Address, entity, or company not found — `{"error":"…"}` |
---
_Generated from `@openapi` JSDoc. Do not edit by hand — run `npm run docs:api`._

View File

@@ -0,0 +1,50 @@
# `POST /entity/{entityId}/contact`
Protected. Requires a valid session cookie (`credentials: 'include'`).
Create entity contact
Creates a contact for the entity. `contactType` and `contact` are required.
## Path parameters
| Param | Required | Type | Description |
|-------|----------|------|-------------|
| `entityId` | yes | integer | |
## Body (JSON)
```json
{
"contactType": "email",
"contact": "anna@example.com"
}
```
## Response `201`
Created contact
```json
{
"contact": {
"id": 1,
"entityId": 1,
"contactType": "…",
"contact": "…"
}
}
```
## Errors
| Status | Description |
|--------|-------------|
| 400 | Contact required, invalid entityId, or no company selected — `{"error":"…"}` |
| 401 | Unauthorized — `{"error":"…"}` |
| 403 | Not authorized — `{"error":"…"}` |
| 404 | Entity or company not found — `{"error":"…"}` |
---
_Generated from `@openapi` JSDoc. Do not edit by hand — run `npm run docs:api`._

View File

@@ -0,0 +1,33 @@
# `DELETE /entity/{entityId}/contact/{id}`
Protected. Requires a valid session cookie (`credentials: 'include'`).
Delete entity contact
Deletes one contact of the entity.
## Path parameters
| Param | Required | Type | Description |
|-------|----------|------|-------------|
| `entityId` | yes | integer | |
| `id` | yes | integer | |
## Response `204`
Deleted
_No content_
## Errors
| Status | Description |
|--------|-------------|
| 400 | No company selected or invalid ids — `{"error":"…"}` |
| 401 | Unauthorized — `{"error":"…"}` |
| 403 | Not authorized — `{"error":"…"}` |
| 404 | Contact or entity not found — `{"error":"…"}` |
---
_Generated from `@openapi` JSDoc. Do not edit by hand — run `npm run docs:api`._

View File

@@ -0,0 +1,43 @@
# `GET /entity/{entityId}/contact`
Protected. Requires a valid session cookie (`credentials: 'include'`).
List entity contacts
Lists contacts for an entity of the selected company (`contactType` e.g. `email`, `phone`).
## Path parameters
| Param | Required | Type | Description |
|-------|----------|------|-------------|
| `entityId` | yes | integer | |
## Response `200`
Contact list
```json
{
"contacts": [
{
"id": 1,
"entityId": 1,
"contactType": "…",
"contact": "…"
}
]
}
```
## Errors
| Status | Description |
|--------|-------------|
| 400 | No company selected or invalid entityId — `{"error":"…"}` |
| 401 | Unauthorized — `{"error":"…"}` |
| 403 | Not authorized — `{"error":"…"}` |
| 404 | Entity or company not found — `{"error":"…"}` |
---
_Generated from `@openapi` JSDoc. Do not edit by hand — run `npm run docs:api`._

View File

@@ -0,0 +1,50 @@
# `PATCH /entity/{entityId}/contact/{id}`
Protected. Requires a valid session cookie (`credentials: 'include'`).
Update entity contact
Patches `contactType` and/or `contact`.
## Path parameters
| Param | Required | Type | Description |
|-------|----------|------|-------------|
| `entityId` | yes | integer | |
| `id` | yes | integer | |
## Body (JSON)
```json
{
"contact": "anna.mueller@example.com"
}
```
## Response `200`
Updated contact
```json
{
"contact": {
"id": 1,
"entityId": 1,
"contactType": "…",
"contact": "…"
}
}
```
## Errors
| Status | Description |
|--------|-------------|
| 400 | Contact required, invalid ids, or no company selected — `{"error":"…"}` |
| 401 | Unauthorized — `{"error":"…"}` |
| 403 | Not authorized — `{"error":"…"}` |
| 404 | Contact, entity, or company not found — `{"error":"…"}` |
---
_Generated from `@openapi` JSDoc. Do not edit by hand — run `npm run docs:api`._

View File

@@ -0,0 +1,48 @@
# `POST /entity`
Protected. Requires a valid session cookie (`credentials: 'include'`).
Create entity
Creates an entity in a company customer group and writes `entityhistory` (`Erstellt`).
## Body (JSON)
```json
{
"customergroupId": 1,
"name": "Müller",
"firstName": "Anna"
}
```
## Response `201`
Created entity
```json
{
"entity": {
"id": 1,
"customergroupId": 1,
"firstName": "…",
"name": "…",
"createdAt": "2026-08-10T00:00:00.000Z",
"updatedAt": "2026-08-10T00:00:00.000Z"
}
}
```
## Errors
| Status | Description |
|--------|-------------|
| 400 | Name required or no company selected — `{"error":"…"}` |
| 401 | Unauthorized — `{"error":"…"}` |
| 403 | Not authorized — `{"error":"…"}` |
| 404 | Company or customer group not found — `{"error":"…"}` |
---
_Generated from `@openapi` JSDoc. Do not edit by hand — run `npm run docs:api`._

View File

@@ -0,0 +1,32 @@
# `DELETE /entity/{id}`
Protected. Requires a valid session cookie (`credentials: 'include'`).
Delete entity
Deletes the entity (`entityhistory` cascades; related addresses/contacts cascade).
## Path parameters
| Param | Required | Type | Description |
|-------|----------|------|-------------|
| `id` | yes | integer | |
## Response `204`
Deleted
_No content_
## Errors
| Status | Description |
|--------|-------------|
| 400 | No company selected or invalid id — `{"error":"…"}` |
| 401 | Unauthorized — `{"error":"…"}` |
| 403 | Not authorized — `{"error":"…"}` |
| 404 | Entity not found — `{"error":"…"}` |
---
_Generated from `@openapi` JSDoc. Do not edit by hand — run `npm run docs:api`._

View File

@@ -0,0 +1,43 @@
# `GET /entity/{id}`
Protected. Requires a valid session cookie (`credentials: 'include'`).
Get entity
Returns one entity for the selected company.
## Path parameters
| Param | Required | Type | Description |
|-------|----------|------|-------------|
| `id` | yes | integer | |
## Response `200`
Entity
```json
{
"entity": {
"id": 1,
"customergroupId": 1,
"firstName": "…",
"name": "…",
"createdAt": "2026-08-10T00:00:00.000Z",
"updatedAt": "2026-08-10T00:00:00.000Z"
}
}
```
## Errors
| Status | Description |
|--------|-------------|
| 400 | No company selected or invalid id — `{"error":"…"}` |
| 401 | Unauthorized — `{"error":"…"}` |
| 403 | Not authorized — `{"error":"…"}` |
| 404 | Entity or company not found — `{"error":"…"}` |
---
_Generated from `@openapi` JSDoc. Do not edit by hand — run `npm run docs:api`._

View File

@@ -0,0 +1,47 @@
# `GET /entity`
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).
## Query parameters
| Param | Required | Type | Description |
|-------|----------|------|-------------|
| `customergroupId` | no | integer | |
## Response `200`
Entity list
```json
{
"entities": [
{
"id": 1,
"customergroupId": 1,
"firstName": "…",
"name": "…",
"createdAt": "2026-08-10T00:00:00.000Z",
"updatedAt": "2026-08-10T00:00:00.000Z"
}
]
}
```
## Errors
| Status | Description |
|--------|-------------|
| 400 | No company selected or invalid customergroupId — `{"error":"…"}` |
| 401 | Unauthorized — `{"error":"…"}` |
| 403 | Not authorized — `{"error":"…"}` |
| 404 | Company or customer group not found — `{"error":"…"}` |
---
_Generated from `@openapi` JSDoc. Do not edit by hand — run `npm run docs:api`._

View File

@@ -0,0 +1,53 @@
# `PATCH /entity/{id}`
Protected. Requires a valid session cookie (`credentials: 'include'`).
Update entity
Patches `name` and/or `firstName`. Writes `entityhistory` when values change.
## Path parameters
| Param | Required | Type | Description |
|-------|----------|------|-------------|
| `id` | yes | integer | |
## Body (JSON)
```json
{
"name": "Müller",
"firstName": "Anna"
}
```
## Response `200`
Updated entity
```json
{
"entity": {
"id": 1,
"customergroupId": 1,
"firstName": "…",
"name": "…",
"createdAt": "2026-08-10T00:00:00.000Z",
"updatedAt": "2026-08-10T00:00:00.000Z"
}
}
```
## Errors
| Status | Description |
|--------|-------------|
| 400 | Name required, invalid id, or no company selected — `{"error":"…"}` |
| 401 | Unauthorized — `{"error":"…"}` |
| 403 | Not authorized — `{"error":"…"}` |
| 404 | Entity or company not found — `{"error":"…"}` |
---
_Generated from `@openapi` JSDoc. Do not edit by hand — run `npm run docs:api`._