Skip to content
Merged

Dev #191

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion share/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@grimity/dto",
"version": "1.0.30",
"version": "1.0.31",
"types": "dist/share/index.d.ts",
"exports": {
".": {
Expand Down
6 changes: 3 additions & 3 deletions src/module/chat/chat.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down Expand Up @@ -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<UserBaseWithBlockedResponse> {
): Promise<OpponentUserResponse> {
return await this.chatService.getOpponentUser(userId, chatId);
}

Expand Down
8 changes: 8 additions & 0 deletions src/module/chat/dto/chat.response.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
13 changes: 12 additions & 1 deletion src/module/chat/repository/chat.reader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,16 @@ export class ChatReader {
'User.image as image',
'User.url as url',
])
.select((eb) =>
eb
.fn<boolean>('EXISTS', [
eb
.selectFrom('Block')
.where('Block.blockingId', '=', kyselyUuid(userId))
.whereRef('Block.blockerId', '=', 'User.id'),
])
.as('isBlocked'),
)
.select((eb) =>
eb
.fn<boolean>('EXISTS', [
Expand All @@ -101,7 +111,7 @@ export class ChatReader {
.where('Block.blockerId', '=', kyselyUuid(userId))
.whereRef('Block.blockingId', '=', 'User.id'),
])
.as('isBlocked'),
.as('isBlocking'),
)
.executeTakeFirst();

Expand All @@ -112,6 +122,7 @@ export class ChatReader {
image: result.image,
url: result.url,
isBlocked: result.isBlocked,
isBlocking: result.isBlocking,
};
}

Expand Down
8 changes: 8 additions & 0 deletions test/e2e/chat/get-opponent-user.e2e-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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);
});
});
Loading