Skip to content

Commit

Permalink
fix: axios로 호출하도록 변경
Browse files Browse the repository at this point in the history
  • Loading branch information
juyeong-s committed Oct 19, 2024
1 parent 7f6f488 commit 9d6ddfb
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 18 deletions.
3 changes: 2 additions & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ import * as https from 'https';

export const CONFIG_URL = `${process.env.SCHEME}://${process.env.ESC_CONFIG}${process.env.ESC_CONFIG_PORT}`;
// NOTE: dev사용 안하고 싶으면 https://api.meething.net로 바꿔서 사용
export const API_URL = `https://${process.env.ESC_API}${process.env.ESC_API_PORT}`;
export const API_URL = 'https://api.meething.net';
// `https://${process.env.ESC_API}${process.env.ESC_API_PORT}`;

export async function bootstrap() {
// const result = await fetch(`${CONFIG_URL}/meeting/default`).then((result) =>
Expand Down
32 changes: 19 additions & 13 deletions src/room/meeting/meeting.service.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
import { Injectable, NotFoundException } from '@nestjs/common';
import { Meeting } from '../entity/room.schema';
import { API_URL } from '../../main';
import { HttpService } from '@nestjs/axios';
import { firstValueFrom } from 'rxjs';

@Injectable()
export class MeetingService {
constructor(private readonly httpService: HttpService) {}

private baseUrl = `${API_URL}/api/v1/meetings`;

public async find(meetingId: string) {
const meetings = await this.findByIdIn([meetingId]);
if (meetings.length == 0) {
Expand All @@ -17,18 +22,19 @@ export class MeetingService {
}

public async findByIdIn(meetingIds: string[]) {
const result: Meeting[] = await fetch(
`${this.baseUrl}/list?ids=` +
meetingIds.reduce(
(previousValue, currentValue) => `${previousValue},${currentValue}`,
'',
),
{
method: 'GET',
},
)
.then((result) => result.json())
.then((res) => res.data);
return result ?? [];
console.log(`${this.baseUrl}/list?ids=`);
const result = await firstValueFrom(
this.httpService.get<{ data: Meeting[] }>(
`${this.baseUrl}/list?ids=` +
meetingIds.reduce(
(previousValue, currentValue) => `${previousValue},${currentValue}`,
'',
),
{
method: 'GET',
},
),
).then((res) => res.data);
return result.data ?? [];
}
}
2 changes: 2 additions & 0 deletions src/room/room.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,11 @@ import { RoomController } from './room.controller';
import { NextFunction } from 'express';
import { APP_GUARD } from '@nestjs/core';
import { JwtAuthGuard } from '../jwt/jwt.guard';
import { HttpModule } from '@nestjs/axios';

@Module({
imports: [
HttpModule,
UserModule,
ChatModule,
MongooseModule.forFeature([
Expand Down
6 changes: 2 additions & 4 deletions src/room/room.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,20 +70,18 @@ export class RoomService {
}
public async create(meetingId: string) {
const meeting = await this.meetingService.find(meetingId);
console.log('미팅 정보 찾음: ', meeting);
const chatRoom = await this.repository.upsert(
{ 'meeting.id': meeting.id },
{ meeting },
);
console.log('채팅방 upsert: ', chatRoom);

const participantIds = this.getParticipantIds(meeting);
await this.userService.addRoom(chatRoom, participantIds);
console.log('addRoom 완료');

this.roomGateway.io.server
.of('/chat-rooms')
.in(participantIds)
.emit('room-append', { ...chatRoom, id: chatRoom._id, meeting });
console.log('생성 완료');
}

public async search(userId: string) {
Expand Down

0 comments on commit 9d6ddfb

Please sign in to comment.