updated delivery note

This commit is contained in:
2025-12-11 19:30:46 +01:00
parent 586c9458b1
commit d160a29a56
6 changed files with 58 additions and 32 deletions

View File

@@ -137,39 +137,43 @@ export class DelivereryNoteTable implements OnInit {
async edit(id: number, updateDelivereryNoteComponent: DelivereryNoteForm) {
if (updateDelivereryNoteComponent.deliveryNoteForm.invalid) {
this.notificationService.error(
'Erreur',
'Erreur d\'écriture dans le formulaire'
)
this.notificationService.error('Erreur', 'Formulaire invalide');
return;
}
try {
const estimateDate = updateDelivereryNoteComponent.deliveryNoteForm.get('estimatedDate').value;
const expeditionDate = updateDelivereryNoteComponent.deliveryNoteForm.get('expeditionDate').value;
const realDate = updateDelivereryNoteComponent.deliveryNoteForm.get('realDeliveryDate').value;
const raw = updateDelivereryNoteComponent.deliveryNoteForm.getRawValue();
const estimateDateResult = format(estimateDate, 'yyyy-MM-dd');
const expeditionDateResult = format(expeditionDate, 'yyyy-MM-dd');
const realDateResult = format(realDate, 'yyyy-MM-dd');
// convertit proprement les dates (string OU Date)
const toIso = (val: any) => {
if (!val) return null;
const deliveryNotes = updateDelivereryNoteComponent.deliveryNoteForm.getRawValue();
deliveryNotes.estimatedDate = estimateDateResult;
deliveryNotes.expeditionDate = expeditionDateResult;
deliveryNotes.realDeliveryDate = realDateResult;
// si cest déjà un string ISO "yyyy-MM-dd", on renvoie tel quel
if (typeof val === 'string' && /^\d{4}-\d{2}-\d{2}/.test(val)) {
return val.substring(0, 10);
}
await firstValueFrom(this.deliveryNotesService.updateDeliveryNoteEndpoint(id, deliveryNotes))
// sinon on reconstruit une Date
const d = new Date(val);
if (isNaN(d.getTime())) return null;
this.notificationService.success(
'Success',
'Bon de livraison modifié'
)
return d.toISOString().substring(0, 10); // yyyy-MM-dd
};
const deliveryNoteDto = {
trackingNumber: raw.trackingNumber,
delivererId: raw.delivererId,
expeditionDate: toIso(raw.expeditionDate),
estimatedDate: toIso(raw.estimatedDate),
realDeliveryDate: toIso(raw.realDeliveryDate)
};
await firstValueFrom(this.deliveryNotesService.updateDeliveryNoteEndpoint(id, deliveryNoteDto));
this.notificationService.success('Success', 'Bon de livraison modifié');
} catch (e) {
this.notificationService.error(
'Erreur',
'Erreur lors de la modification'
)
console.error(e);
this.notificationService.error('Erreur', 'Erreur lors de la modification');
}
}
}