u
This commit is contained in:
@@ -2,10 +2,12 @@ import { DELETE_BY_COMPANY_AND_ID as MSSQL_DELETE_BY_COMPANY_AND_ID } from '../.
|
||||
import { DELETE_BY_COMPANY_AND_ID as SQLITE_DELETE_BY_COMPANY_AND_ID } from '../../providers/sqlite3/queries/customergroup.js';
|
||||
import { isForeignKeyConstraintError } from '../../providers/provider.js';
|
||||
import resolveSelectedCompanyAccess from '../companyuser/resolveSelectedCompanyAccess.js';
|
||||
import recordTombstone from '../posterminal/recordTombstone.js';
|
||||
import makeRunner from '../runner.js';
|
||||
|
||||
export default function del(provider) {
|
||||
const access = resolveSelectedCompanyAccess(provider);
|
||||
const tombstone = recordTombstone(provider);
|
||||
const sql =
|
||||
provider?.dialect === 'sqlite3'
|
||||
? SQLITE_DELETE_BY_COMPANY_AND_ID
|
||||
@@ -31,7 +33,8 @@ export default function del(provider) {
|
||||
const { companyId } = await access(googleAuthId, tx);
|
||||
|
||||
try {
|
||||
const result = await makeRunner(provider, tx).query(sql, {
|
||||
const runner = makeRunner(provider, tx);
|
||||
const result = await runner.query(sql, {
|
||||
id,
|
||||
companyId,
|
||||
});
|
||||
@@ -39,6 +42,8 @@ export default function del(provider) {
|
||||
if (!result.rowsAffected) {
|
||||
throw new Error('Customer group not found');
|
||||
}
|
||||
|
||||
await tombstone({ companyId, entityType: 'customergroup', entityId: id }, runner);
|
||||
} catch (err) {
|
||||
if (isForeignKeyConstraintError(err)) {
|
||||
throw new Error('Customer group in use');
|
||||
|
||||
Reference in New Issue
Block a user