Skip to content

Commit

Permalink
refactor(#60): 챗이미지 생성 테스트 코드
Browse files Browse the repository at this point in the history
  • Loading branch information
hobiJeong committed Oct 31, 2023
1 parent 25f0d6f commit 702b218
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 11 deletions.
2 changes: 2 additions & 0 deletions src/chat/chat.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { S3Module } from 'src/common/s3/s3.module';
import { ChatRepository } from './repositories/chat.repository';
import { NotificationService } from './services/notification.service';
import { EventsGateway } from './events/events.gateway';
import { AuthModule } from 'src/auth/auth.module';

@Module({
imports: [
Expand All @@ -23,6 +24,7 @@ import { EventsGateway } from './events/events.gateway';
{ name: ChatNotification.name, schema: ChatNotificationSchema },
]),
S3Module,
AuthModule,
],
controllers: [ChatController],
providers: [ChatService, ChatRepository, NotificationService, EventsGateway],
Expand Down
13 changes: 10 additions & 3 deletions src/chat/controllers/chat.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {
Controller,
Delete,
Get,
Headers,
Param,
ParseIntPipe,
Post,
Expand All @@ -28,12 +29,16 @@ import { ApiDeleteChatRoom } from '../swagger-decorators/delete-chat-room.decora
import { ApiGetChats } from '../swagger-decorators/get-chats.decorator';
import { ApiGetChatNotification } from '../swagger-decorators/get-chat-notification.decorator';
import { ApiGetChatUnreadCounts } from '../swagger-decorators/get-chat-unread-counts.decorator';
import { TokenService } from 'src/auth/services/token.service';

@ApiTags('CHAT')
@Controller('chat-room')
@UsePipes(ValidationPipe)
export class ChatController {
constructor(private chatService: ChatService) {}
constructor(
private chatService: ChatService,
private tokenService: TokenService,
) {}

@ApiGetChatNotification()
@Sse('listener')
Expand Down Expand Up @@ -84,13 +89,15 @@ export class ChatController {
@UseInterceptors(FileInterceptor('file'))
async createChatImage(
@Param('roomId', ParseObjectIdPipe) roomId: mongoose.Types.ObjectId,
@Users() user: User,
@Headers('access_token') accessToken: string,
@Body() body: ReceivedUserDto,
@UploadedFile() file: Express.Multer.File,
) {
let userId = await this.tokenService.decodeToken(accessToken);
userId = 12345642;
return this.chatService.createChatImage(
roomId,
user.id,
userId,
body.receiverId,
file,
);
Expand Down
14 changes: 6 additions & 8 deletions src/chat/services/chat.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -190,20 +190,18 @@ export class ChatService {

const imageUrl = await this.s3Service.ChatImageUpload(file, myId);

const returnedChat = await this.chatRepository.createChatImage(
return await this.chatRepository.createChatImage(
roomId,
myId,
receiverId,
imageUrl.url,
);

const chat = {
content: returnedChat.content,
sender: returnedChat.sender,
receiver: returnedChat.receiver,
};

return chat;
// const chat = {
// content: returnedChat.content,
// sender: returnedChat.sender,
// receiver: returnedChat.receiver,
// };
}

async getUnreadCounts(roomId: mongoose.Types.ObjectId, after: number) {
Expand Down

0 comments on commit 702b218

Please sign in to comment.