-
Notifications
You must be signed in to change notification settings - Fork 1
/
note.repository.ts
103 lines (92 loc) · 2.99 KB
/
note.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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
import type { Note, NoteCreationAttributes, NoteInternalId, NotePublicId } from '@domain/entities/note.js';
import type NoteStorage from '@repository/storage/note.storage.js';
/**
* Repository allows accessing data from business-logic (domain) level
*/
export default class NoteRepository {
/**
* Note storage instance
*/
public storage: NoteStorage;
/**
* Note repository constructor
* @param storage - storage for note
*/
constructor(storage: NoteStorage) {
this.storage = storage;
}
/**
* Add note
* @param options - note adding options
* @returns added note
*/
public async addNote(options: NoteCreationAttributes): Promise<Note> {
return await this.storage.createNote(options);
}
/**
* Update note content in a store
* @param id - note internal id
* @param content - new content
* @param noteTools - tools which are used in note
* @returns Note on success, null on failure
*/
public async updateNoteContentAndToolsById(id: NoteInternalId, content: Note['content'], noteTools: Note['tools']): Promise<Note | null> {
return await this.storage.updateNoteContentAndToolsById(id, content, noteTools);
}
/**
* Gets note by internal id
* @param id - note id
* @returns found note
*/
public async getNoteById(id: NoteInternalId): Promise<Note | null> {
return await this.storage.getNoteById(id);
}
/**
* Deletes note by id
* @param id - note id
*/
public async deleteNoteById(id: NoteInternalId): Promise<boolean> {
return await this.storage.deleteNoteById(id);
}
/**
* Gets note by hostname
* @param hostname - custom hostname
* @returns found note
*/
public async getNoteByHostname(hostname: string): Promise<Note | null> {
return await this.storage.getNoteByHostname(hostname);
}
/**
* Returns note by public id. Null if note does not exist.
* @param publicId - public id
*/
public async getNoteByPublicId(publicId: NotePublicId): Promise<Note | null> {
return await this.storage.getNoteByPublicId(publicId);
}
/**
* Gets note list by creator id
* @param id - note creator id
* @param offset - number of skipped notes
* @param limit - number of notes to get
*/
public async getNoteListByUserId(id: number, offset: number, limit: number): Promise<Note[]> {
return await this.storage.getNoteListByUserId(id, offset, limit);
}
/**
* Get all notes based on their ids
* @param noteIds : list of note ids
* @returns an array of notes
*/
public async getNotesByIds(noteIds: NoteInternalId[]): Promise<Note[]> {
return await this.storage.getNotesByIds(noteIds);
}
/**
* Gets note list by parent note id
* @param parentNoteId - parent note id
* @param offset - number of skipped notes
* @param limit - number of notes to get
*/
public async getNoteListByParentNote(parentNoteId: number, offset: number, limit: number): Promise<Note[]> {
return await this.storage.getNoteListByParentNote(parentNoteId, offset, limit);
}
}