UNPKG

kpiplus

Version:

KPI+

1 lines 987 B
var model=require("../../models/follow"),controller=require("../../controllers/controller"),async=require("async"),stp=require("stp-utils");module.exports=function(e){this.contr=new controller(e,model,"follow",{notNeedRight:!0,onFinding:function(e,n,o,l){if(l.req.query.collections)try{var r=stp.parse("{"+l.req.query.collections+"}");for(var c in l.req.query.collections=r,n.collection_name={$in:[]},r)n.collection_name.$in.push(c);o(null,n)}catch(e){o(e)}else o(null,n)},onView:function(e,n,o,l){l.req.query.collections?async.map(n,function(e,n){var o=l.req.query.collections[e.collection_name];if(o){var r,c={};o.split(",").forEach(function(e){c[e]=1,r||(r=e)});var t=e.collection_name;"dmkh"==t&&(t="customer"),"dmtk"==t&&(t="account"),"dmnt"==t&&(t="currency"),require("../../models/"+t).findOne({_id:e.id_object},c).lean().exec(function(o,l){if(o)return n(o);l&&(e.obj=l,e.obj.title=l[r]),n()})}else n()},function(e,l){if(e)return o(e);o(null,n)}):o(null,n)}}),this.contr.route()};