Built motion from commit 85328c08.|2.5.50
[motion2.git] / server / api / userProfile / userProfile.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 _0xc224=['../../config/utils','../../config/license/util','redis','localhost','socket.io-emitter','./userProfile.socket','sendStatus','status','json','offset','limit','count','Content-Range','apply','reject','save','update','then','destroy','end','error','stack','name','send','index','UserProfile','rawAttributes','fieldName','type','key','model','map','query','keys','attributes','intersection','fields','hasOwnProperty','nolimit','order','sort','where','filters','filter','merge','VIRTUAL','includeAll','include','findAll','rows','catch','show','params','length','options','create','find','omit','createdAt','body','updatedAt','sequelize','transaction','get','autoAssociation','sectionId','userProfileId','Resources','UserProfileSection','describe','addSections','UserProfileResource','removeSections','getSections','enabled','isEmpty','includes','subsections','push','findOne','Dashboard','forEach','resourceId','Plugin','addResources','bulkCreate','removeResources','ids','getResources','section','Missing\x20section\x20parameter','No\x20User\x20Profile\x20found\x20for\x20id\x20','eml-format','rimraf','zip-dir','request-promise','moment','bluebird','mustache','util','path','sox','to-csv','squel','crypto','jsforce','desk.js','querystring','papaparse','../../components/auth/service','../../components/parsers/qs','../../config/logger','api'];(function(_0x342476,_0x57cb9f){var _0x27a83c=function(_0x3dd92f){while(--_0x3dd92f){_0x342476['push'](_0x342476['shift']());}};_0x27a83c(++_0x57cb9f);}(_0xc224,0x1af));var _0x4c22=function(_0x52386c,_0x32793d){_0x52386c=_0x52386c-0x0;var _0x1efe96=_0xc224[_0x52386c];return _0x1efe96;};'use strict';var emlformat=require(_0x4c22('0x0'));var rimraf=require(_0x4c22('0x1'));var zipdir=require(_0x4c22('0x2'));var jsonpatch=require('fast-json-patch');var rp=require(_0x4c22('0x3'));var moment=require(_0x4c22('0x4'));var BPromise=require(_0x4c22('0x5'));var Mustache=require(_0x4c22('0x6'));var util=require(_0x4c22('0x7'));var path=require(_0x4c22('0x8'));var sox=require(_0x4c22('0x9'));var csv=require(_0x4c22('0xa'));var ejs=require('ejs');var fs=require('fs');var fs_extra=require('fs-extra');var _=require('lodash');var squel=require(_0x4c22('0xb'));var crypto=require(_0x4c22('0xc'));var jsforce=require(_0x4c22('0xd'));var deskjs=require(_0x4c22('0xe'));var toCsv=require(_0x4c22('0xa'));var querystring=require(_0x4c22('0xf'));var Papa=require(_0x4c22('0x10'));var Redis=require('ioredis');var authService=require(_0x4c22('0x11'));var qs=require(_0x4c22('0x12'));var as=require('../../components/parsers/advancedSearch');var hardwareService=require('../../config/license/hardware');var logger=require(_0x4c22('0x13'))(_0x4c22('0x14'));var utils=require(_0x4c22('0x15'));var config=require('../../config/environment');var licenseUtil=require(_0x4c22('0x16'));var db=require('../../mysqldb')['db'];config['redis']=_['defaults'](config[_0x4c22('0x17')],{'host':_0x4c22('0x18'),'port':0x18eb});var socket=require(_0x4c22('0x19'))(new Redis(config[_0x4c22('0x17')]));require(_0x4c22('0x1a'))['register'](socket);function respondWithStatusCode(_0x284441,_0xcbc9cc){_0xcbc9cc=_0xcbc9cc||0xcc;return function(_0x373421){if(_0x373421){return _0x284441[_0x4c22('0x1b')](_0xcbc9cc);}return _0x284441[_0x4c22('0x1c')](_0xcbc9cc)['end']();};}function respondWithResult(_0x517d9a,_0xf562f8){_0xf562f8=_0xf562f8||0xc8;return function(_0x3617b2){if(_0x3617b2){return _0x517d9a[_0x4c22('0x1c')](_0xf562f8)[_0x4c22('0x1d')](_0x3617b2);}};}function respondWithFilteredResult(_0x32a9c4,_0x20b4db){return function(_0x408f6f){if(_0x408f6f){var _0x1577c6=typeof _0x20b4db[_0x4c22('0x1e')]==='undefined'&&typeof _0x20b4db[_0x4c22('0x1f')]==='undefined';var _0x5bce40=_0x408f6f[_0x4c22('0x20')];var _0x432f4d=_0x1577c6?0x0:_0x20b4db[_0x4c22('0x1e')];var _0x162502=_0x1577c6?_0x408f6f[_0x4c22('0x20')]:_0x20b4db[_0x4c22('0x1e')]+_0x20b4db['limit'];var _0x152923;if(_0x162502>=_0x5bce40){_0x162502=_0x5bce40;_0x152923=0xc8;}else{_0x152923=0xce;}_0x32a9c4['status'](_0x152923);return _0x32a9c4['set'](_0x4c22('0x21'),_0x432f4d+'-'+_0x162502+'/'+_0x5bce40)[_0x4c22('0x1d')](_0x408f6f);}return null;};}function patchUpdates(_0x3eda16){return function(_0xcdbded){try{jsonpatch[_0x4c22('0x22')](_0xcdbded,_0x3eda16,!![]);}catch(_0x45cba2){return BPromise[_0x4c22('0x23')](_0x45cba2);}return _0xcdbded[_0x4c22('0x24')]();};}function saveUpdates(_0x29aedf,_0x3ae915){return function(_0x33d48c){if(_0x33d48c){return _0x33d48c[_0x4c22('0x25')](_0x29aedf)[_0x4c22('0x26')](function(_0x2fa3d8){return _0x2fa3d8;});}return null;};}function removeEntity(_0x365856,_0x47ec7f){return function(_0x2a0607){if(_0x2a0607){return _0x2a0607[_0x4c22('0x27')]()['then'](function(){_0x365856[_0x4c22('0x1c')](0xcc)[_0x4c22('0x28')]();});}};}function handleEntityNotFound(_0x59091f,_0x3569a7){return function(_0x2d5d49){if(!_0x2d5d49){_0x59091f[_0x4c22('0x1b')](0x194);}return _0x2d5d49;};}function handleError(_0x39bbe4,_0x49193f){_0x49193f=_0x49193f||0x1f4;return function(_0x2de117){logger[_0x4c22('0x29')](_0x2de117[_0x4c22('0x2a')]);if(_0x2de117['name']){delete _0x2de117[_0x4c22('0x2b')];}_0x39bbe4[_0x4c22('0x1c')](_0x49193f)[_0x4c22('0x2c')](_0x2de117);};}exports[_0x4c22('0x2d')]=function(_0x2ec214,_0x875822){var _0x47fa82={},_0x1ad5e8={},_0x4d10bd={'count':0x0,'rows':[]};var _0x4f4d67=_['map'](db[_0x4c22('0x2e')][_0x4c22('0x2f')],function(_0x223d6a){return{'name':_0x223d6a[_0x4c22('0x30')],'type':_0x223d6a[_0x4c22('0x31')][_0x4c22('0x32')]};});_0x1ad5e8[_0x4c22('0x33')]=_[_0x4c22('0x34')](_0x4f4d67,_0x4c22('0x2b'));_0x1ad5e8[_0x4c22('0x35')]=_[_0x4c22('0x36')](_0x2ec214[_0x4c22('0x35')]);_0x1ad5e8['filters']=_['intersection'](_0x1ad5e8[_0x4c22('0x33')],_0x1ad5e8[_0x4c22('0x35')]);_0x47fa82[_0x4c22('0x37')]=_[_0x4c22('0x38')](_0x1ad5e8[_0x4c22('0x33')],qs[_0x4c22('0x39')](_0x2ec214[_0x4c22('0x35')][_0x4c22('0x39')]));_0x47fa82['attributes']=_0x47fa82['attributes']['length']?_0x47fa82['attributes']:_0x1ad5e8[_0x4c22('0x33')];if(!_0x2ec214[_0x4c22('0x35')][_0x4c22('0x3a')](_0x4c22('0x3b'))){_0x47fa82[_0x4c22('0x1f')]=qs['limit'](_0x2ec214[_0x4c22('0x35')]['limit']);_0x47fa82[_0x4c22('0x1e')]=qs[_0x4c22('0x1e')](_0x2ec214[_0x4c22('0x35')][_0x4c22('0x1e')]);}_0x47fa82[_0x4c22('0x3c')]=qs[_0x4c22('0x3d')](_0x2ec214[_0x4c22('0x35')][_0x4c22('0x3d')]);_0x47fa82[_0x4c22('0x3e')]=qs[_0x4c22('0x3f')](_['pick'](_0x2ec214[_0x4c22('0x35')],_0x1ad5e8[_0x4c22('0x3f')]),_0x4f4d67);if(_0x2ec214[_0x4c22('0x35')][_0x4c22('0x40')]){_0x47fa82[_0x4c22('0x3e')]=_[_0x4c22('0x41')](_0x47fa82[_0x4c22('0x3e')],{'$or':_[_0x4c22('0x34')](_0x4f4d67,function(_0x39f218){if(_0x39f218['type']!==_0x4c22('0x42')){var _0x243351={};_0x243351[_0x39f218[_0x4c22('0x2b')]]={'$like':'%'+_0x2ec214[_0x4c22('0x35')]['filter']+'%'};return _0x243351;}})});}_0x47fa82=_[_0x4c22('0x41')]({},_0x47fa82,_0x2ec214['options']);var _0x50be05={'where':_0x47fa82[_0x4c22('0x3e')]};return db[_0x4c22('0x2e')][_0x4c22('0x20')](_0x50be05)[_0x4c22('0x26')](function(_0x1afb4b){_0x4d10bd[_0x4c22('0x20')]=_0x1afb4b;if(_0x2ec214['query'][_0x4c22('0x43')]){_0x47fa82[_0x4c22('0x44')]=[{'all':!![]}];}return db[_0x4c22('0x2e')][_0x4c22('0x45')](_0x47fa82);})['then'](function(_0x575bbb){_0x4d10bd[_0x4c22('0x46')]=_0x575bbb;return _0x4d10bd;})['then'](respondWithFilteredResult(_0x875822,_0x47fa82))[_0x4c22('0x47')](handleError(_0x875822,null));};exports[_0x4c22('0x48')]=function(_0x5e1bde,_0x5c6a84){var _0x25f64a={'raw':![],'where':{'id':_0x5e1bde[_0x4c22('0x49')]['id']}},_0x531e84={};_0x531e84[_0x4c22('0x33')]=_['keys'](db[_0x4c22('0x2e')][_0x4c22('0x2f')]);_0x531e84[_0x4c22('0x35')]=_[_0x4c22('0x36')](_0x5e1bde['query']);_0x531e84[_0x4c22('0x3f')]=_['intersection'](_0x531e84[_0x4c22('0x33')],_0x531e84[_0x4c22('0x35')]);_0x25f64a[_0x4c22('0x37')]=_['intersection'](_0x531e84[_0x4c22('0x33')],qs[_0x4c22('0x39')](_0x5e1bde['query'][_0x4c22('0x39')]));_0x25f64a['attributes']=_0x25f64a[_0x4c22('0x37')][_0x4c22('0x4a')]?_0x25f64a[_0x4c22('0x37')]:_0x531e84[_0x4c22('0x33')];if(_0x5e1bde[_0x4c22('0x35')]['includeAll']){_0x25f64a[_0x4c22('0x44')]=[{'all':!![]}];}_0x25f64a=_[_0x4c22('0x41')]({},_0x25f64a,_0x5e1bde[_0x4c22('0x4b')]);return db['UserProfile']['find'](_0x25f64a)[_0x4c22('0x26')](handleEntityNotFound(_0x5c6a84,null))['then'](respondWithResult(_0x5c6a84,null))[_0x4c22('0x47')](handleError(_0x5c6a84,null));};exports[_0x4c22('0x4c')]=function(_0xcd0034,_0x5e4802){return db[_0x4c22('0x2e')]['create'](_0xcd0034['body'],{})[_0x4c22('0x26')](respondWithResult(_0x5e4802,0xc9))[_0x4c22('0x47')](handleError(_0x5e4802,null));};exports['clone']=function(_0x111a5f,_0x1f6b7f){var _0x85a458={'where':{'id':_0x111a5f['params']['id']}},_0xc56aee={};_0xc56aee[_0x4c22('0x33')]=_[_0x4c22('0x36')](db[_0x4c22('0x2e')][_0x4c22('0x2f')]);_0x85a458[_0x4c22('0x37')]=_[_0x4c22('0x38')](_0xc56aee[_0x4c22('0x33')],qs['fields'](_0x111a5f[_0x4c22('0x35')][_0x4c22('0x39')]));_0x85a458[_0x4c22('0x37')]=_0x85a458[_0x4c22('0x37')][_0x4c22('0x4a')]?_0x85a458['attributes']:_0xc56aee[_0x4c22('0x33')];if(_0x111a5f['query'][_0x4c22('0x43')]){_0x85a458['include']=[{'all':!![]}];}_0x85a458=_[_0x4c22('0x41')]({},_0x85a458,_0x111a5f[_0x4c22('0x4b')]);return db['UserProfile'][_0x4c22('0x4d')](_0x85a458)[_0x4c22('0x26')](handleEntityNotFound(_0x1f6b7f,null))[_0x4c22('0x26')](function(_0x3da1ce){if(_0x3da1ce){var _0x4e3e85=_0x3da1ce['get']({'plain':!![]});_0x4e3e85=qs[_0x4c22('0x4e')](_0x4e3e85,['id',_0x4c22('0x4f'),'updatedAt','crudPermissions']);_0x111a5f[_0x4c22('0x50')]=_[_0x4c22('0x4e')](_0x111a5f['body'],['id',_0x4c22('0x4f'),_0x4c22('0x51')]);return db[_0x4c22('0x52')][_0x4c22('0x53')](function(_0x18c7d0){return db[_0x4c22('0x2e')][_0x4c22('0x4c')](_['merge'](_0x4e3e85,_0x111a5f[_0x4c22('0x50')]),{'include':_0x111a5f[_0x4c22('0x35')][_0x4c22('0x43')]?[{'all':!![]}]:undefined,'transaction':_0x18c7d0})[_0x4c22('0x26')](function(_0x58e18b){var _0x2bb2de=_0x58e18b[_0x4c22('0x54')]({'plain':!![]});return db['UserProfileSection'][_0x4c22('0x45')]({'where':{'userProfileId':_0x111a5f[_0x4c22('0x49')]['id']},'raw':!![]})[_0x4c22('0x26')](function(_0x18d510){if(_0x18d510){return BPromise['each'](_0x18d510,function(_0x32fbdc){return new BPromise(function(_0x590b34,_0x2aaa1d){if(_0x32fbdc[_0x4c22('0x55')]===null||_0x32fbdc[_0x4c22('0x55')]===0x1)_0x590b34(null);return db['UserProfileResource'][_0x4c22('0x45')]({'where':{'sectionId':_0x32fbdc['id']},'raw':!![]})[_0x4c22('0x26')](function(_0x266005){var _0x389eb6=_[_0x4c22('0x34')](_0x266005,function(_0x592123){return qs[_0x4c22('0x4e')](_0x592123,['id',_0x4c22('0x4f'),'updatedAt',_0x4c22('0x56')]);});_0x590b34(_0x389eb6);})['catch'](function(_0x10aacd){_0x2aaa1d(_0x10aacd);});})[_0x4c22('0x26')](function(_0x30793f){var _0x384bfe=qs['omit'](_0x32fbdc,['id',_0x4c22('0x4f'),_0x4c22('0x51')]);_0x384bfe[_0x4c22('0x57')]=_0x2bb2de['id'];if(_0x30793f)_0x384bfe[_0x4c22('0x58')]=_0x30793f;return _0x384bfe;})[_0x4c22('0x26')](function(_0x3d6e10){return db[_0x4c22('0x59')][_0x4c22('0x4c')](_0x3d6e10,{'include':[{'model':db['UserProfileResource'],'as':_0x4c22('0x58')}],'raw':!![],'transaction':_0x18c7d0});});})['then'](function(){return _0x2bb2de;});}});});});}})['then'](respondWithResult(_0x1f6b7f,0xc9))[_0x4c22('0x47')](handleError(_0x1f6b7f,null));};exports[_0x4c22('0x25')]=function(_0xe26e6,_0x4f3b87){if(_0xe26e6['body']['id']){delete _0xe26e6[_0x4c22('0x50')]['id'];}return db[_0x4c22('0x2e')]['find']({'where':{'id':_0xe26e6[_0x4c22('0x49')]['id']}})[_0x4c22('0x26')](handleEntityNotFound(_0x4f3b87,null))['then'](saveUpdates(_0xe26e6['body'],null))[_0x4c22('0x26')](respondWithResult(_0x4f3b87,null))[_0x4c22('0x47')](handleError(_0x4f3b87,null));};exports[_0x4c22('0x27')]=function(_0x4abd0e,_0x4a4f3f){return db[_0x4c22('0x2e')][_0x4c22('0x4d')]({'where':{'id':_0x4abd0e[_0x4c22('0x49')]['id']}})['then'](handleEntityNotFound(_0x4a4f3f,null))[_0x4c22('0x26')](removeEntity(_0x4a4f3f,null))[_0x4c22('0x47')](handleError(_0x4a4f3f,null));};exports[_0x4c22('0x5a')]=function(_0x41c32b,_0x2bbec3){return db[_0x4c22('0x2e')][_0x4c22('0x5a')]()[_0x4c22('0x26')](respondWithResult(_0x2bbec3,null))[_0x4c22('0x47')](handleError(_0x2bbec3,null));};exports[_0x4c22('0x5b')]=function(_0x46a3ed,_0x1a62b6){var _0x483528=_0x46a3ed[_0x4c22('0x50')];return db['UserProfile'][_0x4c22('0x4d')]({'where':{'id':_0x46a3ed[_0x4c22('0x49')]['id']}})[_0x4c22('0x26')](handleEntityNotFound(_0x1a62b6,null))['then'](function(_0x3b6b7f){if(_0x3b6b7f){return db[_0x4c22('0x52')][_0x4c22('0x53')](function(_0x526fe6){return db[_0x4c22('0x59')][_0x4c22('0x27')]({'where':{'userProfileId':_0x46a3ed[_0x4c22('0x49')]['id'],'sectionId':_[_0x4c22('0x34')](_0x483528,function(_0x125c81){return _0x125c81[_0x4c22('0x56')];})},'transaction':_0x526fe6})['then'](function(){var _0x1ff27d=_['map'](_0x483528,function(_0x4be5f3){_0x4be5f3[_0x4c22('0x57')]=_0x46a3ed[_0x4c22('0x49')]['id'];return _0x4be5f3;});var _0x4a1c94=[];return BPromise['each'](_0x1ff27d,function(_0x2bef03){return db[_0x4c22('0x59')]['create'](_0x2bef03,{'include':[{'model':db[_0x4c22('0x5c')],'as':'Resources'}],'raw':!![],'transaction':_0x526fe6})[_0x4c22('0x26')](function(_0x5b61ca){_0x4a1c94['push'](_0x5b61ca['get']({'plain':!![]}));});})[_0x4c22('0x26')](function(){return _0x4a1c94;});});});}})['then'](function(_0x275c4e){return _0x275c4e;})['then'](respondWithResult(_0x1a62b6,null))[_0x4c22('0x47')](handleError(_0x1a62b6,null));};exports[_0x4c22('0x5d')]=function(_0x50b407,_0x95606a){var _0x345acc;return db[_0x4c22('0x2e')]['find']({'where':{'id':_0x50b407[_0x4c22('0x49')]['id']},'attributes':['id',_0x4c22('0x2b')]})[_0x4c22('0x26')](handleEntityNotFound(_0x95606a,null))[_0x4c22('0x26')](function(_0x4f118b){if(_0x4f118b){_0x345acc=_0x4f118b;return db['UserProfileSection'][_0x4c22('0x27')]({'where':{'userProfileId':_0x50b407['params']['id'],'sectionId':_0x50b407[_0x4c22('0x35')]['ids']}});}})[_0x4c22('0x26')](function(){return _0x345acc;})[_0x4c22('0x26')](respondWithStatusCode(_0x95606a,null))[_0x4c22('0x47')](handleError(_0x95606a,null));};exports[_0x4c22('0x5e')]=function(_0x64271b,_0x1058eb){var _0x5295e8=[];var _0x5073a7=[];return db[_0x4c22('0x59')]['findAll']({'where':{'userProfileId':_0x64271b['params']['id']},'raw':!![]})[_0x4c22('0x26')](function(_0x389e2a){_0x5295e8=_[_0x4c22('0x40')](_0x389e2a,function(_0x22c778){return _0x22c778[_0x4c22('0x5f')]===0x1||_['includes']([0x3eb,0x709],_0x22c778[_0x4c22('0x56')]);});if(!_[_0x4c22('0x60')](_0x5295e8)){return _[_0x4c22('0x34')](_0x5295e8,function(_0x1db65f){return _0x1db65f[_0x4c22('0x56')];});}else{return;}})['then'](function(_0x461e4a){if(_0x461e4a)_0x5073a7=_0x461e4a;if(_[_0x4c22('0x61')](_0x5073a7,0x64)){var _0x2c77f2=_['find'](_0x5295e8,{'sectionId':0x64});return hasDefaultDashboard(_0x2c77f2)[_0x4c22('0x26')](function(_0x51be51){return _[_0x4c22('0x34')](_0x5295e8,function(_0x5a9306){if(_0x5a9306[_0x4c22('0x56')]===0x64){_0x5a9306[_0x4c22('0x62')]=_0x51be51;}return _0x5a9306;});});}else{return;}})[_0x4c22('0x26')](function(_0x2bbdc1){if(_0x2bbdc1)_0x5295e8=_0x2bbdc1;if(_[_0x4c22('0x61')](_0x5073a7,0x3eb)){var _0x55830d=_['find'](_0x5295e8,{'sectionId':0x3eb});return getCustomDashboards(_0x55830d)['then'](function(_0x100c59){return _[_0x4c22('0x34')](_0x5295e8,function(_0x33b945){if(_0x55830d['enabled']){if(_0x33b945['sectionId']===0x3eb){_0x33b945['subsections']=_0x100c59;}}else{if(_0x33b945[_0x4c22('0x56')]===0x64){_0x33b945[_0x4c22('0x62')]=_0x100c59;}}return _0x33b945;});});}else{return;}})['then'](function(_0x1c07a){if(_0x1c07a)_0x5295e8=_0x1c07a;if(_[_0x4c22('0x61')](_0x5073a7,0x709)){var _0x17621a=_[_0x4c22('0x4d')](_0x5295e8,{'sectionId':0x709});return getPlugins(_0x17621a)['then'](function(_0xa422b0){if(_0x17621a['enabled']){return _[_0x4c22('0x34')](_0x5295e8,function(_0x583e63){if(_0x583e63[_0x4c22('0x56')]===0x709){_0x583e63[_0x4c22('0x62')]=_0xa422b0;}return _0x583e63;});}else{var _0x2f0f94={'sectionId':0x76c,'enabled':0x1,'subsections':_0xa422b0};var _0x1b5433=_['map'](_0x5295e8);_0x1b5433[_0x4c22('0x63')](_0x2f0f94);return _0x1b5433;}});}else{return;}})[_0x4c22('0x26')](function(_0x3611fb){if(_0x3611fb)_0x5295e8=_0x3611fb;return _[_0x4c22('0x40')](_0x5295e8,[_0x4c22('0x5f'),0x1]);})[_0x4c22('0x26')](respondWithResult(_0x1058eb,null))['catch'](handleError(_0x1058eb,null));};function hasDefaultDashboard(_0x4ce14e){var _0x2637c9=[0x65];return new BPromise(function(_0x23b6b4,_0x92a6e9){try{if(_0x4ce14e[_0x4c22('0x55')]){_0x23b6b4(_0x2637c9);}else{return db[_0x4c22('0x5c')][_0x4c22('0x64')]({'where':{'sectionId':_0x4ce14e['id']},'raw':!![]})[_0x4c22('0x26')](function(_0x5ba3f5){_0x5ba3f5?_0x23b6b4(_0x2637c9):_0x23b6b4();});}}catch(_0x35b00c){_0x92a6e9(_0x35b00c);}});}function getCustomDashboards(_0x50cc93){var _0x5d492e=[];return new BPromise(function(_0x4d19b4,_0x34492b){try{if(_0x50cc93[_0x4c22('0x55')]){return db[_0x4c22('0x65')][_0x4c22('0x45')]({'raw':!![]})[_0x4c22('0x26')](function(_0x183ba3){_0x183ba3[_0x4c22('0x66')](function(_0x541038){_0x5d492e['push'](_0x541038['id']+0x1869f);});_0x4d19b4(_0x5d492e);});}else{return db[_0x4c22('0x5c')][_0x4c22('0x45')]({'where':{'sectionId':_0x50cc93['id']},'raw':!![]})['then'](function(_0x3b7295){_0x3b7295[_0x4c22('0x66')](function(_0x213367){_0x5d492e[_0x4c22('0x63')](_0x213367[_0x4c22('0x67')]+0x1869f);});_0x4d19b4(_0x5d492e);});}}catch(_0x497ccb){_0x34492b(_0x497ccb);}});}function getPlugins(_0x81cd9c){var _0x48ff26=[];return new BPromise(function(_0x5b03e0,_0x10c1b5){try{if(_0x81cd9c[_0x4c22('0x55')]){return db[_0x4c22('0x68')][_0x4c22('0x45')]({'raw':!![]})[_0x4c22('0x26')](function(_0x320d60){_0x320d60[_0x4c22('0x66')](function(_0x14e459){_0x48ff26[_0x4c22('0x63')](_0x14e459['id']+0x15b38);});_0x5b03e0(_0x48ff26);});}else{return db['UserProfileResource']['findAll']({'where':{'sectionId':_0x81cd9c['id']},'raw':!![]})[_0x4c22('0x26')](function(_0x4a703c){_0x4a703c[_0x4c22('0x66')](function(_0x5e120a){_0x48ff26[_0x4c22('0x63')](_0x5e120a[_0x4c22('0x67')]+0x15b38);});_0x5b03e0(_0x48ff26);});}}catch(_0x2eb41f){_0x10c1b5(_0x2eb41f);}});}exports[_0x4c22('0x69')]=function(_0x6fe364,_0x1d1f4b){return db[_0x4c22('0x2e')][_0x4c22('0x4d')]({'where':{'id':_0x6fe364[_0x4c22('0x49')]['id']}})[_0x4c22('0x26')](handleEntityNotFound(_0x1d1f4b,null))[_0x4c22('0x26')](function(_0x2dd9c0){if(_0x2dd9c0){return db[_0x4c22('0x52')][_0x4c22('0x53')](function(_0xcc5315){return db[_0x4c22('0x59')][_0x4c22('0x45')]({'where':{'userProfileId':_0x6fe364[_0x4c22('0x49')]['id']},'attributes':['id'],'raw':!![]})[_0x4c22('0x26')](function(_0x36f199){if(_0x36f199){return db[_0x4c22('0x59')][_0x4c22('0x27')]({'where':{'userProfileId':_0x6fe364['params']['id'],'id':_[_0x4c22('0x34')](_0x36f199,function(_0x580c35){return _0x580c35['id'];})},'transaction':_0xcc5315});}})[_0x4c22('0x26')](function(_0x3c6767){var _0x3d2c16=_['map'](_0x6fe364['body'],function(_0x299f28){_0x299f28['userProfileId']=_0x6fe364[_0x4c22('0x49')]['id'];return _0x299f28;});return db[_0x4c22('0x59')][_0x4c22('0x6a')](_0x3d2c16,{'raw':!![],'transaction':_0xcc5315});})[_0x4c22('0x26')](function(_0x512314){var _0x82936a=_[_0x4c22('0x40')](_[_0x4c22('0x34')](_0x512314,function(_0x1211c6){return _0x1211c6['get']({'plain':!![]});}),{'includeAll':![]});if(_0x82936a){return db[_0x4c22('0x59')]['findAll']({'where':{'userProfileId':_0x6fe364[_0x4c22('0x49')]['id'],'sectionId':_[_0x4c22('0x34')](_0x82936a,function(_0x363d0e){return _0x363d0e[_0x4c22('0x56')];})},'attributes':['id',_0x4c22('0x56')],'raw':!![]})[_0x4c22('0x26')](function(_0x1e55a8){var _0x185cdd=_[_0x4c22('0x34')](_0x6fe364['body'],function(_0x294e62){_0x294e62[_0x4c22('0x57')]=_0x6fe364['params']['id'];return _0x294e62;});return db[_0x4c22('0x5c')][_0x4c22('0x6a')](_0x185cdd,{'raw':!![],'transaction':_0xcc5315});});}})[_0x4c22('0x47')](handleError(_0x1d1f4b,null));});}})['then'](function(_0x2c9f40){var _0x9e9d20=_['map'](_0x2c9f40,function(_0x6a4109){return _0x6a4109[_0x4c22('0x54')]({'plain':!![]});});})[_0x4c22('0x26')](respondWithResult(_0x1d1f4b,null))[_0x4c22('0x47')](handleError(_0x1d1f4b,null));};exports[_0x4c22('0x6b')]=function(_0x4b4077,_0x1e4274,_0x486f21){return db[_0x4c22('0x2e')]['find']({'where':{'id':_0x4b4077['params']['id']}})[_0x4c22('0x26')](handleEntityNotFound(_0x1e4274,null))[_0x4c22('0x26')](function(_0x4e2049){if(_0x4e2049){return _0x4e2049['removeResources'](_0x4b4077[_0x4c22('0x35')][_0x4c22('0x6c')]);}})['then'](respondWithStatusCode(_0x1e4274,null))[_0x4c22('0x47')](handleError(_0x1e4274,null));};exports[_0x4c22('0x6d')]=function(_0x1a6ff8,_0x42c56a){var _0x126c22={};if(!_0x1a6ff8[_0x4c22('0x35')][_0x4c22('0x6e')])throw new Error(_0x4c22('0x6f'));if(!_0x1a6ff8[_0x4c22('0x35')][_0x4c22('0x3a')]('nolimit')){_0x126c22[_0x4c22('0x1f')]=qs['limit'](_0x1a6ff8['query'][_0x4c22('0x1f')]);_0x126c22[_0x4c22('0x1e')]=qs[_0x4c22('0x1e')](_0x1a6ff8[_0x4c22('0x35')][_0x4c22('0x1e')]);}return db['UserProfile']['find']({'where':{'id':_0x1a6ff8['params']['id']}})['then'](function(_0x1abd7f){if(!_0x1abd7f)throw new Error(_0x4c22('0x70')+_0x1a6ff8[_0x4c22('0x49')]['id']);return db[_0x4c22('0x2e')][_0x4c22('0x6d')](_0x1a6ff8);})[_0x4c22('0x26')](respondWithFilteredResult(_0x42c56a,_0x126c22))[_0x4c22('0x47')](handleError(_0x42c56a,null));};