feat(articlesupplier): implement store methods, schema constraints, and embed in getBySku
This commit is contained in:
31
src/store/articlesupplier/listByArticleSku.js
Normal file
31
src/store/articlesupplier/listByArticleSku.js
Normal 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);
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user