fixing novo

This commit is contained in:
sdarbinyan
2026-04-13 22:39:33 +04:00
parent 6de461473e
commit 77737f0ba9
3 changed files with 17 additions and 10 deletions

View File

@@ -14,8 +14,8 @@ export const cacheInterceptor: HttpInterceptorFn = (req, next) => {
// Кэшируем списки категорий, товары категорий и отдельные товары // Кэшируем списки категорий, товары категорий и отдельные товары
const isCategoryList = /\/category$/.test(req.url); const isCategoryList = /\/category$/.test(req.url);
const isCategoryItems = /\/category\/\d+/.test(req.url); const isCategoryItems = /\/category\/[^/?]+/.test(req.url);
const isItem = /\/items\/\d+/.test(req.url); const isItem = /\/items\/[^/?]+/.test(req.url);
if (!isCategoryList && !isCategoryItems && !isItem) { if (!isCategoryList && !isCategoryItems && !isItem) {
return next(req); return next(req);
} }

View File

@@ -661,8 +661,10 @@ function getAllVisibleItems(): any[] {
return MOCK_ITEMS.filter(i => i.visible !== false); return MOCK_ITEMS.filter(i => i.visible !== false);
} }
function getItemsByCategoryId(categoryID: number): any[] { function getItemsByCategoryId(categoryID: number | string): any[] {
return getAllVisibleItems().filter(i => i.categoryID === categoryID); return getAllVisibleItems().filter(i =>
i.categoryID === categoryID || i.subcategoryId === categoryID
);
} }
function respond<T>(body: T, delayMs = 150) { function respond<T>(body: T, delayMs = 150) {
@@ -689,18 +691,23 @@ export const mockDataInterceptor: HttpInterceptorFn = (req, next) => {
} }
// ── GET /category/:id (items for a category) // ── GET /category/:id (items for a category)
const catItemsMatch = url.match(/\/category\/(\d+)$/); const catItemsMatch = url.match(/\/category\/([^/?]+)$/);
if (catItemsMatch && req.method === 'GET') { if (catItemsMatch && req.method === 'GET') {
const catId = parseInt(catItemsMatch[1], 10); const raw = catItemsMatch[1];
const num = Number(raw);
const catId = Number.isFinite(num) ? num : raw;
const items = getItemsByCategoryId(catId); const items = getItemsByCategoryId(catId);
return respond(items); return respond(items);
} }
// ── GET /item/:id // ── GET /item/:id
const itemMatch = url.match(/\/item\/(\d+)$/); const itemMatch = url.match(/\/item\/([^/?]+)$/);
if (itemMatch && req.method === 'GET') { if (itemMatch && req.method === 'GET') {
const itemId = parseInt(itemMatch[1], 10); const raw = itemMatch[1];
const item = MOCK_ITEMS.find(i => i.itemID === itemId); const num = Number(raw);
const item = MOCK_ITEMS.find(i =>
Number.isFinite(num) ? i.itemID === num : i.id === raw
);
if (item) { if (item) {
return respond(item); return respond(item);
} }

View File

@@ -15,5 +15,5 @@ export const environment = {
armenia: '+374 98 731231', armenia: '+374 98 731231',
support: '+374 98 731231' support: '+374 98 731231'
}, },
useMockData: true useMockData: false
}; };