import { Injectable } from '@nestjs/common' ; import 'automapper-ts/dist/automapper' ; @ Injectable ( ) export class MapperService { private mapper : AutoMapperJs . AutoMapper ; constructor ( ) { this . mapper = automapper ; this . initializeMapper ( ) ; } private initializeMapper ( ) { this . mapper . initialize ( MapperService . configure ) ; } public createMap ( source , destination ) { return this . mapper . createMap ( source , destination ) ; } private static configure ( config ) { } map < K > ( object , destinationKey , sourceKey ? , isArray = false ) { const _sourceKey = isArray ? `${ sourceKey || object . constructor . name }[]` : sourceKey || object . constructor . name ; const _destinationKey = isArray ? `${ destinationKey }[]` : destinationKey ; const _object = object && typeof object . toJSON === 'function' ? object . toJSON ( ) : object ; return this . mapper . map ( _sourceKey , _destinationKey , _object ) ; } }