Genesis
This commit is contained in:
20
src/queries/product-count.js
Normal file
20
src/queries/product-count.js
Normal file
@@ -0,0 +1,20 @@
|
||||
import sql from 'mssql';
|
||||
import { getPool } from '../db.js';
|
||||
import { CATEGORY_TREE_CTE, categoryTreeRequest, getRootCategoryId } from './category-tree.js';
|
||||
|
||||
const PRODUCT_COUNT_SQL = `
|
||||
${CATEGORY_TREE_CTE}
|
||||
SELECT COUNT(DISTINCT a.kArtikel) AS ProductCount
|
||||
FROM dbo.tArtikel a
|
||||
INNER JOIN dbo.tKategorieArtikel ka ON ka.kArtikel = a.kArtikel
|
||||
WHERE a.cAktiv = 'Y'
|
||||
AND ka.kKategorie IN (SELECT kKategorie FROM CategoryTree)
|
||||
AND CONVERT(BIGINT, a.bRowversion) > @cursor;
|
||||
`;
|
||||
|
||||
export async function getProductCount({ cursor = 0, rootCategoryId = getRootCategoryId() } = {}) {
|
||||
const result = await categoryTreeRequest(getPool(), rootCategoryId)
|
||||
.input('cursor', sql.BigInt, cursor)
|
||||
.query(PRODUCT_COUNT_SQL);
|
||||
return result.recordset[0]?.ProductCount ?? 0;
|
||||
}
|
||||
Reference in New Issue
Block a user