feat(articlesupplier): implement store methods, schema constraints, and embed in getBySku

This commit is contained in:
seb
2026-09-17 11:41:13 +02:00
parent 1fafeeb5f2
commit 4c196c7209
15 changed files with 812 additions and 6 deletions

View File

@@ -0,0 +1,31 @@
import { LIST_BY_ARTICLE_ID } from '../../sql/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<Array<{id: number, articleId: number, entityId: number, supplierName: string|null, sku: string|null, pu: number, stock: number|null, priceId: number|null, price: {net: number, taxId: number, taxRate?: number}|null}>>} 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);
};
}