Skip to content

Commit

Permalink
feat: new deleteNoteById feature
Browse files Browse the repository at this point in the history
  • Loading branch information
e11sy committed Oct 21, 2023
1 parent dd845f3 commit f01ab4f
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 2 deletions.
2 changes: 1 addition & 1 deletion app-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ logging:
database: info

database:
dsn: 'postgres://codex:postgres@postgres:5432/notes'
dsn: 'postgres://localhost:Egoramurin1@postgres:5432/notes'

openai:
token: 'token'
Expand Down
9 changes: 9 additions & 0 deletions src/domain/service/note.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,15 @@ export default class NoteService {
});
}

/**
* Deletes note by id
* @param id - note internal id
* @returns { Promise<boolean | null> }
*/
public async deleteNoteById(id: NoteInternalId){
return await this.repository.deleteNoteById(id);
}

/**
* Updates a note
*
Expand Down
12 changes: 11 additions & 1 deletion src/repository/note.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export default class NoteRepository {
}

/**
* Gets note by id
* Gets note by internal id
*
* @param id - note id
* @returns { Promise<Note | null> } found note
Expand All @@ -51,6 +51,16 @@ export default class NoteRepository {
return await this.storage.getNoteById(id);
}

/**
* Deletes note by id
*
* @param id - note id
* @returns { Promise<boolean | null> }
*/
public async deleteNoteById(id: NoteInternalId){
return await this.storage.deleteNoteById(id)
}

/**
* Gets note by hostname
*
Expand Down
23 changes: 23 additions & 0 deletions src/repository/storage/postgres/orm/sequelize/note.ts
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,29 @@ export default class NoteSequelizeStorage {
return note;
}

/**
* Deletes note by id
*
* @param id - internal id
* @returns { Promise<boolean | null> }
*/
public async deleteNoteById(id: NoteInternalId){
const note = await this.model.destroy({
where:{
id,
}
})

/**
* If note not found, return null
*/
if (!note) {
return null;
}

return note;
}

/**
* Gets note list by creator id
*
Expand Down

0 comments on commit f01ab4f

Please sign in to comment.