From 4a1bec8eec78eeb81822b982e357bc117ff7ffa2 Mon Sep 17 00:00:00 2001 From: David Mehren Date: Sun, 10 Jan 2021 20:25:28 +0100 Subject: [PATCH 1/2] Move note permission route under metadata Signed-off-by: David Mehren --- docs/content/dev/public_api.yml | 2 +- src/api/public/notes/notes.controller.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/content/dev/public_api.yml b/docs/content/dev/public_api.yml index 17c84ae81..f51d4ed11 100644 --- a/docs/content/dev/public_api.yml +++ b/docs/content/dev/public_api.yml @@ -346,7 +346,7 @@ paths: content: text/plain: example: my-note - /notes/{note}/permissions: + /notes/{note}/metadata/permissions: put: tags: [ note ] summary: Set permissions of a note diff --git a/src/api/public/notes/notes.controller.ts b/src/api/public/notes/notes.controller.ts index e50437867..8cf74bb4b 100644 --- a/src/api/public/notes/notes.controller.ts +++ b/src/api/public/notes/notes.controller.ts @@ -115,7 +115,7 @@ export class NotesController { } } - @Put(':noteIdOrAlias/permissions') + @Put(':noteIdOrAlias/metadata/permissions') async updateNotePermissions( @Param('noteIdOrAlias') noteIdOrAlias: string, @Body() updateDto: NotePermissionsUpdateDto, From 6301a264dd84814a3f19566ea56b5b1726d464f2 Mon Sep 17 00:00:00 2001 From: David Mehren Date: Sun, 10 Jan 2021 20:30:45 +0100 Subject: [PATCH 2/2] NotesService: `updateNoteByIdOrAlias` should return the new note Fixes #702 Signed-off-by: David Mehren --- src/notes/notes.service.ts | 3 ++- test/public-api/notes.e2e-spec.ts | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/notes/notes.service.ts b/src/notes/notes.service.ts index f1718aa2b..a1a35533d 100644 --- a/src/notes/notes.service.ts +++ b/src/notes/notes.service.ts @@ -13,7 +13,7 @@ import { Revision } from '../revisions/revision.entity'; import { RevisionsService } from '../revisions/revisions.service'; import { User } from '../users/user.entity'; import { UsersService } from '../users/users.service'; -import { NoteMetadataDto, NoteMetadataUpdateDto } from './note-metadata.dto'; +import { NoteMetadataDto } from './note-metadata.dto'; import { NotePermissionsDto, NotePermissionsUpdateDto, @@ -192,6 +192,7 @@ export class NotesService { revisions.push(Revision.create(noteContent, noteContent)); note.revisions = Promise.resolve(revisions); await this.noteRepository.save(note); + return this.toNoteDto(note); } async getNoteMetadata(noteIdOrAlias: string): Promise { diff --git a/test/public-api/notes.e2e-spec.ts b/test/public-api/notes.e2e-spec.ts index 2fcf1fe70..75c013d66 100644 --- a/test/public-api/notes.e2e-spec.ts +++ b/test/public-api/notes.e2e-spec.ts @@ -103,7 +103,7 @@ describe('Notes', () => { it(`PUT /notes/{note}`, async () => { await notesService.createNote('This is a test note.', 'test4'); - await request(app.getHttpServer()) + const response = await request(app.getHttpServer()) .put('/notes/test4') .set('Content-Type', 'text/markdown') .send('New note text') @@ -111,6 +111,7 @@ describe('Notes', () => { await expect( (await notesService.getNoteDtoByIdOrAlias('test4')).content, ).toEqual('New note text'); + expect(response.body.content).toEqual('New note text'); // check if a missing note correctly returns 404 await request(app.getHttpServer())