31d2da25b0c7f7d86920c15a4ed49a47e1b6e038
[motion2.git] / server / api / dashboard / dashboard.controller.js
1 // *************************************************************************
2 // *                                                                       *
3 // * xCALLY Motion -  The Omnichannel Contact Center                       *
4 // * Copyright (c) Xenialab s.r.l. All Rights Reserved                     *
5 // *                                                                       *
6 // *************************************************************************
7 // *                                                                       *
8 // * Email: info@xcally.com                                                *
9 // * Website: https://www.xcally.com                                       *
10 // *                                                                       *
11 // *************************************************************************
12 // *                                                                       *
13 // * The SOFTWARE PRODUCT is protected by copyright laws and international *
14 // * copyright treaties, as well as other intellectual property laws and   *
15 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                         *
16 // *                                                                       *
17 // *************************************************************************
18 var _0x407f=['model','name','query','keys','attributes','intersection','fields','hasOwnProperty','nolimit','order','sort','filters','where','merge','map','VIRTUAL','filter','options','includeAll','rows','catch','show','params','length','include','create','user','Unable\x20to\x20retrieve\x20the\x20current\x20user','UserProfileSection','find','autoAssociation','Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s','clone','omit','createdAt','updatedAt','body','update','type','iframe','attrUrl','attrs','value','custom','attrPath','attrHourFormat','HH:mm:ss','attrTimezone','0.00','attrFontSize','counter','attrMetric','attrVoiceQueues','multibar-chart','pie-chart','total','attrSerie2','attrSerie3','web-report','attrReport','reportType','attrRefresh','widgetAttributes:\x20%s','stringify','addItem','DashboardId','DashboardItem','getItems','findOne','pick','fast-json-patch','request-promise','moment','bluebird','mustache','util','path','sox','to-csv','ejs','fs-extra','lodash','squel','crypto','jsforce','desk.js','querystring','papaparse','ioredis','../../components/auth/service','../../config/logger','api','../../config/utils','../../config/environment','../../config/license/util','redis','defaults','localhost','socket.io-emitter','./dashboard.socket','register','status','json','undefined','limit','count','offset','set','Content-Range','apply','reject','save','then','destroy','get','UserProfileResource','end','error','stack','send','index','Dashboard','rawAttributes','key'];(function(_0x5dce27,_0x352d03){var _0x8b2e70=function(_0x12f1bd){while(--_0x12f1bd){_0x5dce27['push'](_0x5dce27['shift']());}};_0x8b2e70(++_0x352d03);}(_0x407f,0xc2));var _0xf407=function(_0x3ca44a,_0x4bc76d){_0x3ca44a=_0x3ca44a-0x0;var _0x362653=_0x407f[_0x3ca44a];return _0x362653;};'use strict';var emlformat=require('eml-format');var rimraf=require('rimraf');var zipdir=require('zip-dir');var jsonpatch=require(_0xf407('0x0'));var rp=require(_0xf407('0x1'));var moment=require(_0xf407('0x2'));var BPromise=require(_0xf407('0x3'));var Mustache=require(_0xf407('0x4'));var util=require(_0xf407('0x5'));var path=require(_0xf407('0x6'));var sox=require(_0xf407('0x7'));var csv=require(_0xf407('0x8'));var ejs=require(_0xf407('0x9'));var fs=require('fs');var fs_extra=require(_0xf407('0xa'));var _=require(_0xf407('0xb'));var squel=require(_0xf407('0xc'));var crypto=require(_0xf407('0xd'));var jsforce=require(_0xf407('0xe'));var deskjs=require(_0xf407('0xf'));var toCsv=require('to-csv');var querystring=require(_0xf407('0x10'));var Papa=require(_0xf407('0x11'));var Redis=require(_0xf407('0x12'));var authService=require(_0xf407('0x13'));var qs=require('../../components/parsers/qs');var as=require('../../components/parsers/advancedSearch');var hardwareService=require('../../config/license/hardware');var logger=require(_0xf407('0x14'))(_0xf407('0x15'));var utils=require(_0xf407('0x16'));var config=require(_0xf407('0x17'));var licenseUtil=require(_0xf407('0x18'));var db=require('../../mysqldb')['db'];config[_0xf407('0x19')]=_[_0xf407('0x1a')](config[_0xf407('0x19')],{'host':_0xf407('0x1b'),'port':0x18eb});var socket=require(_0xf407('0x1c'))(new Redis(config[_0xf407('0x19')]));require(_0xf407('0x1d'))[_0xf407('0x1e')](socket);function respondWithStatusCode(_0x5d80ab,_0x50bb74){_0x50bb74=_0x50bb74||0xcc;return function(_0x280a9f){if(_0x280a9f){return _0x5d80ab['sendStatus'](_0x50bb74);}return _0x5d80ab[_0xf407('0x1f')](_0x50bb74)['end']();};}function respondWithResult(_0x48fd5d,_0x768926){_0x768926=_0x768926||0xc8;return function(_0x331782){if(_0x331782){return _0x48fd5d[_0xf407('0x1f')](_0x768926)[_0xf407('0x20')](_0x331782);}};}function respondWithFilteredResult(_0x351252,_0x71f512){return function(_0x4ddbe6){if(_0x4ddbe6){var _0x2e346f=typeof _0x71f512['offset']===_0xf407('0x21')&&typeof _0x71f512[_0xf407('0x22')]===_0xf407('0x21');var _0x334c1a=_0x4ddbe6[_0xf407('0x23')];var _0xac9f0d=_0x2e346f?0x0:_0x71f512['offset'];var _0x2aa4c3=_0x2e346f?_0x4ddbe6[_0xf407('0x23')]:_0x71f512[_0xf407('0x24')]+_0x71f512[_0xf407('0x22')];var _0x4eb0c3;if(_0x2aa4c3>=_0x334c1a){_0x2aa4c3=_0x334c1a;_0x4eb0c3=0xc8;}else{_0x4eb0c3=0xce;}_0x351252[_0xf407('0x1f')](_0x4eb0c3);return _0x351252[_0xf407('0x25')](_0xf407('0x26'),_0xac9f0d+'-'+_0x2aa4c3+'/'+_0x334c1a)[_0xf407('0x20')](_0x4ddbe6);}return null;};}function patchUpdates(_0x5f32bb){return function(_0x4c0b6d){try{jsonpatch[_0xf407('0x27')](_0x4c0b6d,_0x5f32bb,!![]);}catch(_0x100e6e){return BPromise[_0xf407('0x28')](_0x100e6e);}return _0x4c0b6d[_0xf407('0x29')]();};}function saveUpdates(_0x9406cf,_0x4646f0){return function(_0x17309c){if(_0x17309c){return _0x17309c['update'](_0x9406cf)[_0xf407('0x2a')](function(_0x1996c8){return _0x1996c8;});}return null;};}function removeEntity(_0x2f620d,_0x50897a){return function(_0x1b6050){if(_0x1b6050){return _0x1b6050[_0xf407('0x2b')]()[_0xf407('0x2a')](function(){var _0x2c594a=_0x1b6050[_0xf407('0x2c')]({'plain':!![]});var _0x187c93='CustomDashboards';return db[_0xf407('0x2d')]['destroy']({'where':{'type':_0x187c93,'resourceId':_0x2c594a['id']}})['then'](function(){return _0x1b6050;});})[_0xf407('0x2a')](function(){_0x2f620d[_0xf407('0x1f')](0xcc)[_0xf407('0x2e')]();});}};}function handleEntityNotFound(_0x582453,_0x1c5335){return function(_0x249028){if(!_0x249028){_0x582453['sendStatus'](0x194);}return _0x249028;};}function handleError(_0x25b820,_0x350283){_0x350283=_0x350283||0x1f4;return function(_0xa91b61){logger[_0xf407('0x2f')](_0xa91b61[_0xf407('0x30')]);if(_0xa91b61['name']){delete _0xa91b61['name'];}_0x25b820[_0xf407('0x1f')](_0x350283)[_0xf407('0x31')](_0xa91b61);};}exports[_0xf407('0x32')]=function(_0x50c461,_0x153287){var _0x1437d1={},_0x284f5e={},_0x55fef5={'count':0x0,'rows':[]};var _0x377c83=_['map'](db[_0xf407('0x33')][_0xf407('0x34')],function(_0x540833){return{'name':_0x540833['fieldName'],'type':_0x540833['type'][_0xf407('0x35')]};});_0x284f5e[_0xf407('0x36')]=_['map'](_0x377c83,_0xf407('0x37'));_0x284f5e[_0xf407('0x38')]=_[_0xf407('0x39')](_0x50c461[_0xf407('0x38')]);_0x284f5e['filters']=_['intersection'](_0x284f5e[_0xf407('0x36')],_0x284f5e[_0xf407('0x38')]);_0x1437d1[_0xf407('0x3a')]=_[_0xf407('0x3b')](_0x284f5e[_0xf407('0x36')],qs[_0xf407('0x3c')](_0x50c461[_0xf407('0x38')][_0xf407('0x3c')]));_0x1437d1[_0xf407('0x3a')]=_0x1437d1[_0xf407('0x3a')]['length']?_0x1437d1[_0xf407('0x3a')]:_0x284f5e['model'];if(!_0x50c461[_0xf407('0x38')][_0xf407('0x3d')](_0xf407('0x3e'))){_0x1437d1[_0xf407('0x22')]=qs[_0xf407('0x22')](_0x50c461['query'][_0xf407('0x22')]);_0x1437d1[_0xf407('0x24')]=qs[_0xf407('0x24')](_0x50c461[_0xf407('0x38')]['offset']);}_0x1437d1[_0xf407('0x3f')]=qs[_0xf407('0x40')](_0x50c461[_0xf407('0x38')]['sort']);_0x1437d1['where']=qs[_0xf407('0x41')](_['pick'](_0x50c461['query'],_0x284f5e[_0xf407('0x41')]),_0x377c83);if(_0x50c461[_0xf407('0x38')]['filter']){_0x1437d1[_0xf407('0x42')]=_[_0xf407('0x43')](_0x1437d1[_0xf407('0x42')],{'$or':_[_0xf407('0x44')](_0x377c83,function(_0xa4ee62){if(_0xa4ee62['type']!==_0xf407('0x45')){var _0x55be9b={};_0x55be9b[_0xa4ee62['name']]={'$like':'%'+_0x50c461[_0xf407('0x38')][_0xf407('0x46')]+'%'};return _0x55be9b;}})});}_0x1437d1=_['merge']({},_0x1437d1,_0x50c461[_0xf407('0x47')]);var _0x44b01a={'where':_0x1437d1[_0xf407('0x42')]};return db[_0xf407('0x33')][_0xf407('0x23')](_0x44b01a)[_0xf407('0x2a')](function(_0x1c8f17){_0x55fef5[_0xf407('0x23')]=_0x1c8f17;if(_0x50c461['query'][_0xf407('0x48')]){_0x1437d1['include']=[{'all':!![]}];}return db[_0xf407('0x33')]['findAll'](_0x1437d1);})[_0xf407('0x2a')](function(_0x56ea2b){_0x55fef5[_0xf407('0x49')]=_0x56ea2b;return _0x55fef5;})[_0xf407('0x2a')](respondWithFilteredResult(_0x153287,_0x1437d1))[_0xf407('0x4a')](handleError(_0x153287,null));};exports[_0xf407('0x4b')]=function(_0x3ab411,_0x3ba408){var _0x1d978a={'raw':![],'where':{'id':_0x3ab411[_0xf407('0x4c')]['id']}},_0x4fe7a7={};_0x4fe7a7[_0xf407('0x36')]=_[_0xf407('0x39')](db[_0xf407('0x33')][_0xf407('0x34')]);_0x4fe7a7[_0xf407('0x38')]=_['keys'](_0x3ab411[_0xf407('0x38')]);_0x4fe7a7[_0xf407('0x41')]=_[_0xf407('0x3b')](_0x4fe7a7[_0xf407('0x36')],_0x4fe7a7[_0xf407('0x38')]);_0x1d978a[_0xf407('0x3a')]=_['intersection'](_0x4fe7a7[_0xf407('0x36')],qs[_0xf407('0x3c')](_0x3ab411[_0xf407('0x38')]['fields']));_0x1d978a[_0xf407('0x3a')]=_0x1d978a['attributes'][_0xf407('0x4d')]?_0x1d978a[_0xf407('0x3a')]:_0x4fe7a7[_0xf407('0x36')];if(_0x3ab411[_0xf407('0x38')]['includeAll']){_0x1d978a[_0xf407('0x4e')]=[{'all':!![]}];}_0x1d978a=_[_0xf407('0x43')]({},_0x1d978a,_0x3ab411[_0xf407('0x47')]);return db['Dashboard']['find'](_0x1d978a)[_0xf407('0x2a')](handleEntityNotFound(_0x3ba408,null))[_0xf407('0x2a')](respondWithResult(_0x3ba408,null))[_0xf407('0x4a')](handleError(_0x3ba408,null));};exports['create']=function(_0x17a7ba,_0x2e2560){return db[_0xf407('0x33')][_0xf407('0x4f')](_0x17a7ba['body'],{})[_0xf407('0x2a')](function(_0x3d3c9d){var _0x4e8483=_0x17a7ba[_0xf407('0x50')][_0xf407('0x2c')]({'plain':!![]});if(!_0x4e8483)throw new Error(_0xf407('0x51'));if(_0x4e8483['role']===_0xf407('0x50')){var _0xd168af=_0x3d3c9d[_0xf407('0x2c')]({'plain':!![]});var _0x3e3de4='CustomDashboards';return db[_0xf407('0x52')][_0xf407('0x53')]({'where':{'name':_0x3e3de4,'userProfileId':_0x4e8483['userProfileId']},'raw':!![]})[_0xf407('0x2a')](function(_0x588fd7){if(_0x588fd7&&_0x588fd7[_0xf407('0x54')]===0x0){return db[_0xf407('0x2d')]['create']({'name':_0xd168af[_0xf407('0x37')],'resourceId':_0xd168af['id'],'type':_0x588fd7[_0xf407('0x37')],'sectionId':_0x588fd7['id']},{})['then'](function(){return _0x3d3c9d;});}else{return _0x3d3c9d;}})[_0xf407('0x4a')](function(_0x580cf5){logger['error'](_0xf407('0x55'),_0x580cf5);throw _0x580cf5;});}return _0x3d3c9d;})[_0xf407('0x2a')](respondWithResult(_0x2e2560,0xc9))[_0xf407('0x4a')](handleError(_0x2e2560,null));};exports[_0xf407('0x56')]=function(_0x2140e0,_0x1376b9){var _0x48b4d2={'where':{'id':_0x2140e0[_0xf407('0x4c')]['id']}},_0x493727={};_0x493727[_0xf407('0x36')]=_[_0xf407('0x39')](db[_0xf407('0x33')][_0xf407('0x34')]);_0x48b4d2[_0xf407('0x3a')]=_['intersection'](_0x493727[_0xf407('0x36')],qs[_0xf407('0x3c')](_0x2140e0[_0xf407('0x38')][_0xf407('0x3c')]));_0x48b4d2[_0xf407('0x3a')]=_0x48b4d2[_0xf407('0x3a')]['length']?_0x48b4d2[_0xf407('0x3a')]:_0x493727[_0xf407('0x36')];if(_0x2140e0['query']['includeAll']){_0x48b4d2[_0xf407('0x4e')]=[{'all':!![]}];}_0x48b4d2=_[_0xf407('0x43')]({},_0x48b4d2,_0x2140e0[_0xf407('0x47')]);return db[_0xf407('0x33')][_0xf407('0x53')](_0x48b4d2)[_0xf407('0x2a')](handleEntityNotFound(_0x1376b9,null))[_0xf407('0x2a')](function(_0x4c19fd){if(_0x4c19fd){var _0x54c8cb=_0x4c19fd[_0xf407('0x2c')]({'plain':!![]});_0x54c8cb=qs[_0xf407('0x57')](_0x54c8cb,['id',_0xf407('0x58'),_0xf407('0x59')]);_0x2140e0[_0xf407('0x5a')]=_[_0xf407('0x57')](_0x2140e0[_0xf407('0x5a')],['id','createdAt',_0xf407('0x59')]);return db[_0xf407('0x33')]['create'](_[_0xf407('0x43')](_0x54c8cb,_0x2140e0[_0xf407('0x5a')]),{'include':_0x2140e0[_0xf407('0x38')][_0xf407('0x48')]?[{'all':!![]}]:undefined})[_0xf407('0x2a')](function(_0x2d4ced){var _0x4379a9=_0x2140e0[_0xf407('0x50')][_0xf407('0x2c')]({'plain':!![]});if(!_0x4379a9)throw new Error(_0xf407('0x51'));if(_0x4379a9['role']===_0xf407('0x50')){var _0x15bde9=_0x2d4ced[_0xf407('0x2c')]({'plain':!![]});var _0x15dc45='CustomDashboards';return db[_0xf407('0x52')][_0xf407('0x53')]({'where':{'name':_0x15dc45,'userProfileId':_0x4379a9['userProfileId']},'raw':!![]})['then'](function(_0x1b34d4){if(_0x1b34d4&&_0x1b34d4[_0xf407('0x54')]===0x0){return db[_0xf407('0x2d')][_0xf407('0x4f')]({'name':_0x15bde9[_0xf407('0x37')],'resourceId':_0x15bde9['id'],'type':_0x1b34d4[_0xf407('0x37')],'sectionId':_0x1b34d4['id']},{})[_0xf407('0x2a')](function(){return _0x2d4ced;});}else{return _0x2d4ced;}})[_0xf407('0x4a')](function(_0x177cc8){logger[_0xf407('0x2f')](_0xf407('0x55'),_0x177cc8);throw _0x177cc8;});}return _0x2d4ced;});}})[_0xf407('0x2a')](respondWithResult(_0x1376b9,0xc9))[_0xf407('0x4a')](handleError(_0x1376b9,null));};exports[_0xf407('0x5b')]=function(_0x4e4221,_0x568e4e){if(_0x4e4221[_0xf407('0x5a')]['id']){delete _0x4e4221[_0xf407('0x5a')]['id'];}return db[_0xf407('0x33')][_0xf407('0x53')]({'where':{'id':_0x4e4221[_0xf407('0x4c')]['id']}})['then'](handleEntityNotFound(_0x568e4e,null))['then'](saveUpdates(_0x4e4221['body'],null))[_0xf407('0x2a')](respondWithResult(_0x568e4e,null))[_0xf407('0x4a')](handleError(_0x568e4e,null));};exports[_0xf407('0x2b')]=function(_0xc44a2f,_0x278bf7){return db[_0xf407('0x33')][_0xf407('0x53')]({'where':{'id':_0xc44a2f['params']['id']}})['then'](handleEntityNotFound(_0x278bf7,null))[_0xf407('0x2a')](removeEntity(_0x278bf7,null))[_0xf407('0x4a')](handleError(_0x278bf7,null));};function widgetAttributes(_0x3974e2){try{switch(_0x3974e2[_0xf407('0x5c')]){case _0xf407('0x5d'):return[{'name':_0xf407('0x5e'),'value':_0x3974e2[_0xf407('0x5e')]||(_0x3974e2[_0xf407('0x5f')]&&_0x3974e2[_0xf407('0x5f')][0x0]?_0x3974e2[_0xf407('0x5f')][0x0][_0xf407('0x60')]:undefined)||'https://'}];case _0xf407('0x61'):return[{'name':_0xf407('0x62'),'value':_0x3974e2[_0xf407('0x62')]||(_0x3974e2[_0xf407('0x5f')]&&_0x3974e2['attrs'][0x0]?_0x3974e2[_0xf407('0x5f')][0x0][_0xf407('0x60')]:undefined)||''}];case'clock':return[{'name':_0xf407('0x63'),'value':_0x3974e2['attrHourFormat']||(_0x3974e2[_0xf407('0x5f')]&&_0x3974e2[_0xf407('0x5f')][0x0]?_0x3974e2[_0xf407('0x5f')][0x0][_0xf407('0x60')]:undefined)||_0xf407('0x64')},{'name':_0xf407('0x65'),'value':_0x3974e2['attrTimezone']||(_0x3974e2[_0xf407('0x5f')]&&_0x3974e2[_0xf407('0x5f')][0x1]?_0x3974e2[_0xf407('0x5f')][0x1]['value']:undefined)||_0xf407('0x66')},{'name':_0xf407('0x67'),'value':_0x3974e2[_0xf407('0x67')]||(_0x3974e2[_0xf407('0x5f')]&&_0x3974e2[_0xf407('0x5f')][0x2]?_0x3974e2[_0xf407('0x5f')][0x2][_0xf407('0x60')]:undefined)||0xc}];case _0xf407('0x68'):return[{'name':'attrMetric','value':_0x3974e2[_0xf407('0x69')]||(_0x3974e2['attrs']&&_0x3974e2[_0xf407('0x5f')][0x0]?_0x3974e2[_0xf407('0x5f')][0x0][_0xf407('0x60')]:undefined)||'total'},{'name':'attrVoiceQueues','value':_0x3974e2[_0xf407('0x6a')]||(_0x3974e2[_0xf407('0x5f')]&&_0x3974e2[_0xf407('0x5f')][0x1]?_0x3974e2[_0xf407('0x5f')][0x1][_0xf407('0x60')]:undefined)||[]},{'name':_0xf407('0x67'),'value':_0x3974e2['attrFontSize']||(_0x3974e2['attrs']&&_0x3974e2[_0xf407('0x5f')][0x2]?_0x3974e2[_0xf407('0x5f')][0x2][_0xf407('0x60')]:undefined)||0x14}];case _0xf407('0x6b'):case _0xf407('0x6c'):return[{'name':'attrSerie1','value':_0x3974e2['attrSerie1']||(_0x3974e2[_0xf407('0x5f')]&&_0x3974e2[_0xf407('0x5f')][0x0]?_0x3974e2[_0xf407('0x5f')][0x0][_0xf407('0x60')]:undefined)||_0xf407('0x6d')},{'name':_0xf407('0x6e'),'value':_0x3974e2[_0xf407('0x6e')]||(_0x3974e2[_0xf407('0x5f')]&&_0x3974e2[_0xf407('0x5f')][0x1]?_0x3974e2[_0xf407('0x5f')][0x1][_0xf407('0x60')]:undefined)||null},{'name':_0xf407('0x6f'),'value':_0x3974e2[_0xf407('0x6f')]||(_0x3974e2[_0xf407('0x5f')]&&_0x3974e2['attrs'][0x2]?_0x3974e2[_0xf407('0x5f')][0x2]['value']:undefined)||null},{'name':'attrVoiceQueues','value':_0x3974e2[_0xf407('0x6a')]||(_0x3974e2[_0xf407('0x5f')]&&_0x3974e2[_0xf407('0x5f')][0x3]?_0x3974e2['attrs'][0x3]['value']:undefined)||[]}];case _0xf407('0x70'):return[{'name':_0xf407('0x71'),'type':_0x3974e2[_0xf407('0x72')]||(_0x3974e2['attrs']&&_0x3974e2['attrs'][0x0]?_0x3974e2['attrs'][0x0][_0xf407('0x5c')]:undefined)||null,'value':_0x3974e2[_0xf407('0x71')]||(_0x3974e2[_0xf407('0x5f')]&&_0x3974e2[_0xf407('0x5f')][0x0]?_0x3974e2[_0xf407('0x5f')][0x0][_0xf407('0x60')]:undefined)||null},{'name':_0xf407('0x73'),'value':_0x3974e2[_0xf407('0x73')]||(_0x3974e2[_0xf407('0x5f')]&&_0x3974e2[_0xf407('0x5f')][0x1]?_0x3974e2['attrs'][0x1][_0xf407('0x60')]:undefined)||0x0}];default:return[];}}catch(_0xb0bc39){logger[_0xf407('0x2f')](_0xf407('0x74'),JSON[_0xf407('0x75')](_0xb0bc39));return[];}}exports[_0xf407('0x76')]=function(_0x3c905b,_0x4e86d7,_0xa46e95){if(_0x3c905b[_0xf407('0x5a')]['id']){delete _0x3c905b['body']['id'];}return db[_0xf407('0x33')][_0xf407('0x53')]({'where':{'id':_0x3c905b['params']['id']}})[_0xf407('0x2a')](handleEntityNotFound(_0x4e86d7,null))[_0xf407('0x2a')](function(_0x29644a){if(_0x29644a){_0x3c905b[_0xf407('0x5a')][_0xf407('0x77')]=_0x29644a['id'];_0x3c905b[_0xf407('0x5a')][_0xf407('0x5f')]=widgetAttributes(_0x3c905b[_0xf407('0x5a')]);return db[_0xf407('0x78')][_0xf407('0x4f')](_0x3c905b[_0xf407('0x5a')]);}})[_0xf407('0x2a')](respondWithResult(_0x4e86d7,null))[_0xf407('0x4a')](handleError(_0x4e86d7,null));};exports[_0xf407('0x79')]=function(_0x18f3bc,_0x5396cd,_0x459e07){var _0x2ac050={};var _0x4b88e9={};var _0x40dcf9;var _0x51c444;return db[_0xf407('0x33')][_0xf407('0x7a')]({'where':{'id':_0x18f3bc[_0xf407('0x4c')]['id']}})[_0xf407('0x2a')](handleEntityNotFound(_0x5396cd,null))[_0xf407('0x2a')](function(_0x58c47a){if(_0x58c47a){_0x40dcf9=_0x58c47a;_0x4b88e9[_0xf407('0x36')]=_[_0xf407('0x39')](db[_0xf407('0x78')][_0xf407('0x34')]);_0x4b88e9[_0xf407('0x38')]=_[_0xf407('0x39')](_0x18f3bc[_0xf407('0x38')]);_0x4b88e9[_0xf407('0x41')]=_['intersection'](_0x4b88e9[_0xf407('0x36')],_0x4b88e9[_0xf407('0x38')]);_0x2ac050[_0xf407('0x3a')]=_[_0xf407('0x3b')](_0x4b88e9[_0xf407('0x36')],qs[_0xf407('0x3c')](_0x18f3bc['query']['fields']));_0x2ac050[_0xf407('0x3a')]=_0x2ac050[_0xf407('0x3a')][_0xf407('0x4d')]?_0x2ac050['attributes']:_0x4b88e9[_0xf407('0x36')];_0x2ac050['order']=qs['sort'](_0x18f3bc[_0xf407('0x38')][_0xf407('0x40')]);_0x2ac050[_0xf407('0x42')]=qs[_0xf407('0x41')](_[_0xf407('0x7b')](_0x18f3bc[_0xf407('0x38')],_0x4b88e9['filters']));if(_0x18f3bc[_0xf407('0x38')][_0xf407('0x46')]){_0x2ac050['where']=_['merge'](_0x2ac050[_0xf407('0x42')],{'$or':_[_0xf407('0x44')](_0x2ac050[_0xf407('0x3a')],function(_0x45906a){var _0x3d55b3={};_0x3d55b3[_0x45906a]={'$like':'%'+_0x18f3bc[_0xf407('0x38')][_0xf407('0x46')]+'%'};return _0x3d55b3;})});}_0x2ac050=_['merge']({},_0x2ac050,_0x18f3bc[_0xf407('0x47')]);return _0x40dcf9[_0xf407('0x79')](_0x2ac050);}})[_0xf407('0x2a')](function(_0x3ee7cd){if(_0x3ee7cd){_0x51c444=_0x3ee7cd[_0xf407('0x4d')];if(!_0x18f3bc['query'][_0xf407('0x3d')](_0xf407('0x3e'))){_0x2ac050['limit']=qs[_0xf407('0x22')](_0x18f3bc[_0xf407('0x38')]['limit']);_0x2ac050['offset']=qs[_0xf407('0x24')](_0x18f3bc[_0xf407('0x38')][_0xf407('0x24')]);}return _0x40dcf9[_0xf407('0x79')](_0x2ac050);}})[_0xf407('0x2a')](function(_0x3a5f15){if(_0x3a5f15){return _0x3a5f15?{'count':_0x51c444,'rows':_0x3a5f15}:null;}})[_0xf407('0x2a')](respondWithResult(_0x5396cd,null))[_0xf407('0x4a')](handleError(_0x5396cd,null));};