u
This commit is contained in:
@@ -6,6 +6,7 @@ import {
|
||||
GET_BY_COMPANY_AND_ID as SQLITE_GET,
|
||||
DELETE_BY_COMPANY_AND_ID as SQLITE_DELETE,
|
||||
} from '../../providers/sqlite3/queries/attributename.js';
|
||||
import { isForeignKeyConstraintError } from '../../providers/provider.js';
|
||||
import resolveSelectedCompanyAccess from '../companyuser/resolveSelectedCompanyAccess.js';
|
||||
import makeRunner from '../runner.js';
|
||||
|
||||
@@ -22,6 +23,7 @@ export default function deleteAttributename(provider) {
|
||||
* @param {number} id - The attribute name id.
|
||||
* @param {object} [tx] - Optional transaction.
|
||||
* @returns {Promise<void>}
|
||||
* @throws {Error} If attribute name not found or in use.
|
||||
*/
|
||||
return async (googleAuthId, id, tx) => {
|
||||
const runner = makeRunner(provider, tx);
|
||||
@@ -32,6 +34,13 @@ export default function deleteAttributename(provider) {
|
||||
throw new Error('Attribute name not found');
|
||||
}
|
||||
|
||||
await runner.query(deleteSql, { id, companyId });
|
||||
try {
|
||||
await runner.query(deleteSql, { id, companyId });
|
||||
} catch (err) {
|
||||
if (isForeignKeyConstraintError(err)) {
|
||||
throw new Error('Attribute name in use');
|
||||
}
|
||||
throw err;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ import {
|
||||
GET_BY_ID_AND_COMPANY as SQLITE_GET,
|
||||
DELETE_BY_ID as SQLITE_DELETE,
|
||||
} from '../../providers/sqlite3/queries/attributevalue.js';
|
||||
import { isForeignKeyConstraintError } from '../../providers/provider.js';
|
||||
import resolveSelectedCompanyAccess from '../companyuser/resolveSelectedCompanyAccess.js';
|
||||
import makeRunner from '../runner.js';
|
||||
|
||||
@@ -22,6 +23,7 @@ export default function deleteAttributeValue(provider) {
|
||||
* @param {number} id - The attribute value id.
|
||||
* @param {object} [tx] - Optional transaction.
|
||||
* @returns {Promise<void>}
|
||||
* @throws {Error} If attribute value not found or in use.
|
||||
*/
|
||||
return async (googleAuthId, id, tx) => {
|
||||
const valId = Number(id);
|
||||
@@ -37,6 +39,13 @@ export default function deleteAttributeValue(provider) {
|
||||
throw new Error('Attribute value not found');
|
||||
}
|
||||
|
||||
await runner.query(deleteSql, { id: valId });
|
||||
try {
|
||||
await runner.query(deleteSql, { id: valId });
|
||||
} catch (err) {
|
||||
if (isForeignKeyConstraintError(err)) {
|
||||
throw new Error('Attribute value in use');
|
||||
}
|
||||
throw err;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ import {
|
||||
GET_BY_COMPANY_AND_ID as SQLITE_GET,
|
||||
DELETE_BY_COMPANY_AND_ID as SQLITE_DELETE,
|
||||
} from '../../providers/sqlite3/queries/propertyname.js';
|
||||
import { isForeignKeyConstraintError } from '../../providers/provider.js';
|
||||
import resolveSelectedCompanyAccess from '../companyuser/resolveSelectedCompanyAccess.js';
|
||||
import makeRunner from '../runner.js';
|
||||
|
||||
@@ -22,6 +23,7 @@ export default function deletePropertyname(provider) {
|
||||
* @param {number} id - The property name id.
|
||||
* @param {object} [tx] - Optional transaction.
|
||||
* @returns {Promise<void>}
|
||||
* @throws {Error} If property name not found or in use.
|
||||
*/
|
||||
return async (googleAuthId, id, tx) => {
|
||||
const runner = makeRunner(provider, tx);
|
||||
@@ -32,6 +34,13 @@ export default function deletePropertyname(provider) {
|
||||
throw new Error('Property name not found');
|
||||
}
|
||||
|
||||
await runner.query(deleteSql, { id, companyId });
|
||||
try {
|
||||
await runner.query(deleteSql, { id, companyId });
|
||||
} catch (err) {
|
||||
if (isForeignKeyConstraintError(err)) {
|
||||
throw new Error('Property name in use');
|
||||
}
|
||||
throw err;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user