mirror of
https://github.com/dadosfera/maestro.git
synced 2026-10-11 12:59:09 +00:00
nestjs access controll mock swagger implementation middleware changes and lib permissions file back to maestro FEAT: sending permissions to duc on startup FEAT: new permissions.enum format FEAT: permissions injection (maestro -> duc) FIX: changing method invocation order FEAT: refactored permission enum + duc permission injector + grpcHandler FEAT: auth guards FEAT: seq ids updated
120 lines
3.0 KiB
TypeScript
120 lines
3.0 KiB
TypeScript
import {
|
|
Body,
|
|
Controller,
|
|
Delete,
|
|
Get,
|
|
Param,
|
|
Post,
|
|
Put,
|
|
} from '@nestjs/common';
|
|
import { Payload } from '@nestjs/microservices';
|
|
import { ApiTags } from '@nestjs/swagger';
|
|
import { TransformationsClientService } from 'src/clients/transformations/client.service';
|
|
import { IIdRequest } from 'src/clients/transformations/interfaces';
|
|
import { AuthenticateCondition } from 'src/authentication/authentication.decorator';
|
|
import { Permissions } from '../../authentication/permissions.enum';
|
|
import { TransformationsService } from './transformations.service';
|
|
|
|
@ApiTags('Transformations')
|
|
@Controller('transformations')
|
|
@AuthenticateCondition((req, user) => {
|
|
let action;
|
|
|
|
switch (req.method) {
|
|
case 'POST':
|
|
action = 'CREATE';
|
|
break;
|
|
|
|
case 'PUT':
|
|
action = 'UPDATE';
|
|
break;
|
|
|
|
default:
|
|
action = req.method;
|
|
}
|
|
|
|
return user.permissions.includes(Permissions.TRANSFORMATIONS[action].seqid);
|
|
})
|
|
export class TransformationsController {
|
|
constructor(
|
|
private transformationsClientService: TransformationsClientService,
|
|
) {}
|
|
|
|
@Post()
|
|
async create(@Body() createTransformationDto) {
|
|
console.log(process.env.DEV_URL + `/transformation`, 'ON CREATE ROUTE');
|
|
|
|
const transformationService = new TransformationsService(
|
|
this.transformationsClientService,
|
|
);
|
|
const response = await transformationService.create(
|
|
createTransformationDto,
|
|
);
|
|
|
|
return response;
|
|
}
|
|
|
|
@Get()
|
|
async findAll(@Body() data: IIdRequest) {
|
|
console.log(process.env.DEV_URL + `/transformation`, 'ON Find All ROUTE');
|
|
|
|
const transformationService = new TransformationsService(
|
|
this.transformationsClientService,
|
|
);
|
|
const response = await transformationService.findAll(data);
|
|
|
|
return response;
|
|
}
|
|
|
|
@Get('/:id')
|
|
async findOne(@Body() data, @Param() params) {
|
|
const { id } = params;
|
|
console.log(
|
|
process.env.DEV_URL + `/transformation/${id}`,
|
|
'ON Find One ROUTE',
|
|
);
|
|
|
|
const transformationService = new TransformationsService(
|
|
this.transformationsClientService,
|
|
);
|
|
const response = await transformationService.findOne({ id, ...data });
|
|
|
|
return response;
|
|
}
|
|
|
|
@Put(':id')
|
|
async update(@Payload() updateTransformationDto, @Param() params) {
|
|
const { id } = params;
|
|
console.log(
|
|
process.env.DEV_URL + `/transformation/${id}`,
|
|
'ON UPDATE ROUTE',
|
|
);
|
|
|
|
const transformationService = new TransformationsService(
|
|
this.transformationsClientService,
|
|
);
|
|
const response = await transformationService.update(
|
|
id,
|
|
updateTransformationDto,
|
|
);
|
|
|
|
return response;
|
|
}
|
|
|
|
@Delete(':id')
|
|
async delete(@Body() data, @Param() params) {
|
|
const { id } = params;
|
|
console.log(
|
|
process.env.DEV_URL + `/transformation/${id}`,
|
|
'ON DELETE ROUTE',
|
|
);
|
|
|
|
const transformationService = new TransformationsService(
|
|
this.transformationsClientService,
|
|
);
|
|
const response = await transformationService.remove({ id, ...data });
|
|
|
|
return response;
|
|
}
|
|
}
|