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,27 @@
import { DELETE_BY_ENTITY_AND_ID } from '../../sql/entitycontact.js';
import resolveCompanyAccess from '../companyuser/resolveCompanyAccess.js';
import resolveEntityAccess from '../entity/resolveEntityAccess.js';
export default function del(pool) {
const access = resolveCompanyAccess(pool);
const entityAccess = resolveEntityAccess(pool);
return async (googleAuthId, companyId, entityId, id) => {
if (!Number.isFinite(id)) {
throw new Error('Contact not found');
}
await access(googleAuthId, companyId);
await entityAccess(companyId, entityId);
const result = await pool
.request()
.input('id', id)
.input('entityId', entityId)
.query(DELETE_BY_ENTITY_AND_ID);
if (!result.rowsAffected[0]) {
throw new Error('Contact not found');
}
};
}