18 var _0xb86d=['length','hasOwnProperty','nolimit','order','sort','where','pick','filter','merge','VIRTUAL','includeAll','include','rows','catch','show','params','rawAttributes','options','find','create','body','user','Unable\x20to\x20retrieve\x20the\x20current\x20user','role','UserProfileSection','userProfileId','autoAssociation','UserProfileResource','Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s','eml-format','rimraf','fast-json-patch','request-promise','bluebird','mustache','util','sox','to-csv','ejs','fs-extra','lodash','squel','jsforce','querystring','papaparse','ioredis','../../components/auth/service','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','api','../../config/utils','../../config/environment','../../config/license/util','../../mysqldb','sendStatus','status','end','offset','undefined','limit','count','set','Content-Range','json','apply','reject','then','get','Variables','destroy','error','stack','name','send','index','map','Variable','fieldName','type','query','keys','filters','intersection','model','attributes','fields'];(function(_0x46698a,_0x8de1e4){var _0x356db0=function(_0x19e83c){while(--_0x19e83c){_0x46698a['push'](_0x46698a['shift']());}};_0x356db0(++_0x8de1e4);}(_0xb86d,0x74));var _0xdb86=function(_0x21a9d9,_0x4d5ac8){_0x21a9d9=_0x21a9d9-0x0;var _0x46adce=_0xb86d[_0x21a9d9];return _0x46adce;};'use strict';var emlformat=require(_0xdb86('0x0'));var rimraf=require(_0xdb86('0x1'));var zipdir=require('zip-dir');var jsonpatch=require(_0xdb86('0x2'));var rp=require(_0xdb86('0x3'));var moment=require('moment');var BPromise=require(_0xdb86('0x4'));var Mustache=require(_0xdb86('0x5'));var util=require(_0xdb86('0x6'));var path=require('path');var sox=require(_0xdb86('0x7'));var csv=require(_0xdb86('0x8'));var ejs=require(_0xdb86('0x9'));var fs=require('fs');var fs_extra=require(_0xdb86('0xa'));var _=require(_0xdb86('0xb'));var squel=require(_0xdb86('0xc'));var crypto=require('crypto');var jsforce=require(_0xdb86('0xd'));var deskjs=require('desk.js');var toCsv=require('to-csv');var querystring=require(_0xdb86('0xe'));var Papa=require(_0xdb86('0xf'));var Redis=require(_0xdb86('0x10'));var authService=require(_0xdb86('0x11'));var qs=require('../../components/parsers/qs');var as=require(_0xdb86('0x12'));var hardwareService=require(_0xdb86('0x13'));var logger=require(_0xdb86('0x14'))(_0xdb86('0x15'));var utils=require(_0xdb86('0x16'));var config=require(_0xdb86('0x17'));var licenseUtil=require(_0xdb86('0x18'));var db=require(_0xdb86('0x19'))['db'];function respondWithStatusCode(_0x27dafb,_0x18be88){_0x18be88=_0x18be88||0xcc;return function(_0x53e19e){if(_0x53e19e){return _0x27dafb[_0xdb86('0x1a')](_0x18be88);}return _0x27dafb[_0xdb86('0x1b')](_0x18be88)[_0xdb86('0x1c')]();};}function respondWithResult(_0x470cb9,_0x2159b1){_0x2159b1=_0x2159b1||0xc8;return function(_0x37123b){if(_0x37123b){return _0x470cb9[_0xdb86('0x1b')](_0x2159b1)['json'](_0x37123b);}};}function respondWithFilteredResult(_0x55c90d,_0x132b4f){return function(_0x364792){if(_0x364792){var _0x21ee25=typeof _0x132b4f[_0xdb86('0x1d')]===_0xdb86('0x1e')&&typeof _0x132b4f[_0xdb86('0x1f')]===_0xdb86('0x1e');var _0x330e7b=_0x364792['count'];var _0x2c07f1=_0x21ee25?0x0:_0x132b4f[_0xdb86('0x1d')];var _0x4a6fd4=_0x21ee25?_0x364792[_0xdb86('0x20')]:_0x132b4f[_0xdb86('0x1d')]+_0x132b4f[_0xdb86('0x1f')];var _0x288a17;if(_0x4a6fd4>=_0x330e7b){_0x4a6fd4=_0x330e7b;_0x288a17=0xc8;}else{_0x288a17=0xce;}_0x55c90d[_0xdb86('0x1b')](_0x288a17);return _0x55c90d[_0xdb86('0x21')](_0xdb86('0x22'),_0x2c07f1+'-'+_0x4a6fd4+'/'+_0x330e7b)[_0xdb86('0x23')](_0x364792);}return null;};}function patchUpdates(_0x7bfdd2){return function(_0x29ee54){try{jsonpatch[_0xdb86('0x24')](_0x29ee54,_0x7bfdd2,!![]);}catch(_0x51f244){return BPromise[_0xdb86('0x25')](_0x51f244);}return _0x29ee54['save']();};}function saveUpdates(_0x47ceda,_0x1a7875){return function(_0x282fc5){if(_0x282fc5){return _0x282fc5['update'](_0x47ceda)[_0xdb86('0x26')](function(_0x52e4bd){return _0x52e4bd;});}return null;};}function removeEntity(_0x17eeeb,_0x38144d){return function(_0x30a532){if(_0x30a532){return _0x30a532['destroy']()[_0xdb86('0x26')](function(){var _0x3092ee=_0x30a532[_0xdb86('0x27')]({'plain':!![]});var _0x894736=_0xdb86('0x28');return db['UserProfileResource'][_0xdb86('0x29')]({'where':{'type':_0x894736,'resourceId':_0x3092ee['id']}})[_0xdb86('0x26')](function(){return _0x30a532;});})['then'](function(){_0x17eeeb[_0xdb86('0x1b')](0xcc)['end']();});}};}function handleEntityNotFound(_0x3a05b7,_0x2b237e){return function(_0x32e910){if(!_0x32e910){_0x3a05b7[_0xdb86('0x1a')](0x194);}return _0x32e910;};}function handleError(_0x16c749,_0xfa4999){_0xfa4999=_0xfa4999||0x1f4;return function(_0x5f59c1){logger[_0xdb86('0x2a')](_0x5f59c1[_0xdb86('0x2b')]);if(_0x5f59c1[_0xdb86('0x2c')]){delete _0x5f59c1[_0xdb86('0x2c')];}_0x16c749[_0xdb86('0x1b')](_0xfa4999)[_0xdb86('0x2d')](_0x5f59c1);};}exports[_0xdb86('0x2e')]=function(_0x3b99b2,_0x3db36a){var _0x32f4de={},_0x27cfba={},_0x447c23={'count':0x0,'rows':[]};var _0x42158d=_[_0xdb86('0x2f')](db[_0xdb86('0x30')]['rawAttributes'],function(_0x591a74){return{'name':_0x591a74[_0xdb86('0x31')],'type':_0x591a74[_0xdb86('0x32')]['key']};});_0x27cfba['model']=_[_0xdb86('0x2f')](_0x42158d,_0xdb86('0x2c'));_0x27cfba[_0xdb86('0x33')]=_[_0xdb86('0x34')](_0x3b99b2[_0xdb86('0x33')]);_0x27cfba[_0xdb86('0x35')]=_[_0xdb86('0x36')](_0x27cfba[_0xdb86('0x37')],_0x27cfba['query']);_0x32f4de[_0xdb86('0x38')]=_['intersection'](_0x27cfba['model'],qs[_0xdb86('0x39')](_0x3b99b2[_0xdb86('0x33')][_0xdb86('0x39')]));_0x32f4de[_0xdb86('0x38')]=_0x32f4de[_0xdb86('0x38')][_0xdb86('0x3a')]?_0x32f4de[_0xdb86('0x38')]:_0x27cfba[_0xdb86('0x37')];if(!_0x3b99b2[_0xdb86('0x33')][_0xdb86('0x3b')](_0xdb86('0x3c'))){_0x32f4de[_0xdb86('0x1f')]=qs[_0xdb86('0x1f')](_0x3b99b2[_0xdb86('0x33')][_0xdb86('0x1f')]);_0x32f4de[_0xdb86('0x1d')]=qs[_0xdb86('0x1d')](_0x3b99b2[_0xdb86('0x33')][_0xdb86('0x1d')]);}_0x32f4de[_0xdb86('0x3d')]=qs[_0xdb86('0x3e')](_0x3b99b2[_0xdb86('0x33')][_0xdb86('0x3e')]);_0x32f4de[_0xdb86('0x3f')]=qs['filters'](_[_0xdb86('0x40')](_0x3b99b2['query'],_0x27cfba[_0xdb86('0x35')]),_0x42158d);if(_0x3b99b2[_0xdb86('0x33')][_0xdb86('0x41')]){_0x32f4de[_0xdb86('0x3f')]=_[_0xdb86('0x42')](_0x32f4de['where'],{'$or':_['map'](_0x42158d,function(_0x647c){if(_0x647c[_0xdb86('0x32')]!==_0xdb86('0x43')){var _0x18d46b={};_0x18d46b[_0x647c[_0xdb86('0x2c')]]={'$like':'%'+_0x3b99b2[_0xdb86('0x33')][_0xdb86('0x41')]+'%'};return _0x18d46b;}})});}_0x32f4de=_[_0xdb86('0x42')]({},_0x32f4de,_0x3b99b2['options']);var _0x1e0914={'where':_0x32f4de['where']};return db[_0xdb86('0x30')][_0xdb86('0x20')](_0x1e0914)[_0xdb86('0x26')](function(_0x265ad4){_0x447c23[_0xdb86('0x20')]=_0x265ad4;if(_0x3b99b2[_0xdb86('0x33')][_0xdb86('0x44')]){_0x32f4de[_0xdb86('0x45')]=[{'all':!![]}];}return db['Variable']['findAll'](_0x32f4de);})[_0xdb86('0x26')](function(_0x551f3c){_0x447c23[_0xdb86('0x46')]=_0x551f3c;return _0x447c23;})[_0xdb86('0x26')](respondWithFilteredResult(_0x3db36a,_0x32f4de))[_0xdb86('0x47')](handleError(_0x3db36a,null));};exports[_0xdb86('0x48')]=function(_0x1a6f2d,_0x18f394){var _0x28c972={'raw':!![],'where':{'id':_0x1a6f2d[_0xdb86('0x49')]['id']}},_0x11b26b={};_0x11b26b[_0xdb86('0x37')]=_['keys'](db[_0xdb86('0x30')][_0xdb86('0x4a')]);_0x11b26b[_0xdb86('0x33')]=_['keys'](_0x1a6f2d[_0xdb86('0x33')]);_0x11b26b[_0xdb86('0x35')]=_[_0xdb86('0x36')](_0x11b26b[_0xdb86('0x37')],_0x11b26b[_0xdb86('0x33')]);_0x28c972['attributes']=_[_0xdb86('0x36')](_0x11b26b['model'],qs[_0xdb86('0x39')](_0x1a6f2d[_0xdb86('0x33')][_0xdb86('0x39')]));_0x28c972[_0xdb86('0x38')]=_0x28c972['attributes'][_0xdb86('0x3a')]?_0x28c972['attributes']:_0x11b26b[_0xdb86('0x37')];if(_0x1a6f2d[_0xdb86('0x33')][_0xdb86('0x44')]){_0x28c972[_0xdb86('0x45')]=[{'all':!![]}];}_0x28c972=_[_0xdb86('0x42')]({},_0x28c972,_0x1a6f2d[_0xdb86('0x4b')]);return db[_0xdb86('0x30')][_0xdb86('0x4c')](_0x28c972)[_0xdb86('0x26')](handleEntityNotFound(_0x18f394,null))[_0xdb86('0x26')](respondWithResult(_0x18f394,null))[_0xdb86('0x47')](handleError(_0x18f394,null));};exports[_0xdb86('0x4d')]=function(_0x557824,_0xf846ca){return db[_0xdb86('0x30')][_0xdb86('0x4d')](_0x557824[_0xdb86('0x4e')],{})[_0xdb86('0x26')](function(_0x58e0c1){var _0x5133f0=_0x557824[_0xdb86('0x4f')][_0xdb86('0x27')]({'plain':!![]});if(!_0x5133f0)throw new Error(_0xdb86('0x50'));if(_0x5133f0[_0xdb86('0x51')]===_0xdb86('0x4f')){var _0x184c0a=_0x58e0c1[_0xdb86('0x27')]({'plain':!![]});var _0x21f646=_0xdb86('0x28');return db[_0xdb86('0x52')][_0xdb86('0x4c')]({'where':{'name':_0x21f646,'userProfileId':_0x5133f0[_0xdb86('0x53')]},'raw':!![]})[_0xdb86('0x26')](function(_0x4c8f2b){if(_0x4c8f2b&&_0x4c8f2b[_0xdb86('0x54')]===0x0){return db[_0xdb86('0x55')]['create']({'name':_0x184c0a[_0xdb86('0x2c')],'resourceId':_0x184c0a['id'],'type':_0x4c8f2b[_0xdb86('0x2c')],'sectionId':_0x4c8f2b['id']},{})['then'](function(){return _0x58e0c1;});}else{return _0x58e0c1;}})['catch'](function(_0x19a6cc){logger[_0xdb86('0x2a')](_0xdb86('0x56'),_0x19a6cc);throw _0x19a6cc;});}return _0x58e0c1;})[_0xdb86('0x26')](respondWithResult(_0xf846ca,0xc9))[_0xdb86('0x47')](handleError(_0xf846ca,null));};exports['update']=function(_0x8929c6,_0x58313e){if(_0x8929c6[_0xdb86('0x4e')]['id']){delete _0x8929c6[_0xdb86('0x4e')]['id'];}return db[_0xdb86('0x30')]['find']({'where':{'id':_0x8929c6['params']['id']}})[_0xdb86('0x26')](handleEntityNotFound(_0x58313e,null))[_0xdb86('0x26')](saveUpdates(_0x8929c6[_0xdb86('0x4e')],null))[_0xdb86('0x26')](respondWithResult(_0x58313e,null))['catch'](handleError(_0x58313e,null));};exports[_0xdb86('0x29')]=function(_0x382f1a,_0x3de47c){return db[_0xdb86('0x30')]['find']({'where':{'id':_0x382f1a[_0xdb86('0x49')]['id']}})[_0xdb86('0x26')](handleEntityNotFound(_0x3de47c,null))[_0xdb86('0x26')](removeEntity(_0x3de47c,null))[_0xdb86('0x47')](handleError(_0x3de47c,null));};