diff --git a/src/api/controllers/UserController.ts b/src/api/controllers/UserController.ts index e57f975..f8578d7 100644 --- a/src/api/controllers/UserController.ts +++ b/src/api/controllers/UserController.ts @@ -2,7 +2,7 @@ import { Body, CurrentUser, Get, JsonController, Param, Params, Post, Delete} fr import { UserModel } from '../../models/UserModel'; import { UserService } from '../../services/UserService'; -import { BlockUserRequest, EditProfileRequest, GetUserByEmailRequest, GetUserResponse, GetUsersResponse, SaveTokenRequest, SetAdminByEmailRequest } from '../../types'; +import { BlockUserRequest, UnblockUserRequest, EditProfileRequest, GetUserByEmailRequest, GetUserResponse, GetUsersResponse, SaveTokenRequest, SetAdminByEmailRequest } from '../../types'; import { UuidParam } from '../validators/GenericRequests'; @JsonController('user/') @@ -55,8 +55,8 @@ export class UserController { } @Post('unblock/') - async unblockUser(@Body() blockUserRequest: BlockUserRequest, @CurrentUser() user: UserModel): Promise { - return { user: await this.userService.unblockUser(user, blockUserRequest) } + async unblockUser(@Body() unblockUserRequest: UnblockUserRequest, @CurrentUser() user: UserModel): Promise { + return { user: await this.userService.unblockUser(user, unblockUserRequest) } } @Delete('id/:id/') diff --git a/src/services/UserService.ts b/src/services/UserService.ts index ed8451a..37346b6 100644 --- a/src/services/UserService.ts +++ b/src/services/UserService.ts @@ -6,7 +6,7 @@ import { InjectManager } from 'typeorm-typedi-extensions'; import { UuidParam } from '../api/validators/GenericRequests'; import { UserModel } from '../models/UserModel'; import Repositories, { TransactionsManager } from '../repositories'; -import { EditProfileRequest, SaveTokenRequest, SetAdminByEmailRequest, BlockUserRequest } from '../types'; +import { EditProfileRequest, SaveTokenRequest, SetAdminByEmailRequest, BlockUserRequest, UnblockUserRequest } from '../types'; import { uploadImage } from '../utils/Requests'; @Service() @@ -102,12 +102,12 @@ export class UserService { }); } - public async unblockUser(user: UserModel, blockUserRequest: BlockUserRequest): Promise { + public async unblockUser(user: UserModel, blockUserRequest: UnblockUserRequest): Promise { return this.transactions.readWrite(async (transactionalEntityManager) => { const userRepository = Repositories.user(transactionalEntityManager); - const blocked = await userRepository.getUserById(blockUserRequest.blocked); + const blocked = await userRepository.getUserById(blockUserRequest.unblocked); if (!blocked) throw new NotFoundError('Blocked user not found!'); - if (!user.blocking?.find((blockedUser) => blockedUser.id === blockUserRequest.blocked)) { + if (!user.blocking?.find((blockedUser) => blockedUser.id === blockUserRequest.unblocked)) { throw new UnauthorizedError('User is not blocked!'); } return userRepository.unblockUser(user, blocked); diff --git a/src/tests/UserTest.test.ts b/src/tests/UserTest.test.ts index 10a2c74..1bc2d5b 100644 --- a/src/tests/UserTest.test.ts +++ b/src/tests/UserTest.test.ts @@ -251,7 +251,7 @@ describe('user tests', () => { expect(blockUserResponse.user?.blockers).toBeUndefined(); expect(user1.blocking).toHaveLength(1); - const unblockUserResponse = await userController.unblockUser({blocked: user2.id}, user1); + const unblockUserResponse = await userController.unblockUser({unblocked: user2.id}, user1); expect(unblockUserResponse.user?.blocking).toBeUndefined(); expect(unblockUserResponse.user?.blockers).toBeUndefined(); }); @@ -264,7 +264,7 @@ describe('user tests', () => { .write(); try { - await userController.unblockUser({blocked: user2.id}, user1); + await userController.unblockUser({unblocked: user2.id}, user1); } catch (error) { expect(error.message).toBe('User is not blocked!'); } diff --git a/src/types/ApiRequests.ts b/src/types/ApiRequests.ts index 4ba8039..fb20d9d 100644 --- a/src/types/ApiRequests.ts +++ b/src/types/ApiRequests.ts @@ -54,6 +54,10 @@ export interface BlockUserRequest { blocked: Uuid; } +export interface UnblockUserRequest { + unblocked: Uuid; +} + // POST export interface CreatePostRequest {