mirror of
https://gitlab.com/mobicoop/v3/service/matcher.git
synced 2026-01-01 02:22:40 +00:00
29 lines
1.1 KiB
TypeScript
29 lines
1.1 KiB
TypeScript
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<RouteEntity, undefined, undefined, RouteResponseDto>
|
|
{
|
|
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;
|
|
};
|
|
}
|