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
@@ -34,8 +34,10 @@ export class QuotationTable implements OnInit {
private quotationsService = inject(QuotationsService);
private notificationService = inject(NzNotificationService);
private fileService = inject(FileService);
quotations = signal<GetQuotationDto[]>([]);
quotationsLoading = signal<boolean>(false);
modal = viewChild.required<ModalNav>('modalNav');
modalQuantity = viewChild.required<ModalNav>('modalQuantity');
@@ -49,11 +51,8 @@ export class QuotationTable implements OnInit {
try {
const quotations = await firstValueFrom(this.quotationsService.getAllQuotationEndpoint())
this.quotations.set(quotations);
} catch (e) {
this.notificationService.error(
'Erreur',
'Erreur de communication avec l\'API'
)
} catch {
this.notificationService.error('Erreur', 'Erreur lors du chargement des devis')
}
this.quotationsLoading.set(false)
}
@@ -62,15 +61,9 @@ export class QuotationTable implements OnInit {
this.quotationsLoading.set(true)
try {
await firstValueFrom(this.quotationsService.deleteQuotationEndpoint(quotation))
this.notificationService.success(
'Success',
'Suppression effectuée'
)
} catch (e) {
this.notificationService.error(
'Erreur',
'Impossible de supprimer la ligne'
)
this.notificationService.success('Success', 'Suppression effectuée')
} catch {
this.notificationService.error('Erreur', 'Impossible de supprimer la ligne')
}
this.quotationsLoading.set(false)
await this.fetchQuotations();
@@ -83,12 +76,8 @@ export class QuotationTable implements OnInit {
this.quotationsService.getQuotationPdfEndpoint(quotationId, "response")
);
this.fileService.downloadBlob(pdf)
} catch (e) {
console.error(e);
this.notificationService.error(
'Erreur',
'Impossible de générer un PDF'
);
} catch {
this.notificationService.error('Erreur', 'Impossible de générer un PDF');
}
this.quotationsLoading.set(false)
}
@@ -103,8 +92,7 @@ export class QuotationTable implements OnInit {
const quotations = updateQuotationComponent.quotationForm.getRawValue();
await firstValueFrom(this.quotationsService.updateQuotationEndpoint(id, quotations));
this.notificationService.success('Success', 'Devis modifié')
} catch (e) {
console.error(e)
} catch {
this.notificationService.error('Erreur', 'Erreur lors de la modification')
}
}
@@ -113,15 +101,9 @@ export class QuotationTable implements OnInit {
this.quotationsLoading.set(true)
try {
await firstValueFrom(this.quotationsService.deleteProductFromQuotationEndpoint(productId, quotationId))
this.notificationService.success(
'Success',
'Suppression effectuée'
)
} catch (e) {
this.notificationService.error(
'Erreur',
'Impossible de supprimer la ligne'
)
this.notificationService.success('Success', 'Suppression effectuée')
} catch {
this.notificationService.error('Erreur', 'Impossible de supprimer la ligne')
}
this.quotationsLoading.set(false)
await this.fetchQuotations();
@@ -129,10 +111,7 @@ export class QuotationTable implements OnInit {
async editQuantity(productId: number, quotationId: number, updateQuantityComponent: QuantityForm) {
if (updateQuantityComponent.quantityForm.invalid) {
this.notificationService.error(
'Erreur',
'Erreur d\'écriture dans le formulaire'
)
this.notificationService.error('Erreur', 'Formulaire invalide')
return;
}
@@ -141,7 +120,7 @@ export class QuotationTable implements OnInit {
await firstValueFrom(this.quotationsService.patchQuotationProductQuantityEndpoint(productId, quotationId, quantity))
this.notificationService.success('Success', 'Quantité modifiée')
} catch (e) {
} catch {
this.notificationService.error('Erreur', 'Erreur lors de la modification')
}
}
@@ -158,7 +137,7 @@ export class QuotationTable implements OnInit {
await this.edit(id, updateQuotationComponent);
updateQuotationComponent.quotationForm.reset();
modal.isVisible = false;
this.onModalCancel(modal);
await this.fetchQuotations();
}
@@ -178,7 +157,7 @@ export class QuotationTable implements OnInit {
await this.editQuantity(productId, quotationId, updateQuantityComponent);
updateQuantityComponent.quantityForm.reset();
modal.isVisible = false;
this.onModalCancel(modal);
await this.fetchQuotations();
}
}