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
@@ -28,15 +28,14 @@ export class DelivereryNoteTable implements OnInit {
private deliveryNotesService = inject(DeliverynotesService);
private notificationService = inject(NzNotificationService);
private fileService = inject(FileService);
deliveryNotes = signal<GetDeliveryNoteDto[]>([]);
deliveryNotesLoading = signal<boolean>(false);
modal = viewChild.required<ModalNav>('modalNav');
date: string = "";
modal = viewChild.required<ModalNav>('modalNav');
async ngOnInit() {
await this.fetchDeliveryNotes();
this.date = new Date().toISOString().split('T')[0];
}
async fetchDeliveryNotes() {
@@ -44,11 +43,8 @@ export class DelivereryNoteTable implements OnInit {
try {
const deliveryNotes = await firstValueFrom(this.deliveryNotesService.getAllDeliveryNoteEndpoint());
this.deliveryNotes.set(deliveryNotes);
} catch (e) {
this.notificationService.error(
'Erreur',
'Erreur de communication avec l\'API'
)
} catch {
this.notificationService.error('Erreur', 'Erreur lors du chargement des bons de livraison');
}
this.deliveryNotesLoading.set(false)
}
@@ -57,15 +53,9 @@ export class DelivereryNoteTable implements OnInit {
this.deliveryNotesLoading.set(true)
try {
await firstValueFrom(this.deliveryNotesService.deleteDeliveryNoteEndpoint(deliveryNote));
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.deliveryNotesLoading.set(false)
await this.fetchDeliveryNotes();
@@ -80,22 +70,12 @@ export class DelivereryNoteTable implements OnInit {
try {
await firstValueFrom(this.deliveryNotesService.patchRealDeliveryDateEndpoint(deliveryNote, PatchRealDate))
this.notificationService.success(
'Success',
'Date actualisée'
)
} catch (e) {
this.notificationService.error(
'Erreur',
'La date à déjà été actualisée'
)
this.notificationService.success('Success', 'Date actualisée');
} catch {
this.notificationService.error('Erreur', 'La date à déjà été actualisée');
}
} catch (e) {
this.notificationService.error(
'Erreur',
'Erreur d\'actualisation de la date'
)
} catch {
this.notificationService.error('Erreur', 'Erreur d\'actualisation de la date');
}
this.deliveryNotesLoading.set(false)
await this.fetchDeliveryNotes()
@@ -104,15 +84,10 @@ export class DelivereryNoteTable implements OnInit {
async export(deliveryNoteId: number) {
this.deliveryNotesLoading.set(true)
try {
const pdf = await firstValueFrom(
this.deliveryNotesService.getDeliveryNotePdfEndpoint(deliveryNoteId, "response")
);
const pdf = await firstValueFrom(this.deliveryNotesService.getDeliveryNotePdfEndpoint(deliveryNoteId, "response"));
this.fileService.downloadBlob(pdf)
} catch (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.deliveryNotesLoading.set(false)
}
@@ -139,7 +114,7 @@ export class DelivereryNoteTable implements OnInit {
await firstValueFrom(this.deliveryNotesService.updateDeliveryNoteEndpoint(id, deliveryNoteDto));
this.notificationService.success('Success', 'Bon de livraison modifié');
} catch (e) {
} catch {
this.notificationService.error('Erreur', 'Erreur lors de la modification');
}
}
@@ -156,7 +131,7 @@ export class DelivereryNoteTable implements OnInit {
await this.edit(id, updateDelivereryNoteComponent);
updateDelivereryNoteComponent.deliveryNoteForm.reset();
modal.isVisible = false;
this.onModalCancel(modal);
await this.fetchDeliveryNotes();
}