diff --git a/backend/src/routes/product.routes.ts b/backend/src/routes/product.routes.ts index e323af8..6417f10 100644 --- a/backend/src/routes/product.routes.ts +++ b/backend/src/routes/product.routes.ts @@ -9,7 +9,7 @@ import { productController } from '../container'; const router = Router(); const idValidation = [param('id').isInt().withMessage('Invalid ID')]; -const showHiddenValidation = [query('showHidden').isBoolean().withMessage('showHidden should be a boolean')]; +const showHiddenValidation = [query('showHidden').optional().isBoolean().withMessage('showHidden should be a boolean')]; //.custom((value) => value === null || typeof value === 'number').withMessage('Supplier ID must be a number or null') const productValidation = { diff --git a/frontend/src/app/pages/admin/admin.component.ts b/frontend/src/app/pages/admin/admin.component.ts index d1f015f..f4dbd75 100644 --- a/frontend/src/app/pages/admin/admin.component.ts +++ b/frontend/src/app/pages/admin/admin.component.ts @@ -97,7 +97,7 @@ export class AdminComponent implements OnInit { } loadProducts() { - this.productService.getProducts().subscribe({ + this.productService.getAllProducts().subscribe({ next: (res) => { this.products.set((res.data || []).map((p: any) => ({ id: p.id, @@ -141,7 +141,32 @@ export class AdminComponent implements OnInit { loadOrders() { - this.orders.set([]); + this.orderService.getInvoices().subscribe({ + next: (res) => { + this.orders.set((res.data || []).map((i: any) => ({ + id: String(i.id), + createdAt: i.createdAt, + customer: { + firstName: i.billingAddress?.firstName || '', + lastName: i.billingAddress?.lastName || '', + email: i.billingAddress?.email || '', + address: i.billingAddress?.address || '', + city: i.billingAddress?.city || '', + zip: i.billingAddress?.zip || '' + }, + items: (i.items || []).map((it: any) => ({ + type: 'product' as const, + name: it.name, + quantity: it.quantity, + unitPrice: parseFloat(it.price), + customizationSummary: it.customizationSummary + })), + total: parseFloat(i.amount), + status: this.mapBackendStatusToFrontend(i.status) + }))); + }, + error: (err) => console.error('Failed to load orders:', err) + }); } toggleOrder(id: string) { diff --git a/frontend/src/app/pages/shop/shop.component.ts b/frontend/src/app/pages/shop/shop.component.ts index 68f7f5e..253f207 100644 --- a/frontend/src/app/pages/shop/shop.component.ts +++ b/frontend/src/app/pages/shop/shop.component.ts @@ -41,7 +41,9 @@ export class ShopComponent implements OnInit { this.productService.getProducts().subscribe({ next: (res) => { if (res.success) { - const mappedProducts = (res.data || []).map(p => this.mapProduct(p)); + const mappedProducts = (res.data || []) + .filter(p => !p.hidden) + .map(p => this.mapProduct(p)); this.allProducts.set(mappedProducts); } }, diff --git a/frontend/src/app/services/order.service.ts b/frontend/src/app/services/order.service.ts index 69d97af..fb26432 100644 --- a/frontend/src/app/services/order.service.ts +++ b/frontend/src/app/services/order.service.ts @@ -32,4 +32,11 @@ export class OrderService { { headers: this.authHeaders } ); } + + getInvoices(): Observable<{ success: boolean; message: string; data: any[] }> { + return this.http.get<{ success: boolean; message: string; data: any[] }>( + `${this.apiUrl}/invoices`, + { headers: this.authHeaders } + ); + } } diff --git a/frontend/src/app/services/product.service.ts b/frontend/src/app/services/product.service.ts index e610a55..26d4c1b 100644 --- a/frontend/src/app/services/product.service.ts +++ b/frontend/src/app/services/product.service.ts @@ -22,6 +22,10 @@ export class ProductService { return this.http.get<{ success: boolean; message: string; data: any[] }>(`${this.apiUrl}/products`); } + getAllProducts(): Observable<{ success: boolean; message: string; data: any[] }> { + return this.http.get<{ success: boolean; message: string; data: any[] }>(`${this.apiUrl}/products?showHidden=true`); + } + getProductDetail(id: number): Observable<{ success: boolean; message: string; data: any }> { return this.http.get<{ success: boolean; message: string; data: any }>(`${this.apiUrl}/products/${id}/detail`); }