UNPKG

@goteborgco/open-api-js-client

Version:

Official JavaScript client for the Göteborg & Co GraphQL API

104 lines (103 loc) 4.03 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.WpEntity = void 0; const Translations_1 = require("./Translations"); const Media_1 = require("./Media"); const Location_1 = require("./Location"); const Contact_1 = require("./Contact"); const EventDate_1 = require("./EventDate"); const CurrentInTime_1 = require("./CurrentInTime"); class WpEntity { constructor(data) { this.id = data.id; this.title = data.title || ''; this.excerpt = data.excerpt || ''; this.content = data.content; this.date = data.date || new Date().toISOString(); this.modified = data.modified; this.link = data.link; this.categories = data.categories || []; this.areas = data.areas || []; this.tags = data.tags || []; this.category_heading = data.category_heading; this.featuredmedia = data.featuredmedia ? (Array.isArray(data.featuredmedia) ? data.featuredmedia.map((m) => new Media_1.Media(m)) : [new Media_1.Media(data.featuredmedia)]) : undefined; this.gallery = data.gallery ? (Array.isArray(data.gallery) ? data.gallery : [data.gallery]).map((item) => new Media_1.Media(item)) : undefined; this.location = data.location ? new Location_1.Location(data.location) : undefined; this.dates = data.dates ? data.dates.map((date) => new EventDate_1.EventDate(date)) : undefined; this.contact = data.contact ? new Contact_1.Contact(data.contact) : undefined; this.current_in_time = data.current_in_time ? new CurrentInTime_1.CurrentInTime(data.current_in_time) : undefined; this.translations = data.translations ? new Translations_1.Translations(data.translations) : undefined; this.place_id = data.place_id; this.is_free = data.is_free; this.lang = data.lang || 'sv'; } /** * Get the featured media * @returns The first featured media item or undefined if no media exists */ getFeaturedMedia() { return this.featuredmedia?.[0]; } /** * Get the main image URL * @param size The desired image size ('full', 'large', 'medium', 'thumbnail') * @returns The URL for the requested size or undefined */ getImageUrl(size = 'full') { return this.getFeaturedMedia()?.getUrl(size); } /** * Get all gallery image URLs * @param size The desired image size ('full', 'large', 'medium', 'thumbnail') * @returns Array of gallery image URLs */ getGalleryUrls(size = 'full') { return this.gallery?.map(image => image.getUrl(size)).filter((url) => url !== undefined) || []; } /** * Check if the entity is currently active based on its dates * @returns boolean indicating if the entity is currently active */ isActive() { if (!this.dates?.length) return true; return this.dates.some(date => date.isActive()); } /** * Get the location coordinates * @returns Object containing lat and lng, or undefined if no location exists */ getCoordinates() { return this.location?.getCoordinates(); } /** * Get a formatted address string * @returns Formatted address string or undefined if no location exists */ getFormattedAddress() { return this.location?.getFormattedAddress(); } /** * Get contact information * @returns Contact information or undefined if no contact exists */ getContact() { return this.contact; } /** * Get translation for a specific language * @param lang Language code ('en' or 'sv') * @returns Translation ID or undefined if no translation exists */ getTranslation(lang) { return this.translations?.getTranslation(lang); } /** * Get current in time information * @returns CurrentInTime information or undefined if not available */ getCurrentInTime() { return this.current_in_time; } } exports.WpEntity = WpEntity;