Skip to content

Commit

Permalink
Feat(#522): 차단한 유저 채팅 수신x
Browse files Browse the repository at this point in the history
  • Loading branch information
j-zzi committed Jun 6, 2024
1 parent bea2d30 commit 6b44111
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/chats/services/chats.service.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { PrismaService } from './../../prisma/prisma.service';
import { NotificationService } from '@src/notification/services/notification.service';
import { ChatRoomRepository } from './../repositories/chats-room.repository';
import { CreateChatsDto } from './../dtos/create-chats.dto';
Expand All @@ -17,6 +18,7 @@ export class ChatsService {
private readonly chatRoomRepository: ChatRoomRepository,
private readonly eventsGateway: EventsGateway,
private readonly notificationService: NotificationService,
private readonly prismaService: PrismaService,
) {}

async createChats(
Expand All @@ -40,6 +42,15 @@ export class ChatsService {

const chat = await this.chatsRepository.createChats(chatInpuData);

const isUserBlockLecturer =
await this.prismaService.blockedLecturer.findFirst({
where: { ...sender, ...receiver },
});

if (isUserBlockLecturer) {
return;
}

const chatRoom = await this.chatRoomRepository.getChatRoomWithChatRoomId(
roomObjectId,
);
Expand Down
12 changes: 12 additions & 0 deletions src/lecturer/lecturer.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,19 @@ import { PopularLecturerService } from './services/popular-lecturer.service';
import { PopularLecturerRepository } from './repositories/popular-lecturer.repository';
import { PopularLecturerController } from './controllers/popular-lecturer.controller';
import { LectureLikeRepository } from '@src/lecture/repositories/lecture-like.repository';
import { ChatRoomRepository } from '@src/chats/repositories/chats-room.repository';
import { ChatsModule } from '@src/chats/chats.module';
import { MongooseModule } from '@nestjs/mongoose';
import { ChatRoom, ChatRoomSchema } from '@src/chats/schemas/chats-room.schema';
import { Chats, ChatsSchema } from '@src/chats/schemas/chats.schema';

@Module({
imports: [
MongooseModule.forFeature([
{ name: Chats.name, schema: ChatsSchema },
{ name: ChatRoom.name, schema: ChatRoomSchema },
]),
],
providers: [
LecturerService,
LecturerRepository,
Expand All @@ -25,6 +36,7 @@ import { LectureLikeRepository } from '@src/lecture/repositories/lecture-like.re
PopularLecturerService,
PopularLecturerRepository,
LectureLikeRepository,
ChatRoomRepository,
],
controllers: [
LecturerController,
Expand Down
16 changes: 16 additions & 0 deletions src/lecturer/services/lecturer-block.service.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { ChatRoomRepository } from './../../chats/repositories/chats-room.repository';
import { LectureLikeRepository } from './../../lecture/repositories/lecture-like.repository';
import { LecturerLikeRepository } from './../repositories/lecturer-like.repository';
import { Injectable } from '@nestjs/common';
Expand All @@ -9,6 +10,7 @@ export class LecturerBlockService {
private readonly lecturerBlockRepository: LecturerBlockRepository,
private readonly lecturerLikeRepository: LecturerLikeRepository,
private readonly lectureLikeRepository: LectureLikeRepository,
private readonly chatRoomRepository: ChatRoomRepository,
) {}

async createLecturerBlock(lecturerId: number, userId: number) {
Expand All @@ -35,6 +37,20 @@ export class LecturerBlockService {
);
}

const chatRoomExist = await this.chatRoomRepository.getChatRoom(
userId,
lecturerId,
);

if (chatRoomExist) {
const leaveChatRoomUpdateData = { $set: { 'user.participation': false } };

await this.chatRoomRepository.leaveChatRoom(
chatRoomExist._id,
leaveChatRoomUpdateData,
);
}

return await this.lecturerBlockRepository.createLecturerBlock(
lecturerId,
userId,
Expand Down

0 comments on commit 6b44111

Please sign in to comment.