mirror of
https://github.com/dadosfera/maestro.git
synced 2026-11-21 04:09:07 +00:00
FEAT: User module init
This commit is contained in:
@@ -0,0 +1,53 @@
|
||||
import { OnModuleInit, Inject, Injectable } from '@nestjs/common';
|
||||
import { ClientGrpc } from '@nestjs/microservices';
|
||||
import { DadosferaLogger } from 'dadosfera-logs';
|
||||
|
||||
import { ProtoServices } from 'protospack-v2/dist/lib/Duc';
|
||||
import { UsersProtoService } from 'protospack-v2/dist/lib/Duc/interfaces/write-service';
|
||||
import {
|
||||
AssignRoleToUserRequest,
|
||||
AssignRoleToUserResponse,
|
||||
UnassignRoleFromUserRequest,
|
||||
UnassignRoleFromUserResponse,
|
||||
UserFindAllByCustomerIdResponse,
|
||||
} from 'protospack-v2/dist/lib/Duc/interfaces/messages';
|
||||
|
||||
import grpcHandler from '../../utils/grpcHandler';
|
||||
|
||||
@Injectable()
|
||||
export class UsersService implements OnModuleInit {
|
||||
logger: any;
|
||||
|
||||
private usersService: UsersProtoService;
|
||||
constructor(
|
||||
@Inject(DadosferaLogger)
|
||||
dadosferaLogger: DadosferaLogger,
|
||||
@Inject('DUC_PACKAGE') private readonly grpcClient: ClientGrpc,
|
||||
) {
|
||||
this.logger = dadosferaLogger.logger;
|
||||
}
|
||||
|
||||
onModuleInit() {
|
||||
this.usersService = this.grpcClient.getService<UsersProtoService>(
|
||||
ProtoServices.UsersProtoService,
|
||||
);
|
||||
}
|
||||
|
||||
async findAllUsersByCustomerId(customerId, searchQuery) {
|
||||
return grpcHandler<UserFindAllByCustomerIdResponse>(
|
||||
this.usersService.UserFindAllByCustomerId({ customerId }),
|
||||
);
|
||||
}
|
||||
|
||||
async assignRoleToUser(body: AssignRoleToUserRequest) {
|
||||
return grpcHandler<AssignRoleToUserResponse>(
|
||||
this.usersService.AssignRoleToUser(body),
|
||||
);
|
||||
}
|
||||
|
||||
async unassignRoleToUser(body: UnassignRoleFromUserRequest) {
|
||||
return grpcHandler<UnassignRoleFromUserResponse>(
|
||||
this.usersService.UnassignRoleFromUser(body),
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user