This commit is contained in:
seb
2026-09-22 07:25:16 +02:00
parent 4ed6260e91
commit cca131d83a
148 changed files with 5343 additions and 3466 deletions

View File

@@ -1,29 +1,36 @@
import { LIST_BY_COMPANY } from '../../providers/mssql/queries/unit.js';
import { LIST_BY_COMPANY as MSSQL_LIST_BY_COMPANY } from '../../providers/mssql/queries/unit.js';
import { LIST_BY_COMPANY as SQLITE_LIST_BY_COMPANY } from '../../providers/sqlite3/queries/unit.js';
import resolveSelectedCompanyAccess from '../companyuser/resolveSelectedCompanyAccess.js';
import shapeUnit from './shapeUnit.js';
import makeRunner from '../runner.js';
export default function list(pool) {
const access = resolveSelectedCompanyAccess(pool);
export default function list(provider) {
const access = resolveSelectedCompanyAccess(provider);
const sql =
provider?.dialect === 'sqlite3'
? SQLITE_LIST_BY_COMPANY
: MSSQL_LIST_BY_COMPANY;
/**
* Lists the units available for the user's selected company.
*
* @param {number} googleAuthId - The id of the Google auth user.
* @param {object} [tx] - Optional transaction to run within.
* @returns {Promise<Array<{id: number, si: string, basesi: string, basesifactor: number, symbol: string, name: string}>>} The units.
*
* @example
* const units = await store.unit.list(42);
* // => [{ id, si, basesi, basesifactor, symbol, name }]
*/
return async (googleAuthId) => {
const { companyId, languageId } = await access(googleAuthId);
return async (googleAuthId, tx) => {
const runner = makeRunner(provider, tx);
const { companyId, languageId } = await access(googleAuthId, tx);
const result = await pool
.request()
.input('companyId', companyId)
.input('languageId', languageId)
.query(LIST_BY_COMPANY);
const result = await runner.query(sql, {
companyId,
languageId,
});
return result.recordset.map(shapeUnit);
return result.rows.map(shapeUnit);
};
}