2023-04-26 10:10:22 +00:00
|
|
|
import { createMap, forMember, mapFrom, Mapper } from '@automapper/core';
|
2023-04-25 15:49:47 +00:00
|
|
|
import { AutomapperProfile, InjectMapper } from '@automapper/nestjs';
|
|
|
|
import { Injectable } from '@nestjs/common';
|
|
|
|
import { Ad } from '../domain/entities/ad';
|
|
|
|
import { AdPresenter } from '../adapters/primaries/ad.presenter';
|
2023-04-26 10:10:22 +00:00
|
|
|
import { CreateAdRequest } from '../domain/dtos/create-ad.request';
|
2023-04-28 13:53:57 +00:00
|
|
|
import { Coordinates } from '../../geography/domain/entities/coordinates';
|
2023-05-02 09:56:07 +00:00
|
|
|
import { TimeConverter } from '../domain/entities/time-converter';
|
2023-04-25 15:49:47 +00:00
|
|
|
|
|
|
|
@Injectable()
|
|
|
|
export class AdProfile extends AutomapperProfile {
|
|
|
|
constructor(@InjectMapper() mapper: Mapper) {
|
|
|
|
super(mapper);
|
|
|
|
}
|
|
|
|
|
|
|
|
override get profile() {
|
|
|
|
return (mapper: any) => {
|
|
|
|
createMap(mapper, Ad, AdPresenter);
|
2023-04-27 15:52:43 +00:00
|
|
|
createMap(
|
|
|
|
mapper,
|
|
|
|
CreateAdRequest,
|
|
|
|
CreateAdRequest,
|
|
|
|
forMember(
|
|
|
|
(dest) => dest.waypoints,
|
2023-04-28 13:53:57 +00:00
|
|
|
mapFrom((source) =>
|
|
|
|
source.waypoints.map(
|
|
|
|
(waypoint) =>
|
|
|
|
new Coordinates(
|
|
|
|
waypoint.lon ?? undefined,
|
|
|
|
waypoint.lat ?? undefined,
|
|
|
|
),
|
|
|
|
),
|
2023-04-27 15:52:43 +00:00
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
2023-04-26 10:10:22 +00:00
|
|
|
createMap(
|
|
|
|
mapper,
|
|
|
|
CreateAdRequest,
|
|
|
|
Ad,
|
|
|
|
forMember(
|
|
|
|
(dest) => dest.fromDate,
|
|
|
|
mapFrom((source) => new Date(source.fromDate)),
|
|
|
|
),
|
|
|
|
forMember(
|
|
|
|
(dest) => dest.toDate,
|
|
|
|
mapFrom((source) => new Date(source.toDate)),
|
|
|
|
),
|
|
|
|
forMember(
|
|
|
|
(dest) => dest.createdAt,
|
|
|
|
mapFrom((source) => new Date(source.createdAt)),
|
|
|
|
),
|
|
|
|
forMember(
|
|
|
|
(dest) => dest.updatedAt,
|
|
|
|
mapFrom((source) => new Date(source.updatedAt)),
|
|
|
|
),
|
2023-05-02 09:56:07 +00:00
|
|
|
forMember(
|
|
|
|
(dest) => dest.monTime,
|
|
|
|
mapFrom((source) =>
|
|
|
|
TimeConverter.toUtcDatetime(
|
|
|
|
source.fromDate,
|
|
|
|
source.monTime,
|
|
|
|
source.timezone,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
forMember(
|
|
|
|
(dest) => dest.tueTime,
|
|
|
|
mapFrom((source) =>
|
|
|
|
TimeConverter.toUtcDatetime(
|
|
|
|
source.fromDate,
|
|
|
|
source.tueTime,
|
|
|
|
source.timezone,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
forMember(
|
|
|
|
(dest) => dest.wedTime,
|
|
|
|
mapFrom((source) =>
|
|
|
|
TimeConverter.toUtcDatetime(
|
|
|
|
source.fromDate,
|
|
|
|
source.wedTime,
|
|
|
|
source.timezone,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
forMember(
|
|
|
|
(dest) => dest.thuTime,
|
|
|
|
mapFrom((source) =>
|
|
|
|
TimeConverter.toUtcDatetime(
|
|
|
|
source.fromDate,
|
|
|
|
source.thuTime,
|
|
|
|
source.timezone,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
forMember(
|
|
|
|
(dest) => dest.friTime,
|
|
|
|
mapFrom((source) =>
|
|
|
|
TimeConverter.toUtcDatetime(
|
|
|
|
source.fromDate,
|
|
|
|
source.friTime,
|
|
|
|
source.timezone,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
forMember(
|
|
|
|
(dest) => dest.satTime,
|
|
|
|
mapFrom((source) =>
|
|
|
|
TimeConverter.toUtcDatetime(
|
|
|
|
source.fromDate,
|
|
|
|
source.satTime,
|
|
|
|
source.timezone,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
forMember(
|
|
|
|
(dest) => dest.sunTime,
|
|
|
|
mapFrom((source) =>
|
|
|
|
TimeConverter.toUtcDatetime(
|
|
|
|
source.fromDate,
|
|
|
|
source.sunTime,
|
|
|
|
source.timezone,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
2023-04-26 10:10:22 +00:00
|
|
|
);
|
2023-04-25 15:49:47 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|