From 9abdf37efa8f38b6e9c317c3da5faca75b8cc1f7 Mon Sep 17 00:00:00 2001 From: Maicol Battistini Date: Mon, 26 Jun 2023 10:11:41 +0200 Subject: [PATCH] =?UTF-8?q?fix:=20=F0=9F=90=9B=20Date=20non=20settate=20tr?= =?UTF-8?q?amite=20API?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- resources/ts/Models/Model.ts | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/resources/ts/Models/Model.ts b/resources/ts/Models/Model.ts index f2fc5da67..309a01426 100644 --- a/resources/ts/Models/Model.ts +++ b/resources/ts/Models/Model.ts @@ -4,6 +4,7 @@ import { PaginationStrategy, PluralResponse } from 'coloquent'; +import dayjs from 'dayjs'; import type {ValueOf} from 'type-fest'; export interface ModelAttributes { @@ -62,16 +63,17 @@ export default abstract class Model; } - isDateAttribute(attributeName: string) { - // @ts-ignore - return super.isDateAttribute(attributeName) && this.attributes.get(attributeName); - } - getAttributes() { return super.getAttributes() as ModelAttributes; } setAttribute(attributeName: AN, value: ValueOf) { + const date = dayjs(value as string | Date | undefined); + // @ts-expect-error + if (this.isDateAttribute(attributeName) && date.isValid()) { + // @ts-expect-error + value = date.format((this as Model).constructor.dates[attributeName]); + } // @ts-expect-error — This is needed to parse the dates correctly. // eslint-disable-next-line @typescript-eslint/no-unsafe-call,@typescript-eslint/no-unsafe-member-access this.attributes.set(attributeName as string, value);