From b03f5ca5850dfb93f8893100cdd46bc17a68465f Mon Sep 17 00:00:00 2001 From: Fernando Souto <90011575+soutofernando@users.noreply.github.com> Date: Mon, 23 Dec 2024 18:37:27 -0300 Subject: [PATCH] feat: add pickupHolidays type (#963) --- vtex/utils/transform.ts | 26 ++++++++++++++++++++++++++ vtex/utils/types.ts | 7 +++++++ 2 files changed, 33 insertions(+) diff --git a/vtex/utils/transform.ts b/vtex/utils/transform.ts index 4010133f3..2b155d971 100644 --- a/vtex/utils/transform.ts +++ b/vtex/utils/transform.ts @@ -32,6 +32,7 @@ import type { LegacyProduct as LegacyProductVTEX, OrderForm, PageType as PageTypeVTEX, + PickupHolidays, PickupPoint, Product as ProductVTEX, ProductInventoryData, @@ -1120,6 +1121,23 @@ function toHoursSpecification(hours: Hours): OpeningHoursSpecification { }; } +function toSpecialHoursSpecification( + holiday: PickupHolidays, +): OpeningHoursSpecification { + const dateHoliday = new Date(holiday.date ?? ""); + // VTEX provide date in ISO format, at 00h on the day + const validThrough = dateHoliday.setDate(dateHoliday.getDate() + 1) + .toString(); + + return { + "@type": "OpeningHoursSpecification", + opens: holiday.hourBegin, + closes: holiday.hourEnd, + validFrom: holiday.date, + validThrough, + }; +} + function isPickupPointVCS( pickupPoint: PickupPoint | PickupPointVCS, ): pickupPoint is PickupPointVCS { @@ -1135,12 +1153,16 @@ export function toPlace( latitude, longitude, openingHoursSpecification, + specialOpeningHoursSpecification, } = isPickupPointVCS(pickupPoint) ? { name: pickupPoint.name, country: pickupPoint.address?.country?.acronym, latitude: pickupPoint.address?.location?.latitude, longitude: pickupPoint.address?.location?.longitude, + specialOpeningHoursSpecification: pickupPoint.pickupHolidays?.map( + toSpecialHoursSpecification, + ), openingHoursSpecification: pickupPoint.businessHours?.map( toHoursSpecification, ), @@ -1150,6 +1172,9 @@ export function toPlace( country: pickupPoint.address?.country, latitude: pickupPoint.address?.geoCoordinates[0], longitude: pickupPoint.address?.geoCoordinates[1], + specialOpeningHoursSpecification: pickupPoint.pickupHolidays?.map( + toSpecialHoursSpecification, + ), openingHoursSpecification: pickupPoint.businessHours?.map(( { ClosingTime, DayOfWeek, OpeningTime }, ) => @@ -1175,6 +1200,7 @@ export function toPlace( latitude, longitude, name, + specialOpeningHoursSpecification, openingHoursSpecification, additionalProperty: [{ "@type": "PropertyValue", diff --git a/vtex/utils/types.ts b/vtex/utils/types.ts index 0aafb0740..50ec9a8a5 100644 --- a/vtex/utils/types.ts +++ b/vtex/utils/types.ts @@ -449,12 +449,19 @@ export interface PickupStoreInfo { dockId: null; } +export interface PickupHolidays { + date?: string; + hourBegin?: string; + hourEnd?: string; +} + export interface PickupPoint { friendlyName: string; address: Address; additionalInfo: string; id: string; businessHours: BusinessHour[]; + pickupHolidays?: PickupHolidays[]; } export interface BusinessHour {