-
Notifications
You must be signed in to change notification settings - Fork 1
/
noteRelations.repository.ts
79 lines (70 loc) · 2.39 KB
/
noteRelations.repository.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
import type { NoteInternalId } from '@domain/entities/note.js';
import type NoteRelationshipStorage from '@repository/storage/noteRelations.storage.js';
/**
* Repository allows accessing data from business-logic (domain) level
*/
export default class NoteRelationsRepository {
/**
* Note relationship storage instance
*/
public storage: NoteRelationshipStorage;
/**
* Note relationship repository constructor
* @param storage - storage for note relationship
*/
constructor(storage: NoteRelationshipStorage) {
this.storage = storage;
}
/**
* Add note relation
* @param noteId - id of the current note
* @param parentId - id of the parent note
*/
public async addNoteRelation(noteId: NoteInternalId, parentId: NoteInternalId): Promise<boolean> {
return await this.storage.createNoteRelation(noteId, parentId);
}
/**
* Update note relation
* @param noteId - id of the current note
* @param parentId - id of the parent note
*/
public async updateNoteRelationById(noteId: NoteInternalId, parentId: NoteInternalId): Promise<boolean> {
return await this.storage.updateNoteRelationById(noteId, parentId);
}
/**
* Get parent note id by note id
* @param noteId - id of the current note
*/
public async getParentNoteIdByNoteId(noteId: NoteInternalId): Promise<number | null> {
return await this.storage.getParentNoteIdByNoteId(noteId);
}
/**
* Delete all note ralations contains noteId
* @param noteId - id of the current note
*/
public async deleteNoteRelationsByNoteId(noteId: NoteInternalId): Promise<boolean> {
return await this.storage.deleteNoteRelationsByNoteId(noteId);
}
/**
* Unlink parent note from the current note
* @param noteId - id of note to unlink parent
*/
public async unlinkParent(noteId: NoteInternalId): Promise<boolean> {
return await this.storage.unlinkParent(noteId);
}
/**
* Checks if the note has any connection
* @param noteId - id of the current note
*/
public async hasRelation(noteId: NoteInternalId): Promise<boolean> {
return await this.storage.hasRelation(noteId);
}
/**
* Get all note parents based on note id
* @param noteId : note id to get all its parents
* @returns an array of note parents ids
*/
public async getNoteParentsIds(noteId: NoteInternalId): Promise<NoteInternalId[]> {
return await this.storage.getNoteParentsIds(noteId);
}
}