fc28691a31663471195abb12595ca9bc5207950d
[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 _0xf17b=['offset','set','Content-Range','apply','reject','save','update','then','destroy','name','send','map','UserProfile','rawAttributes','fieldName','model','query','attributes','fields','length','nolimit','order','sort','where','filters','pick','filter','merge','VIRTUAL','includeAll','include','findAll','rows','catch','keys','intersection','options','find','create','body','clone','params','get','omit','createdAt','crudPermissions','sequelize','transaction','UserProfileSection','autoAssociation','updatedAt','userProfileId','Resources','describe','addSections','sectionId','each','UserProfileResource','push','removeSections','ids','getSections','enabled','includes','isEmpty','subsections','findOne','Dashboard','forEach','resourceId','addResources','bulkCreate','removeResources','getResources','Missing\x20section\x20parameter','No\x20User\x20Profile\x20found\x20for\x20id\x20','rimraf','zip-dir','fast-json-patch','request-promise','moment','mustache','util','sox','to-csv','fs-extra','crypto','querystring','../../components/auth/service','../../components/parsers/advancedSearch','../../config/logger','api','../../config/utils','../../config/environment','../../config/license/util','../../mysqldb','redis','./userProfile.socket','register','status','end','json','limit','undefined','count'];(function(_0x1eae54,_0x4ad8d1){var _0x16f10f=function(_0x447880){while(--_0x447880){_0x1eae54['push'](_0x1eae54['shift']());}};_0x16f10f(++_0x4ad8d1);}(_0xf17b,0x187));var _0xbf17=function(_0x2474ac,_0x335d3a){_0x2474ac=_0x2474ac-0x0;var _0x384a8f=_0xf17b[_0x2474ac];return _0x384a8f;};'use strict';var emlformat=require('eml-format');var rimraf=require(_0xbf17('0x0'));var zipdir=require(_0xbf17('0x1'));var jsonpatch=require(_0xbf17('0x2'));var rp=require(_0xbf17('0x3'));var moment=require(_0xbf17('0x4'));var BPromise=require('bluebird');var Mustache=require(_0xbf17('0x5'));var util=require(_0xbf17('0x6'));var path=require('path');var sox=require(_0xbf17('0x7'));var csv=require(_0xbf17('0x8'));var ejs=require('ejs');var fs=require('fs');var fs_extra=require(_0xbf17('0x9'));var _=require('lodash');var squel=require('squel');var crypto=require(_0xbf17('0xa'));var jsforce=require('jsforce');var deskjs=require('desk.js');var toCsv=require('to-csv');var querystring=require(_0xbf17('0xb'));var Papa=require('papaparse');var Redis=require('ioredis');var authService=require(_0xbf17('0xc'));var qs=require('../../components/parsers/qs');var as=require(_0xbf17('0xd'));var hardwareService=require('../../config/license/hardware');var logger=require(_0xbf17('0xe'))(_0xbf17('0xf'));var utils=require(_0xbf17('0x10'));var config=require(_0xbf17('0x11'));var licenseUtil=require(_0xbf17('0x12'));var db=require(_0xbf17('0x13'))['db'];config[_0xbf17('0x14')]=_['defaults'](config[_0xbf17('0x14')],{'host':'localhost','port':0x18eb});var socket=require('socket.io-emitter')(new Redis(config['redis']));require(_0xbf17('0x15'))[_0xbf17('0x16')](socket);function respondWithStatusCode(_0x1dd444,_0x44384d){_0x44384d=_0x44384d||0xcc;return function(_0x46cdd0){if(_0x46cdd0){return _0x1dd444['sendStatus'](_0x44384d);}return _0x1dd444[_0xbf17('0x17')](_0x44384d)[_0xbf17('0x18')]();};}function respondWithResult(_0x13adae,_0x514437){_0x514437=_0x514437||0xc8;return function(_0x5de498){if(_0x5de498){return _0x13adae['status'](_0x514437)[_0xbf17('0x19')](_0x5de498);}};}function respondWithFilteredResult(_0x4a497d,_0x13163e){return function(_0x1517b8){if(_0x1517b8){var _0x2c3030=typeof _0x13163e['offset']==='undefined'&&typeof _0x13163e[_0xbf17('0x1a')]===_0xbf17('0x1b');var _0xa29a71=_0x1517b8['count'];var _0x28442a=_0x2c3030?0x0:_0x13163e['offset'];var _0x23dda7=_0x2c3030?_0x1517b8[_0xbf17('0x1c')]:_0x13163e[_0xbf17('0x1d')]+_0x13163e[_0xbf17('0x1a')];var _0x57b819;if(_0x23dda7>=_0xa29a71){_0x23dda7=_0xa29a71;_0x57b819=0xc8;}else{_0x57b819=0xce;}_0x4a497d[_0xbf17('0x17')](_0x57b819);return _0x4a497d[_0xbf17('0x1e')](_0xbf17('0x1f'),_0x28442a+'-'+_0x23dda7+'/'+_0xa29a71)[_0xbf17('0x19')](_0x1517b8);}return null;};}function patchUpdates(_0x345b71){return function(_0x5f30ab){try{jsonpatch[_0xbf17('0x20')](_0x5f30ab,_0x345b71,!![]);}catch(_0x154e3f){return BPromise[_0xbf17('0x21')](_0x154e3f);}return _0x5f30ab[_0xbf17('0x22')]();};}function saveUpdates(_0x1349a0,_0x5d9f7){return function(_0x1325b5){if(_0x1325b5){return _0x1325b5[_0xbf17('0x23')](_0x1349a0)[_0xbf17('0x24')](function(_0x4bbcf1){return _0x4bbcf1;});}return null;};}function removeEntity(_0x5a896e,_0x3a5a06){return function(_0x11d035){if(_0x11d035){return _0x11d035[_0xbf17('0x25')]()[_0xbf17('0x24')](function(){_0x5a896e[_0xbf17('0x17')](0xcc)[_0xbf17('0x18')]();});}};}function handleEntityNotFound(_0x4f92f2,_0x19730){return function(_0xd8d119){if(!_0xd8d119){_0x4f92f2['sendStatus'](0x194);}return _0xd8d119;};}function handleError(_0x1324be,_0x896ba5){_0x896ba5=_0x896ba5||0x1f4;return function(_0x5e8040){logger['error'](_0x5e8040['stack']);if(_0x5e8040[_0xbf17('0x26')]){delete _0x5e8040[_0xbf17('0x26')];}_0x1324be[_0xbf17('0x17')](_0x896ba5)[_0xbf17('0x27')](_0x5e8040);};}exports['index']=function(_0x84daad,_0x406256){var _0x46ba4c={},_0x452ab2={},_0x5dd46d={'count':0x0,'rows':[]};var _0x1bd5a8=_[_0xbf17('0x28')](db[_0xbf17('0x29')][_0xbf17('0x2a')],function(_0x13a086){return{'name':_0x13a086[_0xbf17('0x2b')],'type':_0x13a086['type']['key']};});_0x452ab2[_0xbf17('0x2c')]=_[_0xbf17('0x28')](_0x1bd5a8,_0xbf17('0x26'));_0x452ab2['query']=_['keys'](_0x84daad[_0xbf17('0x2d')]);_0x452ab2['filters']=_['intersection'](_0x452ab2['model'],_0x452ab2[_0xbf17('0x2d')]);_0x46ba4c[_0xbf17('0x2e')]=_['intersection'](_0x452ab2[_0xbf17('0x2c')],qs[_0xbf17('0x2f')](_0x84daad['query']['fields']));_0x46ba4c[_0xbf17('0x2e')]=_0x46ba4c['attributes'][_0xbf17('0x30')]?_0x46ba4c['attributes']:_0x452ab2[_0xbf17('0x2c')];if(!_0x84daad[_0xbf17('0x2d')]['hasOwnProperty'](_0xbf17('0x31'))){_0x46ba4c[_0xbf17('0x1a')]=qs['limit'](_0x84daad[_0xbf17('0x2d')][_0xbf17('0x1a')]);_0x46ba4c['offset']=qs[_0xbf17('0x1d')](_0x84daad[_0xbf17('0x2d')]['offset']);}_0x46ba4c[_0xbf17('0x32')]=qs[_0xbf17('0x33')](_0x84daad[_0xbf17('0x2d')]['sort']);_0x46ba4c[_0xbf17('0x34')]=qs[_0xbf17('0x35')](_[_0xbf17('0x36')](_0x84daad['query'],_0x452ab2[_0xbf17('0x35')]),_0x1bd5a8);if(_0x84daad[_0xbf17('0x2d')][_0xbf17('0x37')]){_0x46ba4c[_0xbf17('0x34')]=_[_0xbf17('0x38')](_0x46ba4c['where'],{'$or':_[_0xbf17('0x28')](_0x1bd5a8,function(_0x6927b3){if(_0x6927b3['type']!==_0xbf17('0x39')){var _0x1733d6={};_0x1733d6[_0x6927b3[_0xbf17('0x26')]]={'$like':'%'+_0x84daad[_0xbf17('0x2d')][_0xbf17('0x37')]+'%'};return _0x1733d6;}})});}_0x46ba4c=_[_0xbf17('0x38')]({},_0x46ba4c,_0x84daad['options']);var _0xc227f7={'where':_0x46ba4c[_0xbf17('0x34')]};return db[_0xbf17('0x29')][_0xbf17('0x1c')](_0xc227f7)[_0xbf17('0x24')](function(_0x27d44c){_0x5dd46d[_0xbf17('0x1c')]=_0x27d44c;if(_0x84daad[_0xbf17('0x2d')][_0xbf17('0x3a')]){_0x46ba4c[_0xbf17('0x3b')]=[{'all':!![]}];}return db[_0xbf17('0x29')][_0xbf17('0x3c')](_0x46ba4c);})['then'](function(_0x38bcb7){_0x5dd46d[_0xbf17('0x3d')]=_0x38bcb7;return _0x5dd46d;})[_0xbf17('0x24')](respondWithFilteredResult(_0x406256,_0x46ba4c))[_0xbf17('0x3e')](handleError(_0x406256,null));};exports['show']=function(_0x1d25ed,_0x2423cb){var _0x4e5457={'raw':![],'where':{'id':_0x1d25ed['params']['id']}},_0x4dbc01={};_0x4dbc01[_0xbf17('0x2c')]=_[_0xbf17('0x3f')](db['UserProfile']['rawAttributes']);_0x4dbc01[_0xbf17('0x2d')]=_[_0xbf17('0x3f')](_0x1d25ed[_0xbf17('0x2d')]);_0x4dbc01['filters']=_[_0xbf17('0x40')](_0x4dbc01['model'],_0x4dbc01[_0xbf17('0x2d')]);_0x4e5457[_0xbf17('0x2e')]=_[_0xbf17('0x40')](_0x4dbc01[_0xbf17('0x2c')],qs[_0xbf17('0x2f')](_0x1d25ed[_0xbf17('0x2d')][_0xbf17('0x2f')]));_0x4e5457[_0xbf17('0x2e')]=_0x4e5457[_0xbf17('0x2e')]['length']?_0x4e5457[_0xbf17('0x2e')]:_0x4dbc01[_0xbf17('0x2c')];if(_0x1d25ed[_0xbf17('0x2d')][_0xbf17('0x3a')]){_0x4e5457[_0xbf17('0x3b')]=[{'all':!![]}];}_0x4e5457=_[_0xbf17('0x38')]({},_0x4e5457,_0x1d25ed[_0xbf17('0x41')]);return db[_0xbf17('0x29')][_0xbf17('0x42')](_0x4e5457)['then'](handleEntityNotFound(_0x2423cb,null))[_0xbf17('0x24')](respondWithResult(_0x2423cb,null))['catch'](handleError(_0x2423cb,null));};exports[_0xbf17('0x43')]=function(_0x18947a,_0x593411){return db['UserProfile'][_0xbf17('0x43')](_0x18947a[_0xbf17('0x44')],{})[_0xbf17('0x24')](respondWithResult(_0x593411,0xc9))[_0xbf17('0x3e')](handleError(_0x593411,null));};exports[_0xbf17('0x45')]=function(_0x5e10b6,_0x363aa1){var _0x41299e={'where':{'id':_0x5e10b6[_0xbf17('0x46')]['id']}},_0x402e21={};_0x402e21[_0xbf17('0x2c')]=_[_0xbf17('0x3f')](db[_0xbf17('0x29')][_0xbf17('0x2a')]);_0x41299e[_0xbf17('0x2e')]=_[_0xbf17('0x40')](_0x402e21[_0xbf17('0x2c')],qs[_0xbf17('0x2f')](_0x5e10b6[_0xbf17('0x2d')][_0xbf17('0x2f')]));_0x41299e['attributes']=_0x41299e[_0xbf17('0x2e')]['length']?_0x41299e['attributes']:_0x402e21[_0xbf17('0x2c')];if(_0x5e10b6[_0xbf17('0x2d')]['includeAll']){_0x41299e[_0xbf17('0x3b')]=[{'all':!![]}];}_0x41299e=_[_0xbf17('0x38')]({},_0x41299e,_0x5e10b6[_0xbf17('0x41')]);return db[_0xbf17('0x29')][_0xbf17('0x42')](_0x41299e)[_0xbf17('0x24')](handleEntityNotFound(_0x363aa1,null))['then'](function(_0x14e362){if(_0x14e362){var _0x8ee991=_0x14e362[_0xbf17('0x47')]({'plain':!![]});_0x8ee991=qs[_0xbf17('0x48')](_0x8ee991,['id',_0xbf17('0x49'),'updatedAt',_0xbf17('0x4a')]);_0x5e10b6[_0xbf17('0x44')]=_[_0xbf17('0x48')](_0x5e10b6['body'],['id','createdAt','updatedAt']);return db[_0xbf17('0x4b')][_0xbf17('0x4c')](function(_0x52d7a3){return db['UserProfile'][_0xbf17('0x43')](_[_0xbf17('0x38')](_0x8ee991,_0x5e10b6['body']),{'include':_0x5e10b6[_0xbf17('0x2d')][_0xbf17('0x3a')]?[{'all':!![]}]:undefined,'transaction':_0x52d7a3})[_0xbf17('0x24')](function(_0x2b78b6){var _0x33e7be=_0x2b78b6['get']({'plain':!![]});return db[_0xbf17('0x4d')][_0xbf17('0x3c')]({'where':{'userProfileId':_0x5e10b6['params']['id']},'raw':!![]})[_0xbf17('0x24')](function(_0xc33e72){if(_0xc33e72){return BPromise['each'](_0xc33e72,function(_0x1a20bd){return new BPromise(function(_0x174fec,_0x4ce7c7){if(_0x1a20bd[_0xbf17('0x4e')]===null||_0x1a20bd[_0xbf17('0x4e')]===0x1)_0x174fec(null);return db['UserProfileResource'][_0xbf17('0x3c')]({'where':{'sectionId':_0x1a20bd['id']},'raw':!![]})[_0xbf17('0x24')](function(_0x5580fe){var _0x30fcf3=_[_0xbf17('0x28')](_0x5580fe,function(_0x2e6bef){return qs[_0xbf17('0x48')](_0x2e6bef,['id',_0xbf17('0x49'),_0xbf17('0x4f'),'sectionId']);});_0x174fec(_0x30fcf3);})[_0xbf17('0x3e')](function(_0x403bf1){_0x4ce7c7(_0x403bf1);});})['then'](function(_0x2b74ee){var _0x610a9c=qs['omit'](_0x1a20bd,['id','createdAt','updatedAt']);_0x610a9c[_0xbf17('0x50')]=_0x33e7be['id'];if(_0x2b74ee)_0x610a9c[_0xbf17('0x51')]=_0x2b74ee;return _0x610a9c;})[_0xbf17('0x24')](function(_0x3b171e){return db[_0xbf17('0x4d')][_0xbf17('0x43')](_0x3b171e,{'include':[{'model':db['UserProfileResource'],'as':_0xbf17('0x51')}],'raw':!![],'transaction':_0x52d7a3});});})[_0xbf17('0x24')](function(){return _0x33e7be;});}});});});}})['then'](respondWithResult(_0x363aa1,0xc9))[_0xbf17('0x3e')](handleError(_0x363aa1,null));};exports[_0xbf17('0x23')]=function(_0x22d5a1,_0x21f77a){if(_0x22d5a1['body']['id']){delete _0x22d5a1[_0xbf17('0x44')]['id'];}return db[_0xbf17('0x29')][_0xbf17('0x42')]({'where':{'id':_0x22d5a1[_0xbf17('0x46')]['id']}})[_0xbf17('0x24')](handleEntityNotFound(_0x21f77a,null))[_0xbf17('0x24')](saveUpdates(_0x22d5a1[_0xbf17('0x44')],null))[_0xbf17('0x24')](respondWithResult(_0x21f77a,null))['catch'](handleError(_0x21f77a,null));};exports[_0xbf17('0x25')]=function(_0xeaff0e,_0x11b39f){return db['UserProfile'][_0xbf17('0x42')]({'where':{'id':_0xeaff0e[_0xbf17('0x46')]['id']}})[_0xbf17('0x24')](handleEntityNotFound(_0x11b39f,null))[_0xbf17('0x24')](removeEntity(_0x11b39f,null))[_0xbf17('0x3e')](handleError(_0x11b39f,null));};exports['describe']=function(_0x26c9aa,_0x36c66f){return db[_0xbf17('0x29')][_0xbf17('0x52')]()[_0xbf17('0x24')](respondWithResult(_0x36c66f,null))[_0xbf17('0x3e')](handleError(_0x36c66f,null));};exports[_0xbf17('0x53')]=function(_0x1cac4c,_0x524a3a){var _0x51e57c=_0x1cac4c[_0xbf17('0x44')];return db[_0xbf17('0x29')][_0xbf17('0x42')]({'where':{'id':_0x1cac4c[_0xbf17('0x46')]['id']}})['then'](handleEntityNotFound(_0x524a3a,null))[_0xbf17('0x24')](function(_0x2d0e64){if(_0x2d0e64){return db[_0xbf17('0x4b')][_0xbf17('0x4c')](function(_0x30788f){return db[_0xbf17('0x4d')][_0xbf17('0x25')]({'where':{'userProfileId':_0x1cac4c[_0xbf17('0x46')]['id'],'sectionId':_[_0xbf17('0x28')](_0x51e57c,function(_0x59cff7){return _0x59cff7[_0xbf17('0x54')];})},'transaction':_0x30788f})[_0xbf17('0x24')](function(){var _0x5989ab=_[_0xbf17('0x28')](_0x51e57c,function(_0x4c6cf1){_0x4c6cf1[_0xbf17('0x50')]=_0x1cac4c['params']['id'];return _0x4c6cf1;});var _0x2d912b=[];return BPromise[_0xbf17('0x55')](_0x5989ab,function(_0x1ca09f){return db['UserProfileSection'][_0xbf17('0x43')](_0x1ca09f,{'include':[{'model':db[_0xbf17('0x56')],'as':'Resources'}],'raw':!![],'transaction':_0x30788f})['then'](function(_0x1e2016){_0x2d912b[_0xbf17('0x57')](_0x1e2016['get']({'plain':!![]}));});})['then'](function(){return _0x2d912b;});});});}})[_0xbf17('0x24')](function(_0x316fff){return _0x316fff;})[_0xbf17('0x24')](respondWithResult(_0x524a3a,null))[_0xbf17('0x3e')](handleError(_0x524a3a,null));};exports[_0xbf17('0x58')]=function(_0x2a02bf,_0x2da753){var _0x3a448e;return db[_0xbf17('0x29')][_0xbf17('0x42')]({'where':{'id':_0x2a02bf[_0xbf17('0x46')]['id']},'attributes':['id',_0xbf17('0x26')]})['then'](handleEntityNotFound(_0x2da753,null))['then'](function(_0x82129d){if(_0x82129d){_0x3a448e=_0x82129d;return db[_0xbf17('0x4d')]['destroy']({'where':{'userProfileId':_0x2a02bf[_0xbf17('0x46')]['id'],'sectionId':_0x2a02bf[_0xbf17('0x2d')][_0xbf17('0x59')]}});}})[_0xbf17('0x24')](function(){return _0x3a448e;})[_0xbf17('0x24')](respondWithStatusCode(_0x2da753,null))[_0xbf17('0x3e')](handleError(_0x2da753,null));};exports[_0xbf17('0x5a')]=function(_0xcd1d91,_0x4d7002){var _0x448b38=[];var _0x1fd9f6=[];return db[_0xbf17('0x4d')][_0xbf17('0x3c')]({'where':{'userProfileId':_0xcd1d91[_0xbf17('0x46')]['id']},'raw':!![]})['then'](function(_0x3822ad){_0x448b38=_[_0xbf17('0x37')](_0x3822ad,function(_0x5224b0){return _0x5224b0[_0xbf17('0x5b')]===0x1||_[_0xbf17('0x5c')]([0x3eb,0x709],_0x5224b0[_0xbf17('0x54')]);});if(!_[_0xbf17('0x5d')](_0x448b38)){return _['map'](_0x448b38,function(_0x3992bc){return _0x3992bc['sectionId'];});}else{return;}})[_0xbf17('0x24')](function(_0x40a2c0){if(_0x40a2c0)_0x1fd9f6=_0x40a2c0;if(_[_0xbf17('0x5c')](_0x1fd9f6,0x64)){var _0x1870cd=_['find'](_0x448b38,{'sectionId':0x64});return hasDefaultDashboard(_0x1870cd)[_0xbf17('0x24')](function(_0x7ea63c){return _[_0xbf17('0x28')](_0x448b38,function(_0x5b06c5){if(_0x5b06c5[_0xbf17('0x54')]===0x64){_0x5b06c5['subsections']=_0x7ea63c;}return _0x5b06c5;});});}else{return;}})[_0xbf17('0x24')](function(_0x52fe4f){if(_0x52fe4f)_0x448b38=_0x52fe4f;if(_['includes'](_0x1fd9f6,0x3eb)){var _0x1e6262=_[_0xbf17('0x42')](_0x448b38,{'sectionId':0x3eb});return getCustomDashboards(_0x1e6262)[_0xbf17('0x24')](function(_0x545399){return _[_0xbf17('0x28')](_0x448b38,function(_0x58bbd7){if(_0x1e6262[_0xbf17('0x5b')]){if(_0x58bbd7[_0xbf17('0x54')]===0x3eb){_0x58bbd7[_0xbf17('0x5e')]=_0x545399;}}else{if(_0x58bbd7[_0xbf17('0x54')]===0x64){if(!_0x58bbd7['subsections']){_0x58bbd7[_0xbf17('0x5e')]=[];}_0x58bbd7['subsections']=_0x58bbd7[_0xbf17('0x5e')]['concat'](_0x545399);}}return _0x58bbd7;});});}else{return;}})['then'](function(_0x1976f0){if(_0x1976f0)_0x448b38=_0x1976f0;if(_['includes'](_0x1fd9f6,0x709)){var _0x26bc16=_[_0xbf17('0x42')](_0x448b38,{'sectionId':0x709});return getPlugins(_0x26bc16)[_0xbf17('0x24')](function(_0x40a0c9){if(_0x26bc16['enabled']){return _['map'](_0x448b38,function(_0x4b45e0){if(_0x4b45e0[_0xbf17('0x54')]===0x709){_0x4b45e0[_0xbf17('0x5e')]=_0x40a0c9;}return _0x4b45e0;});}else{var _0x890f5c={'sectionId':0x76c,'enabled':0x1,'subsections':_0x40a0c9};var _0x2d8a79=_[_0xbf17('0x28')](_0x448b38);_0x2d8a79[_0xbf17('0x57')](_0x890f5c);return _0x2d8a79;}});}else{return;}})[_0xbf17('0x24')](function(_0x2e9c65){if(_0x2e9c65)_0x448b38=_0x2e9c65;return _[_0xbf17('0x37')](_0x448b38,[_0xbf17('0x5b'),0x1]);})[_0xbf17('0x24')](respondWithResult(_0x4d7002,null))['catch'](handleError(_0x4d7002,null));};function hasDefaultDashboard(_0x30b0ca){var _0x41d19c=[0x65];return new BPromise(function(_0x58c3e4,_0xf3747){try{if(_0x30b0ca[_0xbf17('0x4e')]){_0x58c3e4(_0x41d19c);}else{return db[_0xbf17('0x56')][_0xbf17('0x5f')]({'where':{'sectionId':_0x30b0ca['id']},'raw':!![]})['then'](function(_0x550672){_0x550672?_0x58c3e4(_0x41d19c):_0x58c3e4();});}}catch(_0x5b85c6){_0xf3747(_0x5b85c6);}});}function getCustomDashboards(_0x4fc16d){var _0x27f349=[];return new BPromise(function(_0x999df4,_0x5deb8c){try{if(_0x4fc16d[_0xbf17('0x4e')]){return db[_0xbf17('0x60')]['findAll']({'raw':!![]})[_0xbf17('0x24')](function(_0x4ba917){_0x4ba917['forEach'](function(_0x5d2f34){_0x27f349[_0xbf17('0x57')](_0x5d2f34['id']+0x1869f);});_0x999df4(_0x27f349);});}else{return db[_0xbf17('0x56')][_0xbf17('0x3c')]({'where':{'sectionId':_0x4fc16d['id']},'raw':!![]})[_0xbf17('0x24')](function(_0x300dee){_0x300dee[_0xbf17('0x61')](function(_0x3c161e){_0x27f349['push'](_0x3c161e[_0xbf17('0x62')]+0x1869f);});_0x999df4(_0x27f349);});}}catch(_0x169319){_0x5deb8c(_0x169319);}});}function getPlugins(_0x9ba3ae){var _0x221dd6=[];return new BPromise(function(_0x39ea57,_0x435697){try{if(_0x9ba3ae['autoAssociation']){return db['Plugin']['findAll']({'raw':!![]})[_0xbf17('0x24')](function(_0x17593b){_0x17593b['forEach'](function(_0x1cc317){_0x221dd6['push'](_0x1cc317['id']+0x15b38);});_0x39ea57(_0x221dd6);});}else{return db[_0xbf17('0x56')][_0xbf17('0x3c')]({'where':{'sectionId':_0x9ba3ae['id']},'raw':!![]})['then'](function(_0x4c5a51){_0x4c5a51[_0xbf17('0x61')](function(_0x311704){_0x221dd6[_0xbf17('0x57')](_0x311704['resourceId']+0x15b38);});_0x39ea57(_0x221dd6);});}}catch(_0x6d55d2){_0x435697(_0x6d55d2);}});}exports[_0xbf17('0x63')]=function(_0x77478f,_0x5414d1){return db['UserProfile'][_0xbf17('0x42')]({'where':{'id':_0x77478f[_0xbf17('0x46')]['id']}})[_0xbf17('0x24')](handleEntityNotFound(_0x5414d1,null))['then'](function(_0x257576){if(_0x257576){return db['sequelize']['transaction'](function(_0x57ce8d){return db[_0xbf17('0x4d')][_0xbf17('0x3c')]({'where':{'userProfileId':_0x77478f[_0xbf17('0x46')]['id']},'attributes':['id'],'raw':!![]})['then'](function(_0x364bac){if(_0x364bac){return db[_0xbf17('0x4d')]['destroy']({'where':{'userProfileId':_0x77478f[_0xbf17('0x46')]['id'],'id':_[_0xbf17('0x28')](_0x364bac,function(_0xe6a24f){return _0xe6a24f['id'];})},'transaction':_0x57ce8d});}})[_0xbf17('0x24')](function(_0x43141f){var _0x21c6e0=_[_0xbf17('0x28')](_0x77478f[_0xbf17('0x44')],function(_0x266e97){_0x266e97[_0xbf17('0x50')]=_0x77478f[_0xbf17('0x46')]['id'];return _0x266e97;});return db[_0xbf17('0x4d')]['bulkCreate'](_0x21c6e0,{'raw':!![],'transaction':_0x57ce8d});})[_0xbf17('0x24')](function(_0x3dca55){var _0x4012c2=_[_0xbf17('0x37')](_['map'](_0x3dca55,function(_0x4866ce){return _0x4866ce['get']({'plain':!![]});}),{'includeAll':![]});if(_0x4012c2){return db['UserProfileSection'][_0xbf17('0x3c')]({'where':{'userProfileId':_0x77478f[_0xbf17('0x46')]['id'],'sectionId':_[_0xbf17('0x28')](_0x4012c2,function(_0x503627){return _0x503627[_0xbf17('0x54')];})},'attributes':['id',_0xbf17('0x54')],'raw':!![]})[_0xbf17('0x24')](function(_0x224cc2){var _0x567e03=_[_0xbf17('0x28')](_0x77478f['body'],function(_0x5a92be){_0x5a92be[_0xbf17('0x50')]=_0x77478f[_0xbf17('0x46')]['id'];return _0x5a92be;});return db[_0xbf17('0x56')][_0xbf17('0x64')](_0x567e03,{'raw':!![],'transaction':_0x57ce8d});});}})[_0xbf17('0x3e')](handleError(_0x5414d1,null));});}})['then'](function(_0x3d3828){var _0x813bec=_[_0xbf17('0x28')](_0x3d3828,function(_0x5d9817){return _0x5d9817[_0xbf17('0x47')]({'plain':!![]});});})[_0xbf17('0x24')](respondWithResult(_0x5414d1,null))[_0xbf17('0x3e')](handleError(_0x5414d1,null));};exports[_0xbf17('0x65')]=function(_0xc0c5d4,_0x629b13,_0x137f3f){return db['UserProfile']['find']({'where':{'id':_0xc0c5d4[_0xbf17('0x46')]['id']}})[_0xbf17('0x24')](handleEntityNotFound(_0x629b13,null))[_0xbf17('0x24')](function(_0x31488e){if(_0x31488e){return _0x31488e['removeResources'](_0xc0c5d4[_0xbf17('0x2d')][_0xbf17('0x59')]);}})['then'](respondWithStatusCode(_0x629b13,null))[_0xbf17('0x3e')](handleError(_0x629b13,null));};exports[_0xbf17('0x66')]=function(_0x53ebce,_0x41e9e6){var _0x3ec554={};if(!_0x53ebce[_0xbf17('0x2d')]['section'])throw new Error(_0xbf17('0x67'));if(!_0x53ebce[_0xbf17('0x2d')]['hasOwnProperty'](_0xbf17('0x31'))){_0x3ec554['limit']=qs[_0xbf17('0x1a')](_0x53ebce['query'][_0xbf17('0x1a')]);_0x3ec554[_0xbf17('0x1d')]=qs[_0xbf17('0x1d')](_0x53ebce[_0xbf17('0x2d')]['offset']);}return db[_0xbf17('0x29')][_0xbf17('0x42')]({'where':{'id':_0x53ebce[_0xbf17('0x46')]['id']}})[_0xbf17('0x24')](function(_0x300bea){if(!_0x300bea)throw new Error(_0xbf17('0x68')+_0x53ebce['params']['id']);return db['UserProfile'][_0xbf17('0x66')](_0x53ebce);})[_0xbf17('0x24')](respondWithFilteredResult(_0x41e9e6,_0x3ec554))[_0xbf17('0x3e')](handleError(_0x41e9e6,null));};