diff --git a/share/package.json b/share/package.json index d4c3658..376b4cf 100644 --- a/share/package.json +++ b/share/package.json @@ -1,6 +1,6 @@ { "name": "@grimity/dto", - "version": "1.0.30", + "version": "1.0.31", "types": "dist/share/index.d.ts", "exports": { ".": { diff --git a/src/module/chat/chat.controller.ts b/src/module/chat/chat.controller.ts index eb8cf64..464531f 100644 --- a/src/module/chat/chat.controller.ts +++ b/src/module/chat/chat.controller.ts @@ -28,7 +28,7 @@ import { JwtGuard } from 'src/core/guard'; import { CurrentUser } from 'src/core/decorator'; import { ChatService } from './chat.service'; import { IdResponse } from 'src/shared/response'; -import { ChatsResponse } from './dto/chat.response'; +import { ChatsResponse, OpponentUserResponse } from './dto/chat.response'; import { UserBaseResponse, UserBaseWithBlockedResponse } from '../user/dto'; @ApiTags('/chats') @@ -93,12 +93,12 @@ export class ChatController { } @ApiOperation({ summary: '상대 유저 조회' }) - @ApiResponse({ status: 200, type: UserBaseWithBlockedResponse }) + @ApiResponse({ status: 200, type: OpponentUserResponse }) @Get(':id/user') async getOpponentUser( @CurrentUser() userId: string, @Param('id', new ParseUUIDPipe()) chatId: string, - ): Promise { + ): Promise { return await this.chatService.getOpponentUser(userId, chatId); } diff --git a/src/module/chat/dto/chat.response.ts b/src/module/chat/dto/chat.response.ts index 47af0bf..a5789a7 100644 --- a/src/module/chat/dto/chat.response.ts +++ b/src/module/chat/dto/chat.response.ts @@ -38,3 +38,11 @@ export class ChatsResponse extends CursorResponse { @ApiProperty({ type: ChatResponse, isArray: true }) chats: ChatResponse[]; } + +export class OpponentUserResponse extends UserBaseResponse { + @ApiProperty() + isBlocked: boolean; + + @ApiProperty() + isBlocking: boolean; +} diff --git a/src/module/chat/repository/chat.reader.ts b/src/module/chat/repository/chat.reader.ts index d5481a2..89fee9e 100644 --- a/src/module/chat/repository/chat.reader.ts +++ b/src/module/chat/repository/chat.reader.ts @@ -93,6 +93,16 @@ export class ChatReader { 'User.image as image', 'User.url as url', ]) + .select((eb) => + eb + .fn('EXISTS', [ + eb + .selectFrom('Block') + .where('Block.blockingId', '=', kyselyUuid(userId)) + .whereRef('Block.blockerId', '=', 'User.id'), + ]) + .as('isBlocked'), + ) .select((eb) => eb .fn('EXISTS', [ @@ -101,7 +111,7 @@ export class ChatReader { .where('Block.blockerId', '=', kyselyUuid(userId)) .whereRef('Block.blockingId', '=', 'User.id'), ]) - .as('isBlocked'), + .as('isBlocking'), ) .executeTakeFirst(); @@ -112,6 +122,7 @@ export class ChatReader { image: result.image, url: result.url, isBlocked: result.isBlocked, + isBlocking: result.isBlocking, }; } diff --git a/test/e2e/chat/get-opponent-user.e2e-spec.ts b/test/e2e/chat/get-opponent-user.e2e-spec.ts index fa7a600..8a083c5 100644 --- a/test/e2e/chat/get-opponent-user.e2e-spec.ts +++ b/test/e2e/chat/get-opponent-user.e2e-spec.ts @@ -128,6 +128,13 @@ describe('GET /chats/:id/user - 상대유저 조회', () => { }, }); + await prisma.block.create({ + data: { + blockingId: me.id, + blockerId: targetUser.id, + }, + }); + await prisma.block.create({ data: { blockerId: me.id, @@ -145,5 +152,6 @@ describe('GET /chats/:id/user - 상대유저 조회', () => { expect(status).toBe(200); expect(body.id).toBe(targetUser.id); expect(body.isBlocked).toBe(true); + expect(body.isBlocking).toBe(true); }); });