From 031a4e5259b10e2692ec19aa3e86b4af5b301cf8 Mon Sep 17 00:00:00 2001 From: dhain Date: Tue, 11 Oct 2022 08:52:11 +0200 Subject: [PATCH] Create new note in listing now working --- .../strapi/src/api/note/controllers/note.js | 3 +- .../svelte/src/models/StrapiNoteRepository.ts | 10 +++- frontend/svelte/src/routes/+page.svelte | 55 +++++-------------- 3 files changed, 23 insertions(+), 45 deletions(-) diff --git a/backend/strapi/src/api/note/controllers/note.js b/backend/strapi/src/api/note/controllers/note.js index 20de73a..9cf8879 100644 --- a/backend/strapi/src/api/note/controllers/note.js +++ b/backend/strapi/src/api/note/controllers/note.js @@ -87,7 +87,8 @@ module.exports = createCoreController(noteUid, ({strapi}) => ({ */ async create(ctx) { const userId = ctx.state.user.id; - const requestBody = ctx.request.body; + const requestBody = JSON.parse(ctx.request.body); + console.log(requestBody); const response = await strapi.entityService.create(noteUid, { data: { title: requestBody.data.title, diff --git a/frontend/svelte/src/models/StrapiNoteRepository.ts b/frontend/svelte/src/models/StrapiNoteRepository.ts index 9de32cd..ab4a68f 100644 --- a/frontend/svelte/src/models/StrapiNoteRepository.ts +++ b/frontend/svelte/src/models/StrapiNoteRepository.ts @@ -15,9 +15,13 @@ export class StrapiNoteRepository implements NoteRepository { private constructor() {} - private currentNoteId: number | undefined; + private _currentNoteId: number | undefined; private static apiNoteEndpoint: string = "http://localhost:1337/api/notes" + public set currentNoteId(value: number | undefined) { + this._currentNoteId = value; + } + public async getNotes(): Promise{ const response = await StrapiNoteRepository.fetchStrapiNoteEndpoint("/", 'GET'); return await response.json(); @@ -29,10 +33,10 @@ export class StrapiNoteRepository implements NoteRepository { } public async getCurrentNote(): Promise { - if (this.currentNoteId === null || this.currentNoteId === undefined) { + if (this._currentNoteId === null || this._currentNoteId === undefined) { return; } - return await this.getNote(this.currentNoteId); + return await this.getNote(this._currentNoteId); } public async updateNote(id: number, note: Partial): Promise { diff --git a/frontend/svelte/src/routes/+page.svelte b/frontend/svelte/src/routes/+page.svelte index e217981..016d89f 100644 --- a/frontend/svelte/src/routes/+page.svelte +++ b/frontend/svelte/src/routes/+page.svelte @@ -1,19 +1,11 @@