Skip to content

Commit

Permalink
Feat: Allow searching for balancing points using partial assetIds
Browse files Browse the repository at this point in the history
  • Loading branch information
zoernert committed Jan 24, 2024
1 parent a24c88b commit da6aaf9
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 5 deletions.
2 changes: 1 addition & 1 deletion framework/public/devUI/assets/js/uc_assets.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ $(document).ready(function() {
$('#balancingResult').html('...');

$.getJSON("/api/debit/assets?q=" + $('#searchMeter').val(), renderResultSet);
$.getJSON("/api/balancing/assets?q=" + $('#searchMeter').val(), renderBalancingSet);
$.getJSON("/api/assets/find?q=" + $('#searchMeter').val(), renderBalancingSet);

}
$('.delayBtn').click(function() {
Expand Down
4 changes: 2 additions & 2 deletions framework/public/devUI/uc_assets.html
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ <h3>Zählpunkte / Messstellen&nbsp;</h3>
</form>
<div class="card" id="cardBalancing">
<div class="card-body">
<h3>Bilanzierung</h3>
<h3>Bilanzierungspunkte</h3>
<div id="balancingResult" style="margin-top: 25px;"></div>
</div>
</div>
Expand Down Expand Up @@ -86,7 +86,7 @@ <h4 class="modal-title" id="helpTitle">Modal Title</h4><button class="btn-close"
<script src="assets/js/jquery.min.js?h=6bcc3684f18aa21874fa709f122723cf"></script>
<script src="assets/bootstrap/js/bootstrap.min.js?h=e55bde7d6e36ebf17ba0b8c1e80e4065"></script>
<script src="assets/js/utils.js?h=b6a1e690b2a987d9af7e9692dff15273"></script>
<script src="assets/js/uc_assets.js?h=92cc71dd587430917a3ad9911b692824"></script>
<script src="assets/js/uc_assets.js?h=5b2ba7eae554225dcf9bc6fc36bc103a"></script>
<script src="assets/js/3party/marked.min.js?h=26085551a49dd1635b48b42f08c3d583"></script>
</body>

Expand Down
13 changes: 13 additions & 0 deletions framework/services/asset.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,19 @@ module.exports = {
* Actions
*/
actions: {
find: {
rest: "/find",
params: {
q: {
type: "string",
optional:false
}
},
async handler(ctx) {
return await db.collection("assets").find({"assetId" : {$regex : ctx.params.q},"type":"balance"}).toArray();
}

},
upsert: {
rest: "/upsert",
params: {
Expand Down
14 changes: 12 additions & 2 deletions framework/services/balancing.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -248,8 +248,13 @@ module.exports = {
};

// Apply the balancing rule if one exists

if (asset && asset.balancerule) {
if((typeof asset == 'undefined')||(asset == null)) {
await ctx.call("asset.upsert",{
type:"balance",
assetId:ctx.params.meterId,
balance_activated:new Date().getTime()
})
} else if (asset && asset.balancerule) {
if (asset.balancerule.from) {
statement.from = asset.balancerule.from;
statement.counter = asset.balancerule.from;
Expand All @@ -259,6 +264,11 @@ module.exports = {
statement.to = asset.balancerule.to;
statement.counter = asset.balancerule.to;
}
await ctx.call("asset.upsert",{
type:"balance",
assetId:ctx.params.meterId,
balance_updated:new Date().getTime()
})
}

// validate that we do not have a sealed balances for those assets
Expand Down

0 comments on commit da6aaf9

Please sign in to comment.