import { LIST_BY_ARTICLE_ID } from '../../providers/mssql/queries/articlesupplier.js'; import resolveArticleBySku from '../article/resolveArticleBySku.js'; import { shapeArticleSupplier } from './helpers.js'; export default function listByArticleSku(pool) { const resolve = resolveArticleBySku(pool); /** * Lists the supplier assignments for an article by its SKU. * * @param {number} googleAuthId - The id of the Google auth user. * @param {string} sku - The article SKU. * @returns {Promise>} The supplier assignments. * @throws {Error} If the article is not found or the user is not authorized. * * @example * const suppliers = await store.articlesupplier.listByArticleSku(42, 'SKU-1'); * // => [{ id, articleId, entityId, supplierName, sku, pu, stock, priceId, price }] */ return async (googleAuthId, sku) => { const { articleId, companyId } = await resolve(googleAuthId, sku); const result = await pool .request() .input('articleId', articleId) .input('companyId', companyId) .query(LIST_BY_ARTICLE_ID); return result.recordset.map(shapeArticleSupplier); }; }