Skip to content

Commit

Permalink
feat: 채널 생성 시 봇 메세지 생성
Browse files Browse the repository at this point in the history
  • Loading branch information
soomanbaek authored and NaayoungKwon committed Dec 2, 2022
1 parent 0d30ea8 commit eb6ee3b
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 3 deletions.
13 changes: 12 additions & 1 deletion server/apps/api/src/channel/channel.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,26 @@ import { CommunityModule } from '@community/community.module';
import { UserRepository } from '@repository/user.repository';
import { UserModule } from '@user/user.module';
import { ChannelsController } from '@channel/channels.controller';
import { ChatListModule } from '@chat-list/chat-list.module';
import { ChatListService } from '@chat-list/chat-list.service';
import { ChatListRespository } from '@repository/chat-list.respository';

@Module({
imports: [
MongooseModule.forFeature([{ name: Channel.name, schema: ChannelSchema }]),
forwardRef(() => CommunityModule),
UserModule,
forwardRef(() => ChatListModule),
],
controllers: [ChannelController, ChannelsController],
providers: [ChannelService, ChannelRepository, CommunityRepository, UserRepository],
providers: [
ChannelService,
ChannelRepository,
CommunityRepository,
UserRepository,
ChatListService,
ChatListRespository,
],
exports: [MongooseModule],
})
export class ChannelModule {}
12 changes: 12 additions & 0 deletions server/apps/api/src/channel/channel.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,16 @@ import {
import { ExitChannelDto } from '@channel/dto/exit-channel.dto';
import { getChannelBasicInfo, getChannelToUserForm } from '@channel/helper';
import { getUserBasicInfo } from '@user/helper/getUserBasicInfo';
import { ChatListService } from '@chat-list/chat-list.service';
import { BOT_ID } from '@utils/def';

@Injectable()
export class ChannelService {
constructor(
private readonly channelRepository: ChannelRepository,
private readonly communityRepository: CommunityRepository,
private readonly userRepository: UserRepository,
private readonly chatListService: ChatListService,
) {}

async createChannel(createChannelDto: CreateChannelDto) {
Expand All @@ -42,6 +45,15 @@ export class ChannelService {
// 공개 채널일 경우 : 채널 유저에 커뮤니티 사용자 모두 존재
await this.addUserToChannel(community._id, channel._id, community.users);
}
const user = await this.userRepository.findById(managerId);
// TODO: 봇 메세지 content 수정 필요
await this.chatListService.restoreMessage({
channel_id: channel.id,
type: 'TEXT',
content: `${user.nickname}님이 이 채널을 ${new Date()}에 생성했습니다.`,
senderId: BOT_ID,
});

return getChannelBasicInfo(channel);
}

Expand Down
1 change: 1 addition & 0 deletions server/apps/api/src/channel/helper/getChannelBasicInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,6 @@ export const getChannelBasicInfo = (channel) => {
users: channel.users,
createdAt: channel.createdAt,
deletedAt: channel.deletedAt,
lastRead: channel.lastRead,
};
};
5 changes: 3 additions & 2 deletions server/apps/api/src/chat-list/chat-list.module.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Module } from '@nestjs/common';
import { forwardRef, Module } from '@nestjs/common';
import { ChatListController } from '@chat-list/chat-list.controller';
import { ChatListService } from '@chat-list/chat-list.service';
import { ChatListRespository } from '@repository/chat-list.respository';
Expand All @@ -12,10 +12,11 @@ import { UserModule } from '@user/user.module';
@Module({
imports: [
MongooseModule.forFeature([{ name: ChatList.name, schema: ChatListSchema }]),
ChannelModule,
forwardRef(() => ChannelModule),
UserModule,
],
controllers: [ChatListController],
providers: [ChatListService, ChatListRespository, ChannelRepository, UserRepository],
exports: [MongooseModule],
})
export class ChatListModule {}
1 change: 1 addition & 0 deletions server/utils/def.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ export const STATUS = ['ONLINE', 'OFFLINE', 'AFK'];
export const PROVIDER = ['ASNITY', 'GITHUB'];
export const CHANNEL_TYPE = ['CHANNEL', 'DM'];
export const CHAT_TYPE = ['TEXT', 'IMAGE'];
export const BOT_ID = '63888e5a55ab39cc98bfee3c';

0 comments on commit eb6ee3b

Please sign in to comment.