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-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-26 10:10:22 +00:00
|
|
|
createMap(
|
|
|
|
mapper,
|
|
|
|
CreateAdRequest,
|
|
|
|
Ad,
|
2023-05-02 09:56:07 +00:00
|
|
|
forMember(
|
|
|
|
(dest) => dest.monTime,
|
2023-05-02 15:26:04 +00:00
|
|
|
mapFrom(({ monTime: time, fromDate: date, timezone }) =>
|
|
|
|
TimeConverter.toUtcDatetime(date, time, timezone),
|
2023-05-02 09:56:07 +00:00
|
|
|
),
|
|
|
|
),
|
|
|
|
forMember(
|
|
|
|
(dest) => dest.tueTime,
|
2023-05-02 15:26:04 +00:00
|
|
|
mapFrom(({ tueTime: time, fromDate: date, timezone }) =>
|
|
|
|
TimeConverter.toUtcDatetime(date, time, timezone),
|
2023-05-02 09:56:07 +00:00
|
|
|
),
|
|
|
|
),
|
|
|
|
forMember(
|
|
|
|
(dest) => dest.wedTime,
|
2023-05-02 15:26:04 +00:00
|
|
|
mapFrom(({ wedTime: time, fromDate: date, timezone }) =>
|
|
|
|
TimeConverter.toUtcDatetime(date, time, timezone),
|
2023-05-02 09:56:07 +00:00
|
|
|
),
|
|
|
|
),
|
|
|
|
forMember(
|
|
|
|
(dest) => dest.thuTime,
|
2023-05-02 15:26:04 +00:00
|
|
|
mapFrom(({ thuTime: time, fromDate: date, timezone }) =>
|
|
|
|
TimeConverter.toUtcDatetime(date, time, timezone),
|
2023-05-02 09:56:07 +00:00
|
|
|
),
|
|
|
|
),
|
|
|
|
forMember(
|
|
|
|
(dest) => dest.friTime,
|
2023-05-02 15:26:04 +00:00
|
|
|
mapFrom(({ friTime: time, fromDate: date, timezone }) =>
|
|
|
|
TimeConverter.toUtcDatetime(date, time, timezone),
|
2023-05-02 09:56:07 +00:00
|
|
|
),
|
|
|
|
),
|
|
|
|
forMember(
|
|
|
|
(dest) => dest.satTime,
|
2023-05-02 15:26:04 +00:00
|
|
|
mapFrom(({ satTime: time, fromDate: date, timezone }) =>
|
|
|
|
TimeConverter.toUtcDatetime(date, time, timezone),
|
2023-05-02 09:56:07 +00:00
|
|
|
),
|
|
|
|
),
|
|
|
|
forMember(
|
|
|
|
(dest) => dest.sunTime,
|
2023-05-02 15:26:04 +00:00
|
|
|
mapFrom(({ sunTime: time, fromDate: date, timezone }) =>
|
|
|
|
TimeConverter.toUtcDatetime(date, time, timezone),
|
2023-05-02 09:56:07 +00:00
|
|
|
),
|
|
|
|
),
|
2023-04-26 10:10:22 +00:00
|
|
|
);
|
2023-04-25 15:49:47 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|