- Add `external_number NVARCHAR(100)` column to the `manifest` table. - Thread `externalNumber` through manifestDoc and delivery SQL (list, header, create, update). - Include `externalNumber` in shapeSummary and quote/order/delivery create/update/list/getById handlers (optional, clearable on update). - Update README type definitions and regenerate API/schema docs.
34 lines
1.2 KiB
JavaScript
34 lines
1.2 KiB
JavaScript
import { QUOTE_TYPE } from '../../sql/manifestDoc.js';
|
|
import resolveSelectedCompanyAccess from '../companyuser/resolveSelectedCompanyAccess.js';
|
|
import { loadDoc } from '../manifestDoc/helpers.js';
|
|
|
|
export default function getById(pool) {
|
|
const access = resolveSelectedCompanyAccess(pool);
|
|
|
|
/**
|
|
* 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.
|
|
* @returns {Promise<{id: number, number: string, type: string, entityId: number|null, externalNumber: string|null, date: string, lines: Array<object>}>} The quote with its lines.
|
|
* @throws {Error} If the quote is not found.
|
|
*
|
|
* @example
|
|
* const quote = await store.quote.getById(42, 5);
|
|
* // => { id, number, type, entityId, externalNumber, date, lines: [...] }
|
|
*/
|
|
return async (googleAuthId, id) => {
|
|
if (!Number.isFinite(id)) {
|
|
throw new Error('Quote not found');
|
|
}
|
|
|
|
const { companyId } = await access(googleAuthId);
|
|
|
|
const doc = await loadDoc(pool, null, { type: QUOTE_TYPE, companyId, id });
|
|
if (!doc) {
|
|
throw new Error('Quote not found');
|
|
}
|
|
return doc;
|
|
};
|
|
}
|