sqlite
This commit is contained in:
@@ -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);
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user