This commit is contained in:
seb
2026-09-25 12:30:45 +02:00
parent b5255bdd17
commit 607e6cc0ac
10 changed files with 98 additions and 124 deletions

View File

@@ -1,8 +1,16 @@
import { LIST_BY_COMPANY as MSSQL_LIST_BY_COMPANY } from '../../providers/mssql/queries/numbers.js';
import { LIST_BY_COMPANY as SQLITE_LIST_BY_COMPANY } from '../../providers/sqlite3/queries/numbers.js';
import {
ENSURE_TYPE as MSSQL_ENSURE_TYPE,
LIST_BY_COMPANY as MSSQL_LIST_BY_COMPANY,
} from '../../providers/mssql/queries/numbers.js';
import {
ENSURE_TYPE as SQLITE_ENSURE_TYPE,
LIST_BY_COMPANY as SQLITE_LIST_BY_COMPANY,
} from '../../providers/sqlite3/queries/numbers.js';
import resolveSelectedCompanyAccess from '../companyuser/resolveSelectedCompanyAccess.js';
import makeRunner from '../runner.js';
const DEFAULT_TYPES = ['sku', 'entity', 'delivery'];
function shape(row) {
return {
id: row.id,
@@ -15,13 +23,14 @@ function shape(row) {
export default function list(provider) {
const access = resolveSelectedCompanyAccess(provider);
const isSqlite = provider?.dialect === 'sqlite3';
const ensureSql = isSqlite ? SQLITE_ENSURE_TYPE : MSSQL_ENSURE_TYPE;
const sql =
provider?.dialect === 'sqlite3'
? SQLITE_LIST_BY_COMPANY
: MSSQL_LIST_BY_COMPANY;
isSqlite ? SQLITE_LIST_BY_COMPANY : MSSQL_LIST_BY_COMPANY;
/**
* Lists the number sequences of the user's selected company.
* Ensures that default sequences ('sku', 'entity', 'delivery') exist.
*
* @param {number} googleAuthId - The id of the Google auth user.
* @param {object} [tx] - Optional transaction to run within.
@@ -33,9 +42,14 @@ export default function list(provider) {
*/
return async (googleAuthId, tx) => {
const { companyId } = await access(googleAuthId, tx);
const runner = makeRunner(provider, tx);
const result = await makeRunner(provider, tx).query(sql, { companyId });
for (const type of DEFAULT_TYPES) {
await runner.query(ensureSql, { companyId, type });
}
const result = await runner.query(sql, { companyId });
return result.rows.map(shape);
};
}
}