Add entity address/contact tables and CRUD for entity resources

This commit is contained in:
seb
2026-08-06 05:43:50 +02:00
parent 0b7e40ac9c
commit 3b77a1c946
32 changed files with 3078 additions and 1363 deletions

View File

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