This commit is contained in:
seb
2026-07-06 01:31:11 +02:00
commit 917930d0fa
34 changed files with 2912 additions and 0 deletions

View File

@@ -0,0 +1,48 @@
import sql from 'mssql';
import { getPool } from '../db.js';
import { CATEGORY_TREE_CTE, categoryTreeRequest, getRootCategoryId } from './category-tree.js';
const LANGUAGE_ID = Number(process.env.LANGUAGE_ID) || 1;
const IMAGE_PLATFORM_ID = Number(process.env.IMAGE_PLATFORM_ID) || 1;
const IMAGE_SHOP_ID = Number(process.env.IMAGE_SHOP_ID) || 0;
const CATEGORY_LIST_SQL = `
${CATEGORY_TREE_CTE}
SELECT TOP (@limit)
k.kKategorie AS id,
k.kOberKategorie AS pid,
k.nSort AS sort,
ks.cName AS name,
b.cHash AS imgHash,
CONVERT(BIGINT, k.bRowversion) AS lastChanged
FROM dbo.tKategorie k
INNER JOIN dbo.tKategorieSprache ks ON ks.kKategorie = k.kKategorie AND ks.kSprache = @languageId
LEFT JOIN dbo.tKategoriebildPlattform kbp
ON kbp.kKategorie = k.kKategorie AND kbp.kPlattform = @imagePlatformId AND kbp.kShop = @imageShopId
LEFT JOIN dbo.tBild b ON b.kBild = kbp.kBild
WHERE k.kKategorie IN (SELECT kKategorie FROM CategoryTree WHERE kKategorie <> @rootCategoryId)
AND k.cAktiv = 'Y'
AND CONVERT(BIGINT, k.bRowversion) > @cursor
ORDER BY lastChanged ASC;
`;
export async function getCategoryList({ cursor = 0, limit = 20, rootCategoryId = getRootCategoryId() } = {}) {
const result = await categoryTreeRequest(getPool(), rootCategoryId)
.input('cursor', sql.BigInt, cursor)
.input('limit', sql.Int, limit)
.input('languageId', sql.Int, LANGUAGE_ID)
.input('imagePlatformId', sql.Int, IMAGE_PLATFORM_ID)
.input('imageShopId', sql.Int, IMAGE_SHOP_ID)
.query(CATEGORY_LIST_SQL);
return result.recordset.map((row) => ({
_id: String(row.id),
imghash: row.imgHash ?? null,
imgsrc: row.imgHash ?? null,
name: row.name,
pid: String(row.pid),
discounts: [],
sort: String(row.sort),
lastChanged: String(row.lastChanged),
}));
}