FEAT: User Management WIP

This commit is contained in:
Gabriel Rosa
2022-07-08 12:04:56 -03:00
parent 358dd6a15a
commit d1961a9710
8 changed files with 77 additions and 27 deletions
@@ -3,7 +3,6 @@ import {
CanActivate,
OnApplicationBootstrap,
ExecutionContext,
Logger,
Inject,
} from '@nestjs/common';
import { Reflector } from '@nestjs/core';
+1 -4
View File
@@ -1,9 +1,6 @@
import { credentials } from '@grpc/grpc-js';
import { ClientOptions, Transport } from '@nestjs/microservices';
import {
ProtoPackages,
ProtoPaths,
} from 'protospack-v2/dist/lib/Duc';
import { ProtoPackages, ProtoPaths } from 'protospack-v2/dist/lib/Duc';
export class DucClient {
config(): ClientOptions {
+1 -4
View File
@@ -1,10 +1,7 @@
import { Controller, Inject, OnModuleInit } from '@nestjs/common';
import { ClientGrpc, Payload } from '@nestjs/microservices';
import { DadosferaLogger } from 'dadosfera-logs';
import {
OutputServicesNames,
OutputsServiceInterface,
} from 'protospack';
import { OutputServicesNames, OutputsServiceInterface } from 'protospack';
import {
objectCamelToSnake,
objectSnakeToCamel,
+1 -4
View File
@@ -1,8 +1,5 @@
import { ClientOptions, Transport } from '@nestjs/microservices';
import {
PipelinePackages,
PipelineProtoFilePath,
} from 'protospack';
import { PipelinePackages, PipelineProtoFilePath } from 'protospack';
import { credentials } from '@grpc/grpc-js';
export class PipelinesClientConfiguration {
+3 -2
View File
@@ -7,7 +7,7 @@ import { IIdRequest, Info } from 'src/clients/inputs/interfaces';
@Injectable()
export class InputsService {
constructor(private inputClient: InputsClientService) { }
constructor(private inputClient: InputsClientService) {}
secondsInADay = 60 * 60 * 24;
secondsInAnHour = 60 * 60;
@@ -54,7 +54,7 @@ export class InputsService {
switch (data.plugin.toLowerCase()) {
case 'csv':
case 'json':
case 'parquet':
case 'parquet': {
const { info, ...input } = data;
const inputPayload = this.generateInputS3Payload(input);
response = await this.inputClient.createS3Inputs({
@@ -62,6 +62,7 @@ export class InputsService {
info,
});
break;
}
case 'oracle':
case 'mysql':
case 'postgresql':
+44
View File
@@ -75,6 +75,46 @@ export class User {
@ApiProperty()
updatedAt: string;
}
export class CreateUserReq {
@ApiProperty()
name: string;
@ApiProperty()
username: string;
@ApiProperty()
email: string;
@ApiProperty()
roles: string[];
@ApiProperty()
jobTitle: string;
@ApiProperty()
department: string;
@ApiProperty()
hierarchy: number;
@ApiProperty()
customer: Customer;
@ApiProperty()
mfaStatus: string;
@ApiProperty()
createdAt: string;
@ApiProperty()
updatedAt: string;
}
export class CreateUserRes {
@ApiProperty()
id: string;
@ApiProperty()
name: string;
@ApiProperty()
email: string;
@ApiProperty()
roles: string[];
@ApiProperty()
jobTitle: string;
@ApiProperty()
department: string;
@ApiProperty()
hierarchy: number;
}
export class GetAllUsersByCustomerIdReq {
@ApiPropertyOptional()
@@ -97,6 +137,10 @@ export class UnassignRoleToUserReq {
@ApiProperty()
roleId: string;
}
export class DeleteUserRes {
@ApiProperty()
id: string;
}
export class SearchUserReq {
@ApiProperty()
+18
View File
@@ -4,6 +4,8 @@ import {
Delete,
Get,
Inject,
Param,
Post,
Put,
Query,
} from '@nestjs/common';
@@ -12,6 +14,9 @@ import { DadosferaLogger } from 'dadosfera-logs';
import { RequestUser, User } from 'src/authentication/user.decorator';
import {
AssignRoleToUserReq,
CreateUserReq,
CreateUserRes,
DeleteUserRes,
GetAllUsersByCustomerIdReq,
GetAllUsersByCustomerIdRes,
UnassignRoleToUserReq,
@@ -31,6 +36,19 @@ export class UsersController {
this.logger = dadosferaLogger.logger;
}
@Post()
@ApiOkResponse({ type: CreateUserRes })
async createUser(@User() user, @Body() body: CreateUserReq) {
console.log(body);
}
@Delete(':id')
@ApiOkResponse({ type: DeleteUserRes })
async deleteUser(@User() user, @Param('id') id: string) {
this.logger.info('deleteUser', { user });
return await this.userService.deleteUser({ id });
}
@Get()
@ApiOkResponse({
type: GetAllUsersByCustomerIdRes,
+9 -12
View File
@@ -6,13 +6,10 @@ import { ProtoServices } from 'protospack-v2/dist/lib/Duc';
import { UsersProtoService } from 'protospack-v2/dist/lib/Duc/interfaces/write-service';
import {
AssignRoleToUserRequest,
AssignRoleToUserResponse,
IdRequest,
UnassignRoleFromUserRequest,
UnassignRoleFromUserResponse,
UserFindAllByCustomerIdResponse,
} from 'protospack-v2/dist/lib/Duc/interfaces/messages';
import grpcHandler from '../../utils/grpcHandler';
import { lastValueFrom } from 'rxjs';
@Injectable()
export class UsersService implements OnModuleInit {
@@ -34,20 +31,20 @@ export class UsersService implements OnModuleInit {
}
async findAllUsersByCustomerId(customerId, searchQuery) {
return grpcHandler<UserFindAllByCustomerIdResponse>(
return lastValueFrom(
this.usersService.UserFindAllByCustomerId({ customerId }),
);
}
async assignRoleToUser(body: AssignRoleToUserRequest) {
return grpcHandler<AssignRoleToUserResponse>(
this.usersService.AssignRoleToUser(body),
);
return lastValueFrom(this.usersService.AssignRoleToUser(body));
}
async unassignRoleToUser(body: UnassignRoleFromUserRequest) {
return grpcHandler<UnassignRoleFromUserResponse>(
this.usersService.UnassignRoleFromUser(body),
);
return lastValueFrom(this.usersService.UnassignRoleFromUser(body));
}
async deleteUser(id: IdRequest) {
return lastValueFrom(this.usersService.UserRemove(id));
}
}