2022-12-14 10:37:13 +00:00
|
|
|
import { createMap, forMember, ignore, Mapper } from '@automapper/core';
|
2022-12-13 17:00:07 +00:00
|
|
|
import { AutomapperProfile, InjectMapper } from '@automapper/nestjs';
|
|
|
|
import { Injectable } from '@nestjs/common';
|
|
|
|
import { UserPresenter } from '../adapters/primaries/user.presenter';
|
2022-12-14 10:37:13 +00:00
|
|
|
import { CreateUserRequest } from '../domain/dto/create-user.request';
|
|
|
|
import { UpdateUserRequest } from '../domain/dto/update-user.request';
|
2022-12-13 17:00:07 +00:00
|
|
|
import { User } from '../domain/entities/user';
|
|
|
|
|
|
|
|
@Injectable()
|
|
|
|
export class UserProfile extends AutomapperProfile {
|
|
|
|
constructor(@InjectMapper() mapper: Mapper) {
|
|
|
|
super(mapper);
|
|
|
|
}
|
|
|
|
|
|
|
|
override get profile() {
|
|
|
|
return (mapper) => {
|
|
|
|
createMap(mapper, User, UserPresenter);
|
2022-12-14 10:37:13 +00:00
|
|
|
|
|
|
|
createMap(mapper, CreateUserRequest, User);
|
|
|
|
|
|
|
|
createMap(
|
|
|
|
mapper,
|
|
|
|
UpdateUserRequest,
|
|
|
|
User,
|
|
|
|
forMember((dest) => dest.uuid, ignore()),
|
|
|
|
);
|
2022-12-13 17:00:07 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|