Built motion from commit 10af8726.|2.6.34
[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 _0x8c93=['error','stack','name','send','index','map','UserProfile','rawAttributes','fieldName','type','key','query','filters','intersection','model','attributes','fields','length','hasOwnProperty','nolimit','order','sort','pick','filter','where','merge','VIRTUAL','include','findAll','rows','catch','show','params','keys','includeAll','options','find','create','clone','omit','createdAt','updatedAt','crudPermissions','sequelize','transaction','body','get','UserProfileSection','each','autoAssociation','UserProfileResource','sectionId','userProfileId','Resources','describe','addSections','push','removeSections','ids','getSections','enabled','includes','isEmpty','subsections','concat','forEach','resourceId','Plugin','addResources','bulkCreate','removeResources','getResources','section','Missing\x20section\x20parameter','No\x20User\x20Profile\x20found\x20for\x20id\x20','eml-format','rimraf','zip-dir','fast-json-patch','bluebird','mustache','path','sox','to-csv','ejs','fs-extra','squel','crypto','querystring','papaparse','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/logger','../../config/utils','../../config/environment','../../mysqldb','redis','defaults','localhost','socket.io-emitter','register','sendStatus','status','end','json','offset','limit','undefined','count','set','Content-Range','save','update','then','destroy'];(function(_0x4565bf,_0x5ad9d6){var _0x5610ba=function(_0x170988){while(--_0x170988){_0x4565bf['push'](_0x4565bf['shift']());}};_0x5610ba(++_0x5ad9d6);}(_0x8c93,0x1aa));var _0x38c9=function(_0x2ba8b5,_0x4cfc1d){_0x2ba8b5=_0x2ba8b5-0x0;var _0x1f1da9=_0x8c93[_0x2ba8b5];return _0x1f1da9;};'use strict';var emlformat=require(_0x38c9('0x0'));var rimraf=require(_0x38c9('0x1'));var zipdir=require(_0x38c9('0x2'));var jsonpatch=require(_0x38c9('0x3'));var rp=require('request-promise');var moment=require('moment');var BPromise=require(_0x38c9('0x4'));var Mustache=require(_0x38c9('0x5'));var util=require('util');var path=require(_0x38c9('0x6'));var sox=require(_0x38c9('0x7'));var csv=require(_0x38c9('0x8'));var ejs=require(_0x38c9('0x9'));var fs=require('fs');var fs_extra=require(_0x38c9('0xa'));var _=require('lodash');var squel=require(_0x38c9('0xb'));var crypto=require(_0x38c9('0xc'));var jsforce=require('jsforce');var deskjs=require('desk.js');var toCsv=require(_0x38c9('0x8'));var querystring=require(_0x38c9('0xd'));var Papa=require(_0x38c9('0xe'));var Redis=require(_0x38c9('0xf'));var authService=require(_0x38c9('0x10'));var qs=require(_0x38c9('0x11'));var as=require(_0x38c9('0x12'));var hardwareService=require('../../config/license/hardware');var logger=require(_0x38c9('0x13'))('api');var utils=require(_0x38c9('0x14'));var config=require(_0x38c9('0x15'));var licenseUtil=require('../../config/license/util');var db=require(_0x38c9('0x16'))['db'];config[_0x38c9('0x17')]=_[_0x38c9('0x18')](config[_0x38c9('0x17')],{'host':_0x38c9('0x19'),'port':0x18eb});var socket=require(_0x38c9('0x1a'))(new Redis(config[_0x38c9('0x17')]));require('./userProfile.socket')[_0x38c9('0x1b')](socket);function respondWithStatusCode(_0x426f3a,_0x4e89b2){_0x4e89b2=_0x4e89b2||0xcc;return function(_0x9f63af){if(_0x9f63af){return _0x426f3a[_0x38c9('0x1c')](_0x4e89b2);}return _0x426f3a[_0x38c9('0x1d')](_0x4e89b2)[_0x38c9('0x1e')]();};}function respondWithResult(_0x136ecf,_0x38db17){_0x38db17=_0x38db17||0xc8;return function(_0x40e61e){if(_0x40e61e){return _0x136ecf[_0x38c9('0x1d')](_0x38db17)[_0x38c9('0x1f')](_0x40e61e);}};}function respondWithFilteredResult(_0x26e28c,_0xf2c472){return function(_0x10b2dd){if(_0x10b2dd){var _0xc4a474=typeof _0xf2c472[_0x38c9('0x20')]==='undefined'&&typeof _0xf2c472[_0x38c9('0x21')]===_0x38c9('0x22');var _0x4302b3=_0x10b2dd['count'];var _0x178cbd=_0xc4a474?0x0:_0xf2c472[_0x38c9('0x20')];var _0x569933=_0xc4a474?_0x10b2dd[_0x38c9('0x23')]:_0xf2c472[_0x38c9('0x20')]+_0xf2c472[_0x38c9('0x21')];var _0x4cc196;if(_0x569933>=_0x4302b3){_0x569933=_0x4302b3;_0x4cc196=0xc8;}else{_0x4cc196=0xce;}_0x26e28c[_0x38c9('0x1d')](_0x4cc196);return _0x26e28c[_0x38c9('0x24')](_0x38c9('0x25'),_0x178cbd+'-'+_0x569933+'/'+_0x4302b3)[_0x38c9('0x1f')](_0x10b2dd);}return null;};}function patchUpdates(_0x1a6dbb){return function(_0x54fe2d){try{jsonpatch['apply'](_0x54fe2d,_0x1a6dbb,!![]);}catch(_0x4e8bbd){return BPromise['reject'](_0x4e8bbd);}return _0x54fe2d[_0x38c9('0x26')]();};}function saveUpdates(_0x824920,_0xbd589c){return function(_0x178f3c){if(_0x178f3c){return _0x178f3c[_0x38c9('0x27')](_0x824920)[_0x38c9('0x28')](function(_0x295683){return _0x295683;});}return null;};}function removeEntity(_0x49e7fa,_0xbaad99){return function(_0x58b880){if(_0x58b880){return _0x58b880[_0x38c9('0x29')]()['then'](function(){_0x49e7fa[_0x38c9('0x1d')](0xcc)['end']();});}};}function handleEntityNotFound(_0x498588,_0x56a31c){return function(_0x27cd34){if(!_0x27cd34){_0x498588[_0x38c9('0x1c')](0x194);}return _0x27cd34;};}function handleError(_0x1edd86,_0x3a8cc6){_0x3a8cc6=_0x3a8cc6||0x1f4;return function(_0x51f816){logger[_0x38c9('0x2a')](_0x51f816[_0x38c9('0x2b')]);if(_0x51f816['name']){delete _0x51f816[_0x38c9('0x2c')];}_0x1edd86[_0x38c9('0x1d')](_0x3a8cc6)[_0x38c9('0x2d')](_0x51f816);};}exports[_0x38c9('0x2e')]=function(_0x1b3d40,_0x8ece55){var _0x868412={},_0xbd5c47={},_0x10a307={'count':0x0,'rows':[]};var _0x590e81=_[_0x38c9('0x2f')](db[_0x38c9('0x30')][_0x38c9('0x31')],function(_0xc412a9){return{'name':_0xc412a9[_0x38c9('0x32')],'type':_0xc412a9[_0x38c9('0x33')][_0x38c9('0x34')]};});_0xbd5c47['model']=_[_0x38c9('0x2f')](_0x590e81,_0x38c9('0x2c'));_0xbd5c47[_0x38c9('0x35')]=_['keys'](_0x1b3d40[_0x38c9('0x35')]);_0xbd5c47[_0x38c9('0x36')]=_[_0x38c9('0x37')](_0xbd5c47[_0x38c9('0x38')],_0xbd5c47[_0x38c9('0x35')]);_0x868412[_0x38c9('0x39')]=_[_0x38c9('0x37')](_0xbd5c47['model'],qs[_0x38c9('0x3a')](_0x1b3d40[_0x38c9('0x35')]['fields']));_0x868412[_0x38c9('0x39')]=_0x868412['attributes'][_0x38c9('0x3b')]?_0x868412['attributes']:_0xbd5c47[_0x38c9('0x38')];if(!_0x1b3d40[_0x38c9('0x35')][_0x38c9('0x3c')](_0x38c9('0x3d'))){_0x868412[_0x38c9('0x21')]=qs['limit'](_0x1b3d40['query'][_0x38c9('0x21')]);_0x868412[_0x38c9('0x20')]=qs[_0x38c9('0x20')](_0x1b3d40['query'][_0x38c9('0x20')]);}_0x868412[_0x38c9('0x3e')]=qs[_0x38c9('0x3f')](_0x1b3d40['query'][_0x38c9('0x3f')]);_0x868412['where']=qs[_0x38c9('0x36')](_[_0x38c9('0x40')](_0x1b3d40[_0x38c9('0x35')],_0xbd5c47[_0x38c9('0x36')]),_0x590e81);if(_0x1b3d40[_0x38c9('0x35')][_0x38c9('0x41')]){_0x868412[_0x38c9('0x42')]=_[_0x38c9('0x43')](_0x868412['where'],{'$or':_['map'](_0x590e81,function(_0x37c833){if(_0x37c833[_0x38c9('0x33')]!==_0x38c9('0x44')){var _0x28a3ed={};_0x28a3ed[_0x37c833['name']]={'$like':'%'+_0x1b3d40[_0x38c9('0x35')][_0x38c9('0x41')]+'%'};return _0x28a3ed;}})});}_0x868412=_[_0x38c9('0x43')]({},_0x868412,_0x1b3d40['options']);var _0x590f9f={'where':_0x868412[_0x38c9('0x42')]};return db[_0x38c9('0x30')][_0x38c9('0x23')](_0x590f9f)[_0x38c9('0x28')](function(_0x37fa22){_0x10a307['count']=_0x37fa22;if(_0x1b3d40['query']['includeAll']){_0x868412[_0x38c9('0x45')]=[{'all':!![]}];}return db[_0x38c9('0x30')][_0x38c9('0x46')](_0x868412);})['then'](function(_0x2b4331){_0x10a307[_0x38c9('0x47')]=_0x2b4331;return _0x10a307;})[_0x38c9('0x28')](respondWithFilteredResult(_0x8ece55,_0x868412))[_0x38c9('0x48')](handleError(_0x8ece55,null));};exports[_0x38c9('0x49')]=function(_0x4a0074,_0x746bb0){var _0x476bf1={'raw':![],'where':{'id':_0x4a0074[_0x38c9('0x4a')]['id']}},_0x48844d={};_0x48844d[_0x38c9('0x38')]=_[_0x38c9('0x4b')](db['UserProfile']['rawAttributes']);_0x48844d[_0x38c9('0x35')]=_[_0x38c9('0x4b')](_0x4a0074['query']);_0x48844d[_0x38c9('0x36')]=_[_0x38c9('0x37')](_0x48844d['model'],_0x48844d[_0x38c9('0x35')]);_0x476bf1[_0x38c9('0x39')]=_['intersection'](_0x48844d['model'],qs[_0x38c9('0x3a')](_0x4a0074[_0x38c9('0x35')]['fields']));_0x476bf1[_0x38c9('0x39')]=_0x476bf1[_0x38c9('0x39')][_0x38c9('0x3b')]?_0x476bf1['attributes']:_0x48844d['model'];if(_0x4a0074[_0x38c9('0x35')][_0x38c9('0x4c')]){_0x476bf1[_0x38c9('0x45')]=[{'all':!![]}];}_0x476bf1=_[_0x38c9('0x43')]({},_0x476bf1,_0x4a0074[_0x38c9('0x4d')]);return db['UserProfile'][_0x38c9('0x4e')](_0x476bf1)[_0x38c9('0x28')](handleEntityNotFound(_0x746bb0,null))[_0x38c9('0x28')](respondWithResult(_0x746bb0,null))['catch'](handleError(_0x746bb0,null));};exports['create']=function(_0x57f064,_0x3a2eab){return db['UserProfile'][_0x38c9('0x4f')](_0x57f064['body'],{})[_0x38c9('0x28')](respondWithResult(_0x3a2eab,0xc9))[_0x38c9('0x48')](handleError(_0x3a2eab,null));};exports[_0x38c9('0x50')]=function(_0x27af13,_0x471e3e){var _0x66887={'where':{'id':_0x27af13[_0x38c9('0x4a')]['id']}},_0x4b924c={};_0x4b924c[_0x38c9('0x38')]=_[_0x38c9('0x4b')](db[_0x38c9('0x30')]['rawAttributes']);_0x66887[_0x38c9('0x39')]=_['intersection'](_0x4b924c[_0x38c9('0x38')],qs[_0x38c9('0x3a')](_0x27af13['query'][_0x38c9('0x3a')]));_0x66887[_0x38c9('0x39')]=_0x66887[_0x38c9('0x39')]['length']?_0x66887[_0x38c9('0x39')]:_0x4b924c[_0x38c9('0x38')];if(_0x27af13[_0x38c9('0x35')][_0x38c9('0x4c')]){_0x66887[_0x38c9('0x45')]=[{'all':!![]}];}_0x66887=_['merge']({},_0x66887,_0x27af13[_0x38c9('0x4d')]);return db[_0x38c9('0x30')]['find'](_0x66887)[_0x38c9('0x28')](handleEntityNotFound(_0x471e3e,null))[_0x38c9('0x28')](function(_0x2fcb8e){if(_0x2fcb8e){var _0x3b62f3=_0x2fcb8e['get']({'plain':!![]});_0x3b62f3=qs[_0x38c9('0x51')](_0x3b62f3,['id',_0x38c9('0x52'),_0x38c9('0x53'),_0x38c9('0x54')]);_0x27af13['body']=_[_0x38c9('0x51')](_0x27af13['body'],['id',_0x38c9('0x52'),_0x38c9('0x53')]);return db[_0x38c9('0x55')][_0x38c9('0x56')](function(_0x4e6616){return db['UserProfile'][_0x38c9('0x4f')](_[_0x38c9('0x43')](_0x3b62f3,_0x27af13[_0x38c9('0x57')]),{'include':_0x27af13[_0x38c9('0x35')][_0x38c9('0x4c')]?[{'all':!![]}]:undefined,'transaction':_0x4e6616})[_0x38c9('0x28')](function(_0xd2a578){var _0x25804a=_0xd2a578[_0x38c9('0x58')]({'plain':!![]});return db[_0x38c9('0x59')][_0x38c9('0x46')]({'where':{'userProfileId':_0x27af13[_0x38c9('0x4a')]['id']},'raw':!![]})[_0x38c9('0x28')](function(_0x59430c){if(_0x59430c){return BPromise[_0x38c9('0x5a')](_0x59430c,function(_0xfa64ce){return new BPromise(function(_0x2db550,_0x58438a){if(_0xfa64ce['autoAssociation']===null||_0xfa64ce[_0x38c9('0x5b')]===0x1)_0x2db550(null);return db[_0x38c9('0x5c')][_0x38c9('0x46')]({'where':{'sectionId':_0xfa64ce['id']},'raw':!![]})[_0x38c9('0x28')](function(_0x3182c3){var _0x550e33=_[_0x38c9('0x2f')](_0x3182c3,function(_0x1f6f21){return qs[_0x38c9('0x51')](_0x1f6f21,['id',_0x38c9('0x52'),_0x38c9('0x53'),_0x38c9('0x5d')]);});_0x2db550(_0x550e33);})[_0x38c9('0x48')](function(_0x2b0f98){_0x58438a(_0x2b0f98);});})[_0x38c9('0x28')](function(_0x21ce4f){var _0x447aba=qs[_0x38c9('0x51')](_0xfa64ce,['id',_0x38c9('0x52'),_0x38c9('0x53')]);_0x447aba[_0x38c9('0x5e')]=_0x25804a['id'];if(_0x21ce4f)_0x447aba['Resources']=_0x21ce4f;return _0x447aba;})[_0x38c9('0x28')](function(_0x492984){return db['UserProfileSection'][_0x38c9('0x4f')](_0x492984,{'include':[{'model':db[_0x38c9('0x5c')],'as':_0x38c9('0x5f')}],'raw':!![],'transaction':_0x4e6616});});})['then'](function(){return _0x25804a;});}});});});}})[_0x38c9('0x28')](respondWithResult(_0x471e3e,0xc9))[_0x38c9('0x48')](handleError(_0x471e3e,null));};exports[_0x38c9('0x27')]=function(_0x18d3dc,_0x25b704){if(_0x18d3dc['body']['id']){delete _0x18d3dc[_0x38c9('0x57')]['id'];}return db['UserProfile'][_0x38c9('0x4e')]({'where':{'id':_0x18d3dc[_0x38c9('0x4a')]['id']}})[_0x38c9('0x28')](handleEntityNotFound(_0x25b704,null))[_0x38c9('0x28')](saveUpdates(_0x18d3dc[_0x38c9('0x57')],null))[_0x38c9('0x28')](respondWithResult(_0x25b704,null))[_0x38c9('0x48')](handleError(_0x25b704,null));};exports[_0x38c9('0x29')]=function(_0x116d2b,_0x1fbd31){return db[_0x38c9('0x30')][_0x38c9('0x4e')]({'where':{'id':_0x116d2b['params']['id']}})['then'](handleEntityNotFound(_0x1fbd31,null))['then'](removeEntity(_0x1fbd31,null))['catch'](handleError(_0x1fbd31,null));};exports[_0x38c9('0x60')]=function(_0x4e81ad,_0x1dc205){return db[_0x38c9('0x30')][_0x38c9('0x60')]()[_0x38c9('0x28')](respondWithResult(_0x1dc205,null))[_0x38c9('0x48')](handleError(_0x1dc205,null));};exports[_0x38c9('0x61')]=function(_0x515e61,_0xb34527){var _0x36b917=_0x515e61[_0x38c9('0x57')];return db[_0x38c9('0x30')][_0x38c9('0x4e')]({'where':{'id':_0x515e61['params']['id']}})[_0x38c9('0x28')](handleEntityNotFound(_0xb34527,null))[_0x38c9('0x28')](function(_0x2cb19b){if(_0x2cb19b){return db['sequelize'][_0x38c9('0x56')](function(_0x1d5c00){return db[_0x38c9('0x59')][_0x38c9('0x29')]({'where':{'userProfileId':_0x515e61[_0x38c9('0x4a')]['id'],'sectionId':_[_0x38c9('0x2f')](_0x36b917,function(_0x45e34c){return _0x45e34c[_0x38c9('0x5d')];})},'transaction':_0x1d5c00})[_0x38c9('0x28')](function(){var _0x47092e=_[_0x38c9('0x2f')](_0x36b917,function(_0x4d689c){_0x4d689c[_0x38c9('0x5e')]=_0x515e61[_0x38c9('0x4a')]['id'];return _0x4d689c;});var _0x119ff7=[];return BPromise['each'](_0x47092e,function(_0x598a9f){return db[_0x38c9('0x59')][_0x38c9('0x4f')](_0x598a9f,{'include':[{'model':db[_0x38c9('0x5c')],'as':_0x38c9('0x5f')}],'raw':!![],'transaction':_0x1d5c00})[_0x38c9('0x28')](function(_0x269ac5){_0x119ff7[_0x38c9('0x62')](_0x269ac5['get']({'plain':!![]}));});})[_0x38c9('0x28')](function(){return _0x119ff7;});});});}})['then'](function(_0x491621){return _0x491621;})[_0x38c9('0x28')](respondWithResult(_0xb34527,null))[_0x38c9('0x48')](handleError(_0xb34527,null));};exports[_0x38c9('0x63')]=function(_0x4b6937,_0x1855ea){var _0xa41920;return db[_0x38c9('0x30')][_0x38c9('0x4e')]({'where':{'id':_0x4b6937[_0x38c9('0x4a')]['id']},'attributes':['id','name']})['then'](handleEntityNotFound(_0x1855ea,null))[_0x38c9('0x28')](function(_0x3d49b8){if(_0x3d49b8){_0xa41920=_0x3d49b8;return db[_0x38c9('0x59')]['destroy']({'where':{'userProfileId':_0x4b6937[_0x38c9('0x4a')]['id'],'sectionId':_0x4b6937[_0x38c9('0x35')][_0x38c9('0x64')]}});}})['then'](function(){return _0xa41920;})[_0x38c9('0x28')](respondWithStatusCode(_0x1855ea,null))['catch'](handleError(_0x1855ea,null));};exports[_0x38c9('0x65')]=function(_0x350b28,_0x52b405){var _0x209f72=[];var _0x5ebf0b=[];return db[_0x38c9('0x59')][_0x38c9('0x46')]({'where':{'userProfileId':_0x350b28[_0x38c9('0x4a')]['id']},'raw':!![]})[_0x38c9('0x28')](function(_0x1d3223){_0x209f72=_[_0x38c9('0x41')](_0x1d3223,function(_0x255382){return _0x255382[_0x38c9('0x66')]===0x1||_[_0x38c9('0x67')]([0x3eb,0x709],_0x255382['sectionId']);});if(!_[_0x38c9('0x68')](_0x209f72)){return _[_0x38c9('0x2f')](_0x209f72,function(_0x6a0efe){return _0x6a0efe[_0x38c9('0x5d')];});}else{return;}})[_0x38c9('0x28')](function(_0x417700){if(_0x417700)_0x5ebf0b=_0x417700;if(_['includes'](_0x5ebf0b,0x64)){var _0x54bd9c=_['find'](_0x209f72,{'sectionId':0x64});return hasDefaultDashboard(_0x54bd9c)[_0x38c9('0x28')](function(_0x56afb8){return _[_0x38c9('0x2f')](_0x209f72,function(_0x3c4472){if(_0x3c4472['sectionId']===0x64){_0x3c4472[_0x38c9('0x69')]=_0x56afb8;}return _0x3c4472;});});}else{return;}})[_0x38c9('0x28')](function(_0x216756){if(_0x216756)_0x209f72=_0x216756;if(_[_0x38c9('0x67')](_0x5ebf0b,0x3eb)){var _0x91b594=_['find'](_0x209f72,{'sectionId':0x3eb});return getCustomDashboards(_0x91b594)[_0x38c9('0x28')](function(_0x5a5c11){return _[_0x38c9('0x2f')](_0x209f72,function(_0x5a2e30){if(_0x91b594[_0x38c9('0x66')]){if(_0x5a2e30[_0x38c9('0x5d')]===0x3eb){_0x5a2e30[_0x38c9('0x69')]=_0x5a5c11;}}else{if(_0x5a2e30[_0x38c9('0x5d')]===0x64){if(!_0x5a2e30[_0x38c9('0x69')]){_0x5a2e30['subsections']=[];}_0x5a2e30[_0x38c9('0x69')]=_0x5a2e30['subsections'][_0x38c9('0x6a')](_0x5a5c11);}}return _0x5a2e30;});});}else{return;}})[_0x38c9('0x28')](function(_0x89bd9c){if(_0x89bd9c)_0x209f72=_0x89bd9c;if(_[_0x38c9('0x67')](_0x5ebf0b,0x709)){var _0x136e70=_[_0x38c9('0x4e')](_0x209f72,{'sectionId':0x709});return getPlugins(_0x136e70)[_0x38c9('0x28')](function(_0x170c84){if(_0x136e70['enabled']){return _[_0x38c9('0x2f')](_0x209f72,function(_0x2b3035){if(_0x2b3035['sectionId']===0x709){_0x2b3035[_0x38c9('0x69')]=_0x170c84;}return _0x2b3035;});}else{var _0x4c6619={'sectionId':0x76c,'enabled':0x1,'subsections':_0x170c84};var _0x28ecc3=_[_0x38c9('0x2f')](_0x209f72);_0x28ecc3['push'](_0x4c6619);return _0x28ecc3;}});}else{return;}})[_0x38c9('0x28')](function(_0x3dcc5e){if(_0x3dcc5e)_0x209f72=_0x3dcc5e;return _[_0x38c9('0x41')](_0x209f72,[_0x38c9('0x66'),0x1]);})['then'](respondWithResult(_0x52b405,null))[_0x38c9('0x48')](handleError(_0x52b405,null));};function hasDefaultDashboard(_0x434e04){var _0x5e3aa1=[0x65];return new BPromise(function(_0x193d67,_0x5e8868){try{if(_0x434e04[_0x38c9('0x5b')]){_0x193d67(_0x5e3aa1);}else{return db[_0x38c9('0x5c')]['findOne']({'where':{'sectionId':_0x434e04['id']},'raw':!![]})['then'](function(_0x22313b){_0x22313b?_0x193d67(_0x5e3aa1):_0x193d67();});}}catch(_0x32991d){_0x5e8868(_0x32991d);}});}function getCustomDashboards(_0x3b96c9){var _0x19ba23=[];return new BPromise(function(_0x4b7bd6,_0x464f3d){try{if(_0x3b96c9['autoAssociation']){return db['Dashboard'][_0x38c9('0x46')]({'raw':!![]})[_0x38c9('0x28')](function(_0x40767c){_0x40767c[_0x38c9('0x6b')](function(_0x489347){_0x19ba23[_0x38c9('0x62')](_0x489347['id']+0x1869f);});_0x4b7bd6(_0x19ba23);});}else{return db['UserProfileResource'][_0x38c9('0x46')]({'where':{'sectionId':_0x3b96c9['id']},'raw':!![]})[_0x38c9('0x28')](function(_0x5d9d29){_0x5d9d29[_0x38c9('0x6b')](function(_0x27946b){_0x19ba23[_0x38c9('0x62')](_0x27946b[_0x38c9('0x6c')]+0x1869f);});_0x4b7bd6(_0x19ba23);});}}catch(_0x4cb7d0){_0x464f3d(_0x4cb7d0);}});}function getPlugins(_0x370a86){var _0x16c381=[];return new BPromise(function(_0x197fa5,_0x439c86){try{if(_0x370a86['autoAssociation']){return db[_0x38c9('0x6d')][_0x38c9('0x46')]({'raw':!![]})[_0x38c9('0x28')](function(_0x5de5fc){_0x5de5fc[_0x38c9('0x6b')](function(_0x2e23e3){_0x16c381[_0x38c9('0x62')](_0x2e23e3['id']+0x15b38);});_0x197fa5(_0x16c381);});}else{return db[_0x38c9('0x5c')][_0x38c9('0x46')]({'where':{'sectionId':_0x370a86['id']},'raw':!![]})[_0x38c9('0x28')](function(_0x3df47b){_0x3df47b['forEach'](function(_0x4c08b0){_0x16c381[_0x38c9('0x62')](_0x4c08b0['resourceId']+0x15b38);});_0x197fa5(_0x16c381);});}}catch(_0x558859){_0x439c86(_0x558859);}});}exports[_0x38c9('0x6e')]=function(_0x512926,_0x5ea58d){return db[_0x38c9('0x30')][_0x38c9('0x4e')]({'where':{'id':_0x512926[_0x38c9('0x4a')]['id']}})[_0x38c9('0x28')](handleEntityNotFound(_0x5ea58d,null))[_0x38c9('0x28')](function(_0x36a4a8){if(_0x36a4a8){return db[_0x38c9('0x55')][_0x38c9('0x56')](function(_0x27dd5d){return db['UserProfileSection'][_0x38c9('0x46')]({'where':{'userProfileId':_0x512926['params']['id']},'attributes':['id'],'raw':!![]})[_0x38c9('0x28')](function(_0x338672){if(_0x338672){return db['UserProfileSection'][_0x38c9('0x29')]({'where':{'userProfileId':_0x512926[_0x38c9('0x4a')]['id'],'id':_[_0x38c9('0x2f')](_0x338672,function(_0x236686){return _0x236686['id'];})},'transaction':_0x27dd5d});}})['then'](function(_0x2a610a){var _0x14afad=_['map'](_0x512926[_0x38c9('0x57')],function(_0x46398f){_0x46398f[_0x38c9('0x5e')]=_0x512926[_0x38c9('0x4a')]['id'];return _0x46398f;});return db['UserProfileSection'][_0x38c9('0x6f')](_0x14afad,{'raw':!![],'transaction':_0x27dd5d});})['then'](function(_0x326318){var _0x2d33bf=_[_0x38c9('0x41')](_['map'](_0x326318,function(_0x16f2c1){return _0x16f2c1[_0x38c9('0x58')]({'plain':!![]});}),{'includeAll':![]});if(_0x2d33bf){return db[_0x38c9('0x59')]['findAll']({'where':{'userProfileId':_0x512926[_0x38c9('0x4a')]['id'],'sectionId':_[_0x38c9('0x2f')](_0x2d33bf,function(_0x1d3e19){return _0x1d3e19[_0x38c9('0x5d')];})},'attributes':['id',_0x38c9('0x5d')],'raw':!![]})[_0x38c9('0x28')](function(_0x4c8ce7){var _0x454b81=_['map'](_0x512926[_0x38c9('0x57')],function(_0x4bbe49){_0x4bbe49[_0x38c9('0x5e')]=_0x512926[_0x38c9('0x4a')]['id'];return _0x4bbe49;});return db[_0x38c9('0x5c')]['bulkCreate'](_0x454b81,{'raw':!![],'transaction':_0x27dd5d});});}})[_0x38c9('0x48')](handleError(_0x5ea58d,null));});}})['then'](function(_0x2d7cd7){var _0x12cd0a=_[_0x38c9('0x2f')](_0x2d7cd7,function(_0x2839eb){return _0x2839eb[_0x38c9('0x58')]({'plain':!![]});});})[_0x38c9('0x28')](respondWithResult(_0x5ea58d,null))[_0x38c9('0x48')](handleError(_0x5ea58d,null));};exports['removeResources']=function(_0x268bf9,_0x19e802,_0x130e5c){return db['UserProfile']['find']({'where':{'id':_0x268bf9[_0x38c9('0x4a')]['id']}})['then'](handleEntityNotFound(_0x19e802,null))[_0x38c9('0x28')](function(_0x1d37ac){if(_0x1d37ac){return _0x1d37ac[_0x38c9('0x70')](_0x268bf9[_0x38c9('0x35')][_0x38c9('0x64')]);}})[_0x38c9('0x28')](respondWithStatusCode(_0x19e802,null))[_0x38c9('0x48')](handleError(_0x19e802,null));};exports[_0x38c9('0x71')]=function(_0x151c4c,_0x309c88){var _0x30edd6={};if(!_0x151c4c[_0x38c9('0x35')][_0x38c9('0x72')])throw new Error(_0x38c9('0x73'));if(!_0x151c4c[_0x38c9('0x35')]['hasOwnProperty'](_0x38c9('0x3d'))){_0x30edd6[_0x38c9('0x21')]=qs[_0x38c9('0x21')](_0x151c4c[_0x38c9('0x35')][_0x38c9('0x21')]);_0x30edd6[_0x38c9('0x20')]=qs[_0x38c9('0x20')](_0x151c4c[_0x38c9('0x35')][_0x38c9('0x20')]);}return db[_0x38c9('0x30')][_0x38c9('0x4e')]({'where':{'id':_0x151c4c['params']['id']}})['then'](function(_0x45605f){if(!_0x45605f)throw new Error(_0x38c9('0x74')+_0x151c4c[_0x38c9('0x4a')]['id']);return db[_0x38c9('0x30')]['getResources'](_0x151c4c);})[_0x38c9('0x28')](respondWithFilteredResult(_0x309c88,_0x30edd6))[_0x38c9('0x48')](handleError(_0x309c88,null));};