Real value for products under limit

This commit is contained in:
Cristiano
2025-12-11 17:49:32 +01:00
parent a7e099b9db
commit 01848b3920
3 changed files with 68 additions and 2 deletions

View File

@@ -1,5 +1,5 @@
<div class="flex gap-17 ml-20"> <div class="flex gap-17 ml-20">
<app-info-card color="#f59e0b" icon="inbox" [value]="15" description="Produits sous le seuil minimal."></app-info-card> <app-info-card color="#f59e0b" icon="inbox" [value]="productsUnderLimitCount()" description="Produits sous le seuil minimal."></app-info-card>
<app-info-card color="#3b82f6" icon="team" [value]="deliversCount()+suppliersCount()" description="Partenaires actifs."></app-info-card> <app-info-card color="#3b82f6" icon="team" [value]="deliversCount()+suppliersCount()" description="Partenaires actifs."></app-info-card>
<app-info-card color="#10b981" icon="truck" [value]=deliversCount() description="Livreurs partenaires."></app-info-card> <app-info-card color="#10b981" icon="truck" [value]=deliversCount() description="Livreurs partenaires."></app-info-card>
<app-info-card color="#ef4444" icon="shop" [value]="suppliersCount()" description="Fournisseurs travaillant avec nous."></app-info-card> <app-info-card color="#ef4444" icon="shop" [value]="suppliersCount()" description="Fournisseurs travaillant avec nous."></app-info-card>

View File

@@ -2,7 +2,7 @@ import {Component, inject, OnInit, signal} from '@angular/core';
import {InfoCard} from "../../components/info-card/info-card"; import {InfoCard} from "../../components/info-card/info-card";
import {DeliveryValidator} from "../../components/delivery-validator/delivery-validator"; import {DeliveryValidator} from "../../components/delivery-validator/delivery-validator";
import {InfoTable} from "../../components/info-table/info-table"; import {InfoTable} from "../../components/info-table/info-table";
import {DeliverersService, SuppliersService} from "../../services/api"; import {DeliverersService, ProductsService, SuppliersService} from "../../services/api";
import {firstValueFrom} from "rxjs"; import {firstValueFrom} from "rxjs";
import {NzNotificationService} from "ng-zorro-antd/notification"; import {NzNotificationService} from "ng-zorro-antd/notification";
@@ -18,12 +18,14 @@ import {NzNotificationService} from "ng-zorro-antd/notification";
}) })
export class Welcome implements OnInit { export class Welcome implements OnInit {
private productsService = inject(ProductsService);
private deliverersService = inject(DeliverersService); private deliverersService = inject(DeliverersService);
private suppliersService = inject(SuppliersService); private suppliersService = inject(SuppliersService);
private notificationsService = inject(NzNotificationService); private notificationsService = inject(NzNotificationService);
deliversCount = signal<number>(0); deliversCount = signal<number>(0);
suppliersCount = signal<number>(0); suppliersCount = signal<number>(0);
productsUnderLimitCount = signal<number>(0);
async getDeliverers() { async getDeliverers() {
try{ try{
@@ -48,8 +50,22 @@ export class Welcome implements OnInit {
) )
} }
} }
async getProductsUnderLimit(){
try{
const products = await firstValueFrom(this.productsService.getAllProductsUnderLimitEndpoint());
this.productsUnderLimitCount.set(products.length);
}catch(e){
this.notificationsService.error(
'Error',
'Error while getting products.',
)
}
}
async ngOnInit() { async ngOnInit() {
await this.getDeliverers(); await this.getDeliverers();
await this.getSuppliers(); await this.getSuppliers();
await this.getProductsUnderLimit();
} }
} }

View File

@@ -142,6 +142,56 @@ export class ProductsService extends BaseService {
); );
} }
/**
* @endpoint get /API/products/underLimit
* @param observe set whether or not to return the data Observable as the body, response or events. defaults to returning the body.
* @param reportProgress flag to report request and response progress.
*/
public getAllProductsUnderLimitEndpoint(observe?: 'body', reportProgress?: boolean, options?: {httpHeaderAccept?: 'application/json', context?: HttpContext, transferCache?: boolean}): Observable<Array<GetProductDto>>;
public getAllProductsUnderLimitEndpoint(observe?: 'response', reportProgress?: boolean, options?: {httpHeaderAccept?: 'application/json', context?: HttpContext, transferCache?: boolean}): Observable<HttpResponse<Array<GetProductDto>>>;
public getAllProductsUnderLimitEndpoint(observe?: 'events', reportProgress?: boolean, options?: {httpHeaderAccept?: 'application/json', context?: HttpContext, transferCache?: boolean}): Observable<HttpEvent<Array<GetProductDto>>>;
public getAllProductsUnderLimitEndpoint(observe: any = 'body', reportProgress: boolean = false, options?: {httpHeaderAccept?: 'application/json', context?: HttpContext, transferCache?: boolean}): Observable<any> {
let localVarHeaders = this.defaultHeaders;
const localVarHttpHeaderAcceptSelected: string | undefined = options?.httpHeaderAccept ?? this.configuration.selectHeaderAccept([
'application/json'
]);
if (localVarHttpHeaderAcceptSelected !== undefined) {
localVarHeaders = localVarHeaders.set('Accept', localVarHttpHeaderAcceptSelected);
}
const localVarHttpContext: HttpContext = options?.context ?? new HttpContext();
const localVarTransferCache: boolean = options?.transferCache ?? true;
let responseType_: 'text' | 'json' | 'blob' = 'json';
if (localVarHttpHeaderAcceptSelected) {
if (localVarHttpHeaderAcceptSelected.startsWith('text')) {
responseType_ = 'text';
} else if (this.configuration.isJsonMime(localVarHttpHeaderAcceptSelected)) {
responseType_ = 'json';
} else {
responseType_ = 'blob';
}
}
let localVarPath = `/API/products/underLimit`;
const { basePath, withCredentials } = this.configuration;
return this.httpClient.request<Array<GetProductDto>>('get', `${basePath}${localVarPath}`,
{
context: localVarHttpContext,
responseType: <any>responseType_,
...(withCredentials ? { withCredentials } : {}),
headers: localVarHeaders,
observe: observe,
...(localVarTransferCache !== undefined ? { transferCache: localVarTransferCache } : {}),
reportProgress: reportProgress
}
);
}
/** /**
* @endpoint get /API/products/{id} * @endpoint get /API/products/{id}
* @param id * @param id