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,15 +1,20 @@
import { QUOTE_TYPE } from '../../providers/mssql/queries/manifestDoc.js';
import { QUOTE_TYPE as MSSQL_QUOTE_TYPE } from '../../providers/mssql/queries/manifestDoc.js';
import { QUOTE_TYPE as SQLITE_QUOTE_TYPE } from '../../providers/sqlite3/queries/manifestDoc.js';
import resolveSelectedCompanyAccess from '../companyuser/resolveSelectedCompanyAccess.js';
import { loadDoc } from '../manifestDoc/helpers.js';
import makeRunner from '../runner.js';
export default function getById(pool) {
const access = resolveSelectedCompanyAccess(pool);
export default function getById(provider) {
const access = resolveSelectedCompanyAccess(provider);
const isSqlite = provider?.dialect === 'sqlite3';
const quoteType = isSqlite ? SQLITE_QUOTE_TYPE : MSSQL_QUOTE_TYPE;
/**
* Returns a single quote by its id within the user's selected company.
*
* @param {number} googleAuthId - The id of the Google auth user.
* @param {number} id - The id of the quote.
* @param {object} [tx] - Optional transaction.
* @returns {Promise<{id: number, number: string, type: string, entityId: number|null, externalNumber: string|null, date: string, lines: Array<{id: number, sku: string|null, name: string|null, pu: number, amount: number, net: number, rebate: number, taxrate: number, comment: string|null}>}>} The quote with its lines.
* @throws {Error} If the quote is not found.
*
@@ -17,17 +22,19 @@ export default function getById(pool) {
* const quote = await store.quote.getById(42, 5);
* // => { id, number, type, entityId, externalNumber, date, lines: [...] }
*/
return async (googleAuthId, id) => {
return async (googleAuthId, id, tx) => {
if (!Number.isFinite(id)) {
throw new Error('Quote not found');
}
const { companyId } = await access(googleAuthId);
const runner = makeRunner(provider, tx);
const { companyId } = await access(googleAuthId, runner);
const doc = await loadDoc(pool, null, { type: QUOTE_TYPE, companyId, id });
const doc = await loadDoc(runner, { type: quoteType, companyId, id });
if (!doc) {
throw new Error('Quote not found');
}
return doc;
};
}