-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #219 from boostcampwm2023/BE-CreateChatRoom-#218
[BE/#218] 채팅방 만들기 구현
- Loading branch information
Showing
6 changed files
with
98 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,24 @@ | ||
import { Injectable } from '@nestjs/common'; | ||
import { InjectRepository } from '@nestjs/typeorm'; | ||
import { PostEntity } from '../entities/post.entity'; | ||
import { Repository } from 'typeorm'; | ||
import { ChatRoomEntity } from '../entities/chatRoom.entity'; | ||
|
||
@Injectable() | ||
export class ChatService {} | ||
export class ChatService { | ||
constructor( | ||
@InjectRepository(ChatRoomEntity) | ||
private chatRoomRepository: Repository<ChatRoomEntity>, | ||
@InjectRepository(PostEntity) | ||
private postRepository: Repository<PostEntity>, | ||
) {} | ||
async createRoom(postId: number, userId: string, writerId: string) { | ||
const chatRoom = new ChatRoomEntity(); | ||
chatRoom.post_id = postId; | ||
chatRoom.writer = writerId; | ||
chatRoom.sender = userId; | ||
const newChatRoom = await this.chatRoomRepository.save(chatRoom); | ||
// 좀 더 가공해서 채팅 룸에 대한 정보 줄 수 있게 수정하면 될듯 | ||
return newChatRoom; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { IsNumber, IsString } from 'class-validator'; | ||
|
||
export class CreateRoomDto { | ||
@IsNumber() | ||
post_id: number; | ||
@IsString() | ||
writer: string; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import { | ||
Column, | ||
CreateDateColumn, | ||
DeleteDateColumn, | ||
Entity, | ||
PrimaryGeneratedColumn, | ||
UpdateDateColumn, | ||
} from 'typeorm'; | ||
import { PostEntity } from './post.entity'; | ||
import { BlockUserEntity } from './blockUser.entity'; | ||
import { BlockPostEntity } from './blockPost.entity'; | ||
|
||
@Entity('chat_room') | ||
export class ChatRoomEntity { | ||
@PrimaryGeneratedColumn() | ||
id: number; | ||
|
||
@Column({ type: 'int' }) | ||
post_id: number; | ||
|
||
@Column({ length: 45, nullable: false, charset: 'utf8', unique: true }) | ||
writer: string; | ||
|
||
@Column({ length: 45, nullable: false, charset: 'utf8', unique: true }) | ||
sender: string; | ||
|
||
@CreateDateColumn({ | ||
type: 'timestamp', | ||
nullable: false, | ||
}) | ||
create_date: Date; | ||
|
||
@UpdateDateColumn({ | ||
type: 'timestamp', | ||
nullable: true, | ||
}) | ||
update_date: Date; | ||
|
||
@DeleteDateColumn() | ||
delete_date: Date; | ||
} |