import { GET_BY_COMPANY_AND_ID as MSSQL_GET, DELETE_BY_COMPANY_AND_ID as MSSQL_DELETE, } from '../../providers/mssql/queries/propertyname.js'; import { GET_BY_COMPANY_AND_ID as SQLITE_GET, DELETE_BY_COMPANY_AND_ID as SQLITE_DELETE, } from '../../providers/sqlite3/queries/propertyname.js'; import resolveSelectedCompanyAccess from '../companyuser/resolveSelectedCompanyAccess.js'; import makeRunner from '../runner.js'; export default function deletePropertyname(provider) { const access = resolveSelectedCompanyAccess(provider); const isSqlite = provider?.dialect === 'sqlite3'; const getSql = isSqlite ? SQLITE_GET : MSSQL_GET; const deleteSql = isSqlite ? SQLITE_DELETE : MSSQL_DELETE; /** * Deletes a property name for the user's selected company. * * @param {number} googleAuthId - The id of the Google auth user. * @param {number} id - The property name id. * @param {object} [tx] - Optional transaction. * @returns {Promise} */ return async (googleAuthId, id, tx) => { const runner = makeRunner(provider, tx); const { companyId } = await access(googleAuthId, tx); const existing = await runner.query(getSql, { id, companyId }); if (!existing.rows[0]) { throw new Error('Property name not found'); } await runner.query(deleteSql, { id, companyId }); }; }