2025-03-11 20:16:05 +00:00
|
|
|
import { MeasureProductModel } from '../../domain/models/measureproduct.model';
|
|
|
|
|
import { Controller, Get, Param, Put, Body, Post, Delete, HttpException, HttpStatus, Req } from "@nestjs/common";
|
|
|
|
|
import { MeasureProductService } from './measureproduct.service';
|
|
|
|
|
import { ResultModel } from 'src/domain/models/result.model';
|
|
|
|
|
import { ApiExcludeEndpoint, ApiTags } from '@nestjs/swagger';
|
|
|
|
|
|
|
|
|
|
@ApiTags('BackOffice')
|
|
|
|
|
@Controller('v1/measure')
|
|
|
|
|
export class MeasureProductController {
|
|
|
|
|
|
|
|
|
|
constructor(
|
|
|
|
|
private measureProductService: MeasureProductService
|
|
|
|
|
){}
|
|
|
|
|
|
|
|
|
|
@Get()
|
|
|
|
|
@ApiExcludeEndpoint()
|
|
|
|
|
async getAll(@Req() req) {
|
|
|
|
|
try {
|
|
|
|
|
if (req.query['query'] || req.query['query'] !== '')
|
|
|
|
|
{
|
|
|
|
|
const result = await this.measureProductService.findByDescription(req.query['query']);
|
|
|
|
|
return new ResultModel(true, null, result, []);
|
|
|
|
|
}
|
|
|
|
|
const result = await this.measureProductService.findAll();
|
|
|
|
|
return new ResultModel(true, null, result, []);
|
|
|
|
|
} catch (error) {
|
|
|
|
|
console.log(error);
|
|
|
|
|
throw new HttpException(new ResultModel(false, 'Não foi possível consultar lista de medidas de produto.', {}, error), HttpStatus.INTERNAL_SERVER_ERROR);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Get(':id')
|
|
|
|
|
@ApiExcludeEndpoint()
|
|
|
|
|
async get(@Param('id') id) {
|
|
|
|
|
try {
|
|
|
|
|
const result =await this.measureProductService.find(id);
|
|
|
|
|
return new ResultModel(true, null, result, []);
|
|
|
|
|
} catch (error) {
|
|
|
|
|
console.log(error);
|
|
|
|
|
throw new HttpException(new ResultModel(false, 'Não foi possível consultar lista de medidas de produto.', {}, error), HttpStatus.INTERNAL_SERVER_ERROR);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Put(':id')
|
|
|
|
|
@ApiExcludeEndpoint()
|
|
|
|
|
async put(@Param('id') id: number, @Body() body: MeasureProductModel) {
|
|
|
|
|
return await this.measureProductService.update(id, body);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Post()
|
|
|
|
|
@ApiExcludeEndpoint()
|
|
|
|
|
async post(@Body() body: MeasureProductModel) {
|
|
|
|
|
return await this.measureProductService.create(body);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Delete(':id')
|
|
|
|
|
@ApiExcludeEndpoint()
|
|
|
|
|
async delete(@Param('id') id: number) {
|
|
|
|
|
return await this.measureProductService.delete(id);
|
|
|
|
|
}
|
2025-01-27 20:44:27 +00:00
|
|
|
}
|