Add ledger, address/contact sort, and tighter schema-graph layout.

Replace manifestarticle.transactedamount with an append-only ledger, add sort on entity address/contact, and allow same-rank FKs with crossing-aware exits in the graph.
This commit is contained in:
seb
2026-08-06 07:39:48 +02:00
parent 3b77a1c946
commit ae549fd022
17 changed files with 2019 additions and 1656 deletions

View File

@@ -1,4 +1,4 @@
import { CREATE } from '../../sql/entityaddress.js';
import { CREATE, GET_NEXT_SORT } from '../../sql/entityaddress.js';
import resolveCompanyAccess from '../companyuser/resolveCompanyAccess.js';
import resolveEntityAccess from '../entity/resolveEntityAccess.js';
@@ -14,6 +14,7 @@ function shape(row) {
city: row.city ?? null,
county: row.county ?? null,
addressType: row.addressType,
sort: row.sort,
};
}
@@ -38,6 +39,17 @@ export default function create(pool) {
await access(googleAuthId, companyId);
await entityAccess(companyId, entityId);
let sort = input.sort;
if (sort === undefined || sort === null) {
const next = await pool
.request()
.input('entityId', entityId)
.query(GET_NEXT_SORT);
sort = next.recordset[0].sort;
} else if (!Number.isFinite(sort)) {
throw new Error('Invalid sort');
}
const result = await pool
.request()
.input('entityId', entityId)
@@ -49,6 +61,7 @@ export default function create(pool) {
.input('city', optionalString(input.city))
.input('county', optionalString(input.county))
.input('addressType', addressType)
.input('sort', sort)
.query(CREATE);
return shape(result.recordset[0]);