From 85ee6780ad9d768e62c5ac4493b7c04742fec9f2 Mon Sep 17 00:00:00 2001 From: David Mehren Date: Sat, 24 Oct 2020 21:11:06 +0200 Subject: [PATCH] Remove `PUT /notes/{note}/metadata` and corresponding service code Signed-off-by: David Mehren Co-authored-by: Yannick Bungers --- src/api/public/notes/notes.controller.ts | 8 --- src/notes/notes.service.ts | 19 ------- src/revisions/revisions.service.ts | 1 + test/public-api/notes.e2e-spec.ts | 67 ------------------------ 4 files changed, 1 insertion(+), 94 deletions(-) diff --git a/src/api/public/notes/notes.controller.ts b/src/api/public/notes/notes.controller.ts index 79137ce35..9000d63cb 100644 --- a/src/api/public/notes/notes.controller.ts +++ b/src/api/public/notes/notes.controller.ts @@ -73,14 +73,6 @@ export class NotesController { return this.noteService.getNoteMetadata(noteIdOrAlias); } - @Put(':noteIdOrAlias/metadata') - updateNoteMetadata( - @Param('noteIdOrAlias') noteIdOrAlias: string, - @Body() updateDto: NoteMetadataUpdateDto, - ) { - return this.noteService.updateNoteMetadata(noteIdOrAlias, updateDto); - } - @Put(':noteIdOrAlias/permissions') updateNotePermissions( @Param('noteIdOrAlias') noteIdOrAlias: string, diff --git a/src/notes/notes.service.ts b/src/notes/notes.service.ts index 092ad4339..c077f7d35 100644 --- a/src/notes/notes.service.ts +++ b/src/notes/notes.service.ts @@ -220,23 +220,4 @@ export class NotesService { editedByAtPosition: [], }; } - - async updateNoteMetadata( - noteIdOrAlias: string, - updateDto: NoteMetadataUpdateDto, - ) { - const note = await this.getNoteByIdOrAlias(noteIdOrAlias); - note.title = updateDto.title; - note.description = updateDto.description; - note.tags = await Promise.all( - updateDto.tags.map(async tag => { - let dbTag = await this.tagRepository.findOne({ where: { name: tag } }); - if (!dbTag) { - dbTag = await this.tagRepository.create({ name: tag }); - } - return dbTag; - }), - ); - await this.noteRepository.save(note); - } } diff --git a/src/revisions/revisions.service.ts b/src/revisions/revisions.service.ts index af0b5ce7a..cb58a1ded 100644 --- a/src/revisions/revisions.service.ts +++ b/src/revisions/revisions.service.ts @@ -76,6 +76,7 @@ export class RevisionsService { createRevision(content: string) { // TODO: Add previous revision // TODO: Calculate patch + // TODO: Save metadata return this.revisionRepository.create({ content: content, length: content.length, diff --git a/test/public-api/notes.e2e-spec.ts b/test/public-api/notes.e2e-spec.ts index c93f6b36c..1941dbd4b 100644 --- a/test/public-api/notes.e2e-spec.ts +++ b/test/public-api/notes.e2e-spec.ts @@ -98,26 +98,6 @@ describe('Notes', () => { ).toEqual('New note text'); }); - it(`PUT /notes/{note}/metadata`, async () => { - await notesService.createNote('This is a test note.', 'test5'); - await request(app.getHttpServer()) - .put('/notes/test5/metadata') - .send({ - title: 'test title', - description: 'test description', - tags: ['test1', 'test2', 'test3'], - }) - .expect(200); - const note5 = await notesService.getNoteByIdOrAlias('test5'); - expect(note5.title).toEqual('test title'); - expect(note5.description).toEqual('test description'); - expect(note5.tags.map(tag => tag.name)).toEqual([ - 'test1', - 'test2', - 'test3', - ]); - }); - it(`GET /notes/{note}/metadata`, async () => { await notesService.createNote('This is a test note.', 'test6'); const metadata = await request(app.getHttpServer()) @@ -169,53 +149,6 @@ describe('Notes', () => { expect(response.text).toEqual('This is a test note.'); }); - it(`2 notes with tags`, async () => { - //Create first nore - const content10 = 'This is the first test note.'; - const note10 = await request(app.getHttpServer()) - .post('/notes/test10') - .set('Content-Type', 'text/markdown') - .send(content10) - .expect('Content-Type', /json/) - .expect(201); - expect(note10.body.metadata?.id).toBeDefined(); - //Create second note - const content11 = 'This is the second test note.'; - const note11 = await request(app.getHttpServer()) - .post('/notes/test11') - .set('Content-Type', 'text/markdown') - .send(content11) - .expect('Content-Type', /json/) - .expect(201); - expect(note11.body.metadata?.id).toBeDefined(); - //Add tags to both notes - await request(app.getHttpServer()) - .put('/notes/test10/metadata') - .send({ - title: 'Test Note 10', - description: 'test description', - tags: ['test1', 'test2', 'test3'], - }) - .expect(200); - await request(app.getHttpServer()) - .put('/notes/test11/metadata') - .send({ - title: 'Test Note 11', - description: 'test description', - tags: ['test1', 'test2', 'test4'], - }) - .expect(200); - //Delete first note - await request(app.getHttpServer()) - .delete('/notes/test10') - .expect(200); - //Check if all tags are still present - const metadata11 = await request(app.getHttpServer()) - .get('/notes/test11/metadata') - .expect(200); - expect(metadata11.body.tags).toEqual(['test1', 'test2', 'test4']); - }); - afterAll(async () => { await app.close(); });