diff --git a/admin-client/commands/retrieveDebit.js b/admin-client/commands/retrieveDebit.js new file mode 100644 index 0000000..6b74e29 --- /dev/null +++ b/admin-client/commands/retrieveDebit.js @@ -0,0 +1,11 @@ +const axios=require("axios"); + +module.exports = async function(config) { + if(typeof config.baseUrl == 'undefined') config.baseUrl = "http://localhost:3000"; + if(typeof config.meterId == 'undefined') { + throw Error("Requires --meterId "); + } + + const res = await axios.get(config.baseUrl + "/api/debit/open?meterId="+config.meterId); + return res.data; +} \ No newline at end of file diff --git a/admin-client/package.json b/admin-client/package.json index 12ba645..672fe6d 100644 --- a/admin-client/package.json +++ b/admin-client/package.json @@ -1,6 +1,6 @@ { "name": "eaf-admin-client", - "version": "1.0.2", + "version": "1.0.3", "description": "Administration Client for STROMDAO Energy Application Framework", "main": "cli.js", "bin": "cli.js", diff --git a/framework/services/debit.service.js b/framework/services/debit.service.js index f5b481f..2bad64c 100644 --- a/framework/services/debit.service.js +++ b/framework/services/debit.service.js @@ -32,19 +32,74 @@ module.exports = { path: "/assets" }, async handler(ctx) { + let res = []; if((typeof ctx.params.q == 'undefined') || (ctx.params.q.length == 0)) { - return (await ctx.call("debit_model.list",{ pageSize: 50,sort:"-clearingTime"})).rows; + res = (await ctx.call("debit_model.list",{ pageSize: 50,sort:"-clearingTime"})).rows; } else { const regex = new RegExp(`^${ctx.params.q}`, 'i'); // Regex "Find" only works with MongoDB Backend. - console.log(process.db_adapter); + if((!process.db_adapter) ||(process.db_adapter == null)) { - let res = await ctx.call("debit_model.find",{query:{ meterId: ctx.params.q }}); - return res; + res = await ctx.call("debit_model.find",{query:{ meterId: ctx.params.q }}); } else { - return await ctx.call("debit_model.find",{query:{ meterId: { $regex: regex } }}); + res = await ctx.call("debit_model.find",{query:{ meterId: { $regex: regex } }}); + } + } + if(res.length >0) { + for(let i=0;i