Built motion from commit ae138b72.|2.6.28
[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 _0xc97f=['Dashboard','forEach','resourceId','bulkCreate','removeResources','getResources','Missing\x20section\x20parameter','nolimit','No\x20User\x20Profile\x20found\x20for\x20id\x20','zip-dir','fast-json-patch','request-promise','moment','bluebird','mustache','util','path','sox','to-csv','ejs','lodash','squel','crypto','jsforce','papaparse','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/logger','../../config/utils','../../config/environment','../../config/license/util','redis','defaults','localhost','socket.io-emitter','./userProfile.socket','register','sendStatus','end','status','json','offset','limit','undefined','count','Content-Range','reject','update','then','error','stack','name','send','index','map','UserProfile','rawAttributes','key','model','keys','query','intersection','fields','attributes','length','hasOwnProperty','order','where','pick','filters','filter','options','includeAll','include','rows','catch','params','find','create','body','get','omit','createdAt','updatedAt','crudPermissions','sequelize','transaction','merge','each','autoAssociation','findAll','sectionId','userProfileId','Resources','UserProfileSection','UserProfileResource','destroy','describe','push','ids','getSections','enabled','includes','isEmpty','subsections','concat'];(function(_0x25aa4c,_0x5b671f){var _0x332bcd=function(_0x193764){while(--_0x193764){_0x25aa4c['push'](_0x25aa4c['shift']());}};_0x332bcd(++_0x5b671f);}(_0xc97f,0x147));var _0xfc97=function(_0x1d35a3,_0x18d2ee){_0x1d35a3=_0x1d35a3-0x0;var _0x5acd09=_0xc97f[_0x1d35a3];return _0x5acd09;};'use strict';var emlformat=require('eml-format');var rimraf=require('rimraf');var zipdir=require(_0xfc97('0x0'));var jsonpatch=require(_0xfc97('0x1'));var rp=require(_0xfc97('0x2'));var moment=require(_0xfc97('0x3'));var BPromise=require(_0xfc97('0x4'));var Mustache=require(_0xfc97('0x5'));var util=require(_0xfc97('0x6'));var path=require(_0xfc97('0x7'));var sox=require(_0xfc97('0x8'));var csv=require(_0xfc97('0x9'));var ejs=require(_0xfc97('0xa'));var fs=require('fs');var fs_extra=require('fs-extra');var _=require(_0xfc97('0xb'));var squel=require(_0xfc97('0xc'));var crypto=require(_0xfc97('0xd'));var jsforce=require(_0xfc97('0xe'));var deskjs=require('desk.js');var toCsv=require(_0xfc97('0x9'));var querystring=require('querystring');var Papa=require(_0xfc97('0xf'));var Redis=require('ioredis');var authService=require('../../components/auth/service');var qs=require(_0xfc97('0x10'));var as=require(_0xfc97('0x11'));var hardwareService=require('../../config/license/hardware');var logger=require(_0xfc97('0x12'))('api');var utils=require(_0xfc97('0x13'));var config=require(_0xfc97('0x14'));var licenseUtil=require(_0xfc97('0x15'));var db=require('../../mysqldb')['db'];config[_0xfc97('0x16')]=_[_0xfc97('0x17')](config[_0xfc97('0x16')],{'host':_0xfc97('0x18'),'port':0x18eb});var socket=require(_0xfc97('0x19'))(new Redis(config[_0xfc97('0x16')]));require(_0xfc97('0x1a'))[_0xfc97('0x1b')](socket);function respondWithStatusCode(_0x5776bc,_0x27016e){_0x27016e=_0x27016e||0xcc;return function(_0x5d5d53){if(_0x5d5d53){return _0x5776bc[_0xfc97('0x1c')](_0x27016e);}return _0x5776bc['status'](_0x27016e)[_0xfc97('0x1d')]();};}function respondWithResult(_0x5741a0,_0x15f7cc){_0x15f7cc=_0x15f7cc||0xc8;return function(_0x17c2d1){if(_0x17c2d1){return _0x5741a0[_0xfc97('0x1e')](_0x15f7cc)[_0xfc97('0x1f')](_0x17c2d1);}};}function respondWithFilteredResult(_0x3c0a50,_0x4284b1){return function(_0x467b6d){if(_0x467b6d){var _0x27fd47=typeof _0x4284b1[_0xfc97('0x20')]==='undefined'&&typeof _0x4284b1[_0xfc97('0x21')]===_0xfc97('0x22');var _0x292f3a=_0x467b6d['count'];var _0x354936=_0x27fd47?0x0:_0x4284b1[_0xfc97('0x20')];var _0x166bfa=_0x27fd47?_0x467b6d[_0xfc97('0x23')]:_0x4284b1[_0xfc97('0x20')]+_0x4284b1[_0xfc97('0x21')];var _0x2ca80c;if(_0x166bfa>=_0x292f3a){_0x166bfa=_0x292f3a;_0x2ca80c=0xc8;}else{_0x2ca80c=0xce;}_0x3c0a50['status'](_0x2ca80c);return _0x3c0a50['set'](_0xfc97('0x24'),_0x354936+'-'+_0x166bfa+'/'+_0x292f3a)['json'](_0x467b6d);}return null;};}function patchUpdates(_0x430b85){return function(_0x21526f){try{jsonpatch['apply'](_0x21526f,_0x430b85,!![]);}catch(_0x386b54){return BPromise[_0xfc97('0x25')](_0x386b54);}return _0x21526f['save']();};}function saveUpdates(_0x3f6d73,_0x5e61d8){return function(_0x303189){if(_0x303189){return _0x303189[_0xfc97('0x26')](_0x3f6d73)[_0xfc97('0x27')](function(_0x3cb072){return _0x3cb072;});}return null;};}function removeEntity(_0xace455,_0x2562eb){return function(_0x232ed7){if(_0x232ed7){return _0x232ed7['destroy']()[_0xfc97('0x27')](function(){_0xace455[_0xfc97('0x1e')](0xcc)['end']();});}};}function handleEntityNotFound(_0x19f19e,_0x269cc9){return function(_0x251260){if(!_0x251260){_0x19f19e[_0xfc97('0x1c')](0x194);}return _0x251260;};}function handleError(_0x54dd43,_0x2410ac){_0x2410ac=_0x2410ac||0x1f4;return function(_0x56d970){logger[_0xfc97('0x28')](_0x56d970[_0xfc97('0x29')]);if(_0x56d970[_0xfc97('0x2a')]){delete _0x56d970[_0xfc97('0x2a')];}_0x54dd43['status'](_0x2410ac)[_0xfc97('0x2b')](_0x56d970);};}exports[_0xfc97('0x2c')]=function(_0x515797,_0x13540e){var _0x547436={},_0x56167f={},_0x3f59c5={'count':0x0,'rows':[]};var _0x7f096f=_[_0xfc97('0x2d')](db[_0xfc97('0x2e')][_0xfc97('0x2f')],function(_0xf04fa6){return{'name':_0xf04fa6['fieldName'],'type':_0xf04fa6['type'][_0xfc97('0x30')]};});_0x56167f[_0xfc97('0x31')]=_[_0xfc97('0x2d')](_0x7f096f,'name');_0x56167f['query']=_[_0xfc97('0x32')](_0x515797[_0xfc97('0x33')]);_0x56167f['filters']=_[_0xfc97('0x34')](_0x56167f[_0xfc97('0x31')],_0x56167f[_0xfc97('0x33')]);_0x547436['attributes']=_['intersection'](_0x56167f[_0xfc97('0x31')],qs['fields'](_0x515797[_0xfc97('0x33')][_0xfc97('0x35')]));_0x547436[_0xfc97('0x36')]=_0x547436[_0xfc97('0x36')][_0xfc97('0x37')]?_0x547436['attributes']:_0x56167f[_0xfc97('0x31')];if(!_0x515797[_0xfc97('0x33')][_0xfc97('0x38')]('nolimit')){_0x547436['limit']=qs[_0xfc97('0x21')](_0x515797[_0xfc97('0x33')]['limit']);_0x547436[_0xfc97('0x20')]=qs[_0xfc97('0x20')](_0x515797[_0xfc97('0x33')][_0xfc97('0x20')]);}_0x547436[_0xfc97('0x39')]=qs['sort'](_0x515797[_0xfc97('0x33')]['sort']);_0x547436[_0xfc97('0x3a')]=qs['filters'](_[_0xfc97('0x3b')](_0x515797[_0xfc97('0x33')],_0x56167f[_0xfc97('0x3c')]),_0x7f096f);if(_0x515797[_0xfc97('0x33')][_0xfc97('0x3d')]){_0x547436[_0xfc97('0x3a')]=_['merge'](_0x547436[_0xfc97('0x3a')],{'$or':_['map'](_0x7f096f,function(_0x456e66){if(_0x456e66['type']!=='VIRTUAL'){var _0x4f8fcc={};_0x4f8fcc[_0x456e66['name']]={'$like':'%'+_0x515797[_0xfc97('0x33')]['filter']+'%'};return _0x4f8fcc;}})});}_0x547436=_['merge']({},_0x547436,_0x515797[_0xfc97('0x3e')]);var _0x209843={'where':_0x547436[_0xfc97('0x3a')]};return db[_0xfc97('0x2e')][_0xfc97('0x23')](_0x209843)[_0xfc97('0x27')](function(_0x437034){_0x3f59c5[_0xfc97('0x23')]=_0x437034;if(_0x515797[_0xfc97('0x33')][_0xfc97('0x3f')]){_0x547436[_0xfc97('0x40')]=[{'all':!![]}];}return db[_0xfc97('0x2e')]['findAll'](_0x547436);})['then'](function(_0x700a36){_0x3f59c5[_0xfc97('0x41')]=_0x700a36;return _0x3f59c5;})[_0xfc97('0x27')](respondWithFilteredResult(_0x13540e,_0x547436))[_0xfc97('0x42')](handleError(_0x13540e,null));};exports['show']=function(_0x2ff1d7,_0x595be5){var _0x1b0b23={'raw':![],'where':{'id':_0x2ff1d7[_0xfc97('0x43')]['id']}},_0x4b2b89={};_0x4b2b89[_0xfc97('0x31')]=_[_0xfc97('0x32')](db['UserProfile'][_0xfc97('0x2f')]);_0x4b2b89[_0xfc97('0x33')]=_['keys'](_0x2ff1d7[_0xfc97('0x33')]);_0x4b2b89[_0xfc97('0x3c')]=_[_0xfc97('0x34')](_0x4b2b89[_0xfc97('0x31')],_0x4b2b89[_0xfc97('0x33')]);_0x1b0b23['attributes']=_[_0xfc97('0x34')](_0x4b2b89['model'],qs[_0xfc97('0x35')](_0x2ff1d7['query'][_0xfc97('0x35')]));_0x1b0b23[_0xfc97('0x36')]=_0x1b0b23[_0xfc97('0x36')][_0xfc97('0x37')]?_0x1b0b23[_0xfc97('0x36')]:_0x4b2b89[_0xfc97('0x31')];if(_0x2ff1d7[_0xfc97('0x33')][_0xfc97('0x3f')]){_0x1b0b23[_0xfc97('0x40')]=[{'all':!![]}];}_0x1b0b23=_['merge']({},_0x1b0b23,_0x2ff1d7['options']);return db[_0xfc97('0x2e')][_0xfc97('0x44')](_0x1b0b23)[_0xfc97('0x27')](handleEntityNotFound(_0x595be5,null))[_0xfc97('0x27')](respondWithResult(_0x595be5,null))[_0xfc97('0x42')](handleError(_0x595be5,null));};exports[_0xfc97('0x45')]=function(_0x1151bb,_0x54bf57){return db[_0xfc97('0x2e')]['create'](_0x1151bb[_0xfc97('0x46')],{})['then'](respondWithResult(_0x54bf57,0xc9))[_0xfc97('0x42')](handleError(_0x54bf57,null));};exports['clone']=function(_0x31bae5,_0x28926d){var _0x3aefdc={'where':{'id':_0x31bae5[_0xfc97('0x43')]['id']}},_0x33d286={};_0x33d286[_0xfc97('0x31')]=_[_0xfc97('0x32')](db[_0xfc97('0x2e')][_0xfc97('0x2f')]);_0x3aefdc['attributes']=_['intersection'](_0x33d286[_0xfc97('0x31')],qs['fields'](_0x31bae5['query'][_0xfc97('0x35')]));_0x3aefdc[_0xfc97('0x36')]=_0x3aefdc['attributes'][_0xfc97('0x37')]?_0x3aefdc['attributes']:_0x33d286[_0xfc97('0x31')];if(_0x31bae5['query'][_0xfc97('0x3f')]){_0x3aefdc[_0xfc97('0x40')]=[{'all':!![]}];}_0x3aefdc=_['merge']({},_0x3aefdc,_0x31bae5[_0xfc97('0x3e')]);return db['UserProfile'][_0xfc97('0x44')](_0x3aefdc)['then'](handleEntityNotFound(_0x28926d,null))[_0xfc97('0x27')](function(_0x18087f){if(_0x18087f){var _0x29636a=_0x18087f[_0xfc97('0x47')]({'plain':!![]});_0x29636a=qs[_0xfc97('0x48')](_0x29636a,['id',_0xfc97('0x49'),_0xfc97('0x4a'),_0xfc97('0x4b')]);_0x31bae5[_0xfc97('0x46')]=_[_0xfc97('0x48')](_0x31bae5[_0xfc97('0x46')],['id','createdAt',_0xfc97('0x4a')]);return db[_0xfc97('0x4c')][_0xfc97('0x4d')](function(_0x25d6dc){return db['UserProfile'][_0xfc97('0x45')](_[_0xfc97('0x4e')](_0x29636a,_0x31bae5[_0xfc97('0x46')]),{'include':_0x31bae5[_0xfc97('0x33')][_0xfc97('0x3f')]?[{'all':!![]}]:undefined,'transaction':_0x25d6dc})[_0xfc97('0x27')](function(_0x9763b3){var _0x395ad0=_0x9763b3['get']({'plain':!![]});return db['UserProfileSection']['findAll']({'where':{'userProfileId':_0x31bae5[_0xfc97('0x43')]['id']},'raw':!![]})[_0xfc97('0x27')](function(_0x2bdf67){if(_0x2bdf67){return BPromise[_0xfc97('0x4f')](_0x2bdf67,function(_0x33395a){return new BPromise(function(_0x577f8d,_0x3ecb9a){if(_0x33395a[_0xfc97('0x50')]===null||_0x33395a['autoAssociation']===0x1)_0x577f8d(null);return db['UserProfileResource'][_0xfc97('0x51')]({'where':{'sectionId':_0x33395a['id']},'raw':!![]})[_0xfc97('0x27')](function(_0x2d1e5f){var _0x4d505d=_[_0xfc97('0x2d')](_0x2d1e5f,function(_0x4b4cb9){return qs[_0xfc97('0x48')](_0x4b4cb9,['id',_0xfc97('0x49'),_0xfc97('0x4a'),_0xfc97('0x52')]);});_0x577f8d(_0x4d505d);})[_0xfc97('0x42')](function(_0x40762d){_0x3ecb9a(_0x40762d);});})[_0xfc97('0x27')](function(_0x29abd6){var _0x27bac9=qs[_0xfc97('0x48')](_0x33395a,['id',_0xfc97('0x49'),_0xfc97('0x4a')]);_0x27bac9[_0xfc97('0x53')]=_0x395ad0['id'];if(_0x29abd6)_0x27bac9[_0xfc97('0x54')]=_0x29abd6;return _0x27bac9;})[_0xfc97('0x27')](function(_0x5c0d9b){return db[_0xfc97('0x55')][_0xfc97('0x45')](_0x5c0d9b,{'include':[{'model':db[_0xfc97('0x56')],'as':_0xfc97('0x54')}],'raw':!![],'transaction':_0x25d6dc});});})[_0xfc97('0x27')](function(){return _0x395ad0;});}});});});}})[_0xfc97('0x27')](respondWithResult(_0x28926d,0xc9))[_0xfc97('0x42')](handleError(_0x28926d,null));};exports[_0xfc97('0x26')]=function(_0x2e22cf,_0xf9b3ab){if(_0x2e22cf[_0xfc97('0x46')]['id']){delete _0x2e22cf['body']['id'];}return db[_0xfc97('0x2e')][_0xfc97('0x44')]({'where':{'id':_0x2e22cf[_0xfc97('0x43')]['id']}})[_0xfc97('0x27')](handleEntityNotFound(_0xf9b3ab,null))[_0xfc97('0x27')](saveUpdates(_0x2e22cf[_0xfc97('0x46')],null))[_0xfc97('0x27')](respondWithResult(_0xf9b3ab,null))['catch'](handleError(_0xf9b3ab,null));};exports[_0xfc97('0x57')]=function(_0xa895f1,_0x316fb3){return db[_0xfc97('0x2e')][_0xfc97('0x44')]({'where':{'id':_0xa895f1[_0xfc97('0x43')]['id']}})[_0xfc97('0x27')](handleEntityNotFound(_0x316fb3,null))[_0xfc97('0x27')](removeEntity(_0x316fb3,null))[_0xfc97('0x42')](handleError(_0x316fb3,null));};exports['describe']=function(_0x49dbbc,_0x562e0e){return db[_0xfc97('0x2e')][_0xfc97('0x58')]()[_0xfc97('0x27')](respondWithResult(_0x562e0e,null))['catch'](handleError(_0x562e0e,null));};exports['addSections']=function(_0x30eb0c,_0x3a9250){var _0x11e30b=_0x30eb0c['body'];return db['UserProfile'][_0xfc97('0x44')]({'where':{'id':_0x30eb0c[_0xfc97('0x43')]['id']}})[_0xfc97('0x27')](handleEntityNotFound(_0x3a9250,null))[_0xfc97('0x27')](function(_0x3067d5){if(_0x3067d5){return db[_0xfc97('0x4c')]['transaction'](function(_0x10e371){return db['UserProfileSection'][_0xfc97('0x57')]({'where':{'userProfileId':_0x30eb0c[_0xfc97('0x43')]['id'],'sectionId':_[_0xfc97('0x2d')](_0x11e30b,function(_0x5587ae){return _0x5587ae['sectionId'];})},'transaction':_0x10e371})[_0xfc97('0x27')](function(){var _0x2b042b=_[_0xfc97('0x2d')](_0x11e30b,function(_0x5b9bf4){_0x5b9bf4[_0xfc97('0x53')]=_0x30eb0c[_0xfc97('0x43')]['id'];return _0x5b9bf4;});var _0x2123a0=[];return BPromise['each'](_0x2b042b,function(_0xbc93c7){return db[_0xfc97('0x55')][_0xfc97('0x45')](_0xbc93c7,{'include':[{'model':db[_0xfc97('0x56')],'as':_0xfc97('0x54')}],'raw':!![],'transaction':_0x10e371})[_0xfc97('0x27')](function(_0x41be6d){_0x2123a0[_0xfc97('0x59')](_0x41be6d[_0xfc97('0x47')]({'plain':!![]}));});})[_0xfc97('0x27')](function(){return _0x2123a0;});});});}})[_0xfc97('0x27')](function(_0x12509d){return _0x12509d;})[_0xfc97('0x27')](respondWithResult(_0x3a9250,null))['catch'](handleError(_0x3a9250,null));};exports['removeSections']=function(_0x158354,_0x3f6692){var _0x41af09;return db['UserProfile'][_0xfc97('0x44')]({'where':{'id':_0x158354[_0xfc97('0x43')]['id']},'attributes':['id',_0xfc97('0x2a')]})[_0xfc97('0x27')](handleEntityNotFound(_0x3f6692,null))[_0xfc97('0x27')](function(_0x516be2){if(_0x516be2){_0x41af09=_0x516be2;return db[_0xfc97('0x55')][_0xfc97('0x57')]({'where':{'userProfileId':_0x158354[_0xfc97('0x43')]['id'],'sectionId':_0x158354[_0xfc97('0x33')][_0xfc97('0x5a')]}});}})[_0xfc97('0x27')](function(){return _0x41af09;})[_0xfc97('0x27')](respondWithStatusCode(_0x3f6692,null))['catch'](handleError(_0x3f6692,null));};exports[_0xfc97('0x5b')]=function(_0xf8f0e,_0x3f5192){var _0x4e8cf3=[];var _0x5a5ad0=[];return db[_0xfc97('0x55')][_0xfc97('0x51')]({'where':{'userProfileId':_0xf8f0e[_0xfc97('0x43')]['id']},'raw':!![]})['then'](function(_0x2e40cb){_0x4e8cf3=_[_0xfc97('0x3d')](_0x2e40cb,function(_0x4cd3ea){return _0x4cd3ea[_0xfc97('0x5c')]===0x1||_[_0xfc97('0x5d')]([0x3eb,0x709],_0x4cd3ea[_0xfc97('0x52')]);});if(!_[_0xfc97('0x5e')](_0x4e8cf3)){return _[_0xfc97('0x2d')](_0x4e8cf3,function(_0x13667e){return _0x13667e[_0xfc97('0x52')];});}else{return;}})['then'](function(_0x4b754f){if(_0x4b754f)_0x5a5ad0=_0x4b754f;if(_[_0xfc97('0x5d')](_0x5a5ad0,0x64)){var _0x11b6f8=_['find'](_0x4e8cf3,{'sectionId':0x64});return hasDefaultDashboard(_0x11b6f8)[_0xfc97('0x27')](function(_0x42fa83){return _[_0xfc97('0x2d')](_0x4e8cf3,function(_0x441998){if(_0x441998[_0xfc97('0x52')]===0x64){_0x441998['subsections']=_0x42fa83;}return _0x441998;});});}else{return;}})[_0xfc97('0x27')](function(_0x1314b8){if(_0x1314b8)_0x4e8cf3=_0x1314b8;if(_[_0xfc97('0x5d')](_0x5a5ad0,0x3eb)){var _0x4d5f8=_[_0xfc97('0x44')](_0x4e8cf3,{'sectionId':0x3eb});return getCustomDashboards(_0x4d5f8)[_0xfc97('0x27')](function(_0x4f0cb7){return _['map'](_0x4e8cf3,function(_0x469921){if(_0x4d5f8[_0xfc97('0x5c')]){if(_0x469921[_0xfc97('0x52')]===0x3eb){_0x469921[_0xfc97('0x5f')]=_0x4f0cb7;}}else{if(_0x469921[_0xfc97('0x52')]===0x64){if(!_0x469921[_0xfc97('0x5f')]){_0x469921['subsections']=[];}_0x469921[_0xfc97('0x5f')]=_0x469921[_0xfc97('0x5f')][_0xfc97('0x60')](_0x4f0cb7);}}return _0x469921;});});}else{return;}})[_0xfc97('0x27')](function(_0x43db13){if(_0x43db13)_0x4e8cf3=_0x43db13;if(_[_0xfc97('0x5d')](_0x5a5ad0,0x709)){var _0x3952e6=_[_0xfc97('0x44')](_0x4e8cf3,{'sectionId':0x709});return getPlugins(_0x3952e6)[_0xfc97('0x27')](function(_0x5e22b6){if(_0x3952e6['enabled']){return _[_0xfc97('0x2d')](_0x4e8cf3,function(_0x57f824){if(_0x57f824[_0xfc97('0x52')]===0x709){_0x57f824['subsections']=_0x5e22b6;}return _0x57f824;});}else{var _0x261983={'sectionId':0x76c,'enabled':0x1,'subsections':_0x5e22b6};var _0x154e37=_[_0xfc97('0x2d')](_0x4e8cf3);_0x154e37[_0xfc97('0x59')](_0x261983);return _0x154e37;}});}else{return;}})[_0xfc97('0x27')](function(_0x5d9dc2){if(_0x5d9dc2)_0x4e8cf3=_0x5d9dc2;return _[_0xfc97('0x3d')](_0x4e8cf3,[_0xfc97('0x5c'),0x1]);})[_0xfc97('0x27')](respondWithResult(_0x3f5192,null))['catch'](handleError(_0x3f5192,null));};function hasDefaultDashboard(_0x603b0){var _0x47c5ed=[0x65];return new BPromise(function(_0x2a817c,_0x51e647){try{if(_0x603b0[_0xfc97('0x50')]){_0x2a817c(_0x47c5ed);}else{return db[_0xfc97('0x56')]['findOne']({'where':{'sectionId':_0x603b0['id']},'raw':!![]})[_0xfc97('0x27')](function(_0x161178){_0x161178?_0x2a817c(_0x47c5ed):_0x2a817c();});}}catch(_0x2bb628){_0x51e647(_0x2bb628);}});}function getCustomDashboards(_0x24178d){var _0x22451d=[];return new BPromise(function(_0x14aaf8,_0x242020){try{if(_0x24178d[_0xfc97('0x50')]){return db[_0xfc97('0x61')][_0xfc97('0x51')]({'raw':!![]})[_0xfc97('0x27')](function(_0x932788){_0x932788[_0xfc97('0x62')](function(_0x49cc44){_0x22451d['push'](_0x49cc44['id']+0x1869f);});_0x14aaf8(_0x22451d);});}else{return db[_0xfc97('0x56')][_0xfc97('0x51')]({'where':{'sectionId':_0x24178d['id']},'raw':!![]})[_0xfc97('0x27')](function(_0x552363){_0x552363[_0xfc97('0x62')](function(_0xf6ee12){_0x22451d[_0xfc97('0x59')](_0xf6ee12[_0xfc97('0x63')]+0x1869f);});_0x14aaf8(_0x22451d);});}}catch(_0xb31eea){_0x242020(_0xb31eea);}});}function getPlugins(_0x4603d5){var _0x2f888e=[];return new BPromise(function(_0x563b75,_0x26384e){try{if(_0x4603d5[_0xfc97('0x50')]){return db['Plugin'][_0xfc97('0x51')]({'raw':!![]})['then'](function(_0x3bff25){_0x3bff25['forEach'](function(_0x6fa0d0){_0x2f888e[_0xfc97('0x59')](_0x6fa0d0['id']+0x15b38);});_0x563b75(_0x2f888e);});}else{return db[_0xfc97('0x56')][_0xfc97('0x51')]({'where':{'sectionId':_0x4603d5['id']},'raw':!![]})[_0xfc97('0x27')](function(_0x308f2e){_0x308f2e[_0xfc97('0x62')](function(_0x20ab8b){_0x2f888e[_0xfc97('0x59')](_0x20ab8b[_0xfc97('0x63')]+0x15b38);});_0x563b75(_0x2f888e);});}}catch(_0x2a4b84){_0x26384e(_0x2a4b84);}});}exports['addResources']=function(_0xccbd0e,_0x1c1b98){return db['UserProfile'][_0xfc97('0x44')]({'where':{'id':_0xccbd0e[_0xfc97('0x43')]['id']}})[_0xfc97('0x27')](handleEntityNotFound(_0x1c1b98,null))[_0xfc97('0x27')](function(_0x43ffc8){if(_0x43ffc8){return db[_0xfc97('0x4c')][_0xfc97('0x4d')](function(_0x5db63f){return db['UserProfileSection'][_0xfc97('0x51')]({'where':{'userProfileId':_0xccbd0e[_0xfc97('0x43')]['id']},'attributes':['id'],'raw':!![]})[_0xfc97('0x27')](function(_0x51287d){if(_0x51287d){return db[_0xfc97('0x55')][_0xfc97('0x57')]({'where':{'userProfileId':_0xccbd0e[_0xfc97('0x43')]['id'],'id':_[_0xfc97('0x2d')](_0x51287d,function(_0x36477e){return _0x36477e['id'];})},'transaction':_0x5db63f});}})[_0xfc97('0x27')](function(_0x2ecbac){var _0x54205c=_[_0xfc97('0x2d')](_0xccbd0e['body'],function(_0x2e644c){_0x2e644c[_0xfc97('0x53')]=_0xccbd0e[_0xfc97('0x43')]['id'];return _0x2e644c;});return db[_0xfc97('0x55')][_0xfc97('0x64')](_0x54205c,{'raw':!![],'transaction':_0x5db63f});})[_0xfc97('0x27')](function(_0xcae1d3){var _0x32bdcb=_[_0xfc97('0x3d')](_[_0xfc97('0x2d')](_0xcae1d3,function(_0x57da59){return _0x57da59['get']({'plain':!![]});}),{'includeAll':![]});if(_0x32bdcb){return db[_0xfc97('0x55')]['findAll']({'where':{'userProfileId':_0xccbd0e[_0xfc97('0x43')]['id'],'sectionId':_[_0xfc97('0x2d')](_0x32bdcb,function(_0x292531){return _0x292531[_0xfc97('0x52')];})},'attributes':['id',_0xfc97('0x52')],'raw':!![]})[_0xfc97('0x27')](function(_0x52054e){var _0x46a6b5=_[_0xfc97('0x2d')](_0xccbd0e[_0xfc97('0x46')],function(_0x19c911){_0x19c911['userProfileId']=_0xccbd0e['params']['id'];return _0x19c911;});return db[_0xfc97('0x56')]['bulkCreate'](_0x46a6b5,{'raw':!![],'transaction':_0x5db63f});});}})['catch'](handleError(_0x1c1b98,null));});}})['then'](function(_0x266898){var _0x595362=_[_0xfc97('0x2d')](_0x266898,function(_0x1786e9){return _0x1786e9[_0xfc97('0x47')]({'plain':!![]});});})[_0xfc97('0x27')](respondWithResult(_0x1c1b98,null))[_0xfc97('0x42')](handleError(_0x1c1b98,null));};exports[_0xfc97('0x65')]=function(_0x16f1cd,_0x412e24,_0x3840a9){return db[_0xfc97('0x2e')][_0xfc97('0x44')]({'where':{'id':_0x16f1cd[_0xfc97('0x43')]['id']}})[_0xfc97('0x27')](handleEntityNotFound(_0x412e24,null))[_0xfc97('0x27')](function(_0x4538b1){if(_0x4538b1){return _0x4538b1[_0xfc97('0x65')](_0x16f1cd['query'][_0xfc97('0x5a')]);}})[_0xfc97('0x27')](respondWithStatusCode(_0x412e24,null))['catch'](handleError(_0x412e24,null));};exports[_0xfc97('0x66')]=function(_0x4ad791,_0x52f091){var _0x3ec8a1={};if(!_0x4ad791[_0xfc97('0x33')]['section'])throw new Error(_0xfc97('0x67'));if(!_0x4ad791[_0xfc97('0x33')][_0xfc97('0x38')](_0xfc97('0x68'))){_0x3ec8a1[_0xfc97('0x21')]=qs[_0xfc97('0x21')](_0x4ad791['query'][_0xfc97('0x21')]);_0x3ec8a1['offset']=qs[_0xfc97('0x20')](_0x4ad791[_0xfc97('0x33')][_0xfc97('0x20')]);}return db[_0xfc97('0x2e')][_0xfc97('0x44')]({'where':{'id':_0x4ad791[_0xfc97('0x43')]['id']}})['then'](function(_0x4ce635){if(!_0x4ce635)throw new Error(_0xfc97('0x69')+_0x4ad791['params']['id']);return db[_0xfc97('0x2e')][_0xfc97('0x66')](_0x4ad791);})['then'](respondWithFilteredResult(_0x52f091,_0x3ec8a1))['catch'](handleError(_0x52f091,null));};