62 lines
1.9 KiB
TypeScript
62 lines
1.9 KiB
TypeScript
/*
|
|
https://docs.nestjs.com/controllers#controllers
|
|
*/
|
|
|
|
import { Body, Controller, Delete, Get, HttpException, HttpStatus, Param, Post, Query } from '@nestjs/common';
|
|
import { PartnerRange } from 'src/domain/models/partner-range.model';
|
|
import { ResultModel } from 'src/domain/models/result.model';
|
|
import { PartnerRangeService } from './partner-range.service';
|
|
import { ApiTags } from '@nestjs/swagger';
|
|
|
|
@ApiTags('BackOffice')
|
|
@Controller('api/v1/partner/range')
|
|
export class PartnerRangeController {
|
|
constructor(private partnerRangeService: PartnerRangeService) { }
|
|
|
|
@Get()
|
|
getPartnersCategory(@Query() query) {
|
|
let type = 'T';
|
|
type = query['type'];
|
|
if (query['type'] != null) {
|
|
type = query['type'];
|
|
}
|
|
try {
|
|
return this.partnerRangeService.getPartnerRanges(type);
|
|
}
|
|
catch (error) {
|
|
throw new HttpException(error.message, HttpStatus.BAD_REQUEST);
|
|
}
|
|
}
|
|
|
|
@Get(':id')
|
|
getPartnerRangeById(@Param('id') id: number) {
|
|
try {
|
|
return this.partnerRangeService.getPartnerRange(id);
|
|
}
|
|
catch (error) {
|
|
throw new HttpException(error.message, HttpStatus.BAD_REQUEST);
|
|
}
|
|
}
|
|
|
|
@Post('create')
|
|
createPartner(@Body() data: PartnerRange) {
|
|
try {
|
|
return this.partnerRangeService.createOrUpdatePartnerRange(data);
|
|
}
|
|
catch (error) {
|
|
throw new HttpException(error.message, HttpStatus.BAD_REQUEST);
|
|
}
|
|
}
|
|
|
|
@Delete('delete/:id')
|
|
async deleteRange(@Param('id') id: number) {
|
|
try {
|
|
await this.partnerRangeService.deleteRange(id);
|
|
return new ResultModel(true, 'Faixa de comissão excluída com sucesso!', null, null);
|
|
}
|
|
catch(error){
|
|
throw new HttpException(error.message, HttpStatus.BAD_REQUEST);
|
|
}
|
|
}
|
|
}
|