Add entity address/contact tables and CRUD for entity resources
This commit is contained in:
32
src/store/customergroup/update.js
Normal file
32
src/store/customergroup/update.js
Normal file
@@ -0,0 +1,32 @@
|
||||
import { UPDATE_NAME } from '../../sql/customergroup.js';
|
||||
import resolveCompanyAccess from '../companyuser/resolveCompanyAccess.js';
|
||||
|
||||
export default function update(pool) {
|
||||
const access = resolveCompanyAccess(pool);
|
||||
|
||||
return async (googleAuthId, companyId, id, { name } = {}) => {
|
||||
if (!Number.isFinite(id)) {
|
||||
throw new Error('Customer group not found');
|
||||
}
|
||||
|
||||
const cleaned = name?.trim();
|
||||
if (!cleaned) {
|
||||
throw new Error('Name required');
|
||||
}
|
||||
|
||||
await access(googleAuthId, companyId);
|
||||
|
||||
const result = await pool
|
||||
.request()
|
||||
.input('id', id)
|
||||
.input('companyId', companyId)
|
||||
.input('name', cleaned)
|
||||
.query(UPDATE_NAME);
|
||||
|
||||
const row = result.recordset[0];
|
||||
if (!row) {
|
||||
throw new Error('Customer group not found');
|
||||
}
|
||||
return { id: row.id, name: row.name };
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user