Refactor code

This commit is contained in:
2026-05-28 10:52:46 +01:00
parent 7041c5335b
commit d37ff4ace4
31 changed files with 132 additions and 353 deletions
+1 -1
View File
@@ -3,7 +3,7 @@
<div class="header-container"> <div class="header-container">
<!-- LOGO --> <!-- LOGO -->
<div class="logo"> <div class="logo">
<a routerLink="/welcome"> <a routerLink="/dashboard">
<img <img
src="https://www.pyro-fetes.com/wp-content/themes/pcptheme/img/logo-pyro-fetes-OR-top.png" src="https://www.pyro-fetes.com/wp-content/themes/pcptheme/img/logo-pyro-fetes-OR-top.png"
alt="logo" alt="logo"
+3 -3
View File
@@ -4,11 +4,11 @@ export const routes: Routes = [
{ {
path: '', path: '',
pathMatch: 'full', pathMatch: 'full',
redirectTo: '/welcome' redirectTo: '/dashboard'
}, },
{ {
path: 'welcome', path: 'dashboard',
loadComponent: () => import('./pages/welcome/welcome').then(x => x.Welcome) loadComponent: () => import('./pages/dashboard/dashboard').then(x => x.Dashboard)
}, },
{ {
path: 'stock', path: 'stock',
@@ -1,4 +1,4 @@
import {Component, inject, OnInit, output, signal} from '@angular/core'; import {Component, inject, OnInit, signal} from '@angular/core';
import {FormControl, FormGroup, FormsModule, ReactiveFormsModule, Validators} from "@angular/forms"; import {FormControl, FormGroup, FormsModule, ReactiveFormsModule, Validators} from "@angular/forms";
import {NzColDirective, NzRowDirective} from "ng-zorro-antd/grid"; import {NzColDirective, NzRowDirective} from "ng-zorro-antd/grid";
import {NzFlexDirective} from "ng-zorro-antd/flex"; import {NzFlexDirective} from "ng-zorro-antd/flex";
@@ -9,7 +9,6 @@ import {DelivererForm} from "../deliverer-form/deliverer-form";
import {DeliverersService, GetDelivererDto, GetSupplierDto} from "../../services/api"; import {DeliverersService, GetDelivererDto, GetSupplierDto} from "../../services/api";
import {NzNotificationService} from "ng-zorro-antd/notification"; import {NzNotificationService} from "ng-zorro-antd/notification";
import {firstValueFrom} from "rxjs"; import {firstValueFrom} from "rxjs";
import {SupplierForm} from "../supplier-form/supplier-form";
@Component({ @Component({
selector: 'app-deliverer-table', selector: 'app-deliverer-table',
@@ -29,9 +28,10 @@ import {SupplierForm} from "../supplier-form/supplier-form";
export class DelivererTable implements OnInit { export class DelivererTable implements OnInit {
private deliverersService = inject(DeliverersService); private deliverersService = inject(DeliverersService);
private notificationService = inject(NzNotificationService) private notificationService = inject(NzNotificationService)
deliverers = signal<GetDelivererDto[]>([]); deliverers = signal<GetDelivererDto[]>([]);
deliverersLoading = signal<boolean>(false); deliverersLoading = signal<boolean>(false);
updateDeliverer = viewChild.required<DelivererForm>('delivererForm');
modal = viewChild.required<ModalNav>('modalNav'); modal = viewChild.required<ModalNav>('modalNav');
async ngOnInit() { async ngOnInit() {
@@ -44,11 +44,8 @@ export class DelivererTable implements OnInit {
try { try {
const deliverers = await firstValueFrom(this.deliverersService.getAllDelivererEndpoint()) const deliverers = await firstValueFrom(this.deliverersService.getAllDelivererEndpoint())
this.deliverers.set(deliverers); this.deliverers.set(deliverers);
} catch (e) { } catch {
this.notificationService.error( this.notificationService.error('Erreur', 'Erreur lors du chargement des transporteurs');
'Erreur',
'Erreur de communication avec l\'API'
)
} }
this.deliverersLoading.set(false) this.deliverersLoading.set(false)
} }
@@ -56,11 +53,8 @@ export class DelivererTable implements OnInit {
async delete(deliverer: number) { async delete(deliverer: number) {
try { try {
await firstValueFrom(this.deliverersService.deleteDelivererEndpoint(deliverer)) await firstValueFrom(this.deliverersService.deleteDelivererEndpoint(deliverer))
this.notificationService.success( this.notificationService.success('Success', 'Suppression effectuée');
'Success', } catch {
'Suppression effectuée'
)
} catch (e) {
this.notificationService.error( this.notificationService.error(
'Erreur', 'Erreur',
'Impossible de supprimer la ligne' 'Impossible de supprimer la ligne'
@@ -71,10 +65,7 @@ export class DelivererTable implements OnInit {
async edit(id: number, updateDelivererComponent: DelivererForm) { async edit(id: number, updateDelivererComponent: DelivererForm) {
if (updateDelivererComponent.delivererForm.invalid) { if (updateDelivererComponent.delivererForm.invalid) {
this.notificationService.error( this.notificationService.error('Erreur', 'Formulaire invalide');
'Erreur',
'Erreur d\'écriture dans le formulaire'
)
return; return;
} }
@@ -83,7 +74,7 @@ export class DelivererTable implements OnInit {
await firstValueFrom(this.deliverersService.updateDelivererEndpoint(id, deliverers)) await firstValueFrom(this.deliverersService.updateDelivererEndpoint(id, deliverers))
this.notificationService.success('Success', 'Transporteur modifié') this.notificationService.success('Success', 'Transporteur modifié')
} catch (e) { } catch {
this.notificationService.error('Erreur', 'Erreur lors de la modification') this.notificationService.error('Erreur', 'Erreur lors de la modification')
} }
} }
@@ -100,7 +91,7 @@ export class DelivererTable implements OnInit {
await this.edit(supplierId, updateDelivererComponent); await this.edit(supplierId, updateDelivererComponent);
updateDelivererComponent.delivererForm.reset(); updateDelivererComponent.delivererForm.reset();
modal.isVisible = false; this.onModalCancel(modal);
await this.fetchDeliverers(); await this.fetchDeliverers();
} }
@@ -5,7 +5,7 @@
</nz-form-label> </nz-form-label>
<nz-form-control nzSpan="9" nzErrorTip="Ce champ est requis"> <nz-form-control nzSpan="9" nzErrorTip="Ce champ est requis">
<nz-select formControlName="delivererId" [nzPlaceHolder]="'Choisir un transporteur'" nzShowSearch> <nz-select formControlName="delivererId" nzPlaceHolder="Choisir un transporteur" nzShowSearch>
@for (deliverer of deliverers(); track deliverer.id) { @for (deliverer of deliverers(); track deliverer.id) {
<nz-option [nzValue]="deliverer.id" [nzLabel]="deliverer.transporter"></nz-option> <nz-option [nzValue]="deliverer.id" [nzLabel]="deliverer.transporter"></nz-option>
} }
@@ -46,7 +46,7 @@ export class DelivereryNoteForm implements OnInit {
try { try {
const deliverers = await firstValueFrom(this.deliverersService.getAllDelivererEndpoint()); const deliverers = await firstValueFrom(this.deliverersService.getAllDelivererEndpoint());
this.deliverers.set(deliverers); this.deliverers.set(deliverers);
} catch (e) { } catch {
this.notificationService.error('Erreur', 'Impossible de récupérer les transporteurs'); this.notificationService.error('Erreur', 'Impossible de récupérer les transporteurs');
} }
} }
@@ -28,15 +28,14 @@ export class DelivereryNoteTable implements OnInit {
private deliveryNotesService = inject(DeliverynotesService); private deliveryNotesService = inject(DeliverynotesService);
private notificationService = inject(NzNotificationService); private notificationService = inject(NzNotificationService);
private fileService = inject(FileService); private fileService = inject(FileService);
deliveryNotes = signal<GetDeliveryNoteDto[]>([]); deliveryNotes = signal<GetDeliveryNoteDto[]>([]);
deliveryNotesLoading = signal<boolean>(false); deliveryNotesLoading = signal<boolean>(false);
modal = viewChild.required<ModalNav>('modalNav');
date: string = ""; modal = viewChild.required<ModalNav>('modalNav');
async ngOnInit() { async ngOnInit() {
await this.fetchDeliveryNotes(); await this.fetchDeliveryNotes();
this.date = new Date().toISOString().split('T')[0];
} }
async fetchDeliveryNotes() { async fetchDeliveryNotes() {
@@ -44,11 +43,8 @@ export class DelivereryNoteTable implements OnInit {
try { try {
const deliveryNotes = await firstValueFrom(this.deliveryNotesService.getAllDeliveryNoteEndpoint()); const deliveryNotes = await firstValueFrom(this.deliveryNotesService.getAllDeliveryNoteEndpoint());
this.deliveryNotes.set(deliveryNotes); this.deliveryNotes.set(deliveryNotes);
} catch (e) { } catch {
this.notificationService.error( this.notificationService.error('Erreur', 'Erreur lors du chargement des bons de livraison');
'Erreur',
'Erreur de communication avec l\'API'
)
} }
this.deliveryNotesLoading.set(false) this.deliveryNotesLoading.set(false)
} }
@@ -57,15 +53,9 @@ export class DelivereryNoteTable implements OnInit {
this.deliveryNotesLoading.set(true) this.deliveryNotesLoading.set(true)
try { try {
await firstValueFrom(this.deliveryNotesService.deleteDeliveryNoteEndpoint(deliveryNote)); await firstValueFrom(this.deliveryNotesService.deleteDeliveryNoteEndpoint(deliveryNote));
this.notificationService.success( this.notificationService.success('Success', 'Suppression effectuée');
'Success', } catch {
'Suppression effectuée' this.notificationService.error('Erreur', 'Impossible de supprimer la ligne');
)
} catch (e) {
this.notificationService.error(
'Erreur',
'Impossible de supprimer la ligne'
)
} }
this.deliveryNotesLoading.set(false) this.deliveryNotesLoading.set(false)
await this.fetchDeliveryNotes(); await this.fetchDeliveryNotes();
@@ -80,22 +70,12 @@ export class DelivereryNoteTable implements OnInit {
try { try {
await firstValueFrom(this.deliveryNotesService.patchRealDeliveryDateEndpoint(deliveryNote, PatchRealDate)) await firstValueFrom(this.deliveryNotesService.patchRealDeliveryDateEndpoint(deliveryNote, PatchRealDate))
this.notificationService.success('Success', 'Date actualisée');
this.notificationService.success( } catch {
'Success', this.notificationService.error('Erreur', 'La date à déjà été actualisée');
'Date actualisée'
)
} catch (e) {
this.notificationService.error(
'Erreur',
'La date à déjà été actualisée'
)
} }
} catch (e) { } catch {
this.notificationService.error( this.notificationService.error('Erreur', 'Erreur d\'actualisation de la date');
'Erreur',
'Erreur d\'actualisation de la date'
)
} }
this.deliveryNotesLoading.set(false) this.deliveryNotesLoading.set(false)
await this.fetchDeliveryNotes() await this.fetchDeliveryNotes()
@@ -104,15 +84,10 @@ export class DelivereryNoteTable implements OnInit {
async export(deliveryNoteId: number) { async export(deliveryNoteId: number) {
this.deliveryNotesLoading.set(true) this.deliveryNotesLoading.set(true)
try { try {
const pdf = await firstValueFrom( const pdf = await firstValueFrom(this.deliveryNotesService.getDeliveryNotePdfEndpoint(deliveryNoteId, "response"));
this.deliveryNotesService.getDeliveryNotePdfEndpoint(deliveryNoteId, "response")
);
this.fileService.downloadBlob(pdf) this.fileService.downloadBlob(pdf)
} catch (e) { } catch {
this.notificationService.error( this.notificationService.error('Erreur', 'Impossible de générer un PDF');
'Erreur',
'Impossible de générer un PDF'
);
} }
this.deliveryNotesLoading.set(false) this.deliveryNotesLoading.set(false)
} }
@@ -139,7 +114,7 @@ export class DelivereryNoteTable implements OnInit {
await firstValueFrom(this.deliveryNotesService.updateDeliveryNoteEndpoint(id, deliveryNoteDto)); await firstValueFrom(this.deliveryNotesService.updateDeliveryNoteEndpoint(id, deliveryNoteDto));
this.notificationService.success('Success', 'Bon de livraison modifié'); this.notificationService.success('Success', 'Bon de livraison modifié');
} catch (e) { } catch {
this.notificationService.error('Erreur', 'Erreur lors de la modification'); this.notificationService.error('Erreur', 'Erreur lors de la modification');
} }
} }
@@ -156,7 +131,7 @@ export class DelivereryNoteTable implements OnInit {
await this.edit(id, updateDelivereryNoteComponent); await this.edit(id, updateDelivereryNoteComponent);
updateDelivereryNoteComponent.deliveryNoteForm.reset(); updateDelivereryNoteComponent.deliveryNoteForm.reset();
modal.isVisible = false; this.onModalCancel(modal);
await this.fetchDeliveryNotes(); await this.fetchDeliveryNotes();
} }
@@ -43,10 +43,7 @@ export class DeliveryValidator implements OnInit {
const wareHouses = await firstValueFrom(this.warehousesService.getAllWarehouseEndpoint()); const wareHouses = await firstValueFrom(this.warehousesService.getAllWarehouseEndpoint());
this.wareHouses.set(wareHouses); this.wareHouses.set(wareHouses);
} catch { } catch {
this.notificationService.error( this.notificationService.error('Erreur', 'Erreur lors du chargement des quantitées')
'Erreur',
'Erreur de communication avec l\'API'
)
} }
} }
@@ -55,10 +52,7 @@ export class DeliveryValidator implements OnInit {
const deliveries = await firstValueFrom(this.deliveryNotesService.getAllDeliveryNotesNotArrivedEndpoint()); const deliveries = await firstValueFrom(this.deliveryNotesService.getAllDeliveryNotesNotArrivedEndpoint());
this.deliveryNotes.set(deliveries); this.deliveryNotes.set(deliveries);
} catch { } catch {
this.notificationService.error( this.notificationService.error('Erreur', 'Erreur lors du chargement des bon de livraison')
'Erreur',
'Erreur de communication avec l\'API'
)
} }
} }
@@ -76,11 +70,8 @@ export class DeliveryValidator implements OnInit {
realDeliveryDate: format(new Date(), 'yyyy-MM-dd') realDeliveryDate: format(new Date(), 'yyyy-MM-dd')
}; };
await firstValueFrom(this.deliveryNotesService.patchRealDeliveryDateEndpoint(id, PatchRealDate)); await firstValueFrom(this.deliveryNotesService.patchRealDeliveryDateEndpoint(id, PatchRealDate));
} catch (e) { } catch {
this.notificationService.error( this.notificationService.error('Erreur', 'Impossible d\'actualiser la date')
'Erreur',
'Erreur de communication avec l\'API',
)
} }
} }
@@ -98,18 +89,12 @@ export class DeliveryValidator implements OnInit {
)); ));
} }
this.notificationService.success( this.notificationService.success('Succès', 'Les produits sont bien ajoutés au stock')
'Succès',
'Les produits sont bien ajoutés au stock'
)
modal.isVisible = false; modal.isVisible = false;
await this.fetchDeliveryNotes(); await this.fetchDeliveryNotes();
} catch { } catch {
this.notificationService.error( this.notificationService.error('Erreur', 'Vous devez choisir un entrepôt')
'Erreur',
'Vous devez choisir un entrepôt',
)
} }
} }
@@ -1,4 +1,4 @@
import {Component, input, Input, output} from '@angular/core'; import {Component, input, output} from '@angular/core';
import {NzModalComponent} from "ng-zorro-antd/modal"; import {NzModalComponent} from "ng-zorro-antd/modal";
import {NzButtonComponent} from "ng-zorro-antd/button"; import {NzButtonComponent} from "ng-zorro-antd/button";
+1 -1
View File
@@ -1,4 +1,4 @@
import {Component, Input, input, output} from '@angular/core'; import {Component, input, output} from '@angular/core';
import {NzButtonModule} from 'ng-zorro-antd/button'; import {NzButtonModule} from 'ng-zorro-antd/button';
import {NzModalModule} from 'ng-zorro-antd/modal'; import {NzModalModule} from 'ng-zorro-antd/modal';
import {NzIconDirective} from "ng-zorro-antd/icon"; import {NzIconDirective} from "ng-zorro-antd/icon";
+1 -1
View File
@@ -4,7 +4,7 @@ import {NzColDirective} from "ng-zorro-antd/grid";
import {NzFlexDirective} from "ng-zorro-antd/flex"; import {NzFlexDirective} from "ng-zorro-antd/flex";
import {NzFormControlComponent, NzFormDirective, NzFormItemComponent, NzFormLabelComponent} from "ng-zorro-antd/form"; import {NzFormControlComponent, NzFormDirective, NzFormItemComponent, NzFormLabelComponent} from "ng-zorro-antd/form";
import {NzInputDirective} from "ng-zorro-antd/input"; import {NzInputDirective} from "ng-zorro-antd/input";
import {GetPriceDto, GetSupplierDto} from "../../services/api"; import {GetPriceDto} from "../../services/api";
@Component({ @Component({
selector: 'app-price-form', selector: 'app-price-form',
@@ -1,21 +0,0 @@
<form nz-form nzLayout="horizontal" [formGroup]="productForm">
<nz-form-item nz-flex>
<nz-form-label nzSpan="9" nzRequired>
Prix
</nz-form-label>
<nz-form-control nzSpan="8" nzErrorTip="Ce champ est requis">
<input nz-input placeholder="Prix" formControlName="price">
</nz-form-control>
</nz-form-item>
<nz-form-item nz-flex>
<nz-form-label nzSpan="9" nzRequired>
Quantité
</nz-form-label>
<nz-form-control nzSpan="8" nzErrorTip="Ce champ est requis">
<input nz-input placeholder="Quantité" formControlName="quantity">
</nz-form-control>
</nz-form-item>
</form>
@@ -1,29 +0,0 @@
import {Component} from '@angular/core';
import {FormControl, FormGroup, FormsModule, ReactiveFormsModule, Validators} from "@angular/forms";
import {NzColDirective} from "ng-zorro-antd/grid";
import {NzFlexDirective} from "ng-zorro-antd/flex";
import {NzFormControlComponent, NzFormDirective, NzFormItemComponent, NzFormLabelComponent} from "ng-zorro-antd/form";
import {NzInputDirective} from "ng-zorro-antd/input";
@Component({
selector: 'app-product-form',
imports: [
FormsModule,
NzColDirective,
NzFlexDirective,
NzFormControlComponent,
NzFormDirective,
NzFormItemComponent,
NzFormLabelComponent,
NzInputDirective,
ReactiveFormsModule
],
templateUrl: './product-form.html',
styleUrl: './product-form.css',
})
export class ProductForm {
productForm: FormGroup = new FormGroup({
price: new FormControl<string>(null, [Validators.required]),
quantity: new FormControl<string>(null, [Validators.required])
})
}
@@ -56,11 +56,8 @@ export class PurchaseOrderTable implements OnInit {
try { try {
const purchaseOrders = await firstValueFrom(this.purchaseOrdersService.getAllPurchaseOrderEndpoint()) const purchaseOrders = await firstValueFrom(this.purchaseOrdersService.getAllPurchaseOrderEndpoint())
this.purchaseOrders.set(purchaseOrders); this.purchaseOrders.set(purchaseOrders);
} catch (e) { } catch {
this.notificationService.error( this.notificationService.error('Erreur', 'Erreur lors du chargement des bons de commande')
'Erreur',
'Erreur de communication avec l\'API'
)
} }
this.purchaseOrdersLoading.set(false) this.purchaseOrdersLoading.set(false)
} }
@@ -69,15 +66,9 @@ export class PurchaseOrderTable implements OnInit {
this.purchaseOrdersLoading.set(true) this.purchaseOrdersLoading.set(true)
try { try {
await firstValueFrom(this.purchaseOrdersService.deletePurchaseOrderEndpoint(purchaseOrderId)) await firstValueFrom(this.purchaseOrdersService.deletePurchaseOrderEndpoint(purchaseOrderId))
this.notificationService.success( this.notificationService.success('Success', 'Suppression effectuée')
'Success', } catch {
'Suppression effectuée' this.notificationService.error('Erreur', 'Impossible de supprimer la ligne')
)
} catch (e) {
this.notificationService.error(
'Erreur',
'Impossible de supprimer la ligne'
)
} }
this.purchaseOrdersLoading.set(false) this.purchaseOrdersLoading.set(false)
await this.fetchPurchaseOrder(); await this.fetchPurchaseOrder();
@@ -90,11 +81,8 @@ export class PurchaseOrderTable implements OnInit {
this.purchaseOrdersService.getPurchaseOrderPdfEndpoint(purchaseOrderId, "response") this.purchaseOrdersService.getPurchaseOrderPdfEndpoint(purchaseOrderId, "response")
); );
this.fileService.downloadBlob(pdf) this.fileService.downloadBlob(pdf)
} catch (e) { } catch {
this.notificationService.error( this.notificationService.error('Erreur', 'Impossible de générer un PDF');
'Erreur',
'Impossible de générer un PDF'
);
} }
this.purchaseOrdersLoading.set(false) this.purchaseOrdersLoading.set(false)
} }
@@ -138,10 +126,7 @@ export class PurchaseOrderTable implements OnInit {
async edit(id: number, updatePurchaseOrderComponent: PurchaseOrderForm) { async edit(id: number, updatePurchaseOrderComponent: PurchaseOrderForm) {
if (updatePurchaseOrderComponent.purchaseOrderForm.invalid) { if (updatePurchaseOrderComponent.purchaseOrderForm.invalid) {
this.notificationService.error( this.notificationService.error('Erreur', 'Formulaire invalide')
'Erreur',
'Erreur d\'écriture dans le formulaire'
)
return; return;
} }
@@ -150,7 +135,7 @@ export class PurchaseOrderTable implements OnInit {
await firstValueFrom(this.purchaseOrdersService.patchPurchaseOrderPurchaseConditionsEndpoint(id, purchaseOrders)) await firstValueFrom(this.purchaseOrdersService.patchPurchaseOrderPurchaseConditionsEndpoint(id, purchaseOrders))
this.notificationService.success('Success', 'Bon de commande modifié') this.notificationService.success('Success', 'Bon de commande modifié')
} catch (e) { } catch {
this.notificationService.error('Erreur', 'Erreur lors de la modification') this.notificationService.error('Erreur', 'Erreur lors de la modification')
} }
} }
@@ -159,15 +144,9 @@ export class PurchaseOrderTable implements OnInit {
this.purchaseOrdersLoading.set(true) this.purchaseOrdersLoading.set(true)
try { try {
await firstValueFrom(this.purchaseOrdersService.deleteProductFromPurchaseOrderEndpoint(productId, purchaseOrderId)) await firstValueFrom(this.purchaseOrdersService.deleteProductFromPurchaseOrderEndpoint(productId, purchaseOrderId))
this.notificationService.success( this.notificationService.success('Success', 'Suppression effectuée')
'Success', } catch {
'Suppression effectuée' this.notificationService.error('Erreur', 'Impossible de supprimer la ligne')
)
} catch (e) {
this.notificationService.error(
'Erreur',
'Impossible de supprimer la ligne'
)
} }
this.purchaseOrdersLoading.set(false) this.purchaseOrdersLoading.set(false)
await this.fetchPurchaseOrder(); await this.fetchPurchaseOrder();
@@ -175,10 +154,7 @@ export class PurchaseOrderTable implements OnInit {
async editQuantity(productId: number, purchaseOrderId: number, updateQuantityComponent: QuantityForm) { async editQuantity(productId: number, purchaseOrderId: number, updateQuantityComponent: QuantityForm) {
if (updateQuantityComponent.quantityForm.invalid) { if (updateQuantityComponent.quantityForm.invalid) {
this.notificationService.error( this.notificationService.error('Erreur', 'Erreur d\'écriture dans le formulaire')
'Erreur',
'Erreur d\'écriture dans le formulaire'
)
return; return;
} }
@@ -209,7 +185,7 @@ export class PurchaseOrderTable implements OnInit {
await this.edit(id, updatePurchaseOrderComponent); await this.edit(id, updatePurchaseOrderComponent);
updatePurchaseOrderComponent.purchaseOrderForm.reset(); updatePurchaseOrderComponent.purchaseOrderForm.reset();
modal.isVisible = false; this.onModalCancel(modal);
await this.fetchPurchaseOrder(); await this.fetchPurchaseOrder();
} }
@@ -229,7 +205,7 @@ export class PurchaseOrderTable implements OnInit {
await this.editQuantity(productId, purchaseOrderId, updateQuantityComponent); await this.editQuantity(productId, purchaseOrderId, updateQuantityComponent);
updateQuantityComponent.quantityForm.reset(); updateQuantityComponent.quantityForm.reset();
modal.isVisible = false; this.onModalCancel(modal);
await this.fetchPurchaseOrder(); await this.fetchPurchaseOrder();
} }
} }
@@ -4,7 +4,7 @@ import {NzColDirective} from "ng-zorro-antd/grid";
import {NzFlexDirective} from "ng-zorro-antd/flex"; import {NzFlexDirective} from "ng-zorro-antd/flex";
import {NzFormControlComponent, NzFormDirective, NzFormItemComponent, NzFormLabelComponent} from "ng-zorro-antd/form"; import {NzFormControlComponent, NzFormDirective, NzFormItemComponent, NzFormLabelComponent} from "ng-zorro-antd/form";
import {NzInputDirective} from "ng-zorro-antd/input"; import {NzInputDirective} from "ng-zorro-antd/input";
import {GetDelivererDto, GetPurchaseProductDto} from "../../services/api"; import {GetPurchaseProductDto} from "../../services/api";
@Component({ @Component({
selector: 'app-quantity-form', selector: 'app-quantity-form',
@@ -34,8 +34,10 @@ export class QuotationTable implements OnInit {
private quotationsService = inject(QuotationsService); private quotationsService = inject(QuotationsService);
private notificationService = inject(NzNotificationService); private notificationService = inject(NzNotificationService);
private fileService = inject(FileService); private fileService = inject(FileService);
quotations = signal<GetQuotationDto[]>([]); quotations = signal<GetQuotationDto[]>([]);
quotationsLoading = signal<boolean>(false); quotationsLoading = signal<boolean>(false);
modal = viewChild.required<ModalNav>('modalNav'); modal = viewChild.required<ModalNav>('modalNav');
modalQuantity = viewChild.required<ModalNav>('modalQuantity'); modalQuantity = viewChild.required<ModalNav>('modalQuantity');
@@ -49,11 +51,8 @@ export class QuotationTable implements OnInit {
try { try {
const quotations = await firstValueFrom(this.quotationsService.getAllQuotationEndpoint()) const quotations = await firstValueFrom(this.quotationsService.getAllQuotationEndpoint())
this.quotations.set(quotations); this.quotations.set(quotations);
} catch (e) { } catch {
this.notificationService.error( this.notificationService.error('Erreur', 'Erreur lors du chargement des devis')
'Erreur',
'Erreur de communication avec l\'API'
)
} }
this.quotationsLoading.set(false) this.quotationsLoading.set(false)
} }
@@ -62,15 +61,9 @@ export class QuotationTable implements OnInit {
this.quotationsLoading.set(true) this.quotationsLoading.set(true)
try { try {
await firstValueFrom(this.quotationsService.deleteQuotationEndpoint(quotation)) await firstValueFrom(this.quotationsService.deleteQuotationEndpoint(quotation))
this.notificationService.success( this.notificationService.success('Success', 'Suppression effectuée')
'Success', } catch {
'Suppression effectuée' this.notificationService.error('Erreur', 'Impossible de supprimer la ligne')
)
} catch (e) {
this.notificationService.error(
'Erreur',
'Impossible de supprimer la ligne'
)
} }
this.quotationsLoading.set(false) this.quotationsLoading.set(false)
await this.fetchQuotations(); await this.fetchQuotations();
@@ -83,12 +76,8 @@ export class QuotationTable implements OnInit {
this.quotationsService.getQuotationPdfEndpoint(quotationId, "response") this.quotationsService.getQuotationPdfEndpoint(quotationId, "response")
); );
this.fileService.downloadBlob(pdf) this.fileService.downloadBlob(pdf)
} catch (e) { } catch {
console.error(e); this.notificationService.error('Erreur', 'Impossible de générer un PDF');
this.notificationService.error(
'Erreur',
'Impossible de générer un PDF'
);
} }
this.quotationsLoading.set(false) this.quotationsLoading.set(false)
} }
@@ -103,8 +92,7 @@ export class QuotationTable implements OnInit {
const quotations = updateQuotationComponent.quotationForm.getRawValue(); const quotations = updateQuotationComponent.quotationForm.getRawValue();
await firstValueFrom(this.quotationsService.updateQuotationEndpoint(id, quotations)); await firstValueFrom(this.quotationsService.updateQuotationEndpoint(id, quotations));
this.notificationService.success('Success', 'Devis modifié') this.notificationService.success('Success', 'Devis modifié')
} catch (e) { } catch {
console.error(e)
this.notificationService.error('Erreur', 'Erreur lors de la modification') this.notificationService.error('Erreur', 'Erreur lors de la modification')
} }
} }
@@ -113,15 +101,9 @@ export class QuotationTable implements OnInit {
this.quotationsLoading.set(true) this.quotationsLoading.set(true)
try { try {
await firstValueFrom(this.quotationsService.deleteProductFromQuotationEndpoint(productId, quotationId)) await firstValueFrom(this.quotationsService.deleteProductFromQuotationEndpoint(productId, quotationId))
this.notificationService.success( this.notificationService.success('Success', 'Suppression effectuée')
'Success', } catch {
'Suppression effectuée' this.notificationService.error('Erreur', 'Impossible de supprimer la ligne')
)
} catch (e) {
this.notificationService.error(
'Erreur',
'Impossible de supprimer la ligne'
)
} }
this.quotationsLoading.set(false) this.quotationsLoading.set(false)
await this.fetchQuotations(); await this.fetchQuotations();
@@ -129,10 +111,7 @@ export class QuotationTable implements OnInit {
async editQuantity(productId: number, quotationId: number, updateQuantityComponent: QuantityForm) { async editQuantity(productId: number, quotationId: number, updateQuantityComponent: QuantityForm) {
if (updateQuantityComponent.quantityForm.invalid) { if (updateQuantityComponent.quantityForm.invalid) {
this.notificationService.error( this.notificationService.error('Erreur', 'Formulaire invalide')
'Erreur',
'Erreur d\'écriture dans le formulaire'
)
return; return;
} }
@@ -141,7 +120,7 @@ export class QuotationTable implements OnInit {
await firstValueFrom(this.quotationsService.patchQuotationProductQuantityEndpoint(productId, quotationId, quantity)) await firstValueFrom(this.quotationsService.patchQuotationProductQuantityEndpoint(productId, quotationId, quantity))
this.notificationService.success('Success', 'Quantité modifiée') this.notificationService.success('Success', 'Quantité modifiée')
} catch (e) { } catch {
this.notificationService.error('Erreur', 'Erreur lors de la modification') this.notificationService.error('Erreur', 'Erreur lors de la modification')
} }
} }
@@ -158,7 +137,7 @@ export class QuotationTable implements OnInit {
await this.edit(id, updateQuotationComponent); await this.edit(id, updateQuotationComponent);
updateQuotationComponent.quotationForm.reset(); updateQuotationComponent.quotationForm.reset();
modal.isVisible = false; this.onModalCancel(modal);
await this.fetchQuotations(); await this.fetchQuotations();
} }
@@ -178,7 +157,7 @@ export class QuotationTable implements OnInit {
await this.editQuantity(productId, quotationId, updateQuantityComponent); await this.editQuantity(productId, quotationId, updateQuantityComponent);
updateQuantityComponent.quantityForm.reset(); updateQuantityComponent.quantityForm.reset();
modal.isVisible = false; this.onModalCancel(modal);
await this.fetchQuotations(); await this.fetchQuotations();
} }
} }
@@ -49,10 +49,7 @@ export class SettingForm implements OnInit {
const settingsPicture = await firstValueFrom(this.settingsService.getSettingEndpoint()); const settingsPicture = await firstValueFrom(this.settingsService.getSettingEndpoint());
this.settings.set(settingsPicture); this.settings.set(settingsPicture);
} catch { } catch {
this.notificationService.error( this.notificationService.error('Erreur', 'Aucun paramètre défini')
'Erreur',
'Aucun paramètre défini'
)
} }
} }
@@ -78,7 +75,7 @@ export class SettingForm implements OnInit {
} }
await this.fetchSettings(); await this.fetchSettings();
} catch { } catch {
this.notificationService.error('Erreur', "Erreur de communication avec l'API"); this.notificationService.error('Erreur', 'Impossible de changer les paramètres actuellement');
} }
this.settingForm.reset(); this.settingForm.reset();
@@ -6,7 +6,7 @@
</nz-form-label> </nz-form-label>
<nz-form-control nzSpan="4" nzErrorTip="Requis"> <nz-form-control nzSpan="4" nzErrorTip="Requis">
<input nz-input type="number" placeholder="12345" formControlName="minimalQuantity"> <input nz-input type="number" placeholder="0" formControlName="minimalQuantity">
</nz-form-control> </nz-form-control>
</nz-form-item> </nz-form-item>
</form> </form>
@@ -76,7 +76,7 @@ export class StockTable implements OnInit {
); );
this.products.set(productsWithQuantity); this.products.set(productsWithQuantity);
} catch { } catch {
this.notificationService.error('Erreur', 'Erreur de communication avec l\'API'); this.notificationService.error('Erreur', 'Impossible de charger le catalogue');
} }
this.productsLoading.set(false); this.productsLoading.set(false);
} }
@@ -93,7 +93,7 @@ export class StockTable implements OnInit {
async edit(id: number, updateProductComponent: StockForm) { async edit(id: number, updateProductComponent: StockForm) {
if (updateProductComponent.stockForm.invalid) { if (updateProductComponent.stockForm.invalid) {
this.notificationService.error('Erreur', 'Erreur d\'écriture dans le formulaire') this.notificationService.error('Erreur', 'Formulaire invalide')
return; return;
} }
try { try {
@@ -115,7 +115,7 @@ export class StockTable implements OnInit {
if (!this.selectedProduct) return; if (!this.selectedProduct) return;
await this.edit(productId, updateProductComponent); await this.edit(productId, updateProductComponent);
updateProductComponent.stockForm.reset(); updateProductComponent.stockForm.reset();
modal.isVisible = false; this.onModalCancel(modal);
await this.fetchProducts(); await this.fetchProducts();
} }
@@ -1,4 +1,4 @@
<nz-table [nzData]="filteredSuppliers()" <nz-table [nzData]="suppliers()"
[nzLoading]="suppliersLoading()" [nzLoading]="suppliersLoading()"
[nzFrontPagination]="false"> [nzFrontPagination]="false">
<thead> <thead>
@@ -15,7 +15,7 @@
</tr> </tr>
</thead> </thead>
<tbody style="text-align: center"> <tbody style="text-align: center">
@for (supplier of filteredSuppliers(); track supplier.id) { @for (supplier of suppliers(); track supplier.id) {
<tr> <tr>
<td>{{ supplier.name }}</td> <td>{{ supplier.name }}</td>
<td>{{ supplier.phone }}</td> <td>{{ supplier.phone }}</td>
@@ -26,7 +26,7 @@
<td>{{ supplier.deliveryDelay }} jours</td> <td>{{ supplier.deliveryDelay }} jours</td>
<td> <td>
<app-modal-button type="link" [name]="'Voir les produits'" size="45%"> <app-modal-button type="link" [name]="'Voir les produits'" size="45%">
<nz-table [nzData]="filteredSuppliers()" [nzFrontPagination]="false"> <nz-table [nzData]="suppliers()" [nzFrontPagination]="false">
<thead> <thead>
<tr class="text-center"> <tr class="text-center">
<th>Produit</th> <th>Produit</th>
@@ -1,4 +1,4 @@
import {Component, computed, inject, OnInit, signal, viewChild} from '@angular/core'; import {Component, inject, OnInit, signal, viewChild} from '@angular/core';
import {ModalNav} from "../modal-nav/modal-nav"; import {ModalNav} from "../modal-nav/modal-nav";
import {NzDividerComponent} from "ng-zorro-antd/divider"; import {NzDividerComponent} from "ng-zorro-antd/divider";
import {NzIconDirective} from "ng-zorro-antd/icon"; import {NzIconDirective} from "ng-zorro-antd/icon";
@@ -29,11 +29,13 @@ export class SupplierTable implements OnInit {
private suppliersService = inject(SuppliersService); private suppliersService = inject(SuppliersService);
private pricesService = inject(PricesService); private pricesService = inject(PricesService);
private notificationService = inject(NzNotificationService); private notificationService = inject(NzNotificationService);
suppliers = signal<GetSupplierDto[]>([]); suppliers = signal<GetSupplierDto[]>([]);
suppliersLoading = signal<boolean>(false); suppliersLoading = signal<boolean>(false);
updateSupplier = viewChild.required<SupplierForm>('supplierForm');
supplierModal = viewChild.required<ModalNav>('supplierModal'); supplierModal = viewChild.required<ModalNav>('supplierModal');
productModal = viewChild.required<ModalNav>('productModal'); productModal = viewChild.required<ModalNav>('productModal');
selectedSupplier: GetSupplierDto | null = null; selectedSupplier: GetSupplierDto | null = null;
selectedProduct: GetPriceDto | null = null; selectedProduct: GetPriceDto | null = null;
selectedProductSupplierId: number | null = null; selectedProductSupplierId: number | null = null;
@@ -42,29 +44,12 @@ export class SupplierTable implements OnInit {
await this.fetchSuppliers(); await this.fetchSuppliers();
} }
private searchQuery = signal<string>('');
filteredSuppliers = computed(() => {
const q = this.searchQuery().toLowerCase().trim();
if (!q) return this.suppliers();
return this.suppliers().filter(s => {
const name = (s.name ?? '').toLowerCase();
return name.includes(q);
});
});
applySearch(query: string) {
this.searchQuery.set(query);
}
async fetchSuppliers() { async fetchSuppliers() {
this.suppliersLoading.set(true); this.suppliersLoading.set(true);
try { try {
const suppliers = await firstValueFrom(this.suppliersService.getAllSuppliersEndpoint()); const suppliers = await firstValueFrom(this.suppliersService.getAllSuppliersEndpoint());
this.suppliers.set(suppliers); this.suppliers.set(suppliers);
} catch (e) { } catch {
this.notificationService.error('Erreur', 'Erreur de communication avec l\'API'); this.notificationService.error('Erreur', 'Erreur de communication avec l\'API');
} }
this.suppliersLoading.set(false); this.suppliersLoading.set(false);
@@ -79,8 +64,7 @@ export class SupplierTable implements OnInit {
const suppliers = updateSupplierComponent.supplierForm.getRawValue(); const suppliers = updateSupplierComponent.supplierForm.getRawValue();
await firstValueFrom(this.suppliersService.updateSupplierEndpoint(id, suppliers)); await firstValueFrom(this.suppliersService.updateSupplierEndpoint(id, suppliers));
this.notificationService.success('Success', 'Fournisseur modifié'); this.notificationService.success('Success', 'Fournisseur modifié');
} catch (e) { } catch {
console.error(e);
this.notificationService.error('Erreur', 'Erreur lors de la modification'); this.notificationService.error('Erreur', 'Erreur lors de la modification');
} }
} }
@@ -90,7 +74,7 @@ export class SupplierTable implements OnInit {
await firstValueFrom(this.suppliersService.deleteSupplierEndpoint(supplier)); await firstValueFrom(this.suppliersService.deleteSupplierEndpoint(supplier));
this.notificationService.success('Succès', 'Suppression effectuée'); this.notificationService.success('Succès', 'Suppression effectuée');
await this.fetchSuppliers(); await this.fetchSuppliers();
} catch (e) { } catch {
this.notificationService.error('Erreur', 'Impossible de supprimer la ligne'); this.notificationService.error('Erreur', 'Impossible de supprimer la ligne');
} }
} }
@@ -122,13 +106,13 @@ export class SupplierTable implements OnInit {
modal: ModalNav modal: ModalNav
) { ) {
if (productId == null || supplierId == null || !this.selectedProduct) { if (productId == null || supplierId == null || !this.selectedProduct) {
this.notificationService.error('Erreur', 'Identifiants produit/fournisseur manquants'); this.notificationService.error('Erreur', 'Identifiants produit ou fournisseur manquants');
return; return;
} }
await this.editPrice(productId, supplierId, updateProductComponent); await this.editPrice(productId, supplierId, updateProductComponent);
updateProductComponent.priceForm.reset(); updateProductComponent.priceForm.reset();
modal.isVisible = false; this.onModalCancel(modal);
await this.fetchSuppliers(); await this.fetchSuppliers();
} }
@@ -150,8 +134,7 @@ export class SupplierTable implements OnInit {
}; };
await firstValueFrom(this.pricesService.patchPriceEndpoint(productId, supplierId, body)); await firstValueFrom(this.pricesService.patchPriceEndpoint(productId, supplierId, body));
this.notificationService.success('Success', 'Prix modifié'); this.notificationService.success('Success', 'Prix modifié');
} catch (e) { } catch {
console.error(e);
this.notificationService.error('Erreur', 'Erreur lors de la modification'); this.notificationService.error('Erreur', 'Erreur lors de la modification');
} }
} }
@@ -162,7 +145,7 @@ export class SupplierTable implements OnInit {
await firstValueFrom(this.suppliersService.deleteProductToSupplierEndpoint(idSupplier, idProduct)); await firstValueFrom(this.suppliersService.deleteProductToSupplierEndpoint(idSupplier, idProduct));
this.notificationService.success('Succès', 'Produit supprimé'); this.notificationService.success('Succès', 'Produit supprimé');
await this.fetchSuppliers(); await this.fetchSuppliers();
} catch (e) { } catch {
this.notificationService.error('Erreur', 'Impossible de supprimer le produit'); this.notificationService.error('Erreur', 'Impossible de supprimer le produit');
} }
} }
+12 -33
View File
@@ -23,9 +23,10 @@ import {firstValueFrom} from "rxjs";
export class UserTable implements OnInit { export class UserTable implements OnInit {
private usersService = inject(UsersService); private usersService = inject(UsersService);
private notificationService = inject(NzNotificationService) private notificationService = inject(NzNotificationService)
users = signal<GetUserDto[]>([]); users = signal<GetUserDto[]>([]);
usersLoading = signal<boolean>(false); usersLoading = signal<boolean>(false);
updateUser = viewChild.required<ProfilForm>('profilForm');
modal = viewChild.required<ModalNav>('modalNav'); modal = viewChild.required<ModalNav>('modalNav');
async ngOnInit() { async ngOnInit() {
@@ -38,11 +39,8 @@ export class UserTable implements OnInit {
try { try {
const users = await firstValueFrom(this.usersService.getAllUsersEndpoint()) const users = await firstValueFrom(this.usersService.getAllUsersEndpoint())
this.users.set(users); this.users.set(users);
} catch (e) { } catch {
this.notificationService.error( this.notificationService.error('Erreur', 'Impossible de charger les utilisateurs')
'Erreur',
'Erreur de communication avec l\'API'
)
} }
this.usersLoading.set(false) this.usersLoading.set(false)
} }
@@ -50,25 +48,16 @@ export class UserTable implements OnInit {
async delete(user: number) { async delete(user: number) {
try { try {
await firstValueFrom(this.usersService.deleteUserEndpoint(user)) await firstValueFrom(this.usersService.deleteUserEndpoint(user))
this.notificationService.success( this.notificationService.success('Success', 'Suppression effectuée')
'Success', } catch {
'Suppression effectuée' this.notificationService.error('Erreur', 'Impossible de supprimer la ligne')
)
} catch (e) {
this.notificationService.error(
'Erreur',
'Impossible de supprimer la ligne'
)
} }
await this.fetchUsers(); await this.fetchUsers();
} }
async edit(id: number, updateUserComponent: ProfilForm) { async edit(id: number, updateUserComponent: ProfilForm) {
if (updateUserComponent.profilForm.invalid) { if (updateUserComponent.profilForm.invalid) {
this.notificationService.error( this.notificationService.error('Erreur', 'Formulaire invalide')
'Erreur',
'Erreur d\'écriture dans le formulaire'
)
return; return;
} }
@@ -76,15 +65,9 @@ export class UserTable implements OnInit {
const users = updateUserComponent.profilForm.getRawValue(); const users = updateUserComponent.profilForm.getRawValue();
await firstValueFrom(this.usersService.updateUserEndpoint(id, users)) await firstValueFrom(this.usersService.updateUserEndpoint(id, users))
this.notificationService.success( this.notificationService.success('Success', 'Utilisateur modifié')
'Success', } catch {
'Utilisateur modifié' this.notificationService.error('Erreur', 'Erreur lors de la modification')
)
} catch (e) {
this.notificationService.error(
'Erreur',
'Erreur lors de la modification'
)
} }
} }
@@ -100,15 +83,11 @@ export class UserTable implements OnInit {
await this.edit(userId, updateUserComponent); await this.edit(userId, updateUserComponent);
updateUserComponent.profilForm.reset(); updateUserComponent.profilForm.reset();
modal.isVisible = false; this.onModalCancel(modal);
await this.fetchUsers(); await this.fetchUsers();
} }
onModalCancel(modal: ModalNav) { onModalCancel(modal: ModalNav) {
modal.isVisible = false; modal.isVisible = false;
} }
filterUser(input: string, option: any) {
return option.nzLabel.toLowerCase().includes(input.toLowerCase());
}
} }
@@ -7,16 +7,16 @@ import {firstValueFrom} from "rxjs";
import {StockAlert} from "../../services/stock.alert"; import {StockAlert} from "../../services/stock.alert";
@Component({ @Component({
selector: 'app-welcome', selector: 'app-dashboard',
imports: [ imports: [
InfoCard, InfoCard,
DeliveryValidator, DeliveryValidator,
], ],
templateUrl: './welcome.html', templateUrl: './dashboard.html',
styleUrl: './welcome.css' styleUrl: './dashboard.css'
}) })
export class Welcome { export class Dashboard {
private productsService = inject(ProductsService); private productsService = inject(ProductsService);
private deliverersService = inject(DeliverersService); private deliverersService = inject(DeliverersService);
private suppliersService = inject(SuppliersService); private suppliersService = inject(SuppliersService);
@@ -32,8 +32,8 @@ export class Welcome {
try { try {
const deliverers = await firstValueFrom(this.deliverersService.getAllDelivererEndpoint()); const deliverers = await firstValueFrom(this.deliverersService.getAllDelivererEndpoint());
this.deliversCount.set(deliverers.length); this.deliversCount.set(deliverers.length);
} catch (e) { } catch {
this.notificationsService.error('Error', 'Error while getting deliverers.'); this.notificationsService.error('Erreur', 'Impossible de charger les transporteurs');
} }
} }
@@ -43,7 +43,7 @@ export class Welcome {
this.suppliers.set(suppliers); this.suppliers.set(suppliers);
this.suppliersCount.set(suppliers.length); this.suppliersCount.set(suppliers.length);
} catch { } catch {
this.notificationsService.error('Error', 'Error while getting suppliers.'); this.notificationsService.error('Erreur', 'Impossible de charger les fournisseurs');
} }
} }
@@ -52,11 +52,8 @@ export class Welcome {
const products = await firstValueFrom(this.productsService.getAllProductsUnderLimitEndpoint()); const products = await firstValueFrom(this.productsService.getAllProductsUnderLimitEndpoint());
this.productsUnderLimitCount.set(products.length); this.productsUnderLimitCount.set(products.length);
await this.stockAlertService.generatePurchaseOrder(products, this.suppliers()); await this.stockAlertService.generatePurchaseOrder(products, this.suppliers());
} catch (e) { } catch {
this.notificationsService.error( this.notificationsService.error('Error', 'Impossible de charger les produits.');
'Error',
'Error while getting products.',
)
} }
} }
+5 -14
View File
@@ -26,7 +26,7 @@ export class Deliverer {
async onModalOk() { async onModalOk() {
await this.addDeliverer() await this.addDeliverer()
this.createDeliverer().delivererForm.reset(); this.createDeliverer().delivererForm.reset();
this.modal().isVisible = false; this.onModalCancel();
await this.delivererTable().fetchDeliverers() await this.delivererTable().fetchDeliverers()
} }
@@ -36,24 +36,15 @@ export class Deliverer {
async addDeliverer() { async addDeliverer() {
if (this.createDeliverer().delivererForm.invalid) { if (this.createDeliverer().delivererForm.invalid) {
this.notificationService.error( this.notificationService.error('Erreur', 'Formulaire invalide')
'Erreur',
'Erreur d\'écriture dans le formulaire'
)
} }
try { try {
const deliverers = this.createDeliverer().delivererForm.getRawValue(); const deliverers = this.createDeliverer().delivererForm.getRawValue();
await firstValueFrom(this.deliverersService.createDelivererEndpoint(deliverers)) await firstValueFrom(this.deliverersService.createDelivererEndpoint(deliverers))
this.notificationService.success( this.notificationService.success('Success', 'Transporteur enregistré')
'Success', } catch {
'Transporteur enregistré' this.notificationService.error('Erreur', 'Erreur d\'enregistrement')
)
} catch (e) {
this.notificationService.error(
'Erreur',
'Erreur d\'enregistrement'
)
} }
} }
} }
+1 -1
View File
@@ -52,7 +52,7 @@ export class Stock implements OnInit {
const suppliers = await firstValueFrom(this.suppliersService.getAllSuppliersEndpoint()); const suppliers = await firstValueFrom(this.suppliersService.getAllSuppliersEndpoint());
this.suppliers.set(suppliers); this.suppliers.set(suppliers);
} catch { } catch {
this.notificationService.error('Erreur', 'Erreur de communication avec l\'API'); this.notificationService.error('Erreur', 'Impossible de charger les fournisseurs');
} }
} }
+5 -14
View File
@@ -26,7 +26,7 @@ export class Supplier {
async onModalOk() { async onModalOk() {
await this.addSupplier() await this.addSupplier()
this.createSupplier().supplierForm.reset(); this.createSupplier().supplierForm.reset();
this.modal().isVisible = false; this.onModalCancel();
await this.supplierTable().fetchSuppliers() await this.supplierTable().fetchSuppliers()
} }
@@ -36,24 +36,15 @@ export class Supplier {
async addSupplier() { async addSupplier() {
if (this.createSupplier().supplierForm.invalid) { if (this.createSupplier().supplierForm.invalid) {
this.notificationService.error( this.notificationService.error('Erreur', 'Formulaire invalide')
'Erreur',
'Erreur d\'écriture dans le formulaire'
)
} }
try { try {
const suppliers = this.createSupplier().supplierForm.getRawValue(); const suppliers = this.createSupplier().supplierForm.getRawValue();
await firstValueFrom(this.suppliersService.createSupplierEndpoint(suppliers)) await firstValueFrom(this.suppliersService.createSupplierEndpoint(suppliers))
this.notificationService.success( this.notificationService.success('Success', 'Fournisseur enregistré')
'Success', } catch {
'Fournisseur enregistré' this.notificationService.error('Erreur', 'Erreur d\'enregistrement')
)
} catch (e) {
this.notificationService.error(
'Erreur',
'Erreur d\'enregistrement'
)
} }
} }
} }
+5 -14
View File
@@ -26,7 +26,7 @@ export class User {
async onModalOk() { async onModalOk() {
await this.addUser() await this.addUser()
this.createUser().profilForm.reset(); this.createUser().profilForm.reset();
this.modal().isVisible = false; this.onModalCancel();
await this.usersTable().fetchUsers() await this.usersTable().fetchUsers()
} }
@@ -36,24 +36,15 @@ export class User {
async addUser() { async addUser() {
if (this.createUser().profilForm.invalid) { if (this.createUser().profilForm.invalid) {
this.notificationService.error( this.notificationService.error('Erreur', 'Formulaire invalide')
'Erreur',
'Erreur d\'écriture dans le formulaire'
)
} }
try { try {
const users = this.createUser().profilForm.getRawValue(); const users = this.createUser().profilForm.getRawValue();
await firstValueFrom(this.usersService.createUserEndpoint(users)) await firstValueFrom(this.usersService.createUserEndpoint(users))
this.notificationService.success( this.notificationService.success('Success', 'Utilisateur crée')
'Success', } catch {
'Utilisateur crée' this.notificationService.error('Erreur', 'Erreur d\'enregistrement')
)
} catch (e) {
this.notificationService.error(
'Erreur',
'Erreur d\'enregistrement'
)
} }
} }
} }
View File
-6
View File
@@ -1,6 +0,0 @@
import {Routes} from '@angular/router';
import {Welcome} from './welcome';
export const WELCOME_ROUTES: Routes = [
{path: '', component: Welcome},
];