Fixed error with estimateDeliveryDate in form to update the raw

This commit is contained in:
2026-05-26 14:57:36 +01:00
parent f233c46853
commit 4dd1d7e81d
5 changed files with 26 additions and 31 deletions
@@ -5,7 +5,7 @@ import {NzDividerComponent} from "ng-zorro-antd/divider";
import {NzIconDirective} from "ng-zorro-antd/icon";
import {NzTableComponent} from "ng-zorro-antd/table";
import {DelivereryNoteForm} from "../deliverery-note-form/deliverery-note-form";
import {DeliverynotesService, GetDeliveryNoteDto} from "../../services/api";
import {DeliverynotesService, GetDeliveryNoteDto, UpdateDeliveryNoteDto} from "../../services/api";
import {NzNotificationService} from "ng-zorro-antd/notification";
import {firstValueFrom} from "rxjs";
import {format} from "date-fns";
@@ -32,8 +32,11 @@ export class DelivereryNoteTable implements OnInit {
deliveryNotesLoading = signal<boolean>(false);
modal = viewChild.required<ModalNav>('modalNav');
date: string = "";
async ngOnInit() {
await this.fetchDeliveryNotes();
this.date = new Date().toISOString().split('T')[0];
}
async fetchDeliveryNotes() {
@@ -123,34 +126,20 @@ export class DelivereryNoteTable implements OnInit {
try {
const raw = updateDelivereryNoteComponent.deliveryNoteForm.getRawValue();
// convertit proprement les dates (string OU Date)
const toIso = (val: any) => {
if (!val) return null;
const toIso = (val: any) =>
val ? new Date(val).toISOString().substring(0, 10) : null;
// 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);
}
// sinon on reconstruit une Date
const d = new Date(val);
if (isNaN(d.getTime())) return null;
return d.toISOString().substring(0, 10); // yyyy-MM-dd
};
const deliveryNoteDto = {
const deliveryNoteDto: UpdateDeliveryNoteDto = {
trackingNumber: raw.trackingNumber,
delivererId: raw.delivererId,
expeditionDate: toIso(raw.expeditionDate),
estimatedDate: toIso(raw.estimatedDate),
estimateDeliveryDate: toIso(raw.estimatedDate),
realDeliveryDate: toIso(raw.realDeliveryDate)
};
await firstValueFrom(this.deliveryNotesService.updateDeliveryNoteEndpoint(id, deliveryNoteDto));
this.notificationService.success('Success', 'Bon de livraison modifié');
} catch (e) {
console.error(e);
this.notificationService.error('Erreur', 'Erreur lors de la modification');
}
}