From c96573069e896c616a060699c1045ab2afc84291 Mon Sep 17 00:00:00 2001 From: Rory Powell Date: Fri, 28 Jan 2022 13:27:19 +0000 Subject: [PATCH] Fix app update endpoint --- .../server/src/api/controllers/application.js | 21 ++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/packages/server/src/api/controllers/application.js b/packages/server/src/api/controllers/application.js index 7aaeebc025..db8f261aef 100644 --- a/packages/server/src/api/controllers/application.js +++ b/packages/server/src/api/controllers/application.js @@ -81,12 +81,13 @@ async function getAppUrl(ctx) { if (ctx.request.body.url) { // if the url is provided, use that url = encodeURI(ctx.request.body.url) - } else { + } else if (ctx.request.body.name) { // otherwise use the name url = encodeURI(`${ctx.request.body.name}`) } - url = `/${url.replace(URL_REGEX_SLASH, "")}`.toLowerCase() - + if (url) { + url = `/${url.replace(URL_REGEX_SLASH, "")}`.toLowerCase() + } return url } @@ -276,16 +277,22 @@ exports.create = async ctx => { ctx.body = newApplication } +// This endpoint currently operates as a PATCH rather than a PUT +// Thus name and url fields are handled only if present exports.update = async ctx => { const apps = await getAllApps(CouchDB, { dev: true }) // validation const name = ctx.request.body.name - checkAppName(ctx, apps, name, ctx.params.appId) + if (name) { + checkAppName(ctx, apps, name, ctx.params.appId) + } const url = await getAppUrl(ctx) - checkAppUrl(ctx, apps, url, ctx.params.appId) + if (url) { + checkAppUrl(ctx, apps, url, ctx.params.appId) + ctx.request.body.url = url + } - const appPackageUpdates = { name, url } - const data = await updateAppPackage(appPackageUpdates, ctx.params.appId) + const data = await updateAppPackage(ctx.request.body, ctx.params.appId) ctx.status = 200 ctx.body = data }