Built motion from commit c738b9ac.|2.6.25
[motion2.git] / server / api / intSugarcrmAccount / intSugarcrmAccount.controller.js
index fdd872e..533553e 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0xec85=['path','to-csv','ejs','fs-extra','lodash','crypto','desk.js','querystring','papaparse','ioredis','../../components/auth/service','../../components/parsers/advancedSearch','../../config/license/hardware','api','../../config/utils','../../config/environment','../../config/license/util','../../components/integrations/configuration','sendStatus','status','end','offset','undefined','count','limit','set','Content-Range','json','apply','save','then','destroy','stack','name','send','index','map','SugarcrmAccount','rawAttributes','fieldName','type','key','query','keys','model','attributes','intersection','fields','hasOwnProperty','order','sort','filters','filter','where','VIRTUAL','include','findAll','rows','catch','show','params','includeAll','merge','create','body','update','find','getConfigurations','findOne','SugarcrmConfiguration','length','pick','options','nolimit','AccountId','getSubjects','channel','Descriptions','getDescriptions','SugarcrmField','Subjects','getFields','description','date_start','duration_minutes','parent_id','parent_type','direction','password','remoteUri','slice','substring','lastIndexOf','POST','format','%s%s','/service/v4_1/rest.php','login','stringify','username','PLAIN','Password\x20Expired','get_module_fields','Calls','values','remove','includes','label','endsWith','test','statusCode','Wrong\x20credentials','eml-format','zip-dir','fast-json-patch','request-promise','bluebird','mustache'];(function(_0x5c2f82,_0x10cab0){var _0x400648=function(_0x5b7f1a){while(--_0x5b7f1a){_0x5c2f82['push'](_0x5c2f82['shift']());}};_0x400648(++_0x10cab0);}(_0xec85,0x1d2));var _0x5ec8=function(_0x35fa81,_0xf6be33){_0x35fa81=_0x35fa81-0x0;var _0x10bbff=_0xec85[_0x35fa81];return _0x10bbff;};'use strict';var emlformat=require(_0x5ec8('0x0'));var rimraf=require('rimraf');var zipdir=require(_0x5ec8('0x1'));var jsonpatch=require(_0x5ec8('0x2'));var rp=require(_0x5ec8('0x3'));var moment=require('moment');var BPromise=require(_0x5ec8('0x4'));var Mustache=require(_0x5ec8('0x5'));var util=require('util');var path=require(_0x5ec8('0x6'));var sox=require('sox');var csv=require(_0x5ec8('0x7'));var ejs=require(_0x5ec8('0x8'));var fs=require('fs');var fs_extra=require(_0x5ec8('0x9'));var _=require(_0x5ec8('0xa'));var squel=require('squel');var crypto=require(_0x5ec8('0xb'));var jsforce=require('jsforce');var deskjs=require(_0x5ec8('0xc'));var toCsv=require(_0x5ec8('0x7'));var querystring=require(_0x5ec8('0xd'));var Papa=require(_0x5ec8('0xe'));var Redis=require(_0x5ec8('0xf'));var authService=require(_0x5ec8('0x10'));var qs=require('../../components/parsers/qs');var as=require(_0x5ec8('0x11'));var hardwareService=require(_0x5ec8('0x12'));var logger=require('../../config/logger')(_0x5ec8('0x13'));var utils=require(_0x5ec8('0x14'));var config=require(_0x5ec8('0x15'));var licenseUtil=require(_0x5ec8('0x16'));var db=require('../../mysqldb')['db'];var integrations=require(_0x5ec8('0x17'));function respondWithStatusCode(_0x38f6b8,_0x316e5d){_0x316e5d=_0x316e5d||0xcc;return function(_0x35b8f2){if(_0x35b8f2){return _0x38f6b8[_0x5ec8('0x18')](_0x316e5d);}return _0x38f6b8[_0x5ec8('0x19')](_0x316e5d)[_0x5ec8('0x1a')]();};}function respondWithResult(_0x42227c,_0x564bd3){_0x564bd3=_0x564bd3||0xc8;return function(_0x41a3d7){if(_0x41a3d7){return _0x42227c[_0x5ec8('0x19')](_0x564bd3)['json'](_0x41a3d7);}};}function respondWithFilteredResult(_0x5d5b99,_0x194f63){return function(_0x4ead1c){if(_0x4ead1c){var _0x737f73=typeof _0x194f63[_0x5ec8('0x1b')]===_0x5ec8('0x1c')&&typeof _0x194f63['limit']===_0x5ec8('0x1c');var _0x1907aa=_0x4ead1c[_0x5ec8('0x1d')];var _0x420b61=_0x737f73?0x0:_0x194f63[_0x5ec8('0x1b')];var _0x5e9089=_0x737f73?_0x4ead1c['count']:_0x194f63[_0x5ec8('0x1b')]+_0x194f63[_0x5ec8('0x1e')];var _0x24ec99;if(_0x5e9089>=_0x1907aa){_0x5e9089=_0x1907aa;_0x24ec99=0xc8;}else{_0x24ec99=0xce;}_0x5d5b99['status'](_0x24ec99);return _0x5d5b99[_0x5ec8('0x1f')](_0x5ec8('0x20'),_0x420b61+'-'+_0x5e9089+'/'+_0x1907aa)[_0x5ec8('0x21')](_0x4ead1c);}return null;};}function patchUpdates(_0x49952d){return function(_0x2278bc){try{jsonpatch[_0x5ec8('0x22')](_0x2278bc,_0x49952d,!![]);}catch(_0x3339c8){return BPromise['reject'](_0x3339c8);}return _0x2278bc[_0x5ec8('0x23')]();};}function saveUpdates(_0x48ab90,_0xf22d06){return function(_0x53bec7){if(_0x53bec7){return _0x53bec7['update'](_0x48ab90)[_0x5ec8('0x24')](function(_0x340dd7){return _0x340dd7;});}return null;};}function removeEntity(_0x149fd8,_0x5845a7){return function(_0x113c16){if(_0x113c16){return _0x113c16[_0x5ec8('0x25')]()['then'](function(){_0x149fd8[_0x5ec8('0x19')](0xcc)[_0x5ec8('0x1a')]();});}};}function handleEntityNotFound(_0x3d91ea,_0x211a57){return function(_0x540bf3){if(!_0x540bf3){_0x3d91ea['sendStatus'](0x194);}return _0x540bf3;};}function handleError(_0x56862d,_0x4bda7a){_0x4bda7a=_0x4bda7a||0x1f4;return function(_0x56d036){logger['error'](_0x56d036[_0x5ec8('0x26')]);if(_0x56d036['name']){delete _0x56d036[_0x5ec8('0x27')];}_0x56862d[_0x5ec8('0x19')](_0x4bda7a)[_0x5ec8('0x28')](_0x56d036);};}exports[_0x5ec8('0x29')]=function(_0x10dec0,_0x24e1ee){var _0x4cd7a7={},_0x29e417={},_0x90b485={'count':0x0,'rows':[]};var _0x43a9ba=_[_0x5ec8('0x2a')](db[_0x5ec8('0x2b')][_0x5ec8('0x2c')],function(_0x52d79a){return{'name':_0x52d79a[_0x5ec8('0x2d')],'type':_0x52d79a[_0x5ec8('0x2e')][_0x5ec8('0x2f')]};});_0x29e417['model']=_[_0x5ec8('0x2a')](_0x43a9ba,_0x5ec8('0x27'));_0x29e417[_0x5ec8('0x30')]=_[_0x5ec8('0x31')](_0x10dec0[_0x5ec8('0x30')]);_0x29e417['filters']=_['intersection'](_0x29e417[_0x5ec8('0x32')],_0x29e417[_0x5ec8('0x30')]);_0x4cd7a7[_0x5ec8('0x33')]=_[_0x5ec8('0x34')](_0x29e417[_0x5ec8('0x32')],qs[_0x5ec8('0x35')](_0x10dec0[_0x5ec8('0x30')]['fields']));_0x4cd7a7[_0x5ec8('0x33')]=_0x4cd7a7['attributes']['length']?_0x4cd7a7[_0x5ec8('0x33')]:_0x29e417[_0x5ec8('0x32')];if(!_0x10dec0[_0x5ec8('0x30')][_0x5ec8('0x36')]('nolimit')){_0x4cd7a7[_0x5ec8('0x1e')]=qs[_0x5ec8('0x1e')](_0x10dec0[_0x5ec8('0x30')][_0x5ec8('0x1e')]);_0x4cd7a7['offset']=qs[_0x5ec8('0x1b')](_0x10dec0['query'][_0x5ec8('0x1b')]);}_0x4cd7a7[_0x5ec8('0x37')]=qs[_0x5ec8('0x38')](_0x10dec0['query']['sort']);_0x4cd7a7['where']=qs[_0x5ec8('0x39')](_['pick'](_0x10dec0['query'],_0x29e417[_0x5ec8('0x39')]),_0x43a9ba);if(_0x10dec0[_0x5ec8('0x30')][_0x5ec8('0x3a')]){_0x4cd7a7['where']=_['merge'](_0x4cd7a7[_0x5ec8('0x3b')],{'$or':_[_0x5ec8('0x2a')](_0x43a9ba,function(_0x3388ee){if(_0x3388ee['type']!==_0x5ec8('0x3c')){var _0x1530f9={};_0x1530f9[_0x3388ee[_0x5ec8('0x27')]]={'$like':'%'+_0x10dec0[_0x5ec8('0x30')][_0x5ec8('0x3a')]+'%'};return _0x1530f9;}})});}_0x4cd7a7=_['merge']({},_0x4cd7a7,_0x10dec0['options']);var _0x61b42b={'where':_0x4cd7a7['where']};return db[_0x5ec8('0x2b')][_0x5ec8('0x1d')](_0x61b42b)[_0x5ec8('0x24')](function(_0x166aa3){_0x90b485[_0x5ec8('0x1d')]=_0x166aa3;if(_0x10dec0[_0x5ec8('0x30')]['includeAll']){_0x4cd7a7[_0x5ec8('0x3d')]=[{'all':!![]}];}return db[_0x5ec8('0x2b')][_0x5ec8('0x3e')](_0x4cd7a7);})[_0x5ec8('0x24')](function(_0xc8b1a7){_0x90b485[_0x5ec8('0x3f')]=_0xc8b1a7;return _0x90b485;})[_0x5ec8('0x24')](respondWithFilteredResult(_0x24e1ee,_0x4cd7a7))[_0x5ec8('0x40')](handleError(_0x24e1ee,null));};exports[_0x5ec8('0x41')]=function(_0x5143eb,_0xa74db5){var _0x4f553e={'raw':![],'where':{'id':_0x5143eb[_0x5ec8('0x42')]['id']}},_0x59ae65={};_0x59ae65[_0x5ec8('0x32')]=_[_0x5ec8('0x31')](db[_0x5ec8('0x2b')][_0x5ec8('0x2c')]);_0x59ae65[_0x5ec8('0x30')]=_['keys'](_0x5143eb[_0x5ec8('0x30')]);_0x59ae65[_0x5ec8('0x39')]=_[_0x5ec8('0x34')](_0x59ae65[_0x5ec8('0x32')],_0x59ae65[_0x5ec8('0x30')]);_0x4f553e[_0x5ec8('0x33')]=_[_0x5ec8('0x34')](_0x59ae65[_0x5ec8('0x32')],qs[_0x5ec8('0x35')](_0x5143eb[_0x5ec8('0x30')][_0x5ec8('0x35')]));_0x4f553e[_0x5ec8('0x33')]=_0x4f553e[_0x5ec8('0x33')]['length']?_0x4f553e[_0x5ec8('0x33')]:_0x59ae65[_0x5ec8('0x32')];if(_0x5143eb[_0x5ec8('0x30')][_0x5ec8('0x43')]){_0x4f553e[_0x5ec8('0x3d')]=[{'all':!![]}];}_0x4f553e=_[_0x5ec8('0x44')]({},_0x4f553e,_0x5143eb['options']);return db[_0x5ec8('0x2b')]['find'](_0x4f553e)['then'](handleEntityNotFound(_0xa74db5,null))['then'](respondWithResult(_0xa74db5,null))[_0x5ec8('0x40')](handleError(_0xa74db5,null));};exports[_0x5ec8('0x45')]=function(_0x27a6e9,_0x1b9866){return db[_0x5ec8('0x2b')][_0x5ec8('0x45')](_0x27a6e9[_0x5ec8('0x46')],{})[_0x5ec8('0x24')](respondWithResult(_0x1b9866,0xc9))['catch'](handleError(_0x1b9866,null));};exports[_0x5ec8('0x47')]=function(_0x16bcf9,_0x2d3df0){if(_0x16bcf9[_0x5ec8('0x46')]['id']){delete _0x16bcf9['body']['id'];}return db['SugarcrmAccount'][_0x5ec8('0x48')]({'where':{'id':_0x16bcf9[_0x5ec8('0x42')]['id']}})[_0x5ec8('0x24')](handleEntityNotFound(_0x2d3df0,null))['then'](saveUpdates(_0x16bcf9[_0x5ec8('0x46')],null))['then'](respondWithResult(_0x2d3df0,null))[_0x5ec8('0x40')](handleError(_0x2d3df0,null));};exports[_0x5ec8('0x25')]=function(_0x53430e,_0x3109ed){return db[_0x5ec8('0x2b')][_0x5ec8('0x48')]({'where':{'id':_0x53430e[_0x5ec8('0x42')]['id']}})[_0x5ec8('0x24')](handleEntityNotFound(_0x3109ed,null))[_0x5ec8('0x24')](removeEntity(_0x3109ed,null))[_0x5ec8('0x40')](handleError(_0x3109ed,null));};exports[_0x5ec8('0x49')]=function(_0x679799,_0x5ca55a,_0x34e1bb){var _0x3d4eeb={};var _0x2b57c2={};var _0x1454e1;var _0x4c1e4c;return db['SugarcrmAccount'][_0x5ec8('0x4a')]({'where':{'id':_0x679799[_0x5ec8('0x42')]['id']}})[_0x5ec8('0x24')](handleEntityNotFound(_0x5ca55a,null))[_0x5ec8('0x24')](function(_0x529efb){if(_0x529efb){_0x1454e1=_0x529efb;_0x2b57c2[_0x5ec8('0x32')]=_[_0x5ec8('0x31')](db[_0x5ec8('0x4b')][_0x5ec8('0x2c')]);_0x2b57c2[_0x5ec8('0x30')]=_[_0x5ec8('0x31')](_0x679799[_0x5ec8('0x30')]);_0x2b57c2[_0x5ec8('0x39')]=_['intersection'](_0x2b57c2[_0x5ec8('0x32')],_0x2b57c2[_0x5ec8('0x30')]);_0x3d4eeb[_0x5ec8('0x33')]=_[_0x5ec8('0x34')](_0x2b57c2[_0x5ec8('0x32')],qs[_0x5ec8('0x35')](_0x679799[_0x5ec8('0x30')][_0x5ec8('0x35')]));_0x3d4eeb['attributes']=_0x3d4eeb[_0x5ec8('0x33')][_0x5ec8('0x4c')]?_0x3d4eeb[_0x5ec8('0x33')]:_0x2b57c2[_0x5ec8('0x32')];_0x3d4eeb['order']=qs[_0x5ec8('0x38')](_0x679799['query'][_0x5ec8('0x38')]);_0x3d4eeb[_0x5ec8('0x3b')]=qs[_0x5ec8('0x39')](_[_0x5ec8('0x4d')](_0x679799[_0x5ec8('0x30')],_0x2b57c2[_0x5ec8('0x39')]));if(_0x679799[_0x5ec8('0x30')][_0x5ec8('0x3a')]){_0x3d4eeb[_0x5ec8('0x3b')]=_['merge'](_0x3d4eeb['where'],{'$or':_[_0x5ec8('0x2a')](_0x3d4eeb['attributes'],function(_0x182565){var _0x5a45e6={};_0x5a45e6[_0x182565]={'$like':'%'+_0x679799[_0x5ec8('0x30')]['filter']+'%'};return _0x5a45e6;})});}_0x3d4eeb=_[_0x5ec8('0x44')]({},_0x3d4eeb,_0x679799[_0x5ec8('0x4e')]);return _0x1454e1['getConfigurations'](_0x3d4eeb);}})[_0x5ec8('0x24')](function(_0x518095){if(_0x518095){_0x4c1e4c=_0x518095['length'];if(!_0x679799[_0x5ec8('0x30')][_0x5ec8('0x36')](_0x5ec8('0x4f'))){_0x3d4eeb['limit']=qs[_0x5ec8('0x1e')](_0x679799['query']['limit']);_0x3d4eeb[_0x5ec8('0x1b')]=qs['offset'](_0x679799[_0x5ec8('0x30')][_0x5ec8('0x1b')]);}return _0x1454e1[_0x5ec8('0x49')](_0x3d4eeb);}})[_0x5ec8('0x24')](function(_0x1e8797){if(_0x1e8797){return _0x1e8797?{'count':_0x4c1e4c,'rows':_0x1e8797}:null;}})[_0x5ec8('0x24')](respondWithResult(_0x5ca55a,null))[_0x5ec8('0x40')](handleError(_0x5ca55a,null));};exports['addConfiguration']=function(_0x587890,_0x55dde0,_0x3d8310){if(_0x587890['body']['id']){delete _0x587890[_0x5ec8('0x46')]['id'];}return db[_0x5ec8('0x2b')][_0x5ec8('0x4a')]({'where':{'id':_0x587890[_0x5ec8('0x42')]['id']}})['then'](handleEntityNotFound(_0x55dde0,null))[_0x5ec8('0x24')](function(_0x3851de){if(_0x3851de){_0x587890['body'][_0x5ec8('0x50')]=_0x3851de['id'];_0x587890[_0x5ec8('0x46')]['Subjects']=integrations[_0x5ec8('0x51')](_0x587890[_0x5ec8('0x46')][_0x5ec8('0x52')],_0x587890['body'][_0x5ec8('0x2e')]);_0x587890[_0x5ec8('0x46')][_0x5ec8('0x53')]=integrations[_0x5ec8('0x54')](_0x587890[_0x5ec8('0x46')][_0x5ec8('0x52')],_0x587890[_0x5ec8('0x46')][_0x5ec8('0x2e')]);return db['SugarcrmConfiguration']['create'](_0x587890[_0x5ec8('0x46')],{'include':[{'model':db[_0x5ec8('0x55')],'as':_0x5ec8('0x56')},{'model':db[_0x5ec8('0x55')],'as':_0x5ec8('0x53')}]});}return null;})['then'](respondWithResult(_0x55dde0,null))['catch'](handleError(_0x55dde0,null));};exports[_0x5ec8('0x57')]=function(_0xe76e99,_0x1a281d,_0x239ab4){var _0x1f6288='';var _0x55b90c=['id',_0x5ec8('0x27'),'assigned_user_id','created_by',_0x5ec8('0x58'),_0x5ec8('0x59'),'duration_hours',_0x5ec8('0x5a'),_0x5ec8('0x5b'),_0x5ec8('0x5c'),'parent_name',_0x5ec8('0x5d')];return db[_0x5ec8('0x2b')][_0x5ec8('0x4a')]({'where':{'id':_0xe76e99['params']['id']},'attributes':['id','username',_0x5ec8('0x5e'),_0x5ec8('0x5f')]})[_0x5ec8('0x24')](handleEntityNotFound(_0x1a281d,null))[_0x5ec8('0x24')](function(_0x116556){if(_0x116556){_0x1f6288=_0x116556['remoteUri'];var _0x343f25=_0x1f6288[_0x5ec8('0x60')](-0x1);if(_0x343f25==='/'){_0x1f6288=_0x1f6288[_0x5ec8('0x61')](0x0,_0x1f6288[_0x5ec8('0x62')](_0x343f25));}return rp({'method':_0x5ec8('0x63'),'uri':util[_0x5ec8('0x64')](_0x5ec8('0x65'),_0x1f6288,_0x5ec8('0x66')),'json':!![],'form':{'method':_0x5ec8('0x67'),'input_type':'JSON','response_type':'JSON','rest_data':JSON[_0x5ec8('0x68')]({'user_auth':{'user_name':_0x116556[_0x5ec8('0x69')],'password':_0x116556[_0x5ec8('0x5e')],'encryption':_0x5ec8('0x6a')},'application':'xCALLY\x20Motion\x20Integration'})}});}})[_0x5ec8('0x24')](function(_0x125724){if(_0x125724&&_0x125724['name']!=='Invalid\x20Login'&&_0x125724[_0x5ec8('0x27')]!==_0x5ec8('0x6b')){return rp({'method':_0x5ec8('0x63'),'uri':util[_0x5ec8('0x64')]('%s%s',_0x1f6288,_0x5ec8('0x66')),'json':!![],'form':{'method':_0x5ec8('0x6c'),'input_type':'JSON','response_type':'JSON','rest_data':JSON[_0x5ec8('0x68')]({'session':_0x125724['id'],'module_name':_0x5ec8('0x6d')})}})[_0x5ec8('0x24')](function(_0x99203f){if(_0x99203f){var _0x4a2985=_[_0x5ec8('0x6e')](_0x99203f['module_fields']);_[_0x5ec8('0x6f')](_0x4a2985,function(_0x4fe375){return _0x55b90c[_0x5ec8('0x70')](_0x4fe375['name']);});return{'count':_0x4a2985[_0x5ec8('0x4c')],'rows':_['map'](_0x4a2985,function(_0x3448e9){return{'id':_0x3448e9['name'],'name':_0x3448e9[_0x5ec8('0x71')],'custom':_[_0x5ec8('0x72')](_0x3448e9[_0x5ec8('0x27')],'_c')?!![]:![],'options':_0x3448e9['options']?_[_0x5ec8('0x2a')](_[_0x5ec8('0x6e')](_0x3448e9[_0x5ec8('0x4e')]),function(_0x2d5382){return{'name':_0x2d5382['value'],'value':_0x2d5382['name']};}):[]};})};}})['then'](respondWithResult(_0x1a281d,null))['catch'](function(_0x252d6a){var _0x1d8bad=_0xe76e99[_0x5ec8('0x30')][_0x5ec8('0x73')]?0x1f4:_0x252d6a[_0x5ec8('0x74')]||0x1f4;logger['error']('getFields,\x20%s,\x20%s,\x20%s',_0x5ec8('0x57'),_0x1d8bad,JSON[_0x5ec8('0x68')](_0x252d6a));delete _0x252d6a[_0x5ec8('0x27')];if(_0x1d8bad===0x191){_0x1d8bad=0x190;}_0x1a281d[_0x5ec8('0x19')](_0x1d8bad)[_0x5ec8('0x28')](_0xe76e99[_0x5ec8('0x30')][_0x5ec8('0x73')]?{'message':_0x5ec8('0x75'),'statusCode':_0x252d6a[_0x5ec8('0x74')]}:_0x252d6a);});}else{var _0x3d36c5=0x1f4;_0x1a281d['status'](_0x3d36c5)[_0x5ec8('0x28')]({'message':_0x5ec8('0x75'),'statusCode':0x190});}});};
\ No newline at end of file
+var _0x91a5=['remove','label','endsWith','test','Wrong\x20credentials','statusCode','eml-format','zip-dir','fast-json-patch','request-promise','util','path','sox','to-csv','fs-extra','lodash','squel','crypto','jsforce','desk.js','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','api','../../config/license/util','../../mysqldb','../../components/integrations/configuration','sendStatus','status','end','json','limit','undefined','count','offset','Content-Range','apply','reject','save','update','then','destroy','error','stack','name','send','index','SugarcrmAccount','rawAttributes','type','model','map','keys','query','filters','intersection','attributes','fields','length','nolimit','sort','where','pick','merge','VIRTUAL','options','include','findAll','show','params','includeAll','create','catch','body','find','getConfigurations','findOne','order','hasOwnProperty','AccountId','Subjects','getSubjects','channel','SugarcrmConfiguration','SugarcrmField','Descriptions','getFields','assigned_user_id','created_by','description','date_start','duration_hours','duration_minutes','parent_type','password','remoteUri','slice','substring','POST','format','/service/v4_1/rest.php','login','JSON','PLAIN','xCALLY\x20Motion\x20Integration','Invalid\x20Login','Password\x20Expired','get_module_fields','stringify','Calls','values','module_fields'];(function(_0x3fb5eb,_0x5947a6){var _0x481291=function(_0x74e4e){while(--_0x74e4e){_0x3fb5eb['push'](_0x3fb5eb['shift']());}};_0x481291(++_0x5947a6);}(_0x91a5,0x78));var _0x591a=function(_0x30033a,_0x5ce4a6){_0x30033a=_0x30033a-0x0;var _0x5e3518=_0x91a5[_0x30033a];return _0x5e3518;};'use strict';var emlformat=require(_0x591a('0x0'));var rimraf=require('rimraf');var zipdir=require(_0x591a('0x1'));var jsonpatch=require(_0x591a('0x2'));var rp=require(_0x591a('0x3'));var moment=require('moment');var BPromise=require('bluebird');var Mustache=require('mustache');var util=require(_0x591a('0x4'));var path=require(_0x591a('0x5'));var sox=require(_0x591a('0x6'));var csv=require(_0x591a('0x7'));var ejs=require('ejs');var fs=require('fs');var fs_extra=require(_0x591a('0x8'));var _=require(_0x591a('0x9'));var squel=require(_0x591a('0xa'));var crypto=require(_0x591a('0xb'));var jsforce=require(_0x591a('0xc'));var deskjs=require(_0x591a('0xd'));var toCsv=require(_0x591a('0x7'));var querystring=require('querystring');var Papa=require('papaparse');var Redis=require(_0x591a('0xe'));var authService=require(_0x591a('0xf'));var qs=require(_0x591a('0x10'));var as=require(_0x591a('0x11'));var hardwareService=require(_0x591a('0x12'));var logger=require('../../config/logger')(_0x591a('0x13'));var utils=require('../../config/utils');var config=require('../../config/environment');var licenseUtil=require(_0x591a('0x14'));var db=require(_0x591a('0x15'))['db'];var integrations=require(_0x591a('0x16'));function respondWithStatusCode(_0x217ad7,_0x24e89e){_0x24e89e=_0x24e89e||0xcc;return function(_0x5e1e75){if(_0x5e1e75){return _0x217ad7[_0x591a('0x17')](_0x24e89e);}return _0x217ad7[_0x591a('0x18')](_0x24e89e)[_0x591a('0x19')]();};}function respondWithResult(_0x27e7cc,_0x22906b){_0x22906b=_0x22906b||0xc8;return function(_0x33abbb){if(_0x33abbb){return _0x27e7cc[_0x591a('0x18')](_0x22906b)[_0x591a('0x1a')](_0x33abbb);}};}function respondWithFilteredResult(_0x7788fd,_0x15dce7){return function(_0x4596a7){if(_0x4596a7){var _0x4ff7cb=typeof _0x15dce7['offset']==='undefined'&&typeof _0x15dce7[_0x591a('0x1b')]===_0x591a('0x1c');var _0x2ac5ce=_0x4596a7[_0x591a('0x1d')];var _0x132309=_0x4ff7cb?0x0:_0x15dce7['offset'];var _0x382225=_0x4ff7cb?_0x4596a7[_0x591a('0x1d')]:_0x15dce7[_0x591a('0x1e')]+_0x15dce7[_0x591a('0x1b')];var _0x8da402;if(_0x382225>=_0x2ac5ce){_0x382225=_0x2ac5ce;_0x8da402=0xc8;}else{_0x8da402=0xce;}_0x7788fd['status'](_0x8da402);return _0x7788fd['set'](_0x591a('0x1f'),_0x132309+'-'+_0x382225+'/'+_0x2ac5ce)[_0x591a('0x1a')](_0x4596a7);}return null;};}function patchUpdates(_0x193485){return function(_0x420c80){try{jsonpatch[_0x591a('0x20')](_0x420c80,_0x193485,!![]);}catch(_0x4a9054){return BPromise[_0x591a('0x21')](_0x4a9054);}return _0x420c80[_0x591a('0x22')]();};}function saveUpdates(_0x5f4272,_0x2e4987){return function(_0x3303d5){if(_0x3303d5){return _0x3303d5[_0x591a('0x23')](_0x5f4272)[_0x591a('0x24')](function(_0x1c4307){return _0x1c4307;});}return null;};}function removeEntity(_0x25234d,_0x390679){return function(_0xfced56){if(_0xfced56){return _0xfced56[_0x591a('0x25')]()[_0x591a('0x24')](function(){_0x25234d[_0x591a('0x18')](0xcc)[_0x591a('0x19')]();});}};}function handleEntityNotFound(_0xba8f28,_0xc3a408){return function(_0xeaf5f2){if(!_0xeaf5f2){_0xba8f28['sendStatus'](0x194);}return _0xeaf5f2;};}function handleError(_0x433b90,_0x3f0b5f){_0x3f0b5f=_0x3f0b5f||0x1f4;return function(_0x19df07){logger[_0x591a('0x26')](_0x19df07[_0x591a('0x27')]);if(_0x19df07['name']){delete _0x19df07[_0x591a('0x28')];}_0x433b90[_0x591a('0x18')](_0x3f0b5f)[_0x591a('0x29')](_0x19df07);};}exports[_0x591a('0x2a')]=function(_0x361162,_0x3cd041){var _0x369320={},_0xb23a29={},_0x6f66ff={'count':0x0,'rows':[]};var _0x6537ad=_['map'](db[_0x591a('0x2b')][_0x591a('0x2c')],function(_0x10e763){return{'name':_0x10e763['fieldName'],'type':_0x10e763[_0x591a('0x2d')]['key']};});_0xb23a29[_0x591a('0x2e')]=_[_0x591a('0x2f')](_0x6537ad,_0x591a('0x28'));_0xb23a29['query']=_[_0x591a('0x30')](_0x361162[_0x591a('0x31')]);_0xb23a29[_0x591a('0x32')]=_[_0x591a('0x33')](_0xb23a29[_0x591a('0x2e')],_0xb23a29['query']);_0x369320[_0x591a('0x34')]=_['intersection'](_0xb23a29[_0x591a('0x2e')],qs[_0x591a('0x35')](_0x361162['query']['fields']));_0x369320[_0x591a('0x34')]=_0x369320['attributes'][_0x591a('0x36')]?_0x369320[_0x591a('0x34')]:_0xb23a29[_0x591a('0x2e')];if(!_0x361162[_0x591a('0x31')]['hasOwnProperty'](_0x591a('0x37'))){_0x369320['limit']=qs[_0x591a('0x1b')](_0x361162[_0x591a('0x31')]['limit']);_0x369320[_0x591a('0x1e')]=qs[_0x591a('0x1e')](_0x361162[_0x591a('0x31')][_0x591a('0x1e')]);}_0x369320['order']=qs[_0x591a('0x38')](_0x361162['query'][_0x591a('0x38')]);_0x369320[_0x591a('0x39')]=qs[_0x591a('0x32')](_[_0x591a('0x3a')](_0x361162[_0x591a('0x31')],_0xb23a29[_0x591a('0x32')]),_0x6537ad);if(_0x361162[_0x591a('0x31')]['filter']){_0x369320['where']=_[_0x591a('0x3b')](_0x369320[_0x591a('0x39')],{'$or':_[_0x591a('0x2f')](_0x6537ad,function(_0x3f0a4){if(_0x3f0a4['type']!==_0x591a('0x3c')){var _0x9a4422={};_0x9a4422[_0x3f0a4['name']]={'$like':'%'+_0x361162['query']['filter']+'%'};return _0x9a4422;}})});}_0x369320=_[_0x591a('0x3b')]({},_0x369320,_0x361162[_0x591a('0x3d')]);var _0x58d195={'where':_0x369320[_0x591a('0x39')]};return db[_0x591a('0x2b')]['count'](_0x58d195)[_0x591a('0x24')](function(_0x3c50aa){_0x6f66ff[_0x591a('0x1d')]=_0x3c50aa;if(_0x361162[_0x591a('0x31')]['includeAll']){_0x369320[_0x591a('0x3e')]=[{'all':!![]}];}return db[_0x591a('0x2b')][_0x591a('0x3f')](_0x369320);})[_0x591a('0x24')](function(_0x495a1a){_0x6f66ff['rows']=_0x495a1a;return _0x6f66ff;})[_0x591a('0x24')](respondWithFilteredResult(_0x3cd041,_0x369320))['catch'](handleError(_0x3cd041,null));};exports[_0x591a('0x40')]=function(_0x3202fc,_0x8f6041){var _0x4cf68e={'raw':![],'where':{'id':_0x3202fc[_0x591a('0x41')]['id']}},_0x57adf7={};_0x57adf7[_0x591a('0x2e')]=_['keys'](db[_0x591a('0x2b')][_0x591a('0x2c')]);_0x57adf7[_0x591a('0x31')]=_[_0x591a('0x30')](_0x3202fc[_0x591a('0x31')]);_0x57adf7['filters']=_[_0x591a('0x33')](_0x57adf7['model'],_0x57adf7[_0x591a('0x31')]);_0x4cf68e['attributes']=_[_0x591a('0x33')](_0x57adf7[_0x591a('0x2e')],qs['fields'](_0x3202fc[_0x591a('0x31')][_0x591a('0x35')]));_0x4cf68e[_0x591a('0x34')]=_0x4cf68e[_0x591a('0x34')][_0x591a('0x36')]?_0x4cf68e[_0x591a('0x34')]:_0x57adf7[_0x591a('0x2e')];if(_0x3202fc[_0x591a('0x31')][_0x591a('0x42')]){_0x4cf68e[_0x591a('0x3e')]=[{'all':!![]}];}_0x4cf68e=_['merge']({},_0x4cf68e,_0x3202fc[_0x591a('0x3d')]);return db['SugarcrmAccount']['find'](_0x4cf68e)[_0x591a('0x24')](handleEntityNotFound(_0x8f6041,null))['then'](respondWithResult(_0x8f6041,null))['catch'](handleError(_0x8f6041,null));};exports[_0x591a('0x43')]=function(_0x4658c1,_0x164608){return db[_0x591a('0x2b')][_0x591a('0x43')](_0x4658c1['body'],{})[_0x591a('0x24')](respondWithResult(_0x164608,0xc9))[_0x591a('0x44')](handleError(_0x164608,null));};exports['update']=function(_0x1987d5,_0x13a477){if(_0x1987d5['body']['id']){delete _0x1987d5[_0x591a('0x45')]['id'];}return db[_0x591a('0x2b')][_0x591a('0x46')]({'where':{'id':_0x1987d5[_0x591a('0x41')]['id']}})[_0x591a('0x24')](handleEntityNotFound(_0x13a477,null))[_0x591a('0x24')](saveUpdates(_0x1987d5[_0x591a('0x45')],null))[_0x591a('0x24')](respondWithResult(_0x13a477,null))[_0x591a('0x44')](handleError(_0x13a477,null));};exports[_0x591a('0x25')]=function(_0xfb3696,_0x179dbc){return db['SugarcrmAccount'][_0x591a('0x46')]({'where':{'id':_0xfb3696[_0x591a('0x41')]['id']}})[_0x591a('0x24')](handleEntityNotFound(_0x179dbc,null))[_0x591a('0x24')](removeEntity(_0x179dbc,null))[_0x591a('0x44')](handleError(_0x179dbc,null));};exports[_0x591a('0x47')]=function(_0x5942fd,_0x1e79d2,_0x190698){var _0x55e0c6={};var _0x1b67ca={};var _0x1e5590;var _0x82d343;return db[_0x591a('0x2b')][_0x591a('0x48')]({'where':{'id':_0x5942fd['params']['id']}})['then'](handleEntityNotFound(_0x1e79d2,null))[_0x591a('0x24')](function(_0x8422a4){if(_0x8422a4){_0x1e5590=_0x8422a4;_0x1b67ca['model']=_[_0x591a('0x30')](db['SugarcrmConfiguration'][_0x591a('0x2c')]);_0x1b67ca['query']=_[_0x591a('0x30')](_0x5942fd['query']);_0x1b67ca[_0x591a('0x32')]=_[_0x591a('0x33')](_0x1b67ca[_0x591a('0x2e')],_0x1b67ca[_0x591a('0x31')]);_0x55e0c6['attributes']=_['intersection'](_0x1b67ca[_0x591a('0x2e')],qs['fields'](_0x5942fd['query']['fields']));_0x55e0c6['attributes']=_0x55e0c6[_0x591a('0x34')]['length']?_0x55e0c6['attributes']:_0x1b67ca['model'];_0x55e0c6[_0x591a('0x49')]=qs[_0x591a('0x38')](_0x5942fd[_0x591a('0x31')][_0x591a('0x38')]);_0x55e0c6['where']=qs[_0x591a('0x32')](_[_0x591a('0x3a')](_0x5942fd[_0x591a('0x31')],_0x1b67ca[_0x591a('0x32')]));if(_0x5942fd[_0x591a('0x31')]['filter']){_0x55e0c6[_0x591a('0x39')]=_[_0x591a('0x3b')](_0x55e0c6[_0x591a('0x39')],{'$or':_[_0x591a('0x2f')](_0x55e0c6[_0x591a('0x34')],function(_0x2b2179){var _0xb83127={};_0xb83127[_0x2b2179]={'$like':'%'+_0x5942fd[_0x591a('0x31')]['filter']+'%'};return _0xb83127;})});}_0x55e0c6=_[_0x591a('0x3b')]({},_0x55e0c6,_0x5942fd['options']);return _0x1e5590[_0x591a('0x47')](_0x55e0c6);}})[_0x591a('0x24')](function(_0x3a42b7){if(_0x3a42b7){_0x82d343=_0x3a42b7[_0x591a('0x36')];if(!_0x5942fd[_0x591a('0x31')][_0x591a('0x4a')]('nolimit')){_0x55e0c6[_0x591a('0x1b')]=qs[_0x591a('0x1b')](_0x5942fd['query'][_0x591a('0x1b')]);_0x55e0c6[_0x591a('0x1e')]=qs['offset'](_0x5942fd[_0x591a('0x31')]['offset']);}return _0x1e5590['getConfigurations'](_0x55e0c6);}})[_0x591a('0x24')](function(_0x150e17){if(_0x150e17){return _0x150e17?{'count':_0x82d343,'rows':_0x150e17}:null;}})[_0x591a('0x24')](respondWithResult(_0x1e79d2,null))['catch'](handleError(_0x1e79d2,null));};exports['addConfiguration']=function(_0x23748b,_0x23c503,_0x837f91){if(_0x23748b[_0x591a('0x45')]['id']){delete _0x23748b[_0x591a('0x45')]['id'];}return db[_0x591a('0x2b')][_0x591a('0x48')]({'where':{'id':_0x23748b[_0x591a('0x41')]['id']}})[_0x591a('0x24')](handleEntityNotFound(_0x23c503,null))[_0x591a('0x24')](function(_0x1b4216){if(_0x1b4216){_0x23748b[_0x591a('0x45')][_0x591a('0x4b')]=_0x1b4216['id'];_0x23748b[_0x591a('0x45')][_0x591a('0x4c')]=integrations[_0x591a('0x4d')](_0x23748b[_0x591a('0x45')][_0x591a('0x4e')],_0x23748b['body'][_0x591a('0x2d')]);_0x23748b[_0x591a('0x45')]['Descriptions']=integrations['getDescriptions'](_0x23748b[_0x591a('0x45')][_0x591a('0x4e')],_0x23748b[_0x591a('0x45')]['type']);return db[_0x591a('0x4f')]['create'](_0x23748b['body'],{'include':[{'model':db[_0x591a('0x50')],'as':_0x591a('0x4c')},{'model':db[_0x591a('0x50')],'as':_0x591a('0x51')}]});}return null;})['then'](respondWithResult(_0x23c503,null))[_0x591a('0x44')](handleError(_0x23c503,null));};exports[_0x591a('0x52')]=function(_0x5759f9,_0x4da409,_0x4d6abe){var _0x2f9345='';var _0x3cd9ef=['id',_0x591a('0x28'),_0x591a('0x53'),_0x591a('0x54'),_0x591a('0x55'),_0x591a('0x56'),_0x591a('0x57'),_0x591a('0x58'),'parent_id',_0x591a('0x59'),'parent_name','direction'];return db[_0x591a('0x2b')][_0x591a('0x48')]({'where':{'id':_0x5759f9[_0x591a('0x41')]['id']},'attributes':['id','username',_0x591a('0x5a'),'remoteUri']})[_0x591a('0x24')](handleEntityNotFound(_0x4da409,null))['then'](function(_0x4c32e7){if(_0x4c32e7){_0x2f9345=_0x4c32e7[_0x591a('0x5b')];var _0x4a5ec5=_0x2f9345[_0x591a('0x5c')](-0x1);if(_0x4a5ec5==='/'){_0x2f9345=_0x2f9345[_0x591a('0x5d')](0x0,_0x2f9345['lastIndexOf'](_0x4a5ec5));}return rp({'method':_0x591a('0x5e'),'uri':util[_0x591a('0x5f')]('%s%s',_0x2f9345,_0x591a('0x60')),'json':!![],'form':{'method':_0x591a('0x61'),'input_type':_0x591a('0x62'),'response_type':_0x591a('0x62'),'rest_data':JSON['stringify']({'user_auth':{'user_name':_0x4c32e7['username'],'password':_0x4c32e7['password'],'encryption':_0x591a('0x63')},'application':_0x591a('0x64')})}});}})['then'](function(_0x301d89){if(_0x301d89&&_0x301d89[_0x591a('0x28')]!==_0x591a('0x65')&&_0x301d89[_0x591a('0x28')]!==_0x591a('0x66')){return rp({'method':_0x591a('0x5e'),'uri':util[_0x591a('0x5f')]('%s%s',_0x2f9345,'/service/v4_1/rest.php'),'json':!![],'form':{'method':_0x591a('0x67'),'input_type':_0x591a('0x62'),'response_type':_0x591a('0x62'),'rest_data':JSON[_0x591a('0x68')]({'session':_0x301d89['id'],'module_name':_0x591a('0x69')})}})[_0x591a('0x24')](function(_0x23822a){if(_0x23822a){var _0x13f6b1=_[_0x591a('0x6a')](_0x23822a[_0x591a('0x6b')]);_[_0x591a('0x6c')](_0x13f6b1,function(_0x520d64){return _0x3cd9ef['includes'](_0x520d64[_0x591a('0x28')]);});return{'count':_0x13f6b1[_0x591a('0x36')],'rows':_[_0x591a('0x2f')](_0x13f6b1,function(_0xf2c451){return{'id':_0xf2c451['name'],'name':_0xf2c451[_0x591a('0x6d')],'custom':_[_0x591a('0x6e')](_0xf2c451[_0x591a('0x28')],'_c')?!![]:![],'options':_0xf2c451['options']?_[_0x591a('0x2f')](_[_0x591a('0x6a')](_0xf2c451[_0x591a('0x3d')]),function(_0x679770){return{'name':_0x679770['value'],'value':_0x679770[_0x591a('0x28')]};}):[]};})};}})[_0x591a('0x24')](respondWithResult(_0x4da409,null))[_0x591a('0x44')](function(_0x51d9b8){var _0x147543=_0x5759f9['query'][_0x591a('0x6f')]?0x1f4:_0x51d9b8['statusCode']||0x1f4;logger[_0x591a('0x26')]('getFields,\x20%s,\x20%s,\x20%s',_0x591a('0x52'),_0x147543,JSON[_0x591a('0x68')](_0x51d9b8));delete _0x51d9b8[_0x591a('0x28')];if(_0x147543===0x191){_0x147543=0x190;}_0x4da409[_0x591a('0x18')](_0x147543)[_0x591a('0x29')](_0x5759f9['query'][_0x591a('0x6f')]?{'message':_0x591a('0x70'),'statusCode':_0x51d9b8[_0x591a('0x71')]}:_0x51d9b8);});}else{var _0x14625c=0x1f4;_0x4da409[_0x591a('0x18')](_0x14625c)[_0x591a('0x29')]({'message':_0x591a('0x70'),'statusCode':0x190});}});};
\ No newline at end of file