fixing novo
This commit is contained in:
@@ -14,8 +14,8 @@ export const cacheInterceptor: HttpInterceptorFn = (req, next) => {
|
||||
|
||||
// Кэшируем списки категорий, товары категорий и отдельные товары
|
||||
const isCategoryList = /\/category$/.test(req.url);
|
||||
const isCategoryItems = /\/category\/\d+/.test(req.url);
|
||||
const isItem = /\/items\/\d+/.test(req.url);
|
||||
const isCategoryItems = /\/category\/[^/?]+/.test(req.url);
|
||||
const isItem = /\/items\/[^/?]+/.test(req.url);
|
||||
if (!isCategoryList && !isCategoryItems && !isItem) {
|
||||
return next(req);
|
||||
}
|
||||
|
||||
@@ -661,8 +661,10 @@ function getAllVisibleItems(): any[] {
|
||||
return MOCK_ITEMS.filter(i => i.visible !== false);
|
||||
}
|
||||
|
||||
function getItemsByCategoryId(categoryID: number): any[] {
|
||||
return getAllVisibleItems().filter(i => i.categoryID === categoryID);
|
||||
function getItemsByCategoryId(categoryID: number | string): any[] {
|
||||
return getAllVisibleItems().filter(i =>
|
||||
i.categoryID === categoryID || i.subcategoryId === categoryID
|
||||
);
|
||||
}
|
||||
|
||||
function respond<T>(body: T, delayMs = 150) {
|
||||
@@ -689,18 +691,23 @@ export const mockDataInterceptor: HttpInterceptorFn = (req, next) => {
|
||||
}
|
||||
|
||||
// ── GET /category/:id (items for a category)
|
||||
const catItemsMatch = url.match(/\/category\/(\d+)$/);
|
||||
const catItemsMatch = url.match(/\/category\/([^/?]+)$/);
|
||||
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);
|
||||
return respond(items);
|
||||
}
|
||||
|
||||
// ── GET /item/:id
|
||||
const itemMatch = url.match(/\/item\/(\d+)$/);
|
||||
const itemMatch = url.match(/\/item\/([^/?]+)$/);
|
||||
if (itemMatch && req.method === 'GET') {
|
||||
const itemId = parseInt(itemMatch[1], 10);
|
||||
const item = MOCK_ITEMS.find(i => i.itemID === itemId);
|
||||
const raw = itemMatch[1];
|
||||
const num = Number(raw);
|
||||
const item = MOCK_ITEMS.find(i =>
|
||||
Number.isFinite(num) ? i.itemID === num : i.id === raw
|
||||
);
|
||||
if (item) {
|
||||
return respond(item);
|
||||
}
|
||||
|
||||
@@ -15,5 +15,5 @@ export const environment = {
|
||||
armenia: '+374 98 731231',
|
||||
support: '+374 98 731231'
|
||||
},
|
||||
useMockData: true
|
||||
useMockData: false
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user