Skip to content

Commit

Permalink
Resolve domain-error handle todo in note settings
Browse files Browse the repository at this point in the history
  • Loading branch information
elizachi committed Jan 15, 2024
1 parent ae9dd33 commit 62aba5a
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 7 deletions.
12 changes: 11 additions & 1 deletion src/domain/service/noteSettings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,13 @@ export default class NoteSettingsService {
* @param id - note internal id
*/
public async getNoteSettingsByNoteId(id: NoteInternalId): Promise<NoteSettings> {
return await this.noteSettingsRepository.getNoteSettingsByNoteId(id);
const settings = await this.noteSettingsRepository.getNoteSettingsByNoteId(id);

if (settings === null) {
throw new DomainError(`Note settings not found`);
}

return settings;
}

/**
Expand Down Expand Up @@ -98,6 +104,10 @@ export default class NoteSettingsService {
public async patchNoteSettingsByNoteId(noteId: NoteInternalId, data: Partial<NoteSettings>): Promise<NoteSettings | null> {
const noteSettings = await this.noteSettingsRepository.getNoteSettingsByNoteId(noteId);

if (noteSettings === null) {
throw new DomainError(`Note settings not found`);
}

return await this.noteSettingsRepository.patchNoteSettingsById(noteSettings.id, data);
}

Expand Down
2 changes: 1 addition & 1 deletion src/repository/noteSettings.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export default class NoteSettingsRepository {
* @param id - note id
* @returns found note settings
*/
public async getNoteSettingsByNoteId(id: NoteInternalId): Promise<NoteSettings> {
public async getNoteSettingsByNoteId(id: NoteInternalId): Promise<NoteSettings | null> {
return await this.storage.getNoteSettingsByNoteId(id);
}

Expand Down
7 changes: 2 additions & 5 deletions src/repository/storage/postgres/orm/sequelize/noteSettings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,18 +147,15 @@ export default class NoteSettingsSequelizeStorage {
* @param noteId - note id
* @returns { Promise<NoteSettings | null> } - note settings
*/
public async getNoteSettingsByNoteId(noteId: NoteSettings['noteId']): Promise<NoteSettings> {
public async getNoteSettingsByNoteId(noteId: NoteSettings['noteId']): Promise<NoteSettings | null> {
const settings = await this.model.findOne({
where: {
noteId: noteId,
},
});

if (!settings) {
/**
* TODO: improve exceptions
*/
throw new Error('Note settings not found');
return null;
}

return settings;
Expand Down

0 comments on commit 62aba5a

Please sign in to comment.