import { isEmpty } from 'lodash'; import { Certificate, Charity, Discount, History, Image, Job, Partner, Review, Select, Station, Team, TextResponse, } from '../@types'; export const presentImage = (images: Image[]) => isEmpty(images) ? null : `${process.env.TAYLOR_MEDIA_URL}/${images[0].url}`; export const presentSelect = (selectItems: Select[]) => !isEmpty(selectItems) ? selectItems[0].name : null; export const presentPartners = (partners: Partner) => partners.records.map((record, index) => ({ id: index + 1, name: record._name, poster: presentImage(record._image), })); export const presentJobs = (jobs: Job) => jobs.records.map((job, index) => ({ id: index + 1, name: job._name, tags: job._tags.map((tag) => tag.name), location: presentSelect(job._localtio), type: presentSelect(job._type), })); export const presentTeamMembers = (members: Team) => members.records.map((member) => ({ name: member._name, photo: presentImage(member._foto), profession: member._zvanie, })); export const presentHistoryItems = (historyItems: History) => historyItems.records.map((item) => ({ name: item._name, year: item._god, description: item._opisanie, })); export const presentDiscounts = (discounts: Discount) => discounts.records.map((discount, index) => ({ id: index + 1, name: discount._name, description: discount._opisanie, expiresAt: discount._do, image: presentImage(discount._foto), })); export const presentStations = (stations: Station) => stations.records.map((station, index) => ({ id: index + 1, name: station._name, description: station._opisanie, address: station._adress, workingHours: station._chasyRaboty?.name || null, latitude: station._lat, longitude: station._long, carWash: station._avtomojka || false, ai92: station._dtCopy || false, ai95: station._ai92Copy || false, dt: station._avtomojkaCopy || false, z100: station._ai95Copy || false, propan: station._z100Copy || false, electricCharge: station._propanCopy || false, miniMarket: station._zaryadnayaStanci || false, toilet: station._miniMarketCop || false, region: presentSelect(station._region), image: presentImage(station._foto), })); export const presentTexts = (texts: TextResponse) => texts.records.map((item) => ({ key: item._name, value: item._znachenie, })); export const presentReviews = (reviews: Review) => reviews.records.map((review) => ({ id: review.id, fullname: review._name, review: review._otzyv, rating: review._rejting, })); export const presentCharities = (charities: Charity) => charities.records.map((charity, index) => ({ id: index + 1, name: charity._name, description: charity._opisanie, date: charity._data, location: charity._lokaciya, image: presentImage(charity._foto), })); export const presentCertificates = (certificates: Certificate) => certificates.records.map((certificate, index) => ({ id: index + 1, name: certificate._name, description: certificate._opisanie, issuedAt: certificate._dataVydachi, validUntil: certificate._dejstvitelenDo, image: presentImage(certificate._foto), }));