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:
31
src/store/unit/delete.js
Normal file
31
src/store/unit/delete.js
Normal 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;
|
||||
}
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user