fix(medusa, pricing, types): pass dates as Date-objects rather than strings to the pricing module (#5768)

* init

* remove date string validator;

* add transformOptionalDate transformer to api

* move type conversion to the datalayer

* fix final module integration test

* update arrow-function

* make string optional

* move work to utils

* make check for value exists

* move util back to pricng

* change utils

* refactor get-iso-string

* fix build

* flip transform condition

* add null check for isDate

* feat(pricing): Separate Pricing Module internal types from `@medusajs/types` (#5777)

* create types for pricing repositories

* create RepositoryTypes input

* add service types

* use models for repository types

* fix build

* update types to match interface types

* add aliases

* types instead of moduletypes

* move repository to types for pricing module

* add changeset

* fix merge error

* fix conflict

* fix build

* re-add validation of dates in updatePriceLists_
This commit is contained in:
Philip Korsholm
2023-12-21 08:29:41 +01:00
committed by GitHub
parent 6d1e3cc028
commit c1c470e6b8
72 changed files with 1049 additions and 310 deletions

View File

@@ -0,0 +1,15 @@
import { isDate } from "./is-date"
import { MedusaError } from "./errors"
export const GetIsoStringFromDate = (date: Date | string) => {
if (!isDate(date)) {
throw new MedusaError(
MedusaError.Types.INVALID_DATA,
`Cannot format date to ISO string: ${date}`
)
}
date = new Date(date)
return date.toISOString()
}

View File

@@ -15,6 +15,7 @@ export * from "./is-defined"
export * from "./is-email"
export * from "./is-object"
export * from "./is-string"
export * from "./get-iso-string-from-date"
export * from "./lower-case-first"
export * from "./map-object-to"
export * from "./medusa-container"

View File

@@ -1,4 +1,3 @@
export function isDate(value: any): value is Date {
const date = new Date(value)
return !isNaN(date.valueOf())
return value !== null && !isNaN(new Date(value).valueOf())
}