Skip to content

Commit

Permalink
Fix: #21
Browse files Browse the repository at this point in the history
  • Loading branch information
zoernert committed Feb 5, 2024
1 parent 1488f7f commit 953c7d1
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 9 deletions.
9 changes: 6 additions & 3 deletions framework/services/asset.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,9 +131,12 @@ module.exports = {
if(typeof ctx.params.type !== 'undefined') {
query.type = ctx.params.type;
}
let res = await db.collection("assets").find(query).toArray();
for(let i=0;i<res.length;i++) {
delete res[i]._id;
let res = [];
if(typeof db !== 'undefined') {
res = await db.collection("assets").find(query).toArray();
for(let i=0;i<res.length;i++) {
delete res[i]._id;
}
}
return res;
}
Expand Down
9 changes: 8 additions & 1 deletion framework/services/debit.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,14 @@ module.exports = {
return (await ctx.call("debit_model.list",{ pageSize: 50,sort:"-clearingTime"})).rows;
} else {
const regex = new RegExp(`^${ctx.params.q}`, 'i');
return await ctx.call("debit_model.find",{query:{ meterId: { $regex: regex } }});
// 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;
} else {
return await ctx.call("debit_model.find",{query:{ meterId: { $regex: regex } }});
}
}
}
},
Expand Down
10 changes: 6 additions & 4 deletions framework/services/metering.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -303,14 +303,14 @@ module.exports = {
transientReading.time = ctx.params.time * 1;
transientReading.id = transientReading._id;
transientReading.jwt = await ctx.call("access.createReadingJWT",transientReading);
if(typeof ctx.params.clearing !== 'undefined') {
if((typeof ctx.params.clearing !== 'undefined') || (typeof transientReading.id == 'undefined')) {
// in case we received a clearing we might need to insert first
const findExisting = await ctx.call("readings_model.find",{
query: {
meterId: ctx.params.meterId
}
});
if(findExisting.length == 0) {
if((findExisting.length == 0) || (typeof transientReading.id == 'undefined')) {
await ctx.call("readings_model.insert",{entity:transientReading});
} else {
for(let i=0;i<findExisting.length;i++) {
Expand All @@ -323,6 +323,7 @@ module.exports = {
await ctx.call("readings_model.insert",{entity:transientReading});
}
} else {
console.log(transientReading);
await ctx.call("readings_model.update",transientReading);
}
transientReading.consumption = deltaConumption;
Expand Down Expand Up @@ -356,8 +357,9 @@ module.exports = {
}

const clearing = await ctx.call("clearing.commit",transientClearing);

transientReading.id = transientReading._id;
if(typeof transientReading.id == 'undefined') {
transientReading.id = transientReading._id;
}
if(typeof transientReading._id !== 'undefined') {
transientReading.clearingJWT = clearing.jwt;
delete transientReading._id;
Expand Down
2 changes: 1 addition & 1 deletion framework/services/tariff.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,7 @@ module.exports = {
},
sort:"-epoch"
});
if((typeof price_info !== 'undefined') && (price_info !== null)) {
if((typeof price_info !== 'undefined') && (price_info !== null) && (price_info.length >0)) {
existingEpochs["epoch_"+i].price = price_info[0].price;
existingEpochs["epoch_"+i].priceOfEpoch = price_info[0].epoch;
}
Expand Down

0 comments on commit 953c7d1

Please sign in to comment.