18 var _0x3d95=['then','error','name','send','index','map','type','key','model','keys','query','attributes','intersection','fields','length','hasOwnProperty','nolimit','order','sort','where','filters','pick','filter','merge','VIRTUAL','options','Variable','includeAll','catch','params','rawAttributes','include','find','create','body','user','Unable\x20to\x20retrieve\x20the\x20current\x20user','role','Variables','UserProfileSection','autoAssociation','Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s','rimraf','fast-json-patch','request-promise','moment','bluebird','mustache','path','sox','to-csv','ejs','fs-extra','lodash','squel','crypto','jsforce','desk.js','querystring','papaparse','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','../../config/utils','../../config/environment','../../config/license/util','sendStatus','status','end','json','offset','undefined','count','limit','Content-Range','reject','save','update','destroy','get','UserProfileResource'];(function(_0x3dd15e,_0x1f0015){var _0x231fd0=function(_0x4f680a){while(--_0x4f680a){_0x3dd15e['push'](_0x3dd15e['shift']());}};_0x231fd0(++_0x1f0015);}(_0x3d95,0x126));var _0x53d9=function(_0x426f39,_0x2054cd){_0x426f39=_0x426f39-0x0;var _0x221adb=_0x3d95[_0x426f39];return _0x221adb;};'use strict';var emlformat=require('eml-format');var rimraf=require(_0x53d9('0x0'));var zipdir=require('zip-dir');var jsonpatch=require(_0x53d9('0x1'));var rp=require(_0x53d9('0x2'));var moment=require(_0x53d9('0x3'));var BPromise=require(_0x53d9('0x4'));var Mustache=require(_0x53d9('0x5'));var util=require('util');var path=require(_0x53d9('0x6'));var sox=require(_0x53d9('0x7'));var csv=require(_0x53d9('0x8'));var ejs=require(_0x53d9('0x9'));var fs=require('fs');var fs_extra=require(_0x53d9('0xa'));var _=require(_0x53d9('0xb'));var squel=require(_0x53d9('0xc'));var crypto=require(_0x53d9('0xd'));var jsforce=require(_0x53d9('0xe'));var deskjs=require(_0x53d9('0xf'));var toCsv=require(_0x53d9('0x8'));var querystring=require(_0x53d9('0x10'));var Papa=require(_0x53d9('0x11'));var Redis=require(_0x53d9('0x12'));var authService=require(_0x53d9('0x13'));var qs=require(_0x53d9('0x14'));var as=require(_0x53d9('0x15'));var hardwareService=require(_0x53d9('0x16'));var logger=require(_0x53d9('0x17'))('api');var utils=require(_0x53d9('0x18'));var config=require(_0x53d9('0x19'));var licenseUtil=require(_0x53d9('0x1a'));var db=require('../../mysqldb')['db'];function respondWithStatusCode(_0x42dc15,_0x3f1243){_0x3f1243=_0x3f1243||0xcc;return function(_0x461b2d){if(_0x461b2d){return _0x42dc15[_0x53d9('0x1b')](_0x3f1243);}return _0x42dc15[_0x53d9('0x1c')](_0x3f1243)[_0x53d9('0x1d')]();};}function respondWithResult(_0x29ea15,_0x46442f){_0x46442f=_0x46442f||0xc8;return function(_0x14304f){if(_0x14304f){return _0x29ea15[_0x53d9('0x1c')](_0x46442f)[_0x53d9('0x1e')](_0x14304f);}};}function respondWithFilteredResult(_0x5b0c8b,_0x23f77c){return function(_0x1a2712){if(_0x1a2712){var _0x3a1421=typeof _0x23f77c[_0x53d9('0x1f')]===_0x53d9('0x20')&&typeof _0x23f77c['limit']===_0x53d9('0x20');var _0x2cd45c=_0x1a2712['count'];var _0x2a03f2=_0x3a1421?0x0:_0x23f77c['offset'];var _0x5804da=_0x3a1421?_0x1a2712[_0x53d9('0x21')]:_0x23f77c[_0x53d9('0x1f')]+_0x23f77c[_0x53d9('0x22')];var _0x72d6fe;if(_0x5804da>=_0x2cd45c){_0x5804da=_0x2cd45c;_0x72d6fe=0xc8;}else{_0x72d6fe=0xce;}_0x5b0c8b[_0x53d9('0x1c')](_0x72d6fe);return _0x5b0c8b['set'](_0x53d9('0x23'),_0x2a03f2+'-'+_0x5804da+'/'+_0x2cd45c)[_0x53d9('0x1e')](_0x1a2712);}return null;};}function patchUpdates(_0x52ae97){return function(_0x27b732){try{jsonpatch['apply'](_0x27b732,_0x52ae97,!![]);}catch(_0x42aff9){return BPromise[_0x53d9('0x24')](_0x42aff9);}return _0x27b732[_0x53d9('0x25')]();};}function saveUpdates(_0x919781,_0x411f98){return function(_0x286472){if(_0x286472){return _0x286472[_0x53d9('0x26')](_0x919781)['then'](function(_0x45bf96){return _0x45bf96;});}return null;};}function removeEntity(_0x161858,_0x391fdf){return function(_0x4480c5){if(_0x4480c5){return _0x4480c5[_0x53d9('0x27')]()['then'](function(){var _0x4b2136=_0x4480c5[_0x53d9('0x28')]({'plain':!![]});var _0x4d6132='Variables';return db[_0x53d9('0x29')][_0x53d9('0x27')]({'where':{'type':_0x4d6132,'resourceId':_0x4b2136['id']}})[_0x53d9('0x2a')](function(){return _0x4480c5;});})[_0x53d9('0x2a')](function(){_0x161858[_0x53d9('0x1c')](0xcc)[_0x53d9('0x1d')]();});}};}function handleEntityNotFound(_0xf064f9,_0x1036db){return function(_0x15d4bb){if(!_0x15d4bb){_0xf064f9[_0x53d9('0x1b')](0x194);}return _0x15d4bb;};}function handleError(_0x5b6925,_0x1411f8){_0x1411f8=_0x1411f8||0x1f4;return function(_0x261803){logger[_0x53d9('0x2b')](_0x261803['stack']);if(_0x261803[_0x53d9('0x2c')]){delete _0x261803['name'];}_0x5b6925[_0x53d9('0x1c')](_0x1411f8)[_0x53d9('0x2d')](_0x261803);};}exports[_0x53d9('0x2e')]=function(_0x2a85f1,_0x2efa7c){var _0x2dea72={},_0x4eb24d={},_0x1a8129={'count':0x0,'rows':[]};var _0x3ca15e=_[_0x53d9('0x2f')](db['Variable']['rawAttributes'],function(_0x3646e7){return{'name':_0x3646e7['fieldName'],'type':_0x3646e7[_0x53d9('0x30')][_0x53d9('0x31')]};});_0x4eb24d[_0x53d9('0x32')]=_[_0x53d9('0x2f')](_0x3ca15e,_0x53d9('0x2c'));_0x4eb24d['query']=_[_0x53d9('0x33')](_0x2a85f1[_0x53d9('0x34')]);_0x4eb24d['filters']=_['intersection'](_0x4eb24d[_0x53d9('0x32')],_0x4eb24d[_0x53d9('0x34')]);_0x2dea72[_0x53d9('0x35')]=_[_0x53d9('0x36')](_0x4eb24d['model'],qs[_0x53d9('0x37')](_0x2a85f1[_0x53d9('0x34')][_0x53d9('0x37')]));_0x2dea72[_0x53d9('0x35')]=_0x2dea72['attributes'][_0x53d9('0x38')]?_0x2dea72['attributes']:_0x4eb24d[_0x53d9('0x32')];if(!_0x2a85f1[_0x53d9('0x34')][_0x53d9('0x39')](_0x53d9('0x3a'))){_0x2dea72[_0x53d9('0x22')]=qs['limit'](_0x2a85f1['query'][_0x53d9('0x22')]);_0x2dea72[_0x53d9('0x1f')]=qs['offset'](_0x2a85f1['query']['offset']);}_0x2dea72[_0x53d9('0x3b')]=qs[_0x53d9('0x3c')](_0x2a85f1['query'][_0x53d9('0x3c')]);_0x2dea72[_0x53d9('0x3d')]=qs[_0x53d9('0x3e')](_[_0x53d9('0x3f')](_0x2a85f1['query'],_0x4eb24d[_0x53d9('0x3e')]),_0x3ca15e);if(_0x2a85f1[_0x53d9('0x34')][_0x53d9('0x40')]){_0x2dea72[_0x53d9('0x3d')]=_[_0x53d9('0x41')](_0x2dea72[_0x53d9('0x3d')],{'$or':_[_0x53d9('0x2f')](_0x3ca15e,function(_0x58853f){if(_0x58853f[_0x53d9('0x30')]!==_0x53d9('0x42')){var _0x5b6729={};_0x5b6729[_0x58853f[_0x53d9('0x2c')]]={'$like':'%'+_0x2a85f1[_0x53d9('0x34')][_0x53d9('0x40')]+'%'};return _0x5b6729;}})});}_0x2dea72=_[_0x53d9('0x41')]({},_0x2dea72,_0x2a85f1[_0x53d9('0x43')]);var _0x11519c={'where':_0x2dea72[_0x53d9('0x3d')]};return db[_0x53d9('0x44')][_0x53d9('0x21')](_0x11519c)[_0x53d9('0x2a')](function(_0x1552b5){_0x1a8129[_0x53d9('0x21')]=_0x1552b5;if(_0x2a85f1[_0x53d9('0x34')][_0x53d9('0x45')]){_0x2dea72['include']=[{'all':!![]}];}return db[_0x53d9('0x44')]['findAll'](_0x2dea72);})[_0x53d9('0x2a')](function(_0x640142){_0x1a8129['rows']=_0x640142;return _0x1a8129;})[_0x53d9('0x2a')](respondWithFilteredResult(_0x2efa7c,_0x2dea72))[_0x53d9('0x46')](handleError(_0x2efa7c,null));};exports['show']=function(_0x14e475,_0x2e8fcc){var _0x5d6b02={'raw':!![],'where':{'id':_0x14e475[_0x53d9('0x47')]['id']}},_0x3b0a50={};_0x3b0a50[_0x53d9('0x32')]=_[_0x53d9('0x33')](db['Variable'][_0x53d9('0x48')]);_0x3b0a50[_0x53d9('0x34')]=_[_0x53d9('0x33')](_0x14e475[_0x53d9('0x34')]);_0x3b0a50[_0x53d9('0x3e')]=_[_0x53d9('0x36')](_0x3b0a50[_0x53d9('0x32')],_0x3b0a50[_0x53d9('0x34')]);_0x5d6b02[_0x53d9('0x35')]=_['intersection'](_0x3b0a50[_0x53d9('0x32')],qs[_0x53d9('0x37')](_0x14e475[_0x53d9('0x34')][_0x53d9('0x37')]));_0x5d6b02[_0x53d9('0x35')]=_0x5d6b02[_0x53d9('0x35')][_0x53d9('0x38')]?_0x5d6b02[_0x53d9('0x35')]:_0x3b0a50[_0x53d9('0x32')];if(_0x14e475[_0x53d9('0x34')][_0x53d9('0x45')]){_0x5d6b02[_0x53d9('0x49')]=[{'all':!![]}];}_0x5d6b02=_['merge']({},_0x5d6b02,_0x14e475[_0x53d9('0x43')]);return db[_0x53d9('0x44')][_0x53d9('0x4a')](_0x5d6b02)['then'](handleEntityNotFound(_0x2e8fcc,null))['then'](respondWithResult(_0x2e8fcc,null))[_0x53d9('0x46')](handleError(_0x2e8fcc,null));};exports[_0x53d9('0x4b')]=function(_0x418598,_0x3bbd2c){return db[_0x53d9('0x44')]['create'](_0x418598[_0x53d9('0x4c')],{})[_0x53d9('0x2a')](function(_0x534151){var _0x306f6b=_0x418598[_0x53d9('0x4d')]['get']({'plain':!![]});if(!_0x306f6b)throw new Error(_0x53d9('0x4e'));if(_0x306f6b[_0x53d9('0x4f')]==='user'){var _0x1e3298=_0x534151[_0x53d9('0x28')]({'plain':!![]});var _0x13730f=_0x53d9('0x50');return db[_0x53d9('0x51')][_0x53d9('0x4a')]({'where':{'name':_0x13730f,'userProfileId':_0x306f6b['userProfileId']},'raw':!![]})[_0x53d9('0x2a')](function(_0x48e69f){if(_0x48e69f&&_0x48e69f[_0x53d9('0x52')]===0x0){return db[_0x53d9('0x29')][_0x53d9('0x4b')]({'name':_0x1e3298[_0x53d9('0x2c')],'resourceId':_0x1e3298['id'],'type':_0x48e69f[_0x53d9('0x2c')],'sectionId':_0x48e69f['id']},{})['then'](function(){return _0x534151;});}else{return _0x534151;}})[_0x53d9('0x46')](function(_0x12b4ad){logger['error'](_0x53d9('0x53'),_0x12b4ad);throw _0x12b4ad;});}return _0x534151;})[_0x53d9('0x2a')](respondWithResult(_0x3bbd2c,0xc9))[_0x53d9('0x46')](handleError(_0x3bbd2c,null));};exports['update']=function(_0x2a829c,_0x508d52){if(_0x2a829c[_0x53d9('0x4c')]['id']){delete _0x2a829c[_0x53d9('0x4c')]['id'];}return db[_0x53d9('0x44')][_0x53d9('0x4a')]({'where':{'id':_0x2a829c[_0x53d9('0x47')]['id']}})[_0x53d9('0x2a')](handleEntityNotFound(_0x508d52,null))[_0x53d9('0x2a')](saveUpdates(_0x2a829c[_0x53d9('0x4c')],null))[_0x53d9('0x2a')](respondWithResult(_0x508d52,null))[_0x53d9('0x46')](handleError(_0x508d52,null));};exports['destroy']=function(_0x1c08b2,_0x180ee5){return db[_0x53d9('0x44')]['find']({'where':{'id':_0x1c08b2[_0x53d9('0x47')]['id']}})[_0x53d9('0x2a')](handleEntityNotFound(_0x180ee5,null))[_0x53d9('0x2a')](removeEntity(_0x180ee5,null))[_0x53d9('0x46')](handleError(_0x180ee5,null));};