Built motion from commit d5e4af8c.|2.6.23
[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 _0x4724=['../../config/environment','../../config/license/util','redis','defaults','localhost','socket.io-emitter','./dashboard.socket','register','sendStatus','status','end','json','offset','undefined','count','limit','set','Content-Range','apply','update','destroy','then','get','CustomDashboards','UserProfileResource','stack','name','send','index','rawAttributes','type','model','query','keys','filters','intersection','attributes','fields','hasOwnProperty','order','sort','where','pick','filter','map','VIRTUAL','merge','options','Dashboard','includeAll','include','findAll','rows','catch','show','params','length','find','create','user','Unable\x20to\x20retrieve\x20the\x20current\x20user','role','userProfileId','error','Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s','omit','createdAt','body','updatedAt','iframe','attrUrl','attrs','value','https://','attrPath','attrHourFormat','HH:mm:ss','attrTimezone','0.00','attrFontSize','counter','attrMetric','attrVoiceQueues','attrChannel','voice','attrEmailAccounts','attrFaxAccounts','attrSmsAccounts','attrOpenchannelAccounts','attrWhatsappAccounts','attrChatWebsites','multibar-chart','attrSerie1','attrSerie2','attrSerie3','web-report','attrReport','attrRefresh','widgetAttributes:\x20%s','stringify','addItem','DashboardId','DashboardItem','getItems','findOne','nolimit','eml-format','rimraf','request-promise','bluebird','mustache','ejs','lodash','squel','crypto','jsforce','desk.js','querystring','papaparse','ioredis','../../components/parsers/advancedSearch','api'];(function(_0xcc86ba,_0x1adb0b){var _0x15f863=function(_0x353598){while(--_0x353598){_0xcc86ba['push'](_0xcc86ba['shift']());}};_0x15f863(++_0x1adb0b);}(_0x4724,0x15e));var _0x4472=function(_0x895ad0,_0xf67203){_0x895ad0=_0x895ad0-0x0;var _0x3d32f9=_0x4724[_0x895ad0];return _0x3d32f9;};'use strict';var emlformat=require(_0x4472('0x0'));var rimraf=require(_0x4472('0x1'));var zipdir=require('zip-dir');var jsonpatch=require('fast-json-patch');var rp=require(_0x4472('0x2'));var moment=require('moment');var BPromise=require(_0x4472('0x3'));var Mustache=require(_0x4472('0x4'));var util=require('util');var path=require('path');var sox=require('sox');var csv=require('to-csv');var ejs=require(_0x4472('0x5'));var fs=require('fs');var fs_extra=require('fs-extra');var _=require(_0x4472('0x6'));var squel=require(_0x4472('0x7'));var crypto=require(_0x4472('0x8'));var jsforce=require(_0x4472('0x9'));var deskjs=require(_0x4472('0xa'));var toCsv=require('to-csv');var querystring=require(_0x4472('0xb'));var Papa=require(_0x4472('0xc'));var Redis=require(_0x4472('0xd'));var authService=require('../../components/auth/service');var qs=require('../../components/parsers/qs');var as=require(_0x4472('0xe'));var hardwareService=require('../../config/license/hardware');var logger=require('../../config/logger')(_0x4472('0xf'));var utils=require('../../config/utils');var config=require(_0x4472('0x10'));var licenseUtil=require(_0x4472('0x11'));var db=require('../../mysqldb')['db'];config[_0x4472('0x12')]=_[_0x4472('0x13')](config[_0x4472('0x12')],{'host':_0x4472('0x14'),'port':0x18eb});var socket=require(_0x4472('0x15'))(new Redis(config[_0x4472('0x12')]));require(_0x4472('0x16'))[_0x4472('0x17')](socket);function respondWithStatusCode(_0x20a93d,_0x59828c){_0x59828c=_0x59828c||0xcc;return function(_0x3be893){if(_0x3be893){return _0x20a93d[_0x4472('0x18')](_0x59828c);}return _0x20a93d[_0x4472('0x19')](_0x59828c)[_0x4472('0x1a')]();};}function respondWithResult(_0x4db7a3,_0x36d00b){_0x36d00b=_0x36d00b||0xc8;return function(_0x1bc728){if(_0x1bc728){return _0x4db7a3[_0x4472('0x19')](_0x36d00b)[_0x4472('0x1b')](_0x1bc728);}};}function respondWithFilteredResult(_0x282306,_0x33772c){return function(_0x1b5d59){if(_0x1b5d59){var _0x353de0=typeof _0x33772c[_0x4472('0x1c')]===_0x4472('0x1d')&&typeof _0x33772c['limit']===_0x4472('0x1d');var _0x48d21e=_0x1b5d59[_0x4472('0x1e')];var _0x8d28bd=_0x353de0?0x0:_0x33772c[_0x4472('0x1c')];var _0x2c43f9=_0x353de0?_0x1b5d59[_0x4472('0x1e')]:_0x33772c[_0x4472('0x1c')]+_0x33772c[_0x4472('0x1f')];var _0x169689;if(_0x2c43f9>=_0x48d21e){_0x2c43f9=_0x48d21e;_0x169689=0xc8;}else{_0x169689=0xce;}_0x282306[_0x4472('0x19')](_0x169689);return _0x282306[_0x4472('0x20')](_0x4472('0x21'),_0x8d28bd+'-'+_0x2c43f9+'/'+_0x48d21e)[_0x4472('0x1b')](_0x1b5d59);}return null;};}function patchUpdates(_0x5f3b2f){return function(_0x1924c1){try{jsonpatch[_0x4472('0x22')](_0x1924c1,_0x5f3b2f,!![]);}catch(_0x323764){return BPromise['reject'](_0x323764);}return _0x1924c1['save']();};}function saveUpdates(_0x55e4fc,_0x4e4b62){return function(_0x5b5fd7){if(_0x5b5fd7){return _0x5b5fd7[_0x4472('0x23')](_0x55e4fc)['then'](function(_0x30a824){return _0x30a824;});}return null;};}function removeEntity(_0x30667c,_0x6d9828){return function(_0x33e1fa){if(_0x33e1fa){return _0x33e1fa[_0x4472('0x24')]()[_0x4472('0x25')](function(){var _0x8eb4bf=_0x33e1fa[_0x4472('0x26')]({'plain':!![]});var _0x88e805=_0x4472('0x27');return db[_0x4472('0x28')][_0x4472('0x24')]({'where':{'type':_0x88e805,'resourceId':_0x8eb4bf['id']}})['then'](function(){return _0x33e1fa;});})['then'](function(){_0x30667c['status'](0xcc)[_0x4472('0x1a')]();});}};}function handleEntityNotFound(_0x135f23,_0x1d13d6){return function(_0x538ea1){if(!_0x538ea1){_0x135f23[_0x4472('0x18')](0x194);}return _0x538ea1;};}function handleError(_0x1db8e9,_0x3a8a14){_0x3a8a14=_0x3a8a14||0x1f4;return function(_0x32a945){logger['error'](_0x32a945[_0x4472('0x29')]);if(_0x32a945[_0x4472('0x2a')]){delete _0x32a945[_0x4472('0x2a')];}_0x1db8e9[_0x4472('0x19')](_0x3a8a14)[_0x4472('0x2b')](_0x32a945);};}exports[_0x4472('0x2c')]=function(_0x2f9183,_0x57d352){var _0x40a8fb={},_0x1b4c7f={},_0x55d710={'count':0x0,'rows':[]};var _0x4e7991=_['map'](db['Dashboard'][_0x4472('0x2d')],function(_0x9e0cbd){return{'name':_0x9e0cbd['fieldName'],'type':_0x9e0cbd[_0x4472('0x2e')]['key']};});_0x1b4c7f[_0x4472('0x2f')]=_['map'](_0x4e7991,_0x4472('0x2a'));_0x1b4c7f[_0x4472('0x30')]=_[_0x4472('0x31')](_0x2f9183[_0x4472('0x30')]);_0x1b4c7f[_0x4472('0x32')]=_[_0x4472('0x33')](_0x1b4c7f[_0x4472('0x2f')],_0x1b4c7f[_0x4472('0x30')]);_0x40a8fb[_0x4472('0x34')]=_[_0x4472('0x33')](_0x1b4c7f['model'],qs['fields'](_0x2f9183['query'][_0x4472('0x35')]));_0x40a8fb[_0x4472('0x34')]=_0x40a8fb['attributes']['length']?_0x40a8fb[_0x4472('0x34')]:_0x1b4c7f[_0x4472('0x2f')];if(!_0x2f9183[_0x4472('0x30')][_0x4472('0x36')]('nolimit')){_0x40a8fb['limit']=qs[_0x4472('0x1f')](_0x2f9183['query'][_0x4472('0x1f')]);_0x40a8fb['offset']=qs[_0x4472('0x1c')](_0x2f9183[_0x4472('0x30')][_0x4472('0x1c')]);}_0x40a8fb[_0x4472('0x37')]=qs[_0x4472('0x38')](_0x2f9183['query'][_0x4472('0x38')]);_0x40a8fb[_0x4472('0x39')]=qs[_0x4472('0x32')](_[_0x4472('0x3a')](_0x2f9183[_0x4472('0x30')],_0x1b4c7f[_0x4472('0x32')]),_0x4e7991);if(_0x2f9183[_0x4472('0x30')][_0x4472('0x3b')]){_0x40a8fb['where']=_['merge'](_0x40a8fb[_0x4472('0x39')],{'$or':_[_0x4472('0x3c')](_0x4e7991,function(_0x31602f){if(_0x31602f[_0x4472('0x2e')]!==_0x4472('0x3d')){var _0x4dccec={};_0x4dccec[_0x31602f[_0x4472('0x2a')]]={'$like':'%'+_0x2f9183['query']['filter']+'%'};return _0x4dccec;}})});}_0x40a8fb=_[_0x4472('0x3e')]({},_0x40a8fb,_0x2f9183[_0x4472('0x3f')]);var _0x3f6e28={'where':_0x40a8fb[_0x4472('0x39')]};return db[_0x4472('0x40')]['count'](_0x3f6e28)[_0x4472('0x25')](function(_0x158800){_0x55d710[_0x4472('0x1e')]=_0x158800;if(_0x2f9183[_0x4472('0x30')][_0x4472('0x41')]){_0x40a8fb[_0x4472('0x42')]=[{'all':!![]}];}return db['Dashboard'][_0x4472('0x43')](_0x40a8fb);})[_0x4472('0x25')](function(_0x44d94d){_0x55d710[_0x4472('0x44')]=_0x44d94d;return _0x55d710;})[_0x4472('0x25')](respondWithFilteredResult(_0x57d352,_0x40a8fb))[_0x4472('0x45')](handleError(_0x57d352,null));};exports[_0x4472('0x46')]=function(_0x1619aa,_0x140dcc){var _0x524f74={'raw':![],'where':{'id':_0x1619aa[_0x4472('0x47')]['id']}},_0x34a1d1={};_0x34a1d1['model']=_['keys'](db[_0x4472('0x40')][_0x4472('0x2d')]);_0x34a1d1['query']=_['keys'](_0x1619aa[_0x4472('0x30')]);_0x34a1d1[_0x4472('0x32')]=_[_0x4472('0x33')](_0x34a1d1['model'],_0x34a1d1['query']);_0x524f74['attributes']=_[_0x4472('0x33')](_0x34a1d1[_0x4472('0x2f')],qs['fields'](_0x1619aa[_0x4472('0x30')][_0x4472('0x35')]));_0x524f74[_0x4472('0x34')]=_0x524f74[_0x4472('0x34')][_0x4472('0x48')]?_0x524f74['attributes']:_0x34a1d1[_0x4472('0x2f')];if(_0x1619aa[_0x4472('0x30')][_0x4472('0x41')]){_0x524f74[_0x4472('0x42')]=[{'all':!![]}];}_0x524f74=_[_0x4472('0x3e')]({},_0x524f74,_0x1619aa['options']);return db['Dashboard'][_0x4472('0x49')](_0x524f74)[_0x4472('0x25')](handleEntityNotFound(_0x140dcc,null))[_0x4472('0x25')](respondWithResult(_0x140dcc,null))[_0x4472('0x45')](handleError(_0x140dcc,null));};exports['create']=function(_0x5904e4,_0x471452){return db['Dashboard'][_0x4472('0x4a')](_0x5904e4['body'],{})['then'](function(_0x4b9f50){var _0x5d852a=_0x5904e4[_0x4472('0x4b')][_0x4472('0x26')]({'plain':!![]});if(!_0x5d852a)throw new Error(_0x4472('0x4c'));if(_0x5d852a[_0x4472('0x4d')]===_0x4472('0x4b')){var _0x3a2af7=_0x4b9f50[_0x4472('0x26')]({'plain':!![]});var _0x18d175=_0x4472('0x27');return db['UserProfileSection']['find']({'where':{'name':_0x18d175,'userProfileId':_0x5d852a[_0x4472('0x4e')]},'raw':!![]})[_0x4472('0x25')](function(_0x30c189){if(_0x30c189&&_0x30c189['autoAssociation']===0x0){return db[_0x4472('0x28')]['create']({'name':_0x3a2af7[_0x4472('0x2a')],'resourceId':_0x3a2af7['id'],'type':_0x30c189['name'],'sectionId':_0x30c189['id']},{})[_0x4472('0x25')](function(){return _0x4b9f50;});}else{return _0x4b9f50;}})['catch'](function(_0xd04054){logger[_0x4472('0x4f')](_0x4472('0x50'),_0xd04054);throw _0xd04054;});}return _0x4b9f50;})[_0x4472('0x25')](respondWithResult(_0x471452,0xc9))['catch'](handleError(_0x471452,null));};exports['clone']=function(_0x20fc44,_0x3c35a7){var _0x59f27c={'where':{'id':_0x20fc44[_0x4472('0x47')]['id']}},_0x4cc4be={};_0x4cc4be[_0x4472('0x2f')]=_[_0x4472('0x31')](db['Dashboard']['rawAttributes']);_0x59f27c[_0x4472('0x34')]=_[_0x4472('0x33')](_0x4cc4be['model'],qs[_0x4472('0x35')](_0x20fc44[_0x4472('0x30')][_0x4472('0x35')]));_0x59f27c[_0x4472('0x34')]=_0x59f27c[_0x4472('0x34')][_0x4472('0x48')]?_0x59f27c[_0x4472('0x34')]:_0x4cc4be[_0x4472('0x2f')];if(_0x20fc44[_0x4472('0x30')][_0x4472('0x41')]){_0x59f27c[_0x4472('0x42')]=[{'all':!![]}];}_0x59f27c=_['merge']({},_0x59f27c,_0x20fc44[_0x4472('0x3f')]);return db['Dashboard'][_0x4472('0x49')](_0x59f27c)[_0x4472('0x25')](handleEntityNotFound(_0x3c35a7,null))[_0x4472('0x25')](function(_0x4806b8){if(_0x4806b8){var _0x5be669=_0x4806b8['get']({'plain':!![]});_0x5be669=qs[_0x4472('0x51')](_0x5be669,['id',_0x4472('0x52'),'updatedAt']);_0x20fc44[_0x4472('0x53')]=_[_0x4472('0x51')](_0x20fc44[_0x4472('0x53')],['id','createdAt',_0x4472('0x54')]);return db[_0x4472('0x40')]['create'](_['merge'](_0x5be669,_0x20fc44['body']),{'include':_0x20fc44[_0x4472('0x30')]['includeAll']?[{'all':!![]}]:undefined})[_0x4472('0x25')](function(_0x3cbf61){var _0x54564b=_0x20fc44[_0x4472('0x4b')][_0x4472('0x26')]({'plain':!![]});if(!_0x54564b)throw new Error(_0x4472('0x4c'));if(_0x54564b[_0x4472('0x4d')]===_0x4472('0x4b')){var _0x5610bf=_0x3cbf61['get']({'plain':!![]});var _0x485fff='CustomDashboards';return db['UserProfileSection'][_0x4472('0x49')]({'where':{'name':_0x485fff,'userProfileId':_0x54564b['userProfileId']},'raw':!![]})['then'](function(_0x6ea8aa){if(_0x6ea8aa&&_0x6ea8aa['autoAssociation']===0x0){return db['UserProfileResource'][_0x4472('0x4a')]({'name':_0x5610bf[_0x4472('0x2a')],'resourceId':_0x5610bf['id'],'type':_0x6ea8aa[_0x4472('0x2a')],'sectionId':_0x6ea8aa['id']},{})[_0x4472('0x25')](function(){return _0x3cbf61;});}else{return _0x3cbf61;}})[_0x4472('0x45')](function(_0x50611d){logger[_0x4472('0x4f')](_0x4472('0x50'),_0x50611d);throw _0x50611d;});}return _0x3cbf61;});}})[_0x4472('0x25')](respondWithResult(_0x3c35a7,0xc9))[_0x4472('0x45')](handleError(_0x3c35a7,null));};exports[_0x4472('0x23')]=function(_0x2fa0b2,_0x18af90){if(_0x2fa0b2[_0x4472('0x53')]['id']){delete _0x2fa0b2[_0x4472('0x53')]['id'];}return db[_0x4472('0x40')]['find']({'where':{'id':_0x2fa0b2[_0x4472('0x47')]['id']}})[_0x4472('0x25')](handleEntityNotFound(_0x18af90,null))[_0x4472('0x25')](saveUpdates(_0x2fa0b2[_0x4472('0x53')],null))[_0x4472('0x25')](respondWithResult(_0x18af90,null))[_0x4472('0x45')](handleError(_0x18af90,null));};exports[_0x4472('0x24')]=function(_0x5b7c97,_0x2f73a6){return db['Dashboard'][_0x4472('0x49')]({'where':{'id':_0x5b7c97[_0x4472('0x47')]['id']}})[_0x4472('0x25')](handleEntityNotFound(_0x2f73a6,null))[_0x4472('0x25')](removeEntity(_0x2f73a6,null))['catch'](handleError(_0x2f73a6,null));};function widgetAttributes(_0x8f6339){try{switch(_0x8f6339[_0x4472('0x2e')]){case _0x4472('0x55'):return[{'name':_0x4472('0x56'),'value':_0x8f6339[_0x4472('0x56')]||(_0x8f6339[_0x4472('0x57')]&&_0x8f6339[_0x4472('0x57')][0x0]?_0x8f6339[_0x4472('0x57')][0x0][_0x4472('0x58')]:undefined)||_0x4472('0x59')}];case'custom':return[{'name':'attrPath','value':_0x8f6339[_0x4472('0x5a')]||(_0x8f6339['attrs']&&_0x8f6339[_0x4472('0x57')][0x0]?_0x8f6339[_0x4472('0x57')][0x0][_0x4472('0x58')]:undefined)||''}];case'clock':return[{'name':_0x4472('0x5b'),'value':_0x8f6339[_0x4472('0x5b')]||(_0x8f6339[_0x4472('0x57')]&&_0x8f6339[_0x4472('0x57')][0x0]?_0x8f6339[_0x4472('0x57')][0x0][_0x4472('0x58')]:undefined)||_0x4472('0x5c')},{'name':_0x4472('0x5d'),'value':_0x8f6339[_0x4472('0x5d')]||(_0x8f6339[_0x4472('0x57')]&&_0x8f6339[_0x4472('0x57')][0x1]?_0x8f6339[_0x4472('0x57')][0x1][_0x4472('0x58')]:undefined)||_0x4472('0x5e')},{'name':_0x4472('0x5f'),'value':_0x8f6339[_0x4472('0x5f')]||(_0x8f6339['attrs']&&_0x8f6339[_0x4472('0x57')][0x2]?_0x8f6339[_0x4472('0x57')][0x2][_0x4472('0x58')]:undefined)||0xc}];case _0x4472('0x60'):return[{'name':_0x4472('0x61'),'value':_0x8f6339[_0x4472('0x61')]||(_0x8f6339[_0x4472('0x57')]&&_0x8f6339[_0x4472('0x57')][0x0]?_0x8f6339[_0x4472('0x57')][0x0][_0x4472('0x58')]:undefined)||'total'},{'name':_0x4472('0x62'),'value':_0x8f6339[_0x4472('0x62')]||(_0x8f6339[_0x4472('0x57')]&&_0x8f6339[_0x4472('0x57')][0x1]?_0x8f6339[_0x4472('0x57')][0x1][_0x4472('0x58')]:undefined)||[]},{'name':_0x4472('0x5f'),'value':_0x8f6339[_0x4472('0x5f')]||(_0x8f6339['attrs']&&_0x8f6339['attrs'][0x2]?_0x8f6339['attrs'][0x2][_0x4472('0x58')]:undefined)||0x14},{'name':_0x4472('0x63'),'value':_0x8f6339['attrChannel']||(_0x8f6339[_0x4472('0x57')]&&_0x8f6339[_0x4472('0x57')][0x3]?_0x8f6339[_0x4472('0x57')][0x3][_0x4472('0x58')]:undefined)||_0x4472('0x64')},{'name':_0x4472('0x65'),'value':_0x8f6339[_0x4472('0x65')]||(_0x8f6339['attrs']&&_0x8f6339[_0x4472('0x57')][0x4]?_0x8f6339['attrs'][0x4]['value']:undefined)||''},{'name':'attrFaxAccounts','value':_0x8f6339[_0x4472('0x66')]||(_0x8f6339[_0x4472('0x57')]&&_0x8f6339[_0x4472('0x57')][0x5]?_0x8f6339[_0x4472('0x57')][0x5][_0x4472('0x58')]:undefined)||''},{'name':_0x4472('0x67'),'value':_0x8f6339[_0x4472('0x67')]||(_0x8f6339[_0x4472('0x57')]&&_0x8f6339[_0x4472('0x57')][0x6]?_0x8f6339[_0x4472('0x57')][0x6][_0x4472('0x58')]:undefined)||''},{'name':'attrOpenchannelAccounts','value':_0x8f6339[_0x4472('0x68')]||(_0x8f6339['attrs']&&_0x8f6339['attrs'][0x7]?_0x8f6339[_0x4472('0x57')][0x7][_0x4472('0x58')]:undefined)||''},{'name':_0x4472('0x69'),'value':_0x8f6339['attrWhatsappAccounts']||(_0x8f6339['attrs']&&_0x8f6339[_0x4472('0x57')][0x8]?_0x8f6339['attrs'][0x8][_0x4472('0x58')]:undefined)||''},{'name':_0x4472('0x6a'),'value':_0x8f6339[_0x4472('0x6a')]||(_0x8f6339['attrs']&&_0x8f6339[_0x4472('0x57')][0x9]?_0x8f6339[_0x4472('0x57')][0x9][_0x4472('0x58')]:undefined)||''}];case _0x4472('0x6b'):case'pie-chart':return[{'name':_0x4472('0x6c'),'value':_0x8f6339[_0x4472('0x6c')]||(_0x8f6339[_0x4472('0x57')]&&_0x8f6339[_0x4472('0x57')][0x0]?_0x8f6339['attrs'][0x0]['value']:undefined)||'total'},{'name':_0x4472('0x6d'),'value':_0x8f6339[_0x4472('0x6d')]||(_0x8f6339['attrs']&&_0x8f6339[_0x4472('0x57')][0x1]?_0x8f6339[_0x4472('0x57')][0x1][_0x4472('0x58')]:undefined)||null},{'name':_0x4472('0x6e'),'value':_0x8f6339[_0x4472('0x6e')]||(_0x8f6339[_0x4472('0x57')]&&_0x8f6339['attrs'][0x2]?_0x8f6339['attrs'][0x2][_0x4472('0x58')]:undefined)||null},{'name':'attrVoiceQueues','value':_0x8f6339[_0x4472('0x62')]||(_0x8f6339[_0x4472('0x57')]&&_0x8f6339['attrs'][0x3]?_0x8f6339[_0x4472('0x57')][0x3][_0x4472('0x58')]:undefined)||[]},{'name':_0x4472('0x63'),'value':_0x8f6339[_0x4472('0x63')]||(_0x8f6339[_0x4472('0x57')]&&_0x8f6339[_0x4472('0x57')][0x4]?_0x8f6339[_0x4472('0x57')][0x4][_0x4472('0x58')]:undefined)||'voice'},{'name':'attrEmailAccounts','value':_0x8f6339[_0x4472('0x65')]||(_0x8f6339[_0x4472('0x57')]&&_0x8f6339[_0x4472('0x57')][0x5]?_0x8f6339[_0x4472('0x57')][0x5][_0x4472('0x58')]:undefined)||''},{'name':_0x4472('0x66'),'value':_0x8f6339[_0x4472('0x66')]||(_0x8f6339['attrs']&&_0x8f6339[_0x4472('0x57')][0x6]?_0x8f6339[_0x4472('0x57')][0x6][_0x4472('0x58')]:undefined)||''},{'name':'attrSmsAccounts','value':_0x8f6339['attrSmsAccounts']||(_0x8f6339['attrs']&&_0x8f6339['attrs'][0x7]?_0x8f6339['attrs'][0x7]['value']:undefined)||''},{'name':'attrOpenchannelAccounts','value':_0x8f6339[_0x4472('0x68')]||(_0x8f6339['attrs']&&_0x8f6339[_0x4472('0x57')][0x8]?_0x8f6339[_0x4472('0x57')][0x8][_0x4472('0x58')]:undefined)||''},{'name':_0x4472('0x69'),'value':_0x8f6339[_0x4472('0x69')]||(_0x8f6339['attrs']&&_0x8f6339[_0x4472('0x57')][0x9]?_0x8f6339['attrs'][0x9]['value']:undefined)||''},{'name':'attrChatWebsites','value':_0x8f6339[_0x4472('0x6a')]||(_0x8f6339[_0x4472('0x57')]&&_0x8f6339['attrs'][0xa]?_0x8f6339[_0x4472('0x57')][0xa][_0x4472('0x58')]:undefined)||''}];case _0x4472('0x6f'):return[{'name':_0x4472('0x70'),'type':_0x8f6339['reportType']||(_0x8f6339[_0x4472('0x57')]&&_0x8f6339[_0x4472('0x57')][0x0]?_0x8f6339[_0x4472('0x57')][0x0][_0x4472('0x2e')]:undefined)||null,'value':_0x8f6339[_0x4472('0x70')]||(_0x8f6339[_0x4472('0x57')]&&_0x8f6339['attrs'][0x0]?_0x8f6339[_0x4472('0x57')][0x0][_0x4472('0x58')]:undefined)||null},{'name':_0x4472('0x71'),'value':_0x8f6339[_0x4472('0x71')]||(_0x8f6339[_0x4472('0x57')]&&_0x8f6339[_0x4472('0x57')][0x1]?_0x8f6339[_0x4472('0x57')][0x1][_0x4472('0x58')]:undefined)||0x0}];default:return[];}}catch(_0x40e54c){logger[_0x4472('0x4f')](_0x4472('0x72'),JSON[_0x4472('0x73')](_0x40e54c));return[];}}exports[_0x4472('0x74')]=function(_0x34f06e,_0x4565c5,_0x36ce1c){if(_0x34f06e[_0x4472('0x53')]['id']){delete _0x34f06e[_0x4472('0x53')]['id'];}return db[_0x4472('0x40')][_0x4472('0x49')]({'where':{'id':_0x34f06e['params']['id']}})['then'](handleEntityNotFound(_0x4565c5,null))[_0x4472('0x25')](function(_0x4c2109){if(_0x4c2109){_0x34f06e[_0x4472('0x53')][_0x4472('0x75')]=_0x4c2109['id'];_0x34f06e[_0x4472('0x53')][_0x4472('0x57')]=widgetAttributes(_0x34f06e['body']);return db[_0x4472('0x76')]['create'](_0x34f06e[_0x4472('0x53')]);}})[_0x4472('0x25')](respondWithResult(_0x4565c5,null))[_0x4472('0x45')](handleError(_0x4565c5,null));};exports[_0x4472('0x77')]=function(_0x160e36,_0x5ec5e8,_0x3027a6){var _0x4eff99={};var _0x482dbc={};var _0x4d1e20;var _0x5320ad;return db[_0x4472('0x40')][_0x4472('0x78')]({'where':{'id':_0x160e36[_0x4472('0x47')]['id']}})[_0x4472('0x25')](handleEntityNotFound(_0x5ec5e8,null))[_0x4472('0x25')](function(_0x51d991){if(_0x51d991){_0x4d1e20=_0x51d991;_0x482dbc[_0x4472('0x2f')]=_[_0x4472('0x31')](db[_0x4472('0x76')][_0x4472('0x2d')]);_0x482dbc[_0x4472('0x30')]=_[_0x4472('0x31')](_0x160e36[_0x4472('0x30')]);_0x482dbc[_0x4472('0x32')]=_['intersection'](_0x482dbc[_0x4472('0x2f')],_0x482dbc[_0x4472('0x30')]);_0x4eff99[_0x4472('0x34')]=_[_0x4472('0x33')](_0x482dbc[_0x4472('0x2f')],qs['fields'](_0x160e36[_0x4472('0x30')]['fields']));_0x4eff99[_0x4472('0x34')]=_0x4eff99[_0x4472('0x34')][_0x4472('0x48')]?_0x4eff99[_0x4472('0x34')]:_0x482dbc[_0x4472('0x2f')];_0x4eff99[_0x4472('0x37')]=qs[_0x4472('0x38')](_0x160e36[_0x4472('0x30')]['sort']);_0x4eff99['where']=qs[_0x4472('0x32')](_['pick'](_0x160e36['query'],_0x482dbc[_0x4472('0x32')]));if(_0x160e36['query']['filter']){_0x4eff99[_0x4472('0x39')]=_[_0x4472('0x3e')](_0x4eff99[_0x4472('0x39')],{'$or':_['map'](_0x4eff99[_0x4472('0x34')],function(_0xc3e2e9){var _0x3476c0={};_0x3476c0[_0xc3e2e9]={'$like':'%'+_0x160e36['query']['filter']+'%'};return _0x3476c0;})});}_0x4eff99=_[_0x4472('0x3e')]({},_0x4eff99,_0x160e36['options']);return _0x4d1e20[_0x4472('0x77')](_0x4eff99);}})[_0x4472('0x25')](function(_0x42d773){if(_0x42d773){_0x5320ad=_0x42d773[_0x4472('0x48')];if(!_0x160e36['query']['hasOwnProperty'](_0x4472('0x79'))){_0x4eff99[_0x4472('0x1f')]=qs['limit'](_0x160e36[_0x4472('0x30')][_0x4472('0x1f')]);_0x4eff99[_0x4472('0x1c')]=qs[_0x4472('0x1c')](_0x160e36[_0x4472('0x30')]['offset']);}return _0x4d1e20['getItems'](_0x4eff99);}})[_0x4472('0x25')](function(_0xd93a8d){if(_0xd93a8d){return _0xd93a8d?{'count':_0x5320ad,'rows':_0xd93a8d}:null;}})['then'](respondWithResult(_0x5ec5e8,null))[_0x4472('0x45')](handleError(_0x5ec5e8,null));};