mirror of
https://github.com/dadosfera/maestro.git
synced 2026-11-12 04:09:08 +00:00
FEAT: User Management WIP
This commit is contained in:
@@ -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()
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user