myfreight-assessment/src/tracking/tracking.controller.ts

43 lines
1.0 KiB
TypeScript

import { Body, Controller, HttpCode, Post } from '@nestjs/common';
import {
ApiBody,
ApiExtraModels,
ApiNotFoundResponse,
ApiOkResponse,
ApiUnprocessableEntityResponse,
getSchemaPath,
} from '@nestjs/swagger';
import { TrackingDto } from '@/dtos/tracking.dto';
import { TrackingService } from '@/tracking/tracking.service';
@Controller('tracking')
@ApiExtraModels(TrackingDto)
export class TrackingController {
constructor(private readonly trackingService: TrackingService) {}
@Post()
@ApiBody({
schema: {
$ref: getSchemaPath(TrackingDto),
},
})
@ApiOkResponse({
description: 'Processed',
})
@ApiUnprocessableEntityResponse({
description:
'The shipment has been found, but the shipment data does not match.',
})
@ApiNotFoundResponse({
description: 'We could not find any shipment matching the request.',
})
@HttpCode(200)
track(@Body() body: TrackingDto): Promise<unknown> {
return this.trackingService
.track(body)
.then(() => ({
message: 'Ok',
}));
}
}