fixing novo
This commit is contained in:
@@ -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);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user