import { Mapper } from '@mobicoop/ddd-library'; import { Injectable } from '@nestjs/common'; import { RouteEntity } from './core/domain/route.entity'; import { RouteResponseDto } from './interface/dtos/route.response.dto'; /** * Mapper constructs objects that are used in different layers: * Record is an object that is stored in a database, * Entity is an object that is used in application domain layer, * and a ResponseDTO is an object returned to a user (usually as json). */ @Injectable() export class RouteMapper implements Mapper { toResponse = (entity: RouteEntity): RouteResponseDto => { const response = new RouteResponseDto(); response.distance = Math.round(entity.getProps().distance); response.duration = Math.round(entity.getProps().duration); response.fwdAzimuth = Math.round(entity.getProps().fwdAzimuth); response.backAzimuth = Math.round(entity.getProps().backAzimuth); response.distanceAzimuth = Math.round(entity.getProps().distanceAzimuth); response.points = entity.getProps().points; response.steps = entity.getProps().steps; return response; }; }