Skip to content

Commit a67ea1f

Browse files
Merge pull request #329 from boostcampwm-2024/bug-be-#326
초기 데이터 세팅 이슈 해결
2 parents 796bcef + 2d32bd4 commit a67ea1f

File tree

3 files changed

+42
-8
lines changed

3 files changed

+42
-8
lines changed

apps/backend/src/node/node.repository.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ export class NodeRepository extends Repository<Node> {
1414
}
1515

1616
async findNodesByWorkspace(workspaceId: number): Promise<Node[]> {
17-
return this.find({ where: { workspace: { id: workspaceId } } });
17+
return this.find({
18+
where: { workspace: { id: workspaceId } },
19+
relations: ['page'],
20+
});
1821
}
1922
}

apps/backend/src/node/node.service.spec.ts

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ describe('NodeService', () => {
1414
let service: NodeService;
1515
let nodeRepository: jest.Mocked<NodeRepository>;
1616
let pageRepository: jest.Mocked<PageRepository>;
17+
let workspaceRepository: jest.Mocked<WorkspaceRepository>;
18+
1719

1820
beforeEach(async () => {
1921
const module: TestingModule = await Test.createTestingModule({
@@ -51,11 +53,14 @@ describe('NodeService', () => {
5153
service = module.get<NodeService>(NodeService);
5254
nodeRepository = module.get(NodeRepository);
5355
pageRepository = module.get(PageRepository);
54-
workspaceRepository = module.get<WorkspaceRepository>(WorkspaceRepository);
56+
workspaceRepository = module.get(WorkspaceRepository);
5557
});
5658

5759
it('서비스 클래스가 정상적으로 인스턴스화된다.', () => {
5860
expect(service).toBeDefined();
61+
expect(nodeRepository).toBeDefined();
62+
expect(pageRepository).toBeDefined();
63+
expect(workspaceRepository).toBeDefined();
5964
});
6065

6166
describe('createNode', () => {
@@ -254,5 +259,26 @@ describe('NodeService', () => {
254259
});
255260
});
256261

257-
describe('findNodesByWorkspace', () => {});
262+
describe('findNodesByWorkspace', () => {
263+
it('workspace에 해당하는 노드 조회 성공', async () => {
264+
const currentDate = new Date();
265+
const workspace = {
266+
id: 1,
267+
snowflakeId: '1234567890',
268+
title: 'workspace',
269+
description: 'workspace description',
270+
visibility: 'private',
271+
createdAt: currentDate,
272+
updatedAt: currentDate,
273+
thumbnailUrl: 'https://example.com/thumbnail.jpg',
274+
} as Workspace;
275+
276+
jest.spyOn(workspaceRepository, 'findOneBy').mockResolvedValue(workspace);
277+
await service.findNodesByWorkspace(workspace.snowflakeId);
278+
279+
expect(nodeRepository.findNodesByWorkspace).toHaveBeenCalledWith(
280+
workspace.id,
281+
);
282+
});
283+
});
258284
});

apps/backend/src/yjs/yjs.service.ts

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,7 @@ export class YjsService
4444
private readonly pageService: PageService,
4545
private readonly edgeService: EdgeService,
4646
private readonly redisService: RedisService,
47-
) {
48-
49-
}
47+
) {}
5048

5149
@WebSocketServer()
5250
server: Server;
@@ -71,6 +69,8 @@ export class YjsService
7169
// document name이 flow-room이라면 모든 노드들을 볼 수 있는 화면입니다.
7270
// 노드를 클릭해 페이지를 열었을 때만 해당 페이지 값을 가져와서 초기 데이터로 세팅해줍니다.
7371
if (customDoc.name?.startsWith('document-')) {
72+
const workspaceId = doc.guid;
73+
console.log('workspaceid', workspaceId);
7474
const pageId = parseInt(customDoc.name.split('-')[1]);
7575
const findPage = await this.pageService.findPageById(pageId);
7676

@@ -112,8 +112,13 @@ export class YjsService
112112
// node, edge, page content 가져오기
113113

114114
// TODO: 서비스 함수 workspaceId 입력해야하도록 수정되었습니다!!
115-
const nodes = await this.nodeService.findNodesByWorkspace('temp');
116-
const edges = await this.edgeService.findEdgesByWorkspace('temp');
115+
116+
if (!customDoc.name?.startsWith('flow-room-')) {
117+
return;
118+
}
119+
const workspaceId = customDoc.name.split('-')[2];
120+
const nodes = await this.nodeService.findNodesByWorkspace(workspaceId);
121+
const edges = await this.edgeService.findEdgesByWorkspace(workspaceId);
117122
const nodesMap = doc.getMap('nodes');
118123
const title = doc.getMap('title');
119124
const emoji = doc.getMap('emoji');

0 commit comments

Comments
 (0)