-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #59 from codex-team/refactor/note/settings
Refactor/note/settings
- Loading branch information
Showing
17 changed files
with
550 additions
and
4,434 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
import type { Note, NotePublicId } from '@domain/entities/note.js'; | ||
import type NoteSettings from '@domain/entities/noteSettings.js'; | ||
import type NoteSettingsRepository from '@repository/noteSettings.repository.js'; | ||
|
||
/** | ||
* Service responsible for Note Settings | ||
*/ | ||
export default class NoteSettingsService { | ||
/** | ||
* Note Settings repository | ||
*/ | ||
public repository: NoteSettingsRepository; | ||
|
||
/** | ||
* Note Settings service constructor | ||
* | ||
* @param repository - note repository | ||
*/ | ||
constructor(repository: NoteSettingsRepository) { | ||
this.repository = repository; | ||
} | ||
|
||
/** | ||
* Gets note settings by public id | ||
* | ||
* @param id - note public id | ||
* @returns { Promise<NoteSettings | null> } note settings | ||
*/ | ||
public async getNoteSettingsByPublicId(id: NotePublicId): Promise<NoteSettings> { | ||
/** | ||
* @todo get internal id by public id and resolve note settings by the internal id | ||
*/ | ||
return await this.repository.getNoteSettingsByPublicId(id); | ||
} | ||
|
||
/** | ||
* Gets note settings by note id | ||
* | ||
* @param id - note id | ||
* @returns { Promise<NoteSettings | null> } note | ||
*/ | ||
public async getNoteSettingsByNoteId(id: Note['id']): Promise<NoteSettings | null> { | ||
return await this.repository.getNoteSettingsByNoteId(id); | ||
} | ||
|
||
/** | ||
* Adds note settings | ||
* | ||
* @param noteId - note id | ||
* @param enabled - is note enabled | ||
* @returns { Promise<NoteSettings> } note settings | ||
*/ | ||
public async addNoteSettings(noteId: Note['id'], enabled: boolean = true): Promise<NoteSettings> { | ||
return await this.repository.addNoteSettings({ | ||
noteId: noteId, | ||
enabled: enabled, | ||
}); | ||
} | ||
|
||
/** | ||
* Partially updates note settings | ||
* | ||
* @param data - note settings data with new values | ||
* @param noteId - note public id | ||
* @returns { Promise<NoteSettings> } updated note settings | ||
*/ | ||
public async patchNoteSettingsByPublicId(data: Partial<NoteSettings>, noteId: NotePublicId): Promise<NoteSettings | null> { | ||
const noteSettings = await this.repository.getNoteSettingsByPublicId(noteId); | ||
|
||
return await this.repository.patchNoteSettingsByPublicId(data, noteSettings.id); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.