99 lines
2.7 KiB
JavaScript
99 lines
2.7 KiB
JavaScript
import { http } from './http.js';
|
|
|
|
/**
|
|
* Company-scoped entities (customers / contacts in a customergroup).
|
|
* Shape: Entity = { id, customergroupId, firstName, name, createdAt, updatedAt }
|
|
*/
|
|
export const entity = {
|
|
/**
|
|
* GET /api/entity → { entities: Entity[] }
|
|
* Optional query: customergroupId
|
|
*/
|
|
list({ customergroupId } = {}) {
|
|
const qs =
|
|
customergroupId != null
|
|
? `?customergroupId=${encodeURIComponent(customergroupId)}`
|
|
: '';
|
|
return http(`/api/entity${qs}`);
|
|
},
|
|
|
|
/** GET /api/entity/:id → { entity: Entity } */
|
|
get(id) {
|
|
return http(`/api/entity/${id}`);
|
|
},
|
|
|
|
/**
|
|
* POST /api/entity
|
|
* Body: { customergroupId, name, firstName? }
|
|
* → 201 { entity: Entity }
|
|
*/
|
|
create(body) {
|
|
return http('/api/entity', { method: 'POST', body });
|
|
},
|
|
|
|
/**
|
|
* PATCH /api/entity/:id
|
|
* Body: { name?, firstName? }
|
|
* → 200 { entity: Entity }
|
|
*/
|
|
update(id, body) {
|
|
return http(`/api/entity/${id}`, { method: 'PATCH', body });
|
|
},
|
|
|
|
/** DELETE /api/entity/:id → 204 */
|
|
delete(id) {
|
|
return http(`/api/entity/${id}`, { method: 'DELETE' });
|
|
},
|
|
|
|
/** GET /api/entity/next-number → { number: string } */
|
|
nextNumber() {
|
|
return http('/api/entity/next-number');
|
|
},
|
|
|
|
/** GET /api/entity/:entityId/address → { addresses: EntityAddress[] } */
|
|
listAddresses(entityId) {
|
|
return http(`/api/entity/${entityId}/address`);
|
|
},
|
|
|
|
/** POST /api/entity/:entityId/address → 201 { address } */
|
|
createAddress(entityId, body) {
|
|
return http(`/api/entity/${entityId}/address`, { method: 'POST', body });
|
|
},
|
|
|
|
/** PATCH /api/entity/:entityId/address/:id → { address } */
|
|
updateAddress(entityId, id, body) {
|
|
return http(`/api/entity/${entityId}/address/${id}`, {
|
|
method: 'PATCH',
|
|
body,
|
|
});
|
|
},
|
|
|
|
/** DELETE /api/entity/:entityId/address/:id → 204 */
|
|
deleteAddress(entityId, id) {
|
|
return http(`/api/entity/${entityId}/address/${id}`, { method: 'DELETE' });
|
|
},
|
|
|
|
/** GET /api/entity/:entityId/contact → { contacts: EntityContact[] } */
|
|
listContacts(entityId) {
|
|
return http(`/api/entity/${entityId}/contact`);
|
|
},
|
|
|
|
/** POST /api/entity/:entityId/contact → 201 { contact } */
|
|
createContact(entityId, body) {
|
|
return http(`/api/entity/${entityId}/contact`, { method: 'POST', body });
|
|
},
|
|
|
|
/** PATCH /api/entity/:entityId/contact/:id → { contact } */
|
|
updateContact(entityId, id, body) {
|
|
return http(`/api/entity/${entityId}/contact/${id}`, {
|
|
method: 'PATCH',
|
|
body,
|
|
});
|
|
},
|
|
|
|
/** DELETE /api/entity/:entityId/contact/:id → 204 */
|
|
deleteContact(entityId, id) {
|
|
return http(`/api/entity/${entityId}/contact/${id}`, { method: 'DELETE' });
|
|
},
|
|
};
|