import { createMap, forMember, mapFrom, Mapper } from '@automapper/core'; import { AutomapperProfile, InjectMapper } from '@automapper/nestjs'; import { Injectable } from '@nestjs/common'; import { Ad } from '../domain/entities/ad'; import { AdPresenter } from '../adapters/primaries/ad.presenter'; import { CreateAdRequest } from '../domain/dtos/create-ad.request'; import { TimeConverter } from '../domain/entities/time-converter'; @Injectable() export class AdProfile extends AutomapperProfile { constructor(@InjectMapper() mapper: Mapper) { super(mapper); } override get profile() { return (mapper: any) => { createMap(mapper, Ad, AdPresenter); createMap( mapper, CreateAdRequest, Ad, forMember( (dest) => dest.monTime, mapFrom(({ monTime: time, fromDate: date, timezone }) => TimeConverter.toUtcDatetime(date, time, timezone), ), ), forMember( (dest) => dest.tueTime, mapFrom(({ tueTime: time, fromDate: date, timezone }) => TimeConverter.toUtcDatetime(date, time, timezone), ), ), forMember( (dest) => dest.wedTime, mapFrom(({ wedTime: time, fromDate: date, timezone }) => TimeConverter.toUtcDatetime(date, time, timezone), ), ), forMember( (dest) => dest.thuTime, mapFrom(({ thuTime: time, fromDate: date, timezone }) => TimeConverter.toUtcDatetime(date, time, timezone), ), ), forMember( (dest) => dest.friTime, mapFrom(({ friTime: time, fromDate: date, timezone }) => TimeConverter.toUtcDatetime(date, time, timezone), ), ), forMember( (dest) => dest.satTime, mapFrom(({ satTime: time, fromDate: date, timezone }) => TimeConverter.toUtcDatetime(date, time, timezone), ), ), forMember( (dest) => dest.sunTime, mapFrom(({ sunTime: time, fromDate: date, timezone }) => TimeConverter.toUtcDatetime(date, time, timezone), ), ), ); }; } }