This commit is contained in:
seb
2026-09-29 16:16:05 +02:00
parent 26d2f83d64
commit ae5d5cc6f8
40 changed files with 2139 additions and 0 deletions

View File

@@ -0,0 +1,34 @@
import { LIST_BY_ATTRIBUTE_ID as MSSQL_LIST } from '../../providers/mssql/queries/attributevalue.js';
import { LIST_BY_ATTRIBUTE_ID as SQLITE_LIST } from '../../providers/sqlite3/queries/attributevalue.js';
import resolveSelectedCompanyAccess from '../companyuser/resolveSelectedCompanyAccess.js';
import makeRunner from '../runner.js';
export default function listByAttributeId(provider) {
const access = resolveSelectedCompanyAccess(provider);
const sql = provider?.dialect === 'sqlite3' ? SQLITE_LIST : MSSQL_LIST;
/**
* Lists the values for an attribute.
*
* @param {number} googleAuthId - The id of the Google auth user.
* @param {number} attributeId - The attribute id.
* @param {object} [tx] - Optional transaction.
* @returns {Promise<Array<{id: number, attributeId: number, value: string, sort: number}>>}
*/
return async (googleAuthId, attributeId, tx) => {
if (!attributeId || !Number.isInteger(Number(attributeId))) {
throw new Error('Invalid attributeId');
}
const { companyId } = await access(googleAuthId, tx);
const result = await makeRunner(provider, tx).query(sql, {
attributeId: Number(attributeId),
companyId,
});
return result.rows.map((row) => ({
id: row.id,
attributeId: row.attributeId,
value: row.value,
sort: row.sort,
}));
};
}