Skip to content

Commit

Permalink
fix: switch to schema.org type
Browse files Browse the repository at this point in the history
  • Loading branch information
soutofernando committed Dec 17, 2024
1 parent 319b79f commit ade24c7
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 27 deletions.
16 changes: 0 additions & 16 deletions commerce/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -559,20 +559,6 @@ export interface OpeningHoursSpecification extends Omit<Thing, "@type"> {
/** The date after when the item is not valid. For example the end of an offer, salary period, or a period of opening hours. */
validThrough?: string;
}
export interface PickupHolidays {
/**
* This represents the day when the pickup service will not be available.
*/
date?: string;
/** .
* Indicates when the service begins operating, if applicable.
*/
hourBegin?: string;
/**
* Indicates when the service stops operating, if applicable.
*/
hourEnd?: string;
}
export interface ContactPoint extends Omit<Thing, "@type"> {
"@type": "ContactPoint";
/** The geographic area where a service or offered item is provided. */
Expand Down Expand Up @@ -748,8 +734,6 @@ export interface PlaceLeaf extends Omit<Thing, "@type"> {
longitude?: number;
/** The total number of individuals that may attend an event or venue. */
maximumAttendeeCapacity?: number;
/** The opening hours of a particular location on public holidays */
pickupHolidays?: PickupHolidays[];
/** The opening hours of a certain place. */
openingHoursSpecification?: OpeningHoursSpecification[];
/** A photograph of this place. */
Expand Down
37 changes: 26 additions & 11 deletions vtex/utils/transform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1121,12 +1121,27 @@ function toHoursSpecification(hours: Hours): OpeningHoursSpecification {
};
}

function toHolidayHoursSpecification(holiday: PickupHolidays) {
function toSpecialHoursSpecification(
holiday: PickupHolidays,
): OpeningHoursSpecification {
const days: DayOfWeek[] = [
"Sunday",
"Monday",
"Tuesday",
"Wednesday",
"Thursday",
"Friday",
"Saturday",
];
const date = new Date(holiday.date ?? "");
const dayIndex = date.getDay();
const dayOfWeek = days[dayIndex];

return {
"@type": "PickupHolidays",
date: holiday.date,
hourBegin: holiday.hourBegin,
hourEnd: holiday.hourEnd,
"@type": "OpeningHoursSpecification",
dayOfWeek,
opens: holiday.hourBegin,
closes: holiday.hourEnd,
};
}

Expand All @@ -1145,15 +1160,15 @@ export function toPlace(
latitude,
longitude,
openingHoursSpecification,
pickupHolidays,
specialOpeningHoursSpecification,
} = isPickupPointVCS(pickupPoint)
? {
name: pickupPoint.name,
country: pickupPoint.address?.country?.acronym,
latitude: pickupPoint.address?.location?.latitude,
longitude: pickupPoint.address?.location?.longitude,
pickupHolidays: pickupPoint.pickupHolidays?.map(
toHolidayHoursSpecification,
specialOpeningHoursSpecification: pickupPoint.pickupHolidays?.map(
toSpecialHoursSpecification,
),
openingHoursSpecification: pickupPoint.businessHours?.map(
toHoursSpecification,
Expand All @@ -1164,8 +1179,8 @@ export function toPlace(
country: pickupPoint.address?.country,
latitude: pickupPoint.address?.geoCoordinates[0],
longitude: pickupPoint.address?.geoCoordinates[1],
pickupHolidays: pickupPoint.pickupHolidays?.map(
toHolidayHoursSpecification,
specialOpeningHoursSpecification: pickupPoint.pickupHolidays?.map(
toSpecialHoursSpecification,
),
openingHoursSpecification: pickupPoint.businessHours?.map((
{ ClosingTime, DayOfWeek, OpeningTime },
Expand All @@ -1192,7 +1207,7 @@ export function toPlace(
latitude,
longitude,
name,
pickupHolidays,
specialOpeningHoursSpecification,
openingHoursSpecification,
additionalProperty: [{
"@type": "PropertyValue",
Expand Down

0 comments on commit ade24c7

Please sign in to comment.