From cf88cde5510bb7cefed0faef48db039eb233cd38 Mon Sep 17 00:00:00 2001 From: David Mehren Date: Tue, 22 Sep 2020 20:07:36 +0200 Subject: [PATCH] NotesService: Use the database for delete and update actions. Signed-off-by: David Mehren --- src/notes/notes.service.ts | 46 +++++++++----------------------------- 1 file changed, 10 insertions(+), 36 deletions(-) diff --git a/src/notes/notes.service.ts b/src/notes/notes.service.ts index 11d4f1394..c3b622cdf 100644 --- a/src/notes/notes.service.ts +++ b/src/notes/notes.service.ts @@ -145,44 +145,18 @@ export class NotesService { return this.toNoteDto(note); } - deleteNoteByIdOrAlias(noteIdOrAlias: string) { - this.logger.warn('Using hardcoded data!'); - return; + async deleteNoteByIdOrAlias(noteIdOrAlias: string) { + const note = await this.getNoteByIdOrAlias(noteIdOrAlias); + return await this.noteRepository.remove(note); } - updateNoteByIdOrAlias(noteIdOrAlias: string, noteContent: string) { - this.logger.warn('Using hardcoded data!'); - return { - content: noteContent, - metdata: { - alias: null, - createTime: new Date(), - description: 'Very descriptive text.', - editedBy: [], - id: noteIdOrAlias, - permission: { - owner: { - displayName: 'foo', - userName: 'fooUser', - email: 'foo@example.com', - photo: '', - }, - sharedToUsers: [], - sharedToGroups: [], - }, - tags: [], - title: 'Title!', - updateTime: new Date(), - updateUser: { - displayName: 'foo', - userName: 'fooUser', - email: 'foo@example.com', - photo: '', - }, - viewCount: 42, - }, - editedByAtPosition: [], - }; + async updateNoteByIdOrAlias(noteIdOrAlias: string, noteContent: string) { + const note = await this.getNoteByIdOrAlias(noteIdOrAlias); + const revisions = await note.revisions; + //TODO: Calculate patch + revisions.push(Revision.create(noteContent, noteContent)); + note.revisions = Promise.resolve(revisions); + await this.noteRepository.save(note); } getNoteMetadata(noteIdOrAlias: string): NoteMetadataDto {