Files
dashlibstorage/src/store/articlesupplier/listByArticleSku.js
seb 53a20c4353 refactor: introduce database provider abstraction, isolate MSSQL layer
- Add provider contract (src/providers/provider.js): query() -> {rows,
  rowsAffected, insertId}, callback transaction(fn), exec() for stored
  procs, initialize/purge lifecycle
- Add MssqlProvider (src/providers/mssql/index.js) wrapping an mssql
  ConnectionPool with normalized results, tx commit/rollback and
  constraint-error classifiers (unique 2627/2601, FK 547)
- LibDashStore constructor now takes a provider instead of a pool
  (breaking); adds LibDashStore.create() async factory; keeps pool as
  transitional bridge until store modules are converted (see TODO.md)
- Move MSSQL-specific code into the provider: src/sql/* ->
  src/providers/mssql/queries/*, src/schema.js ->
  src/providers/mssql/schema.js, purge SQL -> purgeSql.js
- Update scripts, generate-schema-graph.js and package.json exports
  (./providers/mssql, ./providers/provider)
- Add TODO.md with the remaining provider/SQLite migration plan

No SQL or behavioral changes.
2026-09-20 13:51:01 +02:00

32 lines
1.3 KiB
JavaScript

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<Array<{id: number, articleId: number, entityId: number, supplierName: string|null, sku: string|null, pu: number, stock: number|null, sort: number, 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);
};
}