07aaf07572667cf06f195ed038ecb87572489c57
[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 _0x97b2=['../../config/logger','api','../../config/utils','../../config/environment','../../config/license/util','../../mysqldb','redis','defaults','localhost','socket.io-emitter','./userProfile.socket','sendStatus','status','end','json','offset','limit','undefined','count','set','Content-Range','apply','reject','update','then','destroy','error','stack','name','send','map','UserProfile','rawAttributes','fieldName','type','key','model','query','keys','filters','intersection','fields','attributes','length','hasOwnProperty','sort','where','merge','VIRTUAL','options','includeAll','include','findAll','show','params','find','catch','create','body','clone','createdAt','updatedAt','crudPermissions','omit','sequelize','transaction','get','each','autoAssociation','UserProfileResource','sectionId','userProfileId','Resources','UserProfileSection','describe','addSections','push','removeSections','ids','getSections','filter','enabled','includes','isEmpty','subsections','findOne','Dashboard','forEach','Plugin','addResources','bulkCreate','removeResources','section','Missing\x20section\x20parameter','nolimit','No\x20User\x20Profile\x20found\x20for\x20id\x20','getResources','eml-format','rimraf','zip-dir','fast-json-patch','request-promise','moment','mustache','util','sox','to-csv','squel','crypto','desk.js','papaparse','../../components/auth/service','../../components/parsers/advancedSearch','../../config/license/hardware'];(function(_0x4671a9,_0x28e264){var _0x12f31f=function(_0x2eb8a9){while(--_0x2eb8a9){_0x4671a9['push'](_0x4671a9['shift']());}};_0x12f31f(++_0x28e264);}(_0x97b2,0x1b7));var _0x297b=function(_0x55c1f0,_0x4f574f){_0x55c1f0=_0x55c1f0-0x0;var _0x1530fa=_0x97b2[_0x55c1f0];return _0x1530fa;};'use strict';var emlformat=require(_0x297b('0x0'));var rimraf=require(_0x297b('0x1'));var zipdir=require(_0x297b('0x2'));var jsonpatch=require(_0x297b('0x3'));var rp=require(_0x297b('0x4'));var moment=require(_0x297b('0x5'));var BPromise=require('bluebird');var Mustache=require(_0x297b('0x6'));var util=require(_0x297b('0x7'));var path=require('path');var sox=require(_0x297b('0x8'));var csv=require(_0x297b('0x9'));var ejs=require('ejs');var fs=require('fs');var fs_extra=require('fs-extra');var _=require('lodash');var squel=require(_0x297b('0xa'));var crypto=require(_0x297b('0xb'));var jsforce=require('jsforce');var deskjs=require(_0x297b('0xc'));var toCsv=require(_0x297b('0x9'));var querystring=require('querystring');var Papa=require(_0x297b('0xd'));var Redis=require('ioredis');var authService=require(_0x297b('0xe'));var qs=require('../../components/parsers/qs');var as=require(_0x297b('0xf'));var hardwareService=require(_0x297b('0x10'));var logger=require(_0x297b('0x11'))(_0x297b('0x12'));var utils=require(_0x297b('0x13'));var config=require(_0x297b('0x14'));var licenseUtil=require(_0x297b('0x15'));var db=require(_0x297b('0x16'))['db'];config[_0x297b('0x17')]=_[_0x297b('0x18')](config[_0x297b('0x17')],{'host':_0x297b('0x19'),'port':0x18eb});var socket=require(_0x297b('0x1a'))(new Redis(config[_0x297b('0x17')]));require(_0x297b('0x1b'))['register'](socket);function respondWithStatusCode(_0x3446e6,_0x25e666){_0x25e666=_0x25e666||0xcc;return function(_0x5c2dad){if(_0x5c2dad){return _0x3446e6[_0x297b('0x1c')](_0x25e666);}return _0x3446e6[_0x297b('0x1d')](_0x25e666)[_0x297b('0x1e')]();};}function respondWithResult(_0x241ff6,_0x11469e){_0x11469e=_0x11469e||0xc8;return function(_0x2b0e25){if(_0x2b0e25){return _0x241ff6['status'](_0x11469e)[_0x297b('0x1f')](_0x2b0e25);}};}function respondWithFilteredResult(_0x34854d,_0x294fad){return function(_0x5618eb){if(_0x5618eb){var _0x5bc19c=typeof _0x294fad[_0x297b('0x20')]==='undefined'&&typeof _0x294fad[_0x297b('0x21')]===_0x297b('0x22');var _0x2379dd=_0x5618eb[_0x297b('0x23')];var _0x40ed57=_0x5bc19c?0x0:_0x294fad['offset'];var _0x478167=_0x5bc19c?_0x5618eb[_0x297b('0x23')]:_0x294fad['offset']+_0x294fad[_0x297b('0x21')];var _0x367c09;if(_0x478167>=_0x2379dd){_0x478167=_0x2379dd;_0x367c09=0xc8;}else{_0x367c09=0xce;}_0x34854d[_0x297b('0x1d')](_0x367c09);return _0x34854d[_0x297b('0x24')](_0x297b('0x25'),_0x40ed57+'-'+_0x478167+'/'+_0x2379dd)[_0x297b('0x1f')](_0x5618eb);}return null;};}function patchUpdates(_0x402c1d){return function(_0x5009b0){try{jsonpatch[_0x297b('0x26')](_0x5009b0,_0x402c1d,!![]);}catch(_0x19d8f3){return BPromise[_0x297b('0x27')](_0x19d8f3);}return _0x5009b0['save']();};}function saveUpdates(_0x279451,_0x2ca784){return function(_0x1ed4cd){if(_0x1ed4cd){return _0x1ed4cd[_0x297b('0x28')](_0x279451)[_0x297b('0x29')](function(_0x4e995f){return _0x4e995f;});}return null;};}function removeEntity(_0x578d13,_0x27ab73){return function(_0x3af713){if(_0x3af713){return _0x3af713[_0x297b('0x2a')]()[_0x297b('0x29')](function(){_0x578d13[_0x297b('0x1d')](0xcc)[_0x297b('0x1e')]();});}};}function handleEntityNotFound(_0x25383f,_0x52bb5c){return function(_0x4ab68b){if(!_0x4ab68b){_0x25383f['sendStatus'](0x194);}return _0x4ab68b;};}function handleError(_0x1f8440,_0x551475){_0x551475=_0x551475||0x1f4;return function(_0x5c2c26){logger[_0x297b('0x2b')](_0x5c2c26[_0x297b('0x2c')]);if(_0x5c2c26[_0x297b('0x2d')]){delete _0x5c2c26[_0x297b('0x2d')];}_0x1f8440[_0x297b('0x1d')](_0x551475)[_0x297b('0x2e')](_0x5c2c26);};}exports['index']=function(_0x3a7105,_0x50d2d0){var _0xf59317={},_0x350fa7={},_0x4544ee={'count':0x0,'rows':[]};var _0x77f3c=_[_0x297b('0x2f')](db[_0x297b('0x30')][_0x297b('0x31')],function(_0x3a7957){return{'name':_0x3a7957[_0x297b('0x32')],'type':_0x3a7957[_0x297b('0x33')][_0x297b('0x34')]};});_0x350fa7[_0x297b('0x35')]=_['map'](_0x77f3c,'name');_0x350fa7[_0x297b('0x36')]=_[_0x297b('0x37')](_0x3a7105[_0x297b('0x36')]);_0x350fa7[_0x297b('0x38')]=_['intersection'](_0x350fa7[_0x297b('0x35')],_0x350fa7['query']);_0xf59317['attributes']=_[_0x297b('0x39')](_0x350fa7[_0x297b('0x35')],qs[_0x297b('0x3a')](_0x3a7105[_0x297b('0x36')]['fields']));_0xf59317[_0x297b('0x3b')]=_0xf59317['attributes'][_0x297b('0x3c')]?_0xf59317[_0x297b('0x3b')]:_0x350fa7['model'];if(!_0x3a7105[_0x297b('0x36')][_0x297b('0x3d')]('nolimit')){_0xf59317['limit']=qs[_0x297b('0x21')](_0x3a7105[_0x297b('0x36')][_0x297b('0x21')]);_0xf59317['offset']=qs[_0x297b('0x20')](_0x3a7105['query'][_0x297b('0x20')]);}_0xf59317['order']=qs[_0x297b('0x3e')](_0x3a7105[_0x297b('0x36')][_0x297b('0x3e')]);_0xf59317[_0x297b('0x3f')]=qs[_0x297b('0x38')](_['pick'](_0x3a7105[_0x297b('0x36')],_0x350fa7[_0x297b('0x38')]),_0x77f3c);if(_0x3a7105[_0x297b('0x36')]['filter']){_0xf59317[_0x297b('0x3f')]=_[_0x297b('0x40')](_0xf59317[_0x297b('0x3f')],{'$or':_[_0x297b('0x2f')](_0x77f3c,function(_0x4df141){if(_0x4df141[_0x297b('0x33')]!==_0x297b('0x41')){var _0xd82ace={};_0xd82ace[_0x4df141[_0x297b('0x2d')]]={'$like':'%'+_0x3a7105[_0x297b('0x36')]['filter']+'%'};return _0xd82ace;}})});}_0xf59317=_['merge']({},_0xf59317,_0x3a7105[_0x297b('0x42')]);var _0x1a5607={'where':_0xf59317[_0x297b('0x3f')]};return db[_0x297b('0x30')][_0x297b('0x23')](_0x1a5607)[_0x297b('0x29')](function(_0x4a3e31){_0x4544ee[_0x297b('0x23')]=_0x4a3e31;if(_0x3a7105[_0x297b('0x36')][_0x297b('0x43')]){_0xf59317[_0x297b('0x44')]=[{'all':!![]}];}return db[_0x297b('0x30')][_0x297b('0x45')](_0xf59317);})[_0x297b('0x29')](function(_0x3b89e3){_0x4544ee['rows']=_0x3b89e3;return _0x4544ee;})[_0x297b('0x29')](respondWithFilteredResult(_0x50d2d0,_0xf59317))['catch'](handleError(_0x50d2d0,null));};exports[_0x297b('0x46')]=function(_0xe103d4,_0x4b8fb2){var _0x1ce0a2={'raw':![],'where':{'id':_0xe103d4[_0x297b('0x47')]['id']}},_0x23ce17={};_0x23ce17[_0x297b('0x35')]=_['keys'](db[_0x297b('0x30')][_0x297b('0x31')]);_0x23ce17['query']=_[_0x297b('0x37')](_0xe103d4[_0x297b('0x36')]);_0x23ce17[_0x297b('0x38')]=_['intersection'](_0x23ce17[_0x297b('0x35')],_0x23ce17[_0x297b('0x36')]);_0x1ce0a2[_0x297b('0x3b')]=_['intersection'](_0x23ce17[_0x297b('0x35')],qs[_0x297b('0x3a')](_0xe103d4[_0x297b('0x36')]['fields']));_0x1ce0a2[_0x297b('0x3b')]=_0x1ce0a2[_0x297b('0x3b')][_0x297b('0x3c')]?_0x1ce0a2[_0x297b('0x3b')]:_0x23ce17[_0x297b('0x35')];if(_0xe103d4['query'][_0x297b('0x43')]){_0x1ce0a2[_0x297b('0x44')]=[{'all':!![]}];}_0x1ce0a2=_['merge']({},_0x1ce0a2,_0xe103d4[_0x297b('0x42')]);return db[_0x297b('0x30')][_0x297b('0x48')](_0x1ce0a2)[_0x297b('0x29')](handleEntityNotFound(_0x4b8fb2,null))[_0x297b('0x29')](respondWithResult(_0x4b8fb2,null))[_0x297b('0x49')](handleError(_0x4b8fb2,null));};exports[_0x297b('0x4a')]=function(_0x4e7e7e,_0x17d098){return db[_0x297b('0x30')][_0x297b('0x4a')](_0x4e7e7e[_0x297b('0x4b')],{})['then'](respondWithResult(_0x17d098,0xc9))[_0x297b('0x49')](handleError(_0x17d098,null));};exports[_0x297b('0x4c')]=function(_0x15c105,_0x4a15e1){var _0x11a6e6={'where':{'id':_0x15c105[_0x297b('0x47')]['id']}},_0x3984d1={};_0x3984d1[_0x297b('0x35')]=_['keys'](db['UserProfile'][_0x297b('0x31')]);_0x11a6e6[_0x297b('0x3b')]=_[_0x297b('0x39')](_0x3984d1['model'],qs[_0x297b('0x3a')](_0x15c105[_0x297b('0x36')][_0x297b('0x3a')]));_0x11a6e6['attributes']=_0x11a6e6[_0x297b('0x3b')]['length']?_0x11a6e6[_0x297b('0x3b')]:_0x3984d1[_0x297b('0x35')];if(_0x15c105['query'][_0x297b('0x43')]){_0x11a6e6[_0x297b('0x44')]=[{'all':!![]}];}_0x11a6e6=_[_0x297b('0x40')]({},_0x11a6e6,_0x15c105['options']);return db['UserProfile']['find'](_0x11a6e6)[_0x297b('0x29')](handleEntityNotFound(_0x4a15e1,null))[_0x297b('0x29')](function(_0x4d6438){if(_0x4d6438){var _0x540639=_0x4d6438['get']({'plain':!![]});_0x540639=qs['omit'](_0x540639,['id',_0x297b('0x4d'),_0x297b('0x4e'),_0x297b('0x4f')]);_0x15c105[_0x297b('0x4b')]=_[_0x297b('0x50')](_0x15c105[_0x297b('0x4b')],['id',_0x297b('0x4d'),_0x297b('0x4e')]);return db[_0x297b('0x51')][_0x297b('0x52')](function(_0xc044e8){return db[_0x297b('0x30')]['create'](_[_0x297b('0x40')](_0x540639,_0x15c105[_0x297b('0x4b')]),{'include':_0x15c105[_0x297b('0x36')][_0x297b('0x43')]?[{'all':!![]}]:undefined,'transaction':_0xc044e8})[_0x297b('0x29')](function(_0x37d574){var _0x23d2f5=_0x37d574[_0x297b('0x53')]({'plain':!![]});return db['UserProfileSection']['findAll']({'where':{'userProfileId':_0x15c105['params']['id']},'raw':!![]})[_0x297b('0x29')](function(_0x4dd71f){if(_0x4dd71f){return BPromise[_0x297b('0x54')](_0x4dd71f,function(_0x14177d){return new BPromise(function(_0x3122be,_0x2e6824){if(_0x14177d['autoAssociation']===null||_0x14177d[_0x297b('0x55')]===0x1)_0x3122be(null);return db[_0x297b('0x56')]['findAll']({'where':{'sectionId':_0x14177d['id']},'raw':!![]})['then'](function(_0xab1740){var _0x1ed582=_[_0x297b('0x2f')](_0xab1740,function(_0x4fd046){return qs[_0x297b('0x50')](_0x4fd046,['id',_0x297b('0x4d'),_0x297b('0x4e'),_0x297b('0x57')]);});_0x3122be(_0x1ed582);})[_0x297b('0x49')](function(_0x2f2735){_0x2e6824(_0x2f2735);});})[_0x297b('0x29')](function(_0x3be4f5){var _0x5590a1=qs[_0x297b('0x50')](_0x14177d,['id',_0x297b('0x4d'),'updatedAt']);_0x5590a1[_0x297b('0x58')]=_0x23d2f5['id'];if(_0x3be4f5)_0x5590a1[_0x297b('0x59')]=_0x3be4f5;return _0x5590a1;})[_0x297b('0x29')](function(_0x30dd82){return db[_0x297b('0x5a')][_0x297b('0x4a')](_0x30dd82,{'include':[{'model':db['UserProfileResource'],'as':_0x297b('0x59')}],'raw':!![],'transaction':_0xc044e8});});})[_0x297b('0x29')](function(){return _0x23d2f5;});}});});});}})[_0x297b('0x29')](respondWithResult(_0x4a15e1,0xc9))[_0x297b('0x49')](handleError(_0x4a15e1,null));};exports[_0x297b('0x28')]=function(_0x2a312e,_0x2cdebf){if(_0x2a312e['body']['id']){delete _0x2a312e[_0x297b('0x4b')]['id'];}return db['UserProfile']['find']({'where':{'id':_0x2a312e[_0x297b('0x47')]['id']}})[_0x297b('0x29')](handleEntityNotFound(_0x2cdebf,null))[_0x297b('0x29')](saveUpdates(_0x2a312e[_0x297b('0x4b')],null))['then'](respondWithResult(_0x2cdebf,null))[_0x297b('0x49')](handleError(_0x2cdebf,null));};exports[_0x297b('0x2a')]=function(_0x5d58e3,_0x5ded6b){return db[_0x297b('0x30')][_0x297b('0x48')]({'where':{'id':_0x5d58e3[_0x297b('0x47')]['id']}})[_0x297b('0x29')](handleEntityNotFound(_0x5ded6b,null))[_0x297b('0x29')](removeEntity(_0x5ded6b,null))['catch'](handleError(_0x5ded6b,null));};exports[_0x297b('0x5b')]=function(_0x1957ff,_0x4cfd72){return db[_0x297b('0x30')][_0x297b('0x5b')]()['then'](respondWithResult(_0x4cfd72,null))[_0x297b('0x49')](handleError(_0x4cfd72,null));};exports[_0x297b('0x5c')]=function(_0x4a3beb,_0x5bf696){var _0x3d2d25=_0x4a3beb[_0x297b('0x4b')];return db['UserProfile'][_0x297b('0x48')]({'where':{'id':_0x4a3beb[_0x297b('0x47')]['id']}})[_0x297b('0x29')](handleEntityNotFound(_0x5bf696,null))['then'](function(_0xc984a0){if(_0xc984a0){return db[_0x297b('0x51')][_0x297b('0x52')](function(_0x588e33){return db['UserProfileSection'][_0x297b('0x2a')]({'where':{'userProfileId':_0x4a3beb['params']['id'],'sectionId':_[_0x297b('0x2f')](_0x3d2d25,function(_0x13901d){return _0x13901d[_0x297b('0x57')];})},'transaction':_0x588e33})[_0x297b('0x29')](function(){var _0x1831f1=_[_0x297b('0x2f')](_0x3d2d25,function(_0x2ca4c7){_0x2ca4c7[_0x297b('0x58')]=_0x4a3beb[_0x297b('0x47')]['id'];return _0x2ca4c7;});var _0x5109c7=[];return BPromise['each'](_0x1831f1,function(_0x1fbc32){return db['UserProfileSection']['create'](_0x1fbc32,{'include':[{'model':db['UserProfileResource'],'as':_0x297b('0x59')}],'raw':!![],'transaction':_0x588e33})[_0x297b('0x29')](function(_0x392b65){_0x5109c7[_0x297b('0x5d')](_0x392b65[_0x297b('0x53')]({'plain':!![]}));});})[_0x297b('0x29')](function(){return _0x5109c7;});});});}})[_0x297b('0x29')](function(_0x2ee056){return _0x2ee056;})[_0x297b('0x29')](respondWithResult(_0x5bf696,null))['catch'](handleError(_0x5bf696,null));};exports[_0x297b('0x5e')]=function(_0x5aa2db,_0x25e230){var _0xb7de91;return db[_0x297b('0x30')][_0x297b('0x48')]({'where':{'id':_0x5aa2db['params']['id']},'attributes':['id',_0x297b('0x2d')]})[_0x297b('0x29')](handleEntityNotFound(_0x25e230,null))['then'](function(_0x28a584){if(_0x28a584){_0xb7de91=_0x28a584;return db[_0x297b('0x5a')][_0x297b('0x2a')]({'where':{'userProfileId':_0x5aa2db[_0x297b('0x47')]['id'],'sectionId':_0x5aa2db['query'][_0x297b('0x5f')]}});}})[_0x297b('0x29')](function(){return _0xb7de91;})[_0x297b('0x29')](respondWithStatusCode(_0x25e230,null))[_0x297b('0x49')](handleError(_0x25e230,null));};exports[_0x297b('0x60')]=function(_0x3e2b48,_0x1aa143){var _0x60d81b=[];var _0x402fcb=[];return db['UserProfileSection'][_0x297b('0x45')]({'where':{'userProfileId':_0x3e2b48[_0x297b('0x47')]['id']},'raw':!![]})[_0x297b('0x29')](function(_0x355ea0){_0x60d81b=_[_0x297b('0x61')](_0x355ea0,function(_0x3dce14){return _0x3dce14[_0x297b('0x62')]===0x1||_[_0x297b('0x63')]([0x3eb,0x709],_0x3dce14[_0x297b('0x57')]);});if(!_[_0x297b('0x64')](_0x60d81b)){return _[_0x297b('0x2f')](_0x60d81b,function(_0x2026e0){return _0x2026e0['sectionId'];});}else{return;}})[_0x297b('0x29')](function(_0x53b5f0){if(_0x53b5f0)_0x402fcb=_0x53b5f0;if(_[_0x297b('0x63')](_0x402fcb,0x64)){var _0x585a27=_[_0x297b('0x48')](_0x60d81b,{'sectionId':0x64});return hasDefaultDashboard(_0x585a27)['then'](function(_0x21c5ae){return _[_0x297b('0x2f')](_0x60d81b,function(_0x50569b){if(_0x50569b[_0x297b('0x57')]===0x64){_0x50569b[_0x297b('0x65')]=_0x21c5ae;}return _0x50569b;});});}else{return;}})[_0x297b('0x29')](function(_0x572e89){if(_0x572e89)_0x60d81b=_0x572e89;if(_[_0x297b('0x63')](_0x402fcb,0x3eb)){var _0x5f0453=_['find'](_0x60d81b,{'sectionId':0x3eb});return getCustomDashboards(_0x5f0453)[_0x297b('0x29')](function(_0x4f6840){return _[_0x297b('0x2f')](_0x60d81b,function(_0x509072){if(_0x5f0453[_0x297b('0x62')]){if(_0x509072[_0x297b('0x57')]===0x3eb){_0x509072[_0x297b('0x65')]=_0x4f6840;}}else{if(_0x509072['sectionId']===0x64){_0x509072[_0x297b('0x65')]=_0x4f6840;}}return _0x509072;});});}else{return;}})[_0x297b('0x29')](function(_0x464971){if(_0x464971)_0x60d81b=_0x464971;if(_[_0x297b('0x63')](_0x402fcb,0x709)){var _0x50f287=_[_0x297b('0x48')](_0x60d81b,{'sectionId':0x709});return getPlugins(_0x50f287)[_0x297b('0x29')](function(_0x3665a7){if(_0x50f287['enabled']){return _[_0x297b('0x2f')](_0x60d81b,function(_0xae5472){if(_0xae5472[_0x297b('0x57')]===0x709){_0xae5472['subsections']=_0x3665a7;}return _0xae5472;});}else{var _0x57d0c4={'sectionId':0x76c,'enabled':0x1,'subsections':_0x3665a7};var _0x4b0b0f=_['map'](_0x60d81b);_0x4b0b0f[_0x297b('0x5d')](_0x57d0c4);return _0x4b0b0f;}});}else{return;}})[_0x297b('0x29')](function(_0x141aa7){if(_0x141aa7)_0x60d81b=_0x141aa7;return _[_0x297b('0x61')](_0x60d81b,[_0x297b('0x62'),0x1]);})[_0x297b('0x29')](respondWithResult(_0x1aa143,null))[_0x297b('0x49')](handleError(_0x1aa143,null));};function hasDefaultDashboard(_0x2e8627){var _0x2a20fb=[0x65];return new BPromise(function(_0x104fc7,_0x107ba0){try{if(_0x2e8627[_0x297b('0x55')]){_0x104fc7(_0x2a20fb);}else{return db[_0x297b('0x56')][_0x297b('0x66')]({'where':{'sectionId':_0x2e8627['id']},'raw':!![]})['then'](function(_0x44dc7e){_0x44dc7e?_0x104fc7(_0x2a20fb):_0x104fc7();});}}catch(_0x55b014){_0x107ba0(_0x55b014);}});}function getCustomDashboards(_0x5e188c){var _0x2fe4f0=[];return new BPromise(function(_0x3f9773,_0x344302){try{if(_0x5e188c[_0x297b('0x55')]){return db[_0x297b('0x67')][_0x297b('0x45')]({'raw':!![]})[_0x297b('0x29')](function(_0x47c0b7){_0x47c0b7[_0x297b('0x68')](function(_0x1c91ab){_0x2fe4f0[_0x297b('0x5d')](_0x1c91ab['id']+0x1869f);});_0x3f9773(_0x2fe4f0);});}else{return db['UserProfileResource'][_0x297b('0x45')]({'where':{'sectionId':_0x5e188c['id']},'raw':!![]})['then'](function(_0x12acc2){_0x12acc2[_0x297b('0x68')](function(_0x392871){_0x2fe4f0[_0x297b('0x5d')](_0x392871['resourceId']+0x1869f);});_0x3f9773(_0x2fe4f0);});}}catch(_0x23aaaf){_0x344302(_0x23aaaf);}});}function getPlugins(_0x8b3d13){var _0x353c60=[];return new BPromise(function(_0xb187f1,_0x1fe2c6){try{if(_0x8b3d13[_0x297b('0x55')]){return db[_0x297b('0x69')][_0x297b('0x45')]({'raw':!![]})[_0x297b('0x29')](function(_0x1e0efc){_0x1e0efc['forEach'](function(_0x5a13ea){_0x353c60['push'](_0x5a13ea['id']+0x15b38);});_0xb187f1(_0x353c60);});}else{return db[_0x297b('0x56')][_0x297b('0x45')]({'where':{'sectionId':_0x8b3d13['id']},'raw':!![]})[_0x297b('0x29')](function(_0x5e5f43){_0x5e5f43['forEach'](function(_0x48d83c){_0x353c60['push'](_0x48d83c['resourceId']+0x15b38);});_0xb187f1(_0x353c60);});}}catch(_0x131acb){_0x1fe2c6(_0x131acb);}});}exports[_0x297b('0x6a')]=function(_0x55f74e,_0x2dd90d){return db[_0x297b('0x30')][_0x297b('0x48')]({'where':{'id':_0x55f74e['params']['id']}})[_0x297b('0x29')](handleEntityNotFound(_0x2dd90d,null))[_0x297b('0x29')](function(_0x1c1bb7){if(_0x1c1bb7){return db[_0x297b('0x51')][_0x297b('0x52')](function(_0x133dad){return db['UserProfileSection'][_0x297b('0x45')]({'where':{'userProfileId':_0x55f74e[_0x297b('0x47')]['id']},'attributes':['id'],'raw':!![]})['then'](function(_0x13febe){if(_0x13febe){return db['UserProfileSection'][_0x297b('0x2a')]({'where':{'userProfileId':_0x55f74e[_0x297b('0x47')]['id'],'id':_[_0x297b('0x2f')](_0x13febe,function(_0xdede09){return _0xdede09['id'];})},'transaction':_0x133dad});}})[_0x297b('0x29')](function(_0x1f2818){var _0x2cc440=_[_0x297b('0x2f')](_0x55f74e[_0x297b('0x4b')],function(_0x277dc3){_0x277dc3[_0x297b('0x58')]=_0x55f74e[_0x297b('0x47')]['id'];return _0x277dc3;});return db[_0x297b('0x5a')][_0x297b('0x6b')](_0x2cc440,{'raw':!![],'transaction':_0x133dad});})[_0x297b('0x29')](function(_0x22c9f2){var _0xd1f501=_[_0x297b('0x61')](_['map'](_0x22c9f2,function(_0x368c4d){return _0x368c4d[_0x297b('0x53')]({'plain':!![]});}),{'includeAll':![]});if(_0xd1f501){return db['UserProfileSection'][_0x297b('0x45')]({'where':{'userProfileId':_0x55f74e['params']['id'],'sectionId':_['map'](_0xd1f501,function(_0x1fa175){return _0x1fa175[_0x297b('0x57')];})},'attributes':['id',_0x297b('0x57')],'raw':!![]})['then'](function(_0x29a16d){var _0x5bc07f=_[_0x297b('0x2f')](_0x55f74e[_0x297b('0x4b')],function(_0x5df628){_0x5df628[_0x297b('0x58')]=_0x55f74e[_0x297b('0x47')]['id'];return _0x5df628;});return db[_0x297b('0x56')][_0x297b('0x6b')](_0x5bc07f,{'raw':!![],'transaction':_0x133dad});});}})['catch'](handleError(_0x2dd90d,null));});}})[_0x297b('0x29')](function(_0x4987d1){var _0x543d2d=_[_0x297b('0x2f')](_0x4987d1,function(_0x14846c){return _0x14846c[_0x297b('0x53')]({'plain':!![]});});})['then'](respondWithResult(_0x2dd90d,null))[_0x297b('0x49')](handleError(_0x2dd90d,null));};exports['removeResources']=function(_0x511021,_0x11201d,_0x104133){return db[_0x297b('0x30')][_0x297b('0x48')]({'where':{'id':_0x511021[_0x297b('0x47')]['id']}})[_0x297b('0x29')](handleEntityNotFound(_0x11201d,null))[_0x297b('0x29')](function(_0x41b5cb){if(_0x41b5cb){return _0x41b5cb[_0x297b('0x6c')](_0x511021[_0x297b('0x36')][_0x297b('0x5f')]);}})['then'](respondWithStatusCode(_0x11201d,null))[_0x297b('0x49')](handleError(_0x11201d,null));};exports['getResources']=function(_0x1b58ae,_0x23b83a){var _0x2e9300={};if(!_0x1b58ae['query'][_0x297b('0x6d')])throw new Error(_0x297b('0x6e'));if(!_0x1b58ae[_0x297b('0x36')][_0x297b('0x3d')](_0x297b('0x6f'))){_0x2e9300['limit']=qs[_0x297b('0x21')](_0x1b58ae[_0x297b('0x36')]['limit']);_0x2e9300[_0x297b('0x20')]=qs[_0x297b('0x20')](_0x1b58ae[_0x297b('0x36')][_0x297b('0x20')]);}return db[_0x297b('0x30')][_0x297b('0x48')]({'where':{'id':_0x1b58ae['params']['id']}})[_0x297b('0x29')](function(_0x4d1030){if(!_0x4d1030)throw new Error(_0x297b('0x70')+_0x1b58ae[_0x297b('0x47')]['id']);return db['UserProfile'][_0x297b('0x71')](_0x1b58ae);})[_0x297b('0x29')](respondWithFilteredResult(_0x23b83a,_0x2e9300))[_0x297b('0x49')](handleError(_0x23b83a,null));};