Add company-scoped unit list/upsert/delete and article unit patches.

Units are isolated per company; article detail exposes full unit shape, and unused units can be deleted safely via FK NO ACTION.
This commit is contained in:
seb
2026-08-01 06:12:24 +02:00
parent 54700a145e
commit 12e83a7ffb
16 changed files with 519 additions and 44 deletions

31
src/store/unit/delete.js Normal file
View File

@@ -0,0 +1,31 @@
import { DELETE_BY_COMPANY_AND_SI } from '../../sql/unit.js';
import resolveCompanyAccess from '../companyuser/resolveCompanyAccess.js';
export default function del(pool) {
const access = resolveCompanyAccess(pool);
return async (googleAuthId, companyId, si) => {
if (!si?.trim()) {
throw new Error('Unit not found');
}
await access(googleAuthId, companyId);
try {
const result = await pool
.request()
.input('companyId', companyId)
.input('si', si.trim())
.query(DELETE_BY_COMPANY_AND_SI);
if (!result.rowsAffected[0]) {
throw new Error('Unit not found');
}
} catch (err) {
if (err.number === 547) {
throw new Error('Unit in use');
}
throw err;
}
};
}