UNPKG

fatsoma-sync

Version:

Sync Fatsoma events with configurable DesignMyNight booking links

44 lines (35 loc) 1.68 kB
const { DateTime } = require("luxon"); module.exports = function transformEvent(event, config) { const attr = event.attributes; const start = DateTime.fromISO(attr["starts-at"], { zone: "Europe/London" }); const end = DateTime.fromISO(attr["ends-at"], { zone: "Europe/London" }); const duration = end.diff(start, "minutes").as("minutes"); const booking_date = start.toFormat("yyyy-MM-dd"); const booking_time = start.toFormat("HH:mm"); const return_url = encodeURIComponent(config.returnUrl); // Only show booking buttons if the description includes this phrase const showButtons = attr.description ?.toLowerCase() .includes("table bookings are also available on our website"); let drinks_url = null; let food_url = null; if (showButtons) { drinks_url = `https://bookings.designmynight.com/book?venue_id=${config.dmnVenueId}&source=partner&type=${config.drinksBookingType}&time=${booking_time}&duration=${duration}&date=${booking_date}&return_url=${return_url}`; food_url = `https://bookings.designmynight.com/book?venue_id=${config.dmnVenueId}&source=partner&type=${config.foodBookingType}&time=${booking_time}&duration=${duration}&date=${booking_date}&return_url=${return_url}`; } return { id: event.id, title: attr.name, description: attr.description, image_url: attr["asset-url"], starts_at: attr["starts-at"], ends_at: attr["ends-at"], booking_date, booking_time, drinks_booking_url: drinks_url, food_booking_url: food_url, vanity_name: attr["vanity-name"], ticket_url: `https://www.fatsoma.com/e/${attr["vanity-name"]}`, booking_buttons_shown: showButtons, }; };