import { rcEnums } from 'types/rc.enums'; import { RCActivityTime } from './coreEntites/Venue'; import { MediaInterface } from 'types/media'; export interface Package { id: number; name: string; price: string; } export interface SpaceMedia { id: number; url: string; name: string; title: string; description: string; } export interface PricePackage { id: number; name: string; price: string; addon: boolean; tooltipTitle: string; tooltipBody: string; duration: number; } export interface SpacePackage { id: number; resourceId: number; packageId: number; package: PricePackage; } export interface Space { id: number; name: string; description: string; shortDescription: string; mainMediaId: number; activityTimes: RCActivityTime[]; amenities: rcEnums.venue.AmenitiesEnum[]; mainMedia: SpaceMedia; media: SpaceMedia[]; spaceType: string; packages: SpacePackage[]; surface: string; properties: string[]; sports: number[]; } /** * This functions filters spaces * who have mainMedia. * * In order to avoid key duplications * were spaces might have the same mainMediaId, * entityId is inserted to the space media object. * * @param spaces - Space entities * * @returns medias - who have mainMedia */ export const getSpacesWithMedia = (spaces: Space[]): MediaInterface[] => { return spaces.reduce((accumulator: MediaInterface[], currentSpace: Space) => { if (currentSpace.mainMediaId && currentSpace.mainMedia) { const mediaToInsert = { ...currentSpace.mainMedia, title: currentSpace.name, // Spaces might have the same main media id // which might cause key duplications entityId: currentSpace.id, spaceType: currentSpace.spaceType, surface: currentSpace.surface, properties: currentSpace.properties, sport: currentSpace.sports[0], }; accumulator.push(mediaToInsert); } return accumulator; }, []); }; export enum SpaceTypeEnum { COURT = 'court', FIELD = 'field', ROOM = 'room', DIAMOND = 'diamond', RINK = 'rink', STUDIO = 'studio', POOL = 'pool', BATTING_CAGE = 'batting cage', SHELTER = 'shelter', GOLF_SIMULATOR = 'golf simulator', }