Built motion from commit 6a92c2cd.|2.6.29
[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 _0xd2e2=['Plugin','addResources','bulkCreate','removeResources','ids','getResources','section','Missing\x20section\x20parameter','rimraf','zip-dir','fast-json-patch','request-promise','bluebird','mustache','path','sox','ejs','fs-extra','lodash','squel','crypto','jsforce','to-csv','querystring','papaparse','ioredis','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','api','../../config/utils','../../config/environment','../../config/license/util','redis','defaults','localhost','socket.io-emitter','./userProfile.socket','sendStatus','status','end','json','offset','limit','undefined','set','Content-Range','reject','save','update','then','destroy','error','name','send','index','map','UserProfile','fieldName','type','key','model','keys','query','filters','intersection','fields','attributes','hasOwnProperty','nolimit','order','sort','filter','where','merge','VIRTUAL','options','count','includeAll','findAll','rows','catch','show','rawAttributes','length','include','find','create','params','get','omit','createdAt','crudPermissions','body','updatedAt','transaction','autoAssociation','UserProfileResource','Resources','describe','UserProfileSection','sectionId','userProfileId','each','push','removeSections','getSections','enabled','includes','isEmpty','subsections','concat','findOne','forEach','resourceId'];(function(_0x285efb,_0x13e320){var _0x540155=function(_0x57f944){while(--_0x57f944){_0x285efb['push'](_0x285efb['shift']());}};_0x540155(++_0x13e320);}(_0xd2e2,0x1d4));var _0x2d2e=function(_0x186156,_0x1c1b7a){_0x186156=_0x186156-0x0;var _0x354699=_0xd2e2[_0x186156];return _0x354699;};'use strict';var emlformat=require('eml-format');var rimraf=require(_0x2d2e('0x0'));var zipdir=require(_0x2d2e('0x1'));var jsonpatch=require(_0x2d2e('0x2'));var rp=require(_0x2d2e('0x3'));var moment=require('moment');var BPromise=require(_0x2d2e('0x4'));var Mustache=require(_0x2d2e('0x5'));var util=require('util');var path=require(_0x2d2e('0x6'));var sox=require(_0x2d2e('0x7'));var csv=require('to-csv');var ejs=require(_0x2d2e('0x8'));var fs=require('fs');var fs_extra=require(_0x2d2e('0x9'));var _=require(_0x2d2e('0xa'));var squel=require(_0x2d2e('0xb'));var crypto=require(_0x2d2e('0xc'));var jsforce=require(_0x2d2e('0xd'));var deskjs=require('desk.js');var toCsv=require(_0x2d2e('0xe'));var querystring=require(_0x2d2e('0xf'));var Papa=require(_0x2d2e('0x10'));var Redis=require(_0x2d2e('0x11'));var authService=require('../../components/auth/service');var qs=require('../../components/parsers/qs');var as=require(_0x2d2e('0x12'));var hardwareService=require(_0x2d2e('0x13'));var logger=require(_0x2d2e('0x14'))(_0x2d2e('0x15'));var utils=require(_0x2d2e('0x16'));var config=require(_0x2d2e('0x17'));var licenseUtil=require(_0x2d2e('0x18'));var db=require('../../mysqldb')['db'];config[_0x2d2e('0x19')]=_[_0x2d2e('0x1a')](config['redis'],{'host':_0x2d2e('0x1b'),'port':0x18eb});var socket=require(_0x2d2e('0x1c'))(new Redis(config[_0x2d2e('0x19')]));require(_0x2d2e('0x1d'))['register'](socket);function respondWithStatusCode(_0x15197a,_0x5f2614){_0x5f2614=_0x5f2614||0xcc;return function(_0x4fdf65){if(_0x4fdf65){return _0x15197a[_0x2d2e('0x1e')](_0x5f2614);}return _0x15197a[_0x2d2e('0x1f')](_0x5f2614)[_0x2d2e('0x20')]();};}function respondWithResult(_0x319323,_0x478574){_0x478574=_0x478574||0xc8;return function(_0x51d858){if(_0x51d858){return _0x319323['status'](_0x478574)[_0x2d2e('0x21')](_0x51d858);}};}function respondWithFilteredResult(_0x20f9dd,_0x19132a){return function(_0x2b31e1){if(_0x2b31e1){var _0x409352=typeof _0x19132a[_0x2d2e('0x22')]==='undefined'&&typeof _0x19132a[_0x2d2e('0x23')]===_0x2d2e('0x24');var _0x2a72fb=_0x2b31e1['count'];var _0x12beff=_0x409352?0x0:_0x19132a[_0x2d2e('0x22')];var _0xbe9b2a=_0x409352?_0x2b31e1['count']:_0x19132a['offset']+_0x19132a['limit'];var _0x55c898;if(_0xbe9b2a>=_0x2a72fb){_0xbe9b2a=_0x2a72fb;_0x55c898=0xc8;}else{_0x55c898=0xce;}_0x20f9dd[_0x2d2e('0x1f')](_0x55c898);return _0x20f9dd[_0x2d2e('0x25')](_0x2d2e('0x26'),_0x12beff+'-'+_0xbe9b2a+'/'+_0x2a72fb)[_0x2d2e('0x21')](_0x2b31e1);}return null;};}function patchUpdates(_0x47979a){return function(_0x1c6a9e){try{jsonpatch['apply'](_0x1c6a9e,_0x47979a,!![]);}catch(_0x52642c){return BPromise[_0x2d2e('0x27')](_0x52642c);}return _0x1c6a9e[_0x2d2e('0x28')]();};}function saveUpdates(_0x420655,_0x59a877){return function(_0x2ffba7){if(_0x2ffba7){return _0x2ffba7[_0x2d2e('0x29')](_0x420655)[_0x2d2e('0x2a')](function(_0x1ba5ff){return _0x1ba5ff;});}return null;};}function removeEntity(_0x256df6,_0x267537){return function(_0x3c29ce){if(_0x3c29ce){return _0x3c29ce[_0x2d2e('0x2b')]()['then'](function(){_0x256df6[_0x2d2e('0x1f')](0xcc)[_0x2d2e('0x20')]();});}};}function handleEntityNotFound(_0x264ecf,_0x437e7c){return function(_0x5aeccf){if(!_0x5aeccf){_0x264ecf[_0x2d2e('0x1e')](0x194);}return _0x5aeccf;};}function handleError(_0x2e6066,_0x45e534){_0x45e534=_0x45e534||0x1f4;return function(_0x3a8b82){logger[_0x2d2e('0x2c')](_0x3a8b82['stack']);if(_0x3a8b82[_0x2d2e('0x2d')]){delete _0x3a8b82[_0x2d2e('0x2d')];}_0x2e6066[_0x2d2e('0x1f')](_0x45e534)[_0x2d2e('0x2e')](_0x3a8b82);};}exports[_0x2d2e('0x2f')]=function(_0x329c27,_0x19c201){var _0x264c4f={},_0x2c32ad={},_0x3df1ad={'count':0x0,'rows':[]};var _0x439e48=_[_0x2d2e('0x30')](db[_0x2d2e('0x31')]['rawAttributes'],function(_0x59a71f){return{'name':_0x59a71f[_0x2d2e('0x32')],'type':_0x59a71f[_0x2d2e('0x33')][_0x2d2e('0x34')]};});_0x2c32ad[_0x2d2e('0x35')]=_['map'](_0x439e48,_0x2d2e('0x2d'));_0x2c32ad['query']=_[_0x2d2e('0x36')](_0x329c27[_0x2d2e('0x37')]);_0x2c32ad[_0x2d2e('0x38')]=_[_0x2d2e('0x39')](_0x2c32ad['model'],_0x2c32ad[_0x2d2e('0x37')]);_0x264c4f['attributes']=_[_0x2d2e('0x39')](_0x2c32ad[_0x2d2e('0x35')],qs[_0x2d2e('0x3a')](_0x329c27['query'][_0x2d2e('0x3a')]));_0x264c4f[_0x2d2e('0x3b')]=_0x264c4f['attributes']['length']?_0x264c4f[_0x2d2e('0x3b')]:_0x2c32ad[_0x2d2e('0x35')];if(!_0x329c27['query'][_0x2d2e('0x3c')](_0x2d2e('0x3d'))){_0x264c4f['limit']=qs[_0x2d2e('0x23')](_0x329c27[_0x2d2e('0x37')][_0x2d2e('0x23')]);_0x264c4f[_0x2d2e('0x22')]=qs[_0x2d2e('0x22')](_0x329c27[_0x2d2e('0x37')][_0x2d2e('0x22')]);}_0x264c4f[_0x2d2e('0x3e')]=qs[_0x2d2e('0x3f')](_0x329c27[_0x2d2e('0x37')][_0x2d2e('0x3f')]);_0x264c4f['where']=qs['filters'](_['pick'](_0x329c27[_0x2d2e('0x37')],_0x2c32ad['filters']),_0x439e48);if(_0x329c27[_0x2d2e('0x37')][_0x2d2e('0x40')]){_0x264c4f[_0x2d2e('0x41')]=_[_0x2d2e('0x42')](_0x264c4f[_0x2d2e('0x41')],{'$or':_['map'](_0x439e48,function(_0x208737){if(_0x208737[_0x2d2e('0x33')]!==_0x2d2e('0x43')){var _0x3cfda5={};_0x3cfda5[_0x208737[_0x2d2e('0x2d')]]={'$like':'%'+_0x329c27['query'][_0x2d2e('0x40')]+'%'};return _0x3cfda5;}})});}_0x264c4f=_[_0x2d2e('0x42')]({},_0x264c4f,_0x329c27[_0x2d2e('0x44')]);var _0x2220e6={'where':_0x264c4f['where']};return db['UserProfile'][_0x2d2e('0x45')](_0x2220e6)[_0x2d2e('0x2a')](function(_0x4328e1){_0x3df1ad[_0x2d2e('0x45')]=_0x4328e1;if(_0x329c27[_0x2d2e('0x37')][_0x2d2e('0x46')]){_0x264c4f['include']=[{'all':!![]}];}return db[_0x2d2e('0x31')][_0x2d2e('0x47')](_0x264c4f);})[_0x2d2e('0x2a')](function(_0x3fce6c){_0x3df1ad[_0x2d2e('0x48')]=_0x3fce6c;return _0x3df1ad;})[_0x2d2e('0x2a')](respondWithFilteredResult(_0x19c201,_0x264c4f))[_0x2d2e('0x49')](handleError(_0x19c201,null));};exports[_0x2d2e('0x4a')]=function(_0x2e7723,_0x462308){var _0x5b55e4={'raw':![],'where':{'id':_0x2e7723['params']['id']}},_0x4edff6={};_0x4edff6[_0x2d2e('0x35')]=_[_0x2d2e('0x36')](db[_0x2d2e('0x31')][_0x2d2e('0x4b')]);_0x4edff6['query']=_[_0x2d2e('0x36')](_0x2e7723['query']);_0x4edff6['filters']=_['intersection'](_0x4edff6[_0x2d2e('0x35')],_0x4edff6[_0x2d2e('0x37')]);_0x5b55e4['attributes']=_[_0x2d2e('0x39')](_0x4edff6[_0x2d2e('0x35')],qs[_0x2d2e('0x3a')](_0x2e7723[_0x2d2e('0x37')]['fields']));_0x5b55e4[_0x2d2e('0x3b')]=_0x5b55e4[_0x2d2e('0x3b')][_0x2d2e('0x4c')]?_0x5b55e4['attributes']:_0x4edff6[_0x2d2e('0x35')];if(_0x2e7723['query']['includeAll']){_0x5b55e4[_0x2d2e('0x4d')]=[{'all':!![]}];}_0x5b55e4=_[_0x2d2e('0x42')]({},_0x5b55e4,_0x2e7723['options']);return db[_0x2d2e('0x31')][_0x2d2e('0x4e')](_0x5b55e4)['then'](handleEntityNotFound(_0x462308,null))[_0x2d2e('0x2a')](respondWithResult(_0x462308,null))[_0x2d2e('0x49')](handleError(_0x462308,null));};exports['create']=function(_0x1f996f,_0x2bcee4){return db['UserProfile'][_0x2d2e('0x4f')](_0x1f996f['body'],{})['then'](respondWithResult(_0x2bcee4,0xc9))[_0x2d2e('0x49')](handleError(_0x2bcee4,null));};exports['clone']=function(_0x16856f,_0x38938c){var _0x5d8472={'where':{'id':_0x16856f[_0x2d2e('0x50')]['id']}},_0x130289={};_0x130289[_0x2d2e('0x35')]=_[_0x2d2e('0x36')](db[_0x2d2e('0x31')]['rawAttributes']);_0x5d8472['attributes']=_[_0x2d2e('0x39')](_0x130289[_0x2d2e('0x35')],qs[_0x2d2e('0x3a')](_0x16856f['query']['fields']));_0x5d8472[_0x2d2e('0x3b')]=_0x5d8472[_0x2d2e('0x3b')][_0x2d2e('0x4c')]?_0x5d8472[_0x2d2e('0x3b')]:_0x130289[_0x2d2e('0x35')];if(_0x16856f[_0x2d2e('0x37')]['includeAll']){_0x5d8472[_0x2d2e('0x4d')]=[{'all':!![]}];}_0x5d8472=_['merge']({},_0x5d8472,_0x16856f[_0x2d2e('0x44')]);return db[_0x2d2e('0x31')][_0x2d2e('0x4e')](_0x5d8472)[_0x2d2e('0x2a')](handleEntityNotFound(_0x38938c,null))[_0x2d2e('0x2a')](function(_0x5661ed){if(_0x5661ed){var _0x45339e=_0x5661ed[_0x2d2e('0x51')]({'plain':!![]});_0x45339e=qs[_0x2d2e('0x52')](_0x45339e,['id',_0x2d2e('0x53'),'updatedAt',_0x2d2e('0x54')]);_0x16856f[_0x2d2e('0x55')]=_[_0x2d2e('0x52')](_0x16856f[_0x2d2e('0x55')],['id','createdAt',_0x2d2e('0x56')]);return db['sequelize'][_0x2d2e('0x57')](function(_0x1a5da1){return db[_0x2d2e('0x31')]['create'](_[_0x2d2e('0x42')](_0x45339e,_0x16856f[_0x2d2e('0x55')]),{'include':_0x16856f['query'][_0x2d2e('0x46')]?[{'all':!![]}]:undefined,'transaction':_0x1a5da1})['then'](function(_0x562fb3){var _0x1f932c=_0x562fb3[_0x2d2e('0x51')]({'plain':!![]});return db['UserProfileSection'][_0x2d2e('0x47')]({'where':{'userProfileId':_0x16856f['params']['id']},'raw':!![]})[_0x2d2e('0x2a')](function(_0x7728e4){if(_0x7728e4){return BPromise['each'](_0x7728e4,function(_0x4e27c2){return new BPromise(function(_0xf1e782,_0x13f8ad){if(_0x4e27c2[_0x2d2e('0x58')]===null||_0x4e27c2['autoAssociation']===0x1)_0xf1e782(null);return db[_0x2d2e('0x59')]['findAll']({'where':{'sectionId':_0x4e27c2['id']},'raw':!![]})[_0x2d2e('0x2a')](function(_0xa0fb83){var _0x1202a7=_[_0x2d2e('0x30')](_0xa0fb83,function(_0x474eed){return qs[_0x2d2e('0x52')](_0x474eed,['id',_0x2d2e('0x53'),'updatedAt','sectionId']);});_0xf1e782(_0x1202a7);})[_0x2d2e('0x49')](function(_0x3bfc89){_0x13f8ad(_0x3bfc89);});})[_0x2d2e('0x2a')](function(_0x4e50ba){var _0x161c2f=qs[_0x2d2e('0x52')](_0x4e27c2,['id',_0x2d2e('0x53'),_0x2d2e('0x56')]);_0x161c2f['userProfileId']=_0x1f932c['id'];if(_0x4e50ba)_0x161c2f[_0x2d2e('0x5a')]=_0x4e50ba;return _0x161c2f;})[_0x2d2e('0x2a')](function(_0x438ec3){return db['UserProfileSection'][_0x2d2e('0x4f')](_0x438ec3,{'include':[{'model':db[_0x2d2e('0x59')],'as':'Resources'}],'raw':!![],'transaction':_0x1a5da1});});})['then'](function(){return _0x1f932c;});}});});});}})['then'](respondWithResult(_0x38938c,0xc9))['catch'](handleError(_0x38938c,null));};exports[_0x2d2e('0x29')]=function(_0x5a78eb,_0x253c11){if(_0x5a78eb['body']['id']){delete _0x5a78eb[_0x2d2e('0x55')]['id'];}return db[_0x2d2e('0x31')][_0x2d2e('0x4e')]({'where':{'id':_0x5a78eb[_0x2d2e('0x50')]['id']}})[_0x2d2e('0x2a')](handleEntityNotFound(_0x253c11,null))['then'](saveUpdates(_0x5a78eb['body'],null))['then'](respondWithResult(_0x253c11,null))['catch'](handleError(_0x253c11,null));};exports[_0x2d2e('0x2b')]=function(_0x432bdf,_0x2da637){return db[_0x2d2e('0x31')]['find']({'where':{'id':_0x432bdf[_0x2d2e('0x50')]['id']}})[_0x2d2e('0x2a')](handleEntityNotFound(_0x2da637,null))[_0x2d2e('0x2a')](removeEntity(_0x2da637,null))[_0x2d2e('0x49')](handleError(_0x2da637,null));};exports[_0x2d2e('0x5b')]=function(_0x279125,_0x374e75){return db['UserProfile'][_0x2d2e('0x5b')]()[_0x2d2e('0x2a')](respondWithResult(_0x374e75,null))[_0x2d2e('0x49')](handleError(_0x374e75,null));};exports['addSections']=function(_0x553f7b,_0xfabc00){var _0x45bf8c=_0x553f7b['body'];return db['UserProfile'][_0x2d2e('0x4e')]({'where':{'id':_0x553f7b[_0x2d2e('0x50')]['id']}})['then'](handleEntityNotFound(_0xfabc00,null))[_0x2d2e('0x2a')](function(_0x1f46b6){if(_0x1f46b6){return db['sequelize'][_0x2d2e('0x57')](function(_0x23baa7){return db[_0x2d2e('0x5c')][_0x2d2e('0x2b')]({'where':{'userProfileId':_0x553f7b[_0x2d2e('0x50')]['id'],'sectionId':_[_0x2d2e('0x30')](_0x45bf8c,function(_0xbde24d){return _0xbde24d[_0x2d2e('0x5d')];})},'transaction':_0x23baa7})['then'](function(){var _0x4621b3=_[_0x2d2e('0x30')](_0x45bf8c,function(_0x3b6a76){_0x3b6a76[_0x2d2e('0x5e')]=_0x553f7b[_0x2d2e('0x50')]['id'];return _0x3b6a76;});var _0x41966b=[];return BPromise[_0x2d2e('0x5f')](_0x4621b3,function(_0x48c4d5){return db[_0x2d2e('0x5c')][_0x2d2e('0x4f')](_0x48c4d5,{'include':[{'model':db[_0x2d2e('0x59')],'as':'Resources'}],'raw':!![],'transaction':_0x23baa7})[_0x2d2e('0x2a')](function(_0x532cf4){_0x41966b[_0x2d2e('0x60')](_0x532cf4[_0x2d2e('0x51')]({'plain':!![]}));});})[_0x2d2e('0x2a')](function(){return _0x41966b;});});});}})[_0x2d2e('0x2a')](function(_0x44be00){return _0x44be00;})[_0x2d2e('0x2a')](respondWithResult(_0xfabc00,null))[_0x2d2e('0x49')](handleError(_0xfabc00,null));};exports[_0x2d2e('0x61')]=function(_0x43de5a,_0x58c652){var _0x420e64;return db[_0x2d2e('0x31')][_0x2d2e('0x4e')]({'where':{'id':_0x43de5a[_0x2d2e('0x50')]['id']},'attributes':['id',_0x2d2e('0x2d')]})[_0x2d2e('0x2a')](handleEntityNotFound(_0x58c652,null))[_0x2d2e('0x2a')](function(_0x29eba8){if(_0x29eba8){_0x420e64=_0x29eba8;return db['UserProfileSection'][_0x2d2e('0x2b')]({'where':{'userProfileId':_0x43de5a[_0x2d2e('0x50')]['id'],'sectionId':_0x43de5a[_0x2d2e('0x37')]['ids']}});}})[_0x2d2e('0x2a')](function(){return _0x420e64;})['then'](respondWithStatusCode(_0x58c652,null))[_0x2d2e('0x49')](handleError(_0x58c652,null));};exports[_0x2d2e('0x62')]=function(_0x5049b6,_0x165293){var _0xb3a141=[];var _0x427b00=[];return db[_0x2d2e('0x5c')]['findAll']({'where':{'userProfileId':_0x5049b6['params']['id']},'raw':!![]})['then'](function(_0x4eb9fa){_0xb3a141=_['filter'](_0x4eb9fa,function(_0x5373c3){return _0x5373c3[_0x2d2e('0x63')]===0x1||_[_0x2d2e('0x64')]([0x3eb,0x709],_0x5373c3[_0x2d2e('0x5d')]);});if(!_[_0x2d2e('0x65')](_0xb3a141)){return _[_0x2d2e('0x30')](_0xb3a141,function(_0x1b2314){return _0x1b2314['sectionId'];});}else{return;}})[_0x2d2e('0x2a')](function(_0x519967){if(_0x519967)_0x427b00=_0x519967;if(_[_0x2d2e('0x64')](_0x427b00,0x64)){var _0x424bc3=_[_0x2d2e('0x4e')](_0xb3a141,{'sectionId':0x64});return hasDefaultDashboard(_0x424bc3)[_0x2d2e('0x2a')](function(_0x4d9044){return _[_0x2d2e('0x30')](_0xb3a141,function(_0x57f2d1){if(_0x57f2d1['sectionId']===0x64){_0x57f2d1['subsections']=_0x4d9044;}return _0x57f2d1;});});}else{return;}})[_0x2d2e('0x2a')](function(_0x9612ea){if(_0x9612ea)_0xb3a141=_0x9612ea;if(_[_0x2d2e('0x64')](_0x427b00,0x3eb)){var _0x30155c=_[_0x2d2e('0x4e')](_0xb3a141,{'sectionId':0x3eb});return getCustomDashboards(_0x30155c)[_0x2d2e('0x2a')](function(_0x2cfa72){return _['map'](_0xb3a141,function(_0x5d80b4){if(_0x30155c[_0x2d2e('0x63')]){if(_0x5d80b4['sectionId']===0x3eb){_0x5d80b4['subsections']=_0x2cfa72;}}else{if(_0x5d80b4[_0x2d2e('0x5d')]===0x64){if(!_0x5d80b4[_0x2d2e('0x66')]){_0x5d80b4[_0x2d2e('0x66')]=[];}_0x5d80b4[_0x2d2e('0x66')]=_0x5d80b4[_0x2d2e('0x66')][_0x2d2e('0x67')](_0x2cfa72);}}return _0x5d80b4;});});}else{return;}})['then'](function(_0x4a91bd){if(_0x4a91bd)_0xb3a141=_0x4a91bd;if(_[_0x2d2e('0x64')](_0x427b00,0x709)){var _0x10ecd0=_[_0x2d2e('0x4e')](_0xb3a141,{'sectionId':0x709});return getPlugins(_0x10ecd0)[_0x2d2e('0x2a')](function(_0x5668b4){if(_0x10ecd0[_0x2d2e('0x63')]){return _[_0x2d2e('0x30')](_0xb3a141,function(_0x314a9e){if(_0x314a9e[_0x2d2e('0x5d')]===0x709){_0x314a9e[_0x2d2e('0x66')]=_0x5668b4;}return _0x314a9e;});}else{var _0x28684b={'sectionId':0x76c,'enabled':0x1,'subsections':_0x5668b4};var _0x5e057b=_[_0x2d2e('0x30')](_0xb3a141);_0x5e057b[_0x2d2e('0x60')](_0x28684b);return _0x5e057b;}});}else{return;}})['then'](function(_0x147f8f){if(_0x147f8f)_0xb3a141=_0x147f8f;return _[_0x2d2e('0x40')](_0xb3a141,[_0x2d2e('0x63'),0x1]);})[_0x2d2e('0x2a')](respondWithResult(_0x165293,null))[_0x2d2e('0x49')](handleError(_0x165293,null));};function hasDefaultDashboard(_0x4226c9){var _0x324e03=[0x65];return new BPromise(function(_0x5034d0,_0x64e772){try{if(_0x4226c9[_0x2d2e('0x58')]){_0x5034d0(_0x324e03);}else{return db[_0x2d2e('0x59')][_0x2d2e('0x68')]({'where':{'sectionId':_0x4226c9['id']},'raw':!![]})[_0x2d2e('0x2a')](function(_0x3bb65e){_0x3bb65e?_0x5034d0(_0x324e03):_0x5034d0();});}}catch(_0x37e940){_0x64e772(_0x37e940);}});}function getCustomDashboards(_0x2e488d){var _0x31b563=[];return new BPromise(function(_0x46c0e0,_0x30b3be){try{if(_0x2e488d['autoAssociation']){return db['Dashboard'][_0x2d2e('0x47')]({'raw':!![]})[_0x2d2e('0x2a')](function(_0x1f6de9){_0x1f6de9[_0x2d2e('0x69')](function(_0x5ca0fb){_0x31b563[_0x2d2e('0x60')](_0x5ca0fb['id']+0x1869f);});_0x46c0e0(_0x31b563);});}else{return db[_0x2d2e('0x59')][_0x2d2e('0x47')]({'where':{'sectionId':_0x2e488d['id']},'raw':!![]})[_0x2d2e('0x2a')](function(_0x2457f5){_0x2457f5[_0x2d2e('0x69')](function(_0x40a512){_0x31b563[_0x2d2e('0x60')](_0x40a512[_0x2d2e('0x6a')]+0x1869f);});_0x46c0e0(_0x31b563);});}}catch(_0x263d3c){_0x30b3be(_0x263d3c);}});}function getPlugins(_0x4c43d4){var _0xb6fc38=[];return new BPromise(function(_0x1def3d,_0x18b094){try{if(_0x4c43d4['autoAssociation']){return db[_0x2d2e('0x6b')][_0x2d2e('0x47')]({'raw':!![]})[_0x2d2e('0x2a')](function(_0x468fd1){_0x468fd1[_0x2d2e('0x69')](function(_0x4a0019){_0xb6fc38[_0x2d2e('0x60')](_0x4a0019['id']+0x15b38);});_0x1def3d(_0xb6fc38);});}else{return db[_0x2d2e('0x59')][_0x2d2e('0x47')]({'where':{'sectionId':_0x4c43d4['id']},'raw':!![]})[_0x2d2e('0x2a')](function(_0x264ca2){_0x264ca2[_0x2d2e('0x69')](function(_0x2a469f){_0xb6fc38['push'](_0x2a469f[_0x2d2e('0x6a')]+0x15b38);});_0x1def3d(_0xb6fc38);});}}catch(_0x43fbba){_0x18b094(_0x43fbba);}});}exports[_0x2d2e('0x6c')]=function(_0x2a8677,_0x24268f){return db['UserProfile']['find']({'where':{'id':_0x2a8677[_0x2d2e('0x50')]['id']}})['then'](handleEntityNotFound(_0x24268f,null))['then'](function(_0x10f306){if(_0x10f306){return db['sequelize']['transaction'](function(_0x12c064){return db['UserProfileSection'][_0x2d2e('0x47')]({'where':{'userProfileId':_0x2a8677[_0x2d2e('0x50')]['id']},'attributes':['id'],'raw':!![]})[_0x2d2e('0x2a')](function(_0x26088a){if(_0x26088a){return db[_0x2d2e('0x5c')][_0x2d2e('0x2b')]({'where':{'userProfileId':_0x2a8677[_0x2d2e('0x50')]['id'],'id':_[_0x2d2e('0x30')](_0x26088a,function(_0x40531e){return _0x40531e['id'];})},'transaction':_0x12c064});}})[_0x2d2e('0x2a')](function(_0x399ed1){var _0x2b4fdb=_['map'](_0x2a8677['body'],function(_0x10cc52){_0x10cc52[_0x2d2e('0x5e')]=_0x2a8677[_0x2d2e('0x50')]['id'];return _0x10cc52;});return db[_0x2d2e('0x5c')][_0x2d2e('0x6d')](_0x2b4fdb,{'raw':!![],'transaction':_0x12c064});})['then'](function(_0x465ce2){var _0x232f3c=_[_0x2d2e('0x40')](_[_0x2d2e('0x30')](_0x465ce2,function(_0x28a291){return _0x28a291[_0x2d2e('0x51')]({'plain':!![]});}),{'includeAll':![]});if(_0x232f3c){return db[_0x2d2e('0x5c')][_0x2d2e('0x47')]({'where':{'userProfileId':_0x2a8677[_0x2d2e('0x50')]['id'],'sectionId':_[_0x2d2e('0x30')](_0x232f3c,function(_0x4a82ab){return _0x4a82ab[_0x2d2e('0x5d')];})},'attributes':['id','sectionId'],'raw':!![]})[_0x2d2e('0x2a')](function(_0x1b60fa){var _0x442079=_[_0x2d2e('0x30')](_0x2a8677['body'],function(_0x4c2bf5){_0x4c2bf5[_0x2d2e('0x5e')]=_0x2a8677['params']['id'];return _0x4c2bf5;});return db['UserProfileResource'][_0x2d2e('0x6d')](_0x442079,{'raw':!![],'transaction':_0x12c064});});}})[_0x2d2e('0x49')](handleError(_0x24268f,null));});}})['then'](function(_0x156e4d){var _0x5c29d7=_[_0x2d2e('0x30')](_0x156e4d,function(_0x542b69){return _0x542b69['get']({'plain':!![]});});})[_0x2d2e('0x2a')](respondWithResult(_0x24268f,null))[_0x2d2e('0x49')](handleError(_0x24268f,null));};exports['removeResources']=function(_0x4428d1,_0x44c08c,_0x3d1511){return db[_0x2d2e('0x31')][_0x2d2e('0x4e')]({'where':{'id':_0x4428d1[_0x2d2e('0x50')]['id']}})['then'](handleEntityNotFound(_0x44c08c,null))[_0x2d2e('0x2a')](function(_0x4d84ff){if(_0x4d84ff){return _0x4d84ff[_0x2d2e('0x6e')](_0x4428d1[_0x2d2e('0x37')][_0x2d2e('0x6f')]);}})[_0x2d2e('0x2a')](respondWithStatusCode(_0x44c08c,null))[_0x2d2e('0x49')](handleError(_0x44c08c,null));};exports[_0x2d2e('0x70')]=function(_0x5d31e8,_0x2797b7){var _0x4d84d1={};if(!_0x5d31e8['query'][_0x2d2e('0x71')])throw new Error(_0x2d2e('0x72'));if(!_0x5d31e8[_0x2d2e('0x37')][_0x2d2e('0x3c')](_0x2d2e('0x3d'))){_0x4d84d1[_0x2d2e('0x23')]=qs[_0x2d2e('0x23')](_0x5d31e8[_0x2d2e('0x37')][_0x2d2e('0x23')]);_0x4d84d1['offset']=qs[_0x2d2e('0x22')](_0x5d31e8[_0x2d2e('0x37')]['offset']);}return db[_0x2d2e('0x31')]['find']({'where':{'id':_0x5d31e8[_0x2d2e('0x50')]['id']}})[_0x2d2e('0x2a')](function(_0x1d3f14){if(!_0x1d3f14)throw new Error('No\x20User\x20Profile\x20found\x20for\x20id\x20'+_0x5d31e8[_0x2d2e('0x50')]['id']);return db[_0x2d2e('0x31')][_0x2d2e('0x70')](_0x5d31e8);})[_0x2d2e('0x2a')](respondWithFilteredResult(_0x2797b7,_0x4d84d1))[_0x2d2e('0x49')](handleError(_0x2797b7,null));};