30 lines
886 B
TypeScript
30 lines
886 B
TypeScript
import { createMap, forMember, ignore, Mapper } from '@automapper/core';
|
|
import { AutomapperProfile, InjectMapper } from '@automapper/nestjs';
|
|
import { Injectable } from '@nestjs/common';
|
|
import { UserPresenter } from '../adapters/primaries/user.presenter';
|
|
import { CreateUserRequest } from '../domain/dtos/create-user.request';
|
|
import { UpdateUserRequest } from '../domain/dtos/update-user.request';
|
|
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);
|
|
|
|
createMap(mapper, CreateUserRequest, User);
|
|
|
|
createMap(
|
|
mapper,
|
|
UpdateUserRequest,
|
|
User,
|
|
forMember((dest) => dest.uuid, ignore()),
|
|
);
|
|
};
|
|
}
|
|
}
|