clean using es6

This commit is contained in:
sbriat 2023-05-05 16:58:03 +02:00
parent f430a4bfb6
commit 0f8233616d
1 changed files with 12 additions and 12 deletions

View File

@ -33,21 +33,21 @@ import { RpcValidationPipe } from '../../../../utils/pipes/rpc.validation-pipe';
@Controller() @Controller()
export class UserController { export class UserController {
constructor( constructor(
private readonly _commandBus: CommandBus, private readonly commandBus: CommandBus,
private readonly _queryBus: QueryBus, private readonly queryBus: QueryBus,
@InjectMapper() private readonly _mapper: Mapper, @InjectMapper() private readonly mapper: Mapper,
) {} ) {}
@GrpcMethod('UsersService', 'FindAll') @GrpcMethod('UsersService', 'FindAll')
@UseInterceptors(CacheInterceptor) @UseInterceptors(CacheInterceptor)
@CacheKey('UsersServiceFindAll') @CacheKey('UsersServiceFindAll')
async findAll(data: FindAllUsersRequest): Promise<ICollection<User>> { async findAll(data: FindAllUsersRequest): Promise<ICollection<User>> {
const userCollection = await this._queryBus.execute( const userCollection = await this.queryBus.execute(
new FindAllUsersQuery(data), new FindAllUsersQuery(data),
); );
return Promise.resolve({ return Promise.resolve({
data: userCollection.data.map((user: User) => data: userCollection.data.map((user: User) =>
this._mapper.map(user, User, UserPresenter), this.mapper.map(user, User, UserPresenter),
), ),
total: userCollection.total, total: userCollection.total,
}); });
@ -58,8 +58,8 @@ export class UserController {
@CacheKey('UsersServiceFindOneByUuid') @CacheKey('UsersServiceFindOneByUuid')
async findOneByUuid(data: FindUserByUuidRequest): Promise<UserPresenter> { async findOneByUuid(data: FindUserByUuidRequest): Promise<UserPresenter> {
try { try {
const user = await this._queryBus.execute(new FindUserByUuidQuery(data)); const user = await this.queryBus.execute(new FindUserByUuidQuery(data));
return this._mapper.map(user, User, UserPresenter); return this.mapper.map(user, User, UserPresenter);
} catch (error) { } catch (error) {
throw new RpcException({ throw new RpcException({
code: 5, code: 5,
@ -71,8 +71,8 @@ export class UserController {
@GrpcMethod('UsersService', 'Create') @GrpcMethod('UsersService', 'Create')
async createUser(data: CreateUserRequest): Promise<UserPresenter> { async createUser(data: CreateUserRequest): Promise<UserPresenter> {
try { try {
const user = await this._commandBus.execute(new CreateUserCommand(data)); const user = await this.commandBus.execute(new CreateUserCommand(data));
return this._mapper.map(user, User, UserPresenter); return this.mapper.map(user, User, UserPresenter);
} catch (e) { } catch (e) {
if (e instanceof DatabaseException) { if (e instanceof DatabaseException) {
if (e.message.includes('Already exists')) { if (e.message.includes('Already exists')) {
@ -89,9 +89,9 @@ export class UserController {
@GrpcMethod('UsersService', 'Update') @GrpcMethod('UsersService', 'Update')
async updateUser(data: UpdateUserRequest): Promise<UserPresenter> { async updateUser(data: UpdateUserRequest): Promise<UserPresenter> {
try { try {
const user = await this._commandBus.execute(new UpdateUserCommand(data)); const user = await this.commandBus.execute(new UpdateUserCommand(data));
return this._mapper.map(user, User, UserPresenter); return this.mapper.map(user, User, UserPresenter);
} catch (e) { } catch (e) {
if (e instanceof DatabaseException) { if (e instanceof DatabaseException) {
if (e.message.includes('not found')) { if (e.message.includes('not found')) {
@ -108,7 +108,7 @@ export class UserController {
@GrpcMethod('UsersService', 'Delete') @GrpcMethod('UsersService', 'Delete')
async deleteUser(data: FindUserByUuidRequest): Promise<void> { async deleteUser(data: FindUserByUuidRequest): Promise<void> {
try { try {
await this._commandBus.execute(new DeleteUserCommand(data.uuid)); await this.commandBus.execute(new DeleteUserCommand(data.uuid));
return Promise.resolve(); return Promise.resolve();
} catch (e) { } catch (e) {