From f6f2dfb8e40367c4a3f3fcee8f65809a25c2faa7 Mon Sep 17 00:00:00 2001 From: kevmodrome Date: Thu, 2 Jul 2020 18:38:00 +0200 Subject: [PATCH] dummy methods wired up to return values to the front-end --- .../src/components/settings/tabs/APIKeys.svelte | 13 ++++++------- packages/server/src/api/controllers/apikeys.js | 11 +++-------- 2 files changed, 9 insertions(+), 15 deletions(-) diff --git a/packages/builder/src/components/settings/tabs/APIKeys.svelte b/packages/builder/src/components/settings/tabs/APIKeys.svelte index db07755d56..4545cf9b85 100644 --- a/packages/builder/src/components/settings/tabs/APIKeys.svelte +++ b/packages/builder/src/components/settings/tabs/APIKeys.svelte @@ -6,11 +6,10 @@ let keys = { budibase: "", sendGrid: "" } - async function updateKey(e) { - console.log("Event Key: ", e.detail) - // Send to endpoint when it exists - const response = await api.put(`/api/${$store.appId}`, data) - // const res = await response.json() + async function updateKey([key, value]) { + const response = await api.put(`/api/keys/${key}`, { value }) + const res = await response.json() + keys = { ...keys, ...res } } // Get Keys @@ -27,7 +26,7 @@
updateKey(['budibase', e.detail])} thin edit value={keys.budibase} @@ -35,7 +34,7 @@
updateKey(['sendgrid', e.detail])} thin edit value={keys.sendgrid} diff --git a/packages/server/src/api/controllers/apikeys.js b/packages/server/src/api/controllers/apikeys.js index 11dd0ac787..88758cb4c3 100644 --- a/packages/server/src/api/controllers/apikeys.js +++ b/packages/server/src/api/controllers/apikeys.js @@ -18,15 +18,10 @@ exports.fetch = async function (ctx) { } exports.update = async function (ctx) { + // Do something with ctx.request.body: <{ value: value }> ctx.status = 200 - ctx.message = `Updated ${ctx.params.key} succesfully.` - ctx.body = { - [ctx.params.key]: "somethingsomethingsomething" - } - - ctx.status = 200 - ctx.message = `User ${ctx.request.body.username} updated successfully.` - ctx.body = response + ctx.message = `Updated ${ctx.params.key} API key succesfully.` + ctx.body = { [ctx.params.key]: ctx.request.body.value } } const checkAccessLevel = async (db, accessLevelId) => {