matcher/src/modules/ad/mappers/ad.profile.ts

68 lines
2.2 KiB
TypeScript
Raw Normal View History

2023-04-26 10:10:22 +00:00
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';
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';
@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
);
};
}
}