mirror of
https://gitlab.com/mobicoop/v3/service/user.git
synced 2026-03-24 12:45:49 +00:00
delete user
This commit is contained in:
@@ -7,6 +7,7 @@ service UsersService {
|
||||
rpc FindAll(UserFilter) returns (Users);
|
||||
rpc Create(User) returns (User);
|
||||
rpc Update(User) returns (User);
|
||||
rpc Delete(UserByUuid) returns (Empty);
|
||||
}
|
||||
|
||||
message UserByUuid {
|
||||
@@ -25,3 +26,5 @@ message UserFilter {}
|
||||
message Users {
|
||||
repeated User users = 1;
|
||||
}
|
||||
|
||||
message Empty {}
|
||||
|
||||
@@ -5,6 +5,7 @@ import { CommandBus, QueryBus } from '@nestjs/cqrs';
|
||||
import { GrpcMethod, RpcException } from '@nestjs/microservices';
|
||||
import { DatabaseException } from 'src/modules/database/src/exceptions/DatabaseException';
|
||||
import { CreateUserCommand } from '../../commands/create-user.command';
|
||||
import { DeleteUserCommand } from '../../commands/delete-user.command';
|
||||
import { UpdateUserCommand } from '../../commands/update-user.command';
|
||||
import { CreateUserRequest } from '../../domain/dto/create-user.request';
|
||||
import { FindUserByUuidRequest } from '../../domain/dto/find-user-by-uuid.request';
|
||||
@@ -71,4 +72,26 @@ export class UsersController {
|
||||
throw new RpcException({});
|
||||
}
|
||||
}
|
||||
|
||||
@GrpcMethod('UsersService', 'Delete')
|
||||
async deleteUser(data: FindUserByUuidRequest): Promise<void> {
|
||||
try {
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
const user = await this._commandBus.execute(
|
||||
new DeleteUserCommand(data.uuid),
|
||||
);
|
||||
|
||||
return Promise.resolve();
|
||||
} catch (e) {
|
||||
if (e instanceof DatabaseException) {
|
||||
if (e.message.includes('not found')) {
|
||||
throw new RpcException({
|
||||
code: 5,
|
||||
message: 'User not found',
|
||||
});
|
||||
}
|
||||
}
|
||||
throw new RpcException({});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user