This commit is contained in:
seb
2026-10-04 11:25:14 +02:00
parent 89fe6e6451
commit 54398d90f2
10 changed files with 51 additions and 11 deletions

View File

@@ -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;
}
};
}