Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion mobileconfiguration/.deta/prog_info
Original file line number Diff line number Diff line change
@@ -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}
{"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":""}
2 changes: 1 addition & 1 deletion mobileconfiguration/.deta/state
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"index.js":"2dfdab7d42569d8f5c20ce1ef58d10b2b91e893a43d5cf889d0c4613faa495fa","package-lock.json":"d55716b32bf92984b4be7cb38392516876396ae60cbd13a5111f6a7ef049adc6"}
{"index.js":"2ee010a8946396822d449929c06f96ee24d281d4346da4ec747464f990e2ce94","package-lock.json":"3c5b150be2346494cfc832744453d6dd50db4af9b86d80c7a217d46be315cc45","package.json":"ee4ff1f18377c6f008b411c11b2e4a69a9063caf0e7bba7c823baa7a3629722c"}
46 changes: 43 additions & 3 deletions mobileconfiguration/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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));
});
Expand All @@ -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)
Expand Down Expand Up @@ -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}!`));
const port = 1337;
app.listen(port, () => console.log(`Hello world app listening on port ${port}!`));