Skip to content

Commit 724c10c

Browse files
committed
fix: 모든 노드를 찾을 때 x, y 좌표 함께 가져오도록 수정
1 parent 3989629 commit 724c10c

File tree

2 files changed

+18
-3
lines changed

2 files changed

+18
-3
lines changed

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,8 @@ export class NodeService {
111111
relations: ['page'],
112112
select: {
113113
id: true,
114+
x: true,
115+
y: true,
114116
page: {
115117
id: true,
116118
title: true, // content 제외하고 title만 선택

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

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ export class YjsService
122122
const edgesMap = doc.getMap('edges');
123123

124124
this.initializeYNodeMap(nodes, nodesMap);
125+
this.initializeYEdgeMap(edges, edgesMap);
125126

126127
// node의 변경 사항을 감지한다.
127128
nodesMap.observe(() => {
@@ -151,8 +152,6 @@ export class YjsService
151152
edgesMap.observe(() => {
152153
const edges = Object.values(doc.getMap('edges').toJSON());
153154
edges.forEach(async (edge: YMapEdge) => {
154-
console.log(edge);
155-
console.log(edge);
156155
const findEdge = await this.edgeService.findEdgeByFromNodeAndToNode(
157156
parseInt(edge.source),
158157
parseInt(edge.target),
@@ -172,7 +171,6 @@ export class YjsService
172171
// YMap에 노드 정보를 넣어준다.
173172
initializeYNodeMap(nodes: Node[], yMap: Y.Map<Object>): void {
174173
nodes.forEach((node) => {
175-
console.log(node);
176174
const nodeId = node.id.toString(); // id를 string으로 변환
177175

178176
// Y.Map에 데이터를 삽입
@@ -193,6 +191,21 @@ export class YjsService
193191
});
194192
}
195193

194+
// yMap에 edge 정보를 넣어준다.
195+
initializeYEdgeMap(edges: Edge[], yMap: Y.Map<Object>): void {
196+
edges.forEach((edge) => {
197+
const edgeId = edge.id.toString(); // id를 string으로 변환
198+
199+
// Y.Map에 데이터를 삽입
200+
yMap.set(edgeId, {
201+
id: edgeId,
202+
source: edge.fromNode.id,
203+
target: edge.toNode.id,
204+
sourceHandle: 'left',
205+
targetHandle: 'left',
206+
});
207+
});
208+
}
196209
// yXmlFragment에 content를 넣어준다.
197210
initializePageContent(content: JSON, yXmlFragment: Y.XmlFragment) {
198211
prosemirrorJSONToYXmlFragment(novelEditorSchema, content, yXmlFragment);

0 commit comments

Comments
 (0)