From 4dfdd1390190c68a65fe4ce650f4285d644413ea Mon Sep 17 00:00:00 2001 From: Stuart Ferguson Date: Tue, 16 Aug 2022 06:25:29 +0100 Subject: [PATCH] Added app center config fields and api --- mobileconfiguration/.deta/prog_info | 2 +- mobileconfiguration/.deta/state | 2 +- mobileconfiguration/index.js | 46 +++++++++++++++++++++++++++-- 3 files changed, 45 insertions(+), 5 deletions(-) diff --git a/mobileconfiguration/.deta/prog_info b/mobileconfiguration/.deta/prog_info index dac4359..0069e2a 100644 --- a/mobileconfiguration/.deta/prog_info +++ b/mobileconfiguration/.deta/prog_info @@ -1 +1 @@ -{"id":"61c394b9-008e-48c3-b470-8a65b4ad89c8","space":1293,"runtime":"nodejs12.x","name":"mobileconfiguration","path":"5r8nmm","project":"a0f24j3l","account":"325177863433","region":"eu-west-2","deps":null,"envs":null,"public":true,"log_level":"debug","cron":"","reload_deps":false} \ No newline at end of file +{"id":"61c394b9-008e-48c3-b470-8a65b4ad89c8","space":1293,"runtime":"nodejs12.x","name":"mobileconfiguration","path":"5r8nmm","project":"a0f24j3l","account":"325177863433","region":"eu-west-2","deps":["express@^4.17.3","deta@^1.1.0"],"envs":null,"public":true,"log_level":"debug","cron":""} \ No newline at end of file diff --git a/mobileconfiguration/.deta/state b/mobileconfiguration/.deta/state index eeb4eeb..47b9290 100644 --- a/mobileconfiguration/.deta/state +++ b/mobileconfiguration/.deta/state @@ -1 +1 @@ -{"index.js":"2dfdab7d42569d8f5c20ce1ef58d10b2b91e893a43d5cf889d0c4613faa495fa","package-lock.json":"d55716b32bf92984b4be7cb38392516876396ae60cbd13a5111f6a7ef049adc6"} \ No newline at end of file +{"index.js":"2ee010a8946396822d449929c06f96ee24d281d4346da4ec747464f990e2ce94","package-lock.json":"3c5b150be2346494cfc832744453d6dd50db4af9b86d80c7a217d46be315cc45","package.json":"ee4ff1f18377c6f008b411c11b2e4a69a9063caf0e7bba7c823baa7a3629722c"} \ No newline at end of file diff --git a/mobileconfiguration/index.js b/mobileconfiguration/index.js index 0b9ded2..afb1a37 100644 --- a/mobileconfiguration/index.js +++ b/mobileconfiguration/index.js @@ -2,6 +2,7 @@ var express = require('express'); const { Deta } = require('deta'); const deta = Deta();// No need to provide a key if running in a micro +const appCenterConfigDatabase = deta.Base('appCenterconfig'); // access your DB const mobileConfigDatabase = deta.Base('mobileconfig'); // access your DB const voucherConfigDatabase = deta.Base('voucherconfig'); // access your DB const mobileLogsDatabase = deta.Base('mobilelogs'); // access your DB @@ -35,7 +36,19 @@ app.post('/voucherconfiguration', async function(req,res) // return a success (created) res.status(201).json(insertedConfigEntry); +}); + +app.post('/appcenterconfiguration', async function(req,res) +{ + // create the new config entry message + const configEntry = req.body; + configEntry.key = req.body.applicationId; + + // Write to the database + const insertedConfigEntry = await appCenterConfigDatabase.put(configEntry); + // return a success (created) + res.status(201).json(insertedConfigEntry); }); app.put('/configuration/:id', async function(req,res) @@ -68,14 +81,32 @@ app.put('/voucherconfiguration/:id', async function(req,res) // return a success (created) res.status(200).send(); +}); + +app.put('/appcenterconfiguration/:id', async function(req,res) +{ + var config = await appCenterConfigDatabase.get(req.params.id); + + const configEntry = req.body; + + var mergedConfig = {...config, ...configEntry}; + mergedConfig.key = req.params.id; + + // Write to the database + await appCenterConfigDatabase.put(mergedConfig); + // return a success (created) + res.status(200).send(); }); app.get('/configuration/:id', async function(req, res) { var config = await mobileConfigDatabase.get(req.params.id); - + var appCenterconfig = await appCenterConfigDatabase.get("transactionMobilePOS"); + + config.appCenterconfig = appCenterconfig; + // send records as a response res.send(JSON.stringify(config)); }); @@ -89,6 +120,15 @@ app.get('/voucherconfiguration/:id', res.send(JSON.stringify(config)); }); +app.get('/appcenterconfiguration/:id', + async function(req, res) + { + var config = await appCenterConfigDatabase.get(req.params.id); + + // send records as a response + res.send(JSON.stringify(config)); + }); + function getLogLevel(logLevel) { switch(logLevel) @@ -147,5 +187,5 @@ app.delete('/logging', async (req,res)=> module.exports = app; // Note: these 2 lines needed for local debugging only -//const port = 1337; -//app.listen(port, () => console.log(`Hello world app listening on port ${port}!`)); \ No newline at end of file +const port = 1337; +app.listen(port, () => console.log(`Hello world app listening on port ${port}!`)); \ No newline at end of file