@@ -10,6 +10,7 @@ import type { NoteList } from '@domain/entities/noteList.js';
1010import type NoteHistoryRepository from '@repository/noteHistory.repository.js' ;
1111import type { NoteHistoryMeta , NoteHistoryRecord , NoteHistoryPublic } from '@domain/entities/noteHistory.js' ;
1212import type { NoteHierarchy } from '@domain/entities/NoteHierarchy.js' ;
13+ import type { DomainLogger } from './shared/logger.js' ;
1314
1415/**
1516 * Note service
@@ -40,6 +41,11 @@ export default class NoteService {
4041 */
4142 public noteHistoryRepository : NoteHistoryRepository ;
4243
44+ /**
45+ * Logger instance
46+ */
47+ private logger : DomainLogger ;
48+
4349 /**
4450 * Number of the notes to be displayed on one page
4551 * it is used to calculate offset and limit for getting notes that the user has recently opened
@@ -58,13 +64,15 @@ export default class NoteService {
5864 * @param noteVisitsRepository - note visits repository
5965 * @param editorToolsRepository - editor tools repositoryn
6066 * @param noteHistoryRepository - note history repository
67+ * @param logger - domain logger
6168 */
62- constructor ( noteRepository : NoteRepository , noteRelationsRepository : NoteRelationsRepository , noteVisitsRepository : NoteVisitsRepository , editorToolsRepository : EditorToolsRepository , noteHistoryRepository : NoteHistoryRepository ) {
69+ constructor ( noteRepository : NoteRepository , noteRelationsRepository : NoteRelationsRepository , noteVisitsRepository : NoteVisitsRepository , editorToolsRepository : EditorToolsRepository , noteHistoryRepository : NoteHistoryRepository , logger : DomainLogger ) {
6370 this . noteRepository = noteRepository ;
6471 this . noteRelationsRepository = noteRelationsRepository ;
6572 this . noteVisitsRepository = noteVisitsRepository ;
6673 this . editorToolsRepository = editorToolsRepository ;
6774 this . noteHistoryRepository = noteHistoryRepository ;
75+ this . logger = logger ;
6876 }
6977
7078 /**
@@ -103,6 +111,12 @@ export default class NoteService {
103111 await this . noteRelationsRepository . addNoteRelation ( note . id , parentNote . id ) ;
104112 }
105113
114+ this . logger . info ( 'Note created' , {
115+ noteId : note . id ,
116+ creatorId,
117+ parentPublicId,
118+ } ) ;
119+
106120 return note ;
107121 }
108122
@@ -139,6 +153,11 @@ export default class NoteService {
139153 throw new DomainError ( `Note with id ${ id } was not deleted` ) ;
140154 }
141155
156+ this . logger . info ( 'Note deleted' , {
157+ noteId : id ,
158+ hadRelation : hasRelation ,
159+ } ) ;
160+
142161 return isNoteDeleted ;
143162 }
144163
@@ -168,6 +187,11 @@ export default class NoteService {
168187 throw new DomainError ( `Note with id ${ id } was not updated` ) ;
169188 }
170189
190+ this . logger . debug ( 'Note updated' , {
191+ noteId : id ,
192+ userId,
193+ } ) ;
194+
171195 return updatedNote ;
172196 }
173197
@@ -176,7 +200,13 @@ export default class NoteService {
176200 * @param noteId - id of note to unlink parent
177201 */
178202 public async unlinkParent ( noteId : NoteInternalId ) : Promise < boolean > {
179- return this . noteRelationsRepository . unlinkParent ( noteId ) ;
203+ const result = await this . noteRelationsRepository . unlinkParent ( noteId ) ;
204+
205+ this . logger . info ( 'Note parent unlinked' , {
206+ noteId,
207+ } ) ;
208+
209+ return result ;
180210 }
181211
182212 /**
@@ -292,6 +322,11 @@ export default class NoteService {
292322 throw new DomainError ( `Relation was not created` ) ;
293323 }
294324
325+ this . logger . info ( 'Note relation created' , {
326+ noteId,
327+ parentNoteId : parentNote . id ,
328+ } ) ;
329+
295330 return parentNote ;
296331 }
297332
@@ -301,6 +336,8 @@ export default class NoteService {
301336 * @param parentPublicId - id of the new parent note
302337 */
303338 public async updateNoteRelation ( noteId : NoteInternalId , parentPublicId : NotePublicId ) : Promise < boolean > {
339+ const currentParentId = await this . noteRelationsRepository . getParentNoteIdByNoteId ( noteId ) ;
340+
304341 const parentNote = await this . noteRepository . getNoteByPublicId ( parentPublicId ) ;
305342
306343 if ( parentNote === null ) {
@@ -320,7 +357,15 @@ export default class NoteService {
320357 parentNoteId = await this . noteRelationsRepository . getParentNoteIdByNoteId ( parentNoteId ) ;
321358 }
322359
323- return await this . noteRelationsRepository . updateNoteRelationById ( noteId , parentNote . id ) ;
360+ const result = await this . noteRelationsRepository . updateNoteRelationById ( noteId , parentNote . id ) ;
361+
362+ this . logger . info ( 'Note relation changed' , {
363+ noteId,
364+ oldParentId : currentParentId ?? undefined ,
365+ newParentId : parentNote . id ,
366+ } ) ;
367+
368+ return result ;
324369 } ;
325370
326371 /**
0 commit comments