nan error fix
This commit is contained in:
BIN
src/app/pages/category/._subcategories.component.html
Normal file
BIN
src/app/pages/category/._subcategories.component.html
Normal file
Binary file not shown.
@@ -40,9 +40,10 @@ export class CategoryComponent implements OnInit, OnDestroy {
|
|||||||
|
|
||||||
ngOnInit(): void {
|
ngOnInit(): void {
|
||||||
this.routeSubscription = this.route.params.subscribe(params => {
|
this.routeSubscription = this.route.params.subscribe(params => {
|
||||||
const id = Number.parseInt(params['id'], 10);
|
const rawId = params['id'];
|
||||||
|
const id = Number(rawId);
|
||||||
|
|
||||||
if (!Number.isFinite(id) || id <= 0) {
|
if (!Number.isInteger(id) || id <= 0 || String(id) !== String(rawId)) {
|
||||||
this.error.set('Invalid category ID');
|
this.error.set('Invalid category ID');
|
||||||
this.items.set([]);
|
this.items.set([]);
|
||||||
this.hasMore.set(false);
|
this.hasMore.set(false);
|
||||||
|
|||||||
@@ -22,7 +22,11 @@
|
|||||||
@if (nestedSubcategories().length > 0) {
|
@if (nestedSubcategories().length > 0) {
|
||||||
<div class="categories-grid">
|
<div class="categories-grid">
|
||||||
@for (sub of nestedSubcategories(); track trackBySubId($index, sub)) {
|
@for (sub of nestedSubcategories(); track trackBySubId($index, sub)) {
|
||||||
<a [routerLink]="['/category', sub.id] | langRoute" class="category-card">
|
@if (getSubcategoryRouteId(sub) !== null) {
|
||||||
|
<a [routerLink]="['/category', getSubcategoryRouteId(sub)] | langRoute" class="category-card">
|
||||||
|
} else {
|
||||||
|
<div class="category-card category-card--disabled">
|
||||||
|
}
|
||||||
<div class="category-image">
|
<div class="category-image">
|
||||||
@if (sub.img) {
|
@if (sub.img) {
|
||||||
<img [src]="sub.img" [alt]="sub.name" loading="lazy" decoding="async" />
|
<img [src]="sub.img" [alt]="sub.name" loading="lazy" decoding="async" />
|
||||||
@@ -36,7 +40,11 @@
|
|||||||
<span class="category-count">{{ sub.itemCount }}</span>
|
<span class="category-count">{{ sub.itemCount }}</span>
|
||||||
}
|
}
|
||||||
</div>
|
</div>
|
||||||
|
@if (getSubcategoryRouteId(sub) !== null) {
|
||||||
</a>
|
</a>
|
||||||
|
} else {
|
||||||
|
</div>
|
||||||
|
}
|
||||||
}
|
}
|
||||||
</div>
|
</div>
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -41,9 +41,10 @@ export class SubcategoriesComponent implements OnInit, OnDestroy {
|
|||||||
|
|
||||||
ngOnInit(): void {
|
ngOnInit(): void {
|
||||||
this.routeSubscription = this.route.params.subscribe(params => {
|
this.routeSubscription = this.route.params.subscribe(params => {
|
||||||
const id = Number.parseInt(params['id'], 10);
|
const rawId = params['id'];
|
||||||
|
const id = Number(rawId);
|
||||||
|
|
||||||
if (!Number.isFinite(id) || id <= 0) {
|
if (!Number.isInteger(id) || id <= 0 || String(id) !== String(rawId)) {
|
||||||
this.error.set('Invalid category ID');
|
this.error.set('Invalid category ID');
|
||||||
this.categories.set([]);
|
this.categories.set([]);
|
||||||
this.subcategories.set([]);
|
this.subcategories.set([]);
|
||||||
@@ -140,6 +141,15 @@ export class SubcategoriesComponent implements OnInit, OnDestroy {
|
|||||||
return sub.id;
|
return sub.id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getSubcategoryRouteId(sub: Subcategory): number | null {
|
||||||
|
if (!sub?.id) return null;
|
||||||
|
const id = Number(sub.id);
|
||||||
|
if (!Number.isInteger(id) || id <= 0 || String(id) !== String(sub.id)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
readonly getDiscountedPrice = getDiscountedPrice;
|
readonly getDiscountedPrice = getDiscountedPrice;
|
||||||
readonly getMainImage = getMainImage;
|
readonly getMainImage = getMainImage;
|
||||||
readonly trackByItemId = trackByItemId;
|
readonly trackByItemId = trackByItemId;
|
||||||
|
|||||||
BIN
src/app/services/._api.service.ts
Normal file
BIN
src/app/services/._api.service.ts
Normal file
Binary file not shown.
@@ -1,6 +1,6 @@
|
|||||||
import { Injectable } from '@angular/core';
|
import { Injectable } from '@angular/core';
|
||||||
import { HttpClient, HttpParams } from '@angular/common/http';
|
import { HttpClient, HttpParams } from '@angular/common/http';
|
||||||
import { Observable, timer } from 'rxjs';
|
import { Observable, timer, throwError } from 'rxjs';
|
||||||
import { map, retry } from 'rxjs/operators';
|
import { map, retry } from 'rxjs/operators';
|
||||||
import { Category, Item, Subcategory } from '../models';
|
import { Category, Item, Subcategory } from '../models';
|
||||||
import { environment } from '../../environments/environment';
|
import { environment } from '../../environments/environment';
|
||||||
@@ -267,6 +267,10 @@ export class ApiService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
getCategoryItems(categoryID: number, count: number = 50, skip: number = 0): Observable<Item[]> {
|
getCategoryItems(categoryID: number, count: number = 50, skip: number = 0): Observable<Item[]> {
|
||||||
|
if (!Number.isInteger(categoryID) || categoryID <= 0) {
|
||||||
|
return throwError(() => new Error('Invalid category ID'));
|
||||||
|
}
|
||||||
|
|
||||||
const params = new HttpParams()
|
const params = new HttpParams()
|
||||||
.set('count', count.toString())
|
.set('count', count.toString())
|
||||||
.set('skip', skip.toString());
|
.set('skip', skip.toString());
|
||||||
|
|||||||
Reference in New Issue
Block a user