Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions packages/collaborative/src/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ import { TypeOrmModule } from '@nestjs/typeorm';
import { CollaborativeModule } from './collaborative/collaborative.module';
import { getMongooseConfig } from './common/config/mongo.config';
import { getTypeOrmConfig } from './common/config/typeorm.config';
import { NoteModule } from './note/note.module';
import { SpaceModule } from './space/space.module';
import { YjsModule } from './yjs/yjs.module';
import { RedisService } from './redis/redis.service';
import { RedisModule } from './redis/redis.module';
Expand All @@ -28,9 +26,7 @@ import { ScheduleModule } from '@nestjs/schedule';
inject: [ConfigService],
useFactory: getTypeOrmConfig,
}),
SpaceModule,
YjsModule,
NoteModule,
CollaborativeModule,
RedisModule,
ResourceMatricsModule,
Expand Down
20 changes: 13 additions & 7 deletions packages/collaborative/src/collaborative/collaborative.module.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
import { Module } from '@nestjs/common';
import { MongooseModule } from '@nestjs/mongoose';

import { NoteModule } from '../note/note.module';
import { SpaceModule } from '../space/space.module';
import { CollaborativeService } from './collaborative.service';

import { CollaborativeSpaceService } from './collaborative.space.service';
import { CollaborativeNoteService } from './collaborative.note.service';
import { NoteDocument, NoteSchema } from './schema/note.schema';
import { SpaceDocument, SpaceSchema } from './schema/space.schema';
@Module({
imports: [NoteModule, SpaceModule],
providers: [CollaborativeService],
exports: [CollaborativeService],
imports: [
MongooseModule.forFeature([
Copy link
Collaborator

@heeyozip heeyozip Jan 22, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

기존에 그냥 import하는 것과 MongooseModule을 활용해서 import하는 것엔 어떤 차이가 있나요?

{ name: NoteDocument.name, schema: NoteSchema },
{ name: SpaceDocument.name, schema: SpaceSchema },
]),
],
providers: [CollaborativeSpaceService,CollaborativeNoteService],
exports: [CollaborativeSpaceService, CollaborativeNoteService]
})
export class CollaborativeModule {}
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ import { InjectModel } from '@nestjs/mongoose';
import { Model } from 'mongoose';

import { ERROR_MESSAGES } from '../common/constants/error.message.constants';
import { NoteDocument } from './note.schema';
import { NoteDocument } from './schema/note.schema';

@Injectable()
export class NoteService {
private readonly logger = new Logger(NoteService.name);
export class CollaborativeNoteService {
private readonly logger = new Logger(CollaborativeNoteService.name);

constructor(
@InjectModel(NoteDocument.name)
Expand Down Expand Up @@ -63,4 +63,58 @@ export class NoteService {
throw new BadRequestException(ERROR_MESSAGES.NOTE.UPDATE_FAILED);
}
}

async updateByNote(id: string, note: string) {
try {
this.logger.log('노트 내용 업데이트 시작', {
method: 'updateByNote',
noteId: id,
length: note.length,
});

const updatedNote = await this.updateContent(id, note);

this.logger.log('노트 내용 업데이트 완료', {
method: 'updateByNote',
noteId: id,
});

return updatedNote;
} catch (error) {
this.logger.error('노트 내용 업데이트 실패', {
method: 'updateByNote',
noteId: id,
error: error.message,
stack: error.stack,
});
throw new BadRequestException(ERROR_MESSAGES.NOTE.UPDATE_FAILED);
}
}

async findByNote(id: string) {
try {
this.logger.log('노트 조회 시작', {
method: 'findByNote',
noteId: id,
});

const note = await this.findById(id);

this.logger.log('노트 조회 완료', {
method: 'findByNote',
noteId: id,
found: !!note,
});

return note;
} catch (error) {
this.logger.error('노트 조회 실패', {
method: 'findByNote',
noteId: id,
error: error.message,
stack: error.stack,
});
throw error;
}
}
}
135 changes: 0 additions & 135 deletions packages/collaborative/src/collaborative/collaborative.service.ts

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
import { BadRequestException, Injectable, Logger } from '@nestjs/common';
import { InjectModel } from '@nestjs/mongoose';
import { Model } from 'mongoose';

import { SpaceDocument } from './schema/space.schema';
import { ERROR_MESSAGES } from 'src/common/constants/error.message.constants';

@Injectable()
export class CollaborativeSpaceService {
private readonly logger = new Logger(CollaborativeSpaceService.name);

constructor(
@InjectModel(SpaceDocument.name)
private readonly spaceModel: Model<SpaceDocument>,
) {}

async updateBySpace(id: string, space: string) {
try {
this.logger.log('스페이스 정보 업데이트 시작', {
method: 'updateBySpace',
spaceId: id,
length: space.length,
});

let spaceJsonData;
try {
spaceJsonData = JSON.parse(space);
} catch (error) {
throw new Error(`유효하지 않은 스페이스 JSON 데이터: ${error.message}`);
}

const updateDto = {
edges: JSON.stringify(spaceJsonData.edges),
nodes: JSON.stringify(spaceJsonData.nodes),
};

const updatedSpace = await this.spaceModel
.findOneAndUpdate({ id }, { $set: updateDto }, { new: true })
.exec();

if (!updatedSpace) {
throw new Error(`ID가 ${id}인 스페이스를 찾을 수 없습니다.`);
}

this.logger.log('스페이스 정보 업데이트 완료', {
method: 'updateBySpace',
spaceId: id,
success: !!updatedSpace,
});

return updatedSpace;
} catch (error) {
this.logger.error('스페이스 정보 업데이트 실패', {
method: 'updateBySpace',
spaceId: id,
error: error.message,
stack: error.stack,
});
throw error;
}
}

async findBySpace(id: string) {
try {
this.logger.log('스페이스 정보 조회 시작', {
method: 'findBySpace',
spaceId: id,
});

const space = await this.spaceModel.findOne({ id }).exec();

if (!space) {
this.logger.error(`ID가 ${id}인 스페이스를 찾을 수 없습니다.`);
throw new BadRequestException(ERROR_MESSAGES.NOTE.NOT_FOUND);
}

this.logger.log('스페이스 정보 조회 완료', {
method: 'findBySpace',
spaceId: id,
found: !!space,
});

return space;
} catch (error) {
this.logger.error('스페이스 정보 조회 실패', {
method: 'findBySpace',
spaceId: id,
error: error.message,
stack: error.stack,
});
throw error;
}
}
}
14 changes: 0 additions & 14 deletions packages/collaborative/src/collaborative/collaborative.type.ts

This file was deleted.

8 changes: 0 additions & 8 deletions packages/collaborative/src/note/dto/note.dto.ts

This file was deleted.

16 changes: 0 additions & 16 deletions packages/collaborative/src/note/note.module.ts

This file was deleted.

Loading
Loading