Built motion from commit 6362bb75.|2.6.13
[motion2.git] / server / api / intSugarcrmAccount / intSugarcrmAccount.controller.js
index 39d2a59..d89cfa6 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0x4f38=['Subjects','Descriptions','type','SugarcrmConfiguration','SugarcrmField','getFields','assigned_user_id','created_by','description','date_start','duration_hours','duration_minutes','parent_id','parent_type','parent_name','direction','username','password','remoteUri','substring','lastIndexOf','format','%s%s','/service/v4_1/rest.php','login','JSON','xCALLY\x20Motion\x20Integration','Invalid\x20Login','Password\x20Expired','POST','stringify','values','module_fields','remove','includes','label','endsWith','value','statusCode','getFields,\x20%s,\x20%s,\x20%s','test','Wrong\x20credentials','eml-format','zip-dir','fast-json-patch','request-promise','moment','bluebird','mustache','util','path','to-csv','squel','crypto','desk.js','querystring','papaparse','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','api','../../config/environment','../../config/license/util','../../mysqldb','../../components/integrations/configuration','sendStatus','status','json','offset','undefined','count','set','Content-Range','reject','save','update','then','end','error','stack','name','send','index','map','SugarcrmAccount','rawAttributes','key','model','query','keys','filters','intersection','attributes','fields','length','hasOwnProperty','nolimit','limit','order','sort','filter','merge','where','VIRTUAL','options','includeAll','include','findAll','rows','catch','show','find','create','body','params','destroy','getConfigurations','findOne','addConfiguration','AccountId'];(function(_0x1cd674,_0x8d3638){var _0x27928f=function(_0x5e3c70){while(--_0x5e3c70){_0x1cd674['push'](_0x1cd674['shift']());}};_0x27928f(++_0x8d3638);}(_0x4f38,0x11c));var _0x84f3=function(_0x42125c,_0x200ebe){_0x42125c=_0x42125c-0x0;var _0x3c990e=_0x4f38[_0x42125c];return _0x3c990e;};'use strict';var emlformat=require(_0x84f3('0x0'));var rimraf=require('rimraf');var zipdir=require(_0x84f3('0x1'));var jsonpatch=require(_0x84f3('0x2'));var rp=require(_0x84f3('0x3'));var moment=require(_0x84f3('0x4'));var BPromise=require(_0x84f3('0x5'));var Mustache=require(_0x84f3('0x6'));var util=require(_0x84f3('0x7'));var path=require(_0x84f3('0x8'));var sox=require('sox');var csv=require(_0x84f3('0x9'));var ejs=require('ejs');var fs=require('fs');var fs_extra=require('fs-extra');var _=require('lodash');var squel=require(_0x84f3('0xa'));var crypto=require(_0x84f3('0xb'));var jsforce=require('jsforce');var deskjs=require(_0x84f3('0xc'));var toCsv=require('to-csv');var querystring=require(_0x84f3('0xd'));var Papa=require(_0x84f3('0xe'));var Redis=require(_0x84f3('0xf'));var authService=require(_0x84f3('0x10'));var qs=require(_0x84f3('0x11'));var as=require(_0x84f3('0x12'));var hardwareService=require('../../config/license/hardware');var logger=require('../../config/logger')(_0x84f3('0x13'));var utils=require('../../config/utils');var config=require(_0x84f3('0x14'));var licenseUtil=require(_0x84f3('0x15'));var db=require(_0x84f3('0x16'))['db'];var integrations=require(_0x84f3('0x17'));function respondWithStatusCode(_0x168e21,_0x348c3f){_0x348c3f=_0x348c3f||0xcc;return function(_0x50fe94){if(_0x50fe94){return _0x168e21[_0x84f3('0x18')](_0x348c3f);}return _0x168e21[_0x84f3('0x19')](_0x348c3f)['end']();};}function respondWithResult(_0x10ee6a,_0x53ab4){_0x53ab4=_0x53ab4||0xc8;return function(_0x5539c0){if(_0x5539c0){return _0x10ee6a[_0x84f3('0x19')](_0x53ab4)[_0x84f3('0x1a')](_0x5539c0);}};}function respondWithFilteredResult(_0x577401,_0x2b3c3d){return function(_0x375d7c){if(_0x375d7c){var _0x5433c5=typeof _0x2b3c3d[_0x84f3('0x1b')]===_0x84f3('0x1c')&&typeof _0x2b3c3d['limit']===_0x84f3('0x1c');var _0x3b0cd9=_0x375d7c[_0x84f3('0x1d')];var _0x3954b8=_0x5433c5?0x0:_0x2b3c3d[_0x84f3('0x1b')];var _0x2f14db=_0x5433c5?_0x375d7c[_0x84f3('0x1d')]:_0x2b3c3d[_0x84f3('0x1b')]+_0x2b3c3d['limit'];var _0x77bcd3;if(_0x2f14db>=_0x3b0cd9){_0x2f14db=_0x3b0cd9;_0x77bcd3=0xc8;}else{_0x77bcd3=0xce;}_0x577401[_0x84f3('0x19')](_0x77bcd3);return _0x577401[_0x84f3('0x1e')](_0x84f3('0x1f'),_0x3954b8+'-'+_0x2f14db+'/'+_0x3b0cd9)[_0x84f3('0x1a')](_0x375d7c);}return null;};}function patchUpdates(_0x47a933){return function(_0x1d1ddc){try{jsonpatch['apply'](_0x1d1ddc,_0x47a933,!![]);}catch(_0x1e2b65){return BPromise[_0x84f3('0x20')](_0x1e2b65);}return _0x1d1ddc[_0x84f3('0x21')]();};}function saveUpdates(_0x39dec6,_0x227b3d){return function(_0x5cdc4d){if(_0x5cdc4d){return _0x5cdc4d[_0x84f3('0x22')](_0x39dec6)['then'](function(_0x4b52c2){return _0x4b52c2;});}return null;};}function removeEntity(_0x25a3d6,_0x2fcfd6){return function(_0x53eec3){if(_0x53eec3){return _0x53eec3['destroy']()[_0x84f3('0x23')](function(){_0x25a3d6[_0x84f3('0x19')](0xcc)[_0x84f3('0x24')]();});}};}function handleEntityNotFound(_0x7383ba,_0x4a99bf){return function(_0x1684d8){if(!_0x1684d8){_0x7383ba['sendStatus'](0x194);}return _0x1684d8;};}function handleError(_0x296284,_0x347767){_0x347767=_0x347767||0x1f4;return function(_0x4920c9){logger[_0x84f3('0x25')](_0x4920c9[_0x84f3('0x26')]);if(_0x4920c9[_0x84f3('0x27')]){delete _0x4920c9[_0x84f3('0x27')];}_0x296284[_0x84f3('0x19')](_0x347767)[_0x84f3('0x28')](_0x4920c9);};}exports[_0x84f3('0x29')]=function(_0x575cdb,_0x5c729b){var _0x4dec31={},_0x43773d={},_0x2df0c2={'count':0x0,'rows':[]};var _0x1a3ad6=_[_0x84f3('0x2a')](db[_0x84f3('0x2b')][_0x84f3('0x2c')],function(_0xf3f166){return{'name':_0xf3f166['fieldName'],'type':_0xf3f166['type'][_0x84f3('0x2d')]};});_0x43773d[_0x84f3('0x2e')]=_[_0x84f3('0x2a')](_0x1a3ad6,_0x84f3('0x27'));_0x43773d[_0x84f3('0x2f')]=_[_0x84f3('0x30')](_0x575cdb[_0x84f3('0x2f')]);_0x43773d[_0x84f3('0x31')]=_[_0x84f3('0x32')](_0x43773d[_0x84f3('0x2e')],_0x43773d[_0x84f3('0x2f')]);_0x4dec31[_0x84f3('0x33')]=_[_0x84f3('0x32')](_0x43773d[_0x84f3('0x2e')],qs[_0x84f3('0x34')](_0x575cdb[_0x84f3('0x2f')]['fields']));_0x4dec31[_0x84f3('0x33')]=_0x4dec31[_0x84f3('0x33')][_0x84f3('0x35')]?_0x4dec31[_0x84f3('0x33')]:_0x43773d[_0x84f3('0x2e')];if(!_0x575cdb[_0x84f3('0x2f')][_0x84f3('0x36')](_0x84f3('0x37'))){_0x4dec31[_0x84f3('0x38')]=qs[_0x84f3('0x38')](_0x575cdb['query'][_0x84f3('0x38')]);_0x4dec31['offset']=qs['offset'](_0x575cdb[_0x84f3('0x2f')][_0x84f3('0x1b')]);}_0x4dec31[_0x84f3('0x39')]=qs[_0x84f3('0x3a')](_0x575cdb['query']['sort']);_0x4dec31['where']=qs[_0x84f3('0x31')](_['pick'](_0x575cdb[_0x84f3('0x2f')],_0x43773d['filters']),_0x1a3ad6);if(_0x575cdb[_0x84f3('0x2f')][_0x84f3('0x3b')]){_0x4dec31['where']=_[_0x84f3('0x3c')](_0x4dec31[_0x84f3('0x3d')],{'$or':_[_0x84f3('0x2a')](_0x1a3ad6,function(_0xe8dfc2){if(_0xe8dfc2['type']!==_0x84f3('0x3e')){var _0xa29b7d={};_0xa29b7d[_0xe8dfc2[_0x84f3('0x27')]]={'$like':'%'+_0x575cdb[_0x84f3('0x2f')][_0x84f3('0x3b')]+'%'};return _0xa29b7d;}})});}_0x4dec31=_[_0x84f3('0x3c')]({},_0x4dec31,_0x575cdb[_0x84f3('0x3f')]);var _0x934d5e={'where':_0x4dec31[_0x84f3('0x3d')]};return db[_0x84f3('0x2b')]['count'](_0x934d5e)['then'](function(_0x3fbf0b){_0x2df0c2['count']=_0x3fbf0b;if(_0x575cdb[_0x84f3('0x2f')][_0x84f3('0x40')]){_0x4dec31[_0x84f3('0x41')]=[{'all':!![]}];}return db[_0x84f3('0x2b')][_0x84f3('0x42')](_0x4dec31);})[_0x84f3('0x23')](function(_0x4f46d5){_0x2df0c2[_0x84f3('0x43')]=_0x4f46d5;return _0x2df0c2;})[_0x84f3('0x23')](respondWithFilteredResult(_0x5c729b,_0x4dec31))[_0x84f3('0x44')](handleError(_0x5c729b,null));};exports[_0x84f3('0x45')]=function(_0x4ecfc7,_0x1ef860){var _0x9e0424={'raw':![],'where':{'id':_0x4ecfc7['params']['id']}},_0x320821={};_0x320821[_0x84f3('0x2e')]=_[_0x84f3('0x30')](db[_0x84f3('0x2b')][_0x84f3('0x2c')]);_0x320821['query']=_[_0x84f3('0x30')](_0x4ecfc7['query']);_0x320821[_0x84f3('0x31')]=_[_0x84f3('0x32')](_0x320821[_0x84f3('0x2e')],_0x320821['query']);_0x9e0424[_0x84f3('0x33')]=_[_0x84f3('0x32')](_0x320821[_0x84f3('0x2e')],qs[_0x84f3('0x34')](_0x4ecfc7[_0x84f3('0x2f')][_0x84f3('0x34')]));_0x9e0424[_0x84f3('0x33')]=_0x9e0424['attributes']['length']?_0x9e0424[_0x84f3('0x33')]:_0x320821[_0x84f3('0x2e')];if(_0x4ecfc7[_0x84f3('0x2f')][_0x84f3('0x40')]){_0x9e0424[_0x84f3('0x41')]=[{'all':!![]}];}_0x9e0424=_['merge']({},_0x9e0424,_0x4ecfc7['options']);return db[_0x84f3('0x2b')][_0x84f3('0x46')](_0x9e0424)[_0x84f3('0x23')](handleEntityNotFound(_0x1ef860,null))[_0x84f3('0x23')](respondWithResult(_0x1ef860,null))[_0x84f3('0x44')](handleError(_0x1ef860,null));};exports['create']=function(_0x303039,_0x58e89d){return db['SugarcrmAccount'][_0x84f3('0x47')](_0x303039['body'],{})[_0x84f3('0x23')](respondWithResult(_0x58e89d,0xc9))[_0x84f3('0x44')](handleError(_0x58e89d,null));};exports[_0x84f3('0x22')]=function(_0xfec068,_0x367925){if(_0xfec068[_0x84f3('0x48')]['id']){delete _0xfec068['body']['id'];}return db[_0x84f3('0x2b')][_0x84f3('0x46')]({'where':{'id':_0xfec068[_0x84f3('0x49')]['id']}})[_0x84f3('0x23')](handleEntityNotFound(_0x367925,null))['then'](saveUpdates(_0xfec068[_0x84f3('0x48')],null))['then'](respondWithResult(_0x367925,null))[_0x84f3('0x44')](handleError(_0x367925,null));};exports[_0x84f3('0x4a')]=function(_0x171bac,_0x3c5f89){return db[_0x84f3('0x2b')][_0x84f3('0x46')]({'where':{'id':_0x171bac[_0x84f3('0x49')]['id']}})['then'](handleEntityNotFound(_0x3c5f89,null))['then'](removeEntity(_0x3c5f89,null))[_0x84f3('0x44')](handleError(_0x3c5f89,null));};exports[_0x84f3('0x4b')]=function(_0x2aa699,_0x3ca6d3,_0x134d4d){var _0x1aa74c={};var _0x554a49={};var _0x3e765;var _0xc0e702;return db[_0x84f3('0x2b')][_0x84f3('0x4c')]({'where':{'id':_0x2aa699[_0x84f3('0x49')]['id']}})[_0x84f3('0x23')](handleEntityNotFound(_0x3ca6d3,null))['then'](function(_0x2c056a){if(_0x2c056a){_0x3e765=_0x2c056a;_0x554a49[_0x84f3('0x2e')]=_[_0x84f3('0x30')](db['SugarcrmConfiguration']['rawAttributes']);_0x554a49[_0x84f3('0x2f')]=_[_0x84f3('0x30')](_0x2aa699[_0x84f3('0x2f')]);_0x554a49[_0x84f3('0x31')]=_[_0x84f3('0x32')](_0x554a49['model'],_0x554a49['query']);_0x1aa74c[_0x84f3('0x33')]=_[_0x84f3('0x32')](_0x554a49[_0x84f3('0x2e')],qs[_0x84f3('0x34')](_0x2aa699[_0x84f3('0x2f')]['fields']));_0x1aa74c[_0x84f3('0x33')]=_0x1aa74c[_0x84f3('0x33')]['length']?_0x1aa74c[_0x84f3('0x33')]:_0x554a49[_0x84f3('0x2e')];_0x1aa74c[_0x84f3('0x39')]=qs[_0x84f3('0x3a')](_0x2aa699[_0x84f3('0x2f')]['sort']);_0x1aa74c[_0x84f3('0x3d')]=qs['filters'](_['pick'](_0x2aa699[_0x84f3('0x2f')],_0x554a49[_0x84f3('0x31')]));if(_0x2aa699[_0x84f3('0x2f')][_0x84f3('0x3b')]){_0x1aa74c[_0x84f3('0x3d')]=_[_0x84f3('0x3c')](_0x1aa74c[_0x84f3('0x3d')],{'$or':_[_0x84f3('0x2a')](_0x1aa74c[_0x84f3('0x33')],function(_0xab703e){var _0x1399fb={};_0x1399fb[_0xab703e]={'$like':'%'+_0x2aa699['query']['filter']+'%'};return _0x1399fb;})});}_0x1aa74c=_[_0x84f3('0x3c')]({},_0x1aa74c,_0x2aa699[_0x84f3('0x3f')]);return _0x3e765[_0x84f3('0x4b')](_0x1aa74c);}})['then'](function(_0x210fb3){if(_0x210fb3){_0xc0e702=_0x210fb3[_0x84f3('0x35')];if(!_0x2aa699[_0x84f3('0x2f')][_0x84f3('0x36')](_0x84f3('0x37'))){_0x1aa74c[_0x84f3('0x38')]=qs[_0x84f3('0x38')](_0x2aa699[_0x84f3('0x2f')][_0x84f3('0x38')]);_0x1aa74c['offset']=qs[_0x84f3('0x1b')](_0x2aa699[_0x84f3('0x2f')][_0x84f3('0x1b')]);}return _0x3e765[_0x84f3('0x4b')](_0x1aa74c);}})[_0x84f3('0x23')](function(_0x16d662){if(_0x16d662){return _0x16d662?{'count':_0xc0e702,'rows':_0x16d662}:null;}})[_0x84f3('0x23')](respondWithResult(_0x3ca6d3,null))[_0x84f3('0x44')](handleError(_0x3ca6d3,null));};exports[_0x84f3('0x4d')]=function(_0x298522,_0x4b6b82,_0x4cdd69){if(_0x298522[_0x84f3('0x48')]['id']){delete _0x298522['body']['id'];}return db[_0x84f3('0x2b')][_0x84f3('0x4c')]({'where':{'id':_0x298522[_0x84f3('0x49')]['id']}})[_0x84f3('0x23')](handleEntityNotFound(_0x4b6b82,null))[_0x84f3('0x23')](function(_0x5659af){if(_0x5659af){_0x298522[_0x84f3('0x48')][_0x84f3('0x4e')]=_0x5659af['id'];_0x298522[_0x84f3('0x48')][_0x84f3('0x4f')]=integrations['getSubjects'](_0x298522[_0x84f3('0x48')]['channel'],_0x298522['body']['type']);_0x298522[_0x84f3('0x48')][_0x84f3('0x50')]=integrations['getDescriptions'](_0x298522['body']['channel'],_0x298522[_0x84f3('0x48')][_0x84f3('0x51')]);return db[_0x84f3('0x52')][_0x84f3('0x47')](_0x298522[_0x84f3('0x48')],{'include':[{'model':db[_0x84f3('0x53')],'as':_0x84f3('0x4f')},{'model':db[_0x84f3('0x53')],'as':'Descriptions'}]});}return null;})['then'](respondWithResult(_0x4b6b82,null))[_0x84f3('0x44')](handleError(_0x4b6b82,null));};exports[_0x84f3('0x54')]=function(_0xf857a8,_0x46ba91,_0x4fcdfe){var _0x6d638='';var _0x32354e=['id',_0x84f3('0x27'),_0x84f3('0x55'),_0x84f3('0x56'),_0x84f3('0x57'),_0x84f3('0x58'),_0x84f3('0x59'),_0x84f3('0x5a'),_0x84f3('0x5b'),_0x84f3('0x5c'),_0x84f3('0x5d'),_0x84f3('0x5e')];return db['SugarcrmAccount'][_0x84f3('0x4c')]({'where':{'id':_0xf857a8['params']['id']},'attributes':['id',_0x84f3('0x5f'),_0x84f3('0x60'),'remoteUri']})['then'](handleEntityNotFound(_0x46ba91,null))[_0x84f3('0x23')](function(_0x4f87b4){if(_0x4f87b4){_0x6d638=_0x4f87b4[_0x84f3('0x61')];var _0x394281=_0x6d638['slice'](-0x1);if(_0x394281==='/'){_0x6d638=_0x6d638[_0x84f3('0x62')](0x0,_0x6d638[_0x84f3('0x63')](_0x394281));}return rp({'method':'POST','uri':util[_0x84f3('0x64')](_0x84f3('0x65'),_0x6d638,_0x84f3('0x66')),'json':!![],'form':{'method':_0x84f3('0x67'),'input_type':_0x84f3('0x68'),'response_type':_0x84f3('0x68'),'rest_data':JSON['stringify']({'user_auth':{'user_name':_0x4f87b4[_0x84f3('0x5f')],'password':_0x4f87b4['password'],'encryption':'PLAIN'},'application':_0x84f3('0x69')})}});}})[_0x84f3('0x23')](function(_0xbf6bb){if(_0xbf6bb&&_0xbf6bb[_0x84f3('0x27')]!==_0x84f3('0x6a')&&_0xbf6bb[_0x84f3('0x27')]!==_0x84f3('0x6b')){return rp({'method':_0x84f3('0x6c'),'uri':util[_0x84f3('0x64')]('%s%s',_0x6d638,_0x84f3('0x66')),'json':!![],'form':{'method':'get_module_fields','input_type':'JSON','response_type':_0x84f3('0x68'),'rest_data':JSON[_0x84f3('0x6d')]({'session':_0xbf6bb['id'],'module_name':'Calls'})}})[_0x84f3('0x23')](function(_0x81d0f2){if(_0x81d0f2){var _0x34cd4f=_[_0x84f3('0x6e')](_0x81d0f2[_0x84f3('0x6f')]);_[_0x84f3('0x70')](_0x34cd4f,function(_0x2d150e){return _0x32354e[_0x84f3('0x71')](_0x2d150e[_0x84f3('0x27')]);});return{'count':_0x34cd4f[_0x84f3('0x35')],'rows':_[_0x84f3('0x2a')](_0x34cd4f,function(_0xcd5ed1){return{'id':_0xcd5ed1[_0x84f3('0x27')],'name':_0xcd5ed1[_0x84f3('0x72')],'custom':_[_0x84f3('0x73')](_0xcd5ed1[_0x84f3('0x27')],'_c')?!![]:![],'options':_0xcd5ed1[_0x84f3('0x3f')]?_[_0x84f3('0x2a')](_[_0x84f3('0x6e')](_0xcd5ed1[_0x84f3('0x3f')]),function(_0x4c92c3){return{'name':_0x4c92c3[_0x84f3('0x74')],'value':_0x4c92c3[_0x84f3('0x27')]};}):[]};})};}})[_0x84f3('0x23')](respondWithResult(_0x46ba91,null))[_0x84f3('0x44')](function(_0x4c6ac8){var _0x469f13=_0xf857a8[_0x84f3('0x2f')]['test']?0x1f4:_0x4c6ac8[_0x84f3('0x75')]||0x1f4;logger[_0x84f3('0x25')](_0x84f3('0x76'),_0x84f3('0x54'),_0x469f13,JSON[_0x84f3('0x6d')](_0x4c6ac8));delete _0x4c6ac8['name'];if(_0x469f13===0x191){_0x469f13=0x190;}_0x46ba91['status'](_0x469f13)['send'](_0xf857a8['query'][_0x84f3('0x77')]?{'message':_0x84f3('0x78'),'statusCode':_0x4c6ac8[_0x84f3('0x75')]}:_0x4c6ac8);});}else{var _0x12af36=0x1f4;_0x46ba91[_0x84f3('0x19')](_0x12af36)[_0x84f3('0x28')]({'message':_0x84f3('0x78'),'statusCode':0x190});}});};
\ No newline at end of file
+var _0xf6f9=['label','endsWith','values','value','test','statusCode','getFields,\x20%s,\x20%s,\x20%s','getFields','eml-format','rimraf','zip-dir','fast-json-patch','request-promise','path','sox','ejs','fs-extra','lodash','jsforce','querystring','ioredis','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/logger','../../config/utils','../../config/environment','../../components/integrations/configuration','sendStatus','status','end','json','offset','undefined','limit','count','set','Content-Range','apply','reject','save','update','then','error','stack','name','send','index','SugarcrmAccount','type','key','model','map','query','keys','attributes','intersection','fields','length','hasOwnProperty','nolimit','order','sort','where','filters','pick','filter','VIRTUAL','merge','options','includeAll','include','findAll','rows','show','params','rawAttributes','find','create','body','catch','destroy','getConfigurations','SugarcrmConfiguration','addConfiguration','findOne','AccountId','Subjects','getSubjects','channel','Descriptions','getDescriptions','SugarcrmField','assigned_user_id','created_by','date_start','duration_hours','duration_minutes','parent_id','parent_type','parent_name','direction','username','password','remoteUri','slice','substring','lastIndexOf','POST','format','%s%s','login','JSON','stringify','/service/v4_1/rest.php','Calls','module_fields','remove','includes'];(function(_0x20a584,_0xe384a5){var _0x4b41a8=function(_0x2127c6){while(--_0x2127c6){_0x20a584['push'](_0x20a584['shift']());}};_0x4b41a8(++_0xe384a5);}(_0xf6f9,0x1e0));var _0x9f6f=function(_0x40ced1,_0x2431e2){_0x40ced1=_0x40ced1-0x0;var _0x147e06=_0xf6f9[_0x40ced1];return _0x147e06;};'use strict';var emlformat=require(_0x9f6f('0x0'));var rimraf=require(_0x9f6f('0x1'));var zipdir=require(_0x9f6f('0x2'));var jsonpatch=require(_0x9f6f('0x3'));var rp=require(_0x9f6f('0x4'));var moment=require('moment');var BPromise=require('bluebird');var Mustache=require('mustache');var util=require('util');var path=require(_0x9f6f('0x5'));var sox=require(_0x9f6f('0x6'));var csv=require('to-csv');var ejs=require(_0x9f6f('0x7'));var fs=require('fs');var fs_extra=require(_0x9f6f('0x8'));var _=require(_0x9f6f('0x9'));var squel=require('squel');var crypto=require('crypto');var jsforce=require(_0x9f6f('0xa'));var deskjs=require('desk.js');var toCsv=require('to-csv');var querystring=require(_0x9f6f('0xb'));var Papa=require('papaparse');var Redis=require(_0x9f6f('0xc'));var authService=require('../../components/auth/service');var qs=require(_0x9f6f('0xd'));var as=require(_0x9f6f('0xe'));var hardwareService=require('../../config/license/hardware');var logger=require(_0x9f6f('0xf'))('api');var utils=require(_0x9f6f('0x10'));var config=require(_0x9f6f('0x11'));var licenseUtil=require('../../config/license/util');var db=require('../../mysqldb')['db'];var integrations=require(_0x9f6f('0x12'));function respondWithStatusCode(_0x471f03,_0x3edceb){_0x3edceb=_0x3edceb||0xcc;return function(_0x9aa0c2){if(_0x9aa0c2){return _0x471f03[_0x9f6f('0x13')](_0x3edceb);}return _0x471f03[_0x9f6f('0x14')](_0x3edceb)[_0x9f6f('0x15')]();};}function respondWithResult(_0x4b303b,_0x5c6df0){_0x5c6df0=_0x5c6df0||0xc8;return function(_0x39552c){if(_0x39552c){return _0x4b303b[_0x9f6f('0x14')](_0x5c6df0)[_0x9f6f('0x16')](_0x39552c);}};}function respondWithFilteredResult(_0x376c8d,_0xa5438c){return function(_0x1aea20){if(_0x1aea20){var _0x373c19=typeof _0xa5438c[_0x9f6f('0x17')]===_0x9f6f('0x18')&&typeof _0xa5438c[_0x9f6f('0x19')]==='undefined';var _0x2a4e61=_0x1aea20[_0x9f6f('0x1a')];var _0x2631ec=_0x373c19?0x0:_0xa5438c['offset'];var _0x2aebe0=_0x373c19?_0x1aea20[_0x9f6f('0x1a')]:_0xa5438c[_0x9f6f('0x17')]+_0xa5438c[_0x9f6f('0x19')];var _0x5792c7;if(_0x2aebe0>=_0x2a4e61){_0x2aebe0=_0x2a4e61;_0x5792c7=0xc8;}else{_0x5792c7=0xce;}_0x376c8d['status'](_0x5792c7);return _0x376c8d[_0x9f6f('0x1b')](_0x9f6f('0x1c'),_0x2631ec+'-'+_0x2aebe0+'/'+_0x2a4e61)[_0x9f6f('0x16')](_0x1aea20);}return null;};}function patchUpdates(_0x140eb3){return function(_0x137f4f){try{jsonpatch[_0x9f6f('0x1d')](_0x137f4f,_0x140eb3,!![]);}catch(_0xbc8594){return BPromise[_0x9f6f('0x1e')](_0xbc8594);}return _0x137f4f[_0x9f6f('0x1f')]();};}function saveUpdates(_0xa215a4,_0x1a8783){return function(_0x24fc18){if(_0x24fc18){return _0x24fc18[_0x9f6f('0x20')](_0xa215a4)[_0x9f6f('0x21')](function(_0xac8c25){return _0xac8c25;});}return null;};}function removeEntity(_0x17b3e6,_0x236828){return function(_0x50b65a){if(_0x50b65a){return _0x50b65a['destroy']()[_0x9f6f('0x21')](function(){_0x17b3e6[_0x9f6f('0x14')](0xcc)[_0x9f6f('0x15')]();});}};}function handleEntityNotFound(_0x5392f5,_0x4b6335){return function(_0x3c459){if(!_0x3c459){_0x5392f5[_0x9f6f('0x13')](0x194);}return _0x3c459;};}function handleError(_0x5d23bf,_0x53b11){_0x53b11=_0x53b11||0x1f4;return function(_0x1aeabb){logger[_0x9f6f('0x22')](_0x1aeabb[_0x9f6f('0x23')]);if(_0x1aeabb[_0x9f6f('0x24')]){delete _0x1aeabb[_0x9f6f('0x24')];}_0x5d23bf['status'](_0x53b11)[_0x9f6f('0x25')](_0x1aeabb);};}exports[_0x9f6f('0x26')]=function(_0x4d2f15,_0x452ae7){var _0x9c70af={},_0x596cf9={},_0x4c0b67={'count':0x0,'rows':[]};var _0x470791=_['map'](db[_0x9f6f('0x27')]['rawAttributes'],function(_0x57daa3){return{'name':_0x57daa3['fieldName'],'type':_0x57daa3[_0x9f6f('0x28')][_0x9f6f('0x29')]};});_0x596cf9[_0x9f6f('0x2a')]=_[_0x9f6f('0x2b')](_0x470791,_0x9f6f('0x24'));_0x596cf9[_0x9f6f('0x2c')]=_[_0x9f6f('0x2d')](_0x4d2f15[_0x9f6f('0x2c')]);_0x596cf9['filters']=_['intersection'](_0x596cf9[_0x9f6f('0x2a')],_0x596cf9[_0x9f6f('0x2c')]);_0x9c70af[_0x9f6f('0x2e')]=_[_0x9f6f('0x2f')](_0x596cf9[_0x9f6f('0x2a')],qs[_0x9f6f('0x30')](_0x4d2f15[_0x9f6f('0x2c')][_0x9f6f('0x30')]));_0x9c70af['attributes']=_0x9c70af[_0x9f6f('0x2e')][_0x9f6f('0x31')]?_0x9c70af[_0x9f6f('0x2e')]:_0x596cf9['model'];if(!_0x4d2f15[_0x9f6f('0x2c')][_0x9f6f('0x32')](_0x9f6f('0x33'))){_0x9c70af[_0x9f6f('0x19')]=qs[_0x9f6f('0x19')](_0x4d2f15[_0x9f6f('0x2c')][_0x9f6f('0x19')]);_0x9c70af['offset']=qs['offset'](_0x4d2f15[_0x9f6f('0x2c')][_0x9f6f('0x17')]);}_0x9c70af[_0x9f6f('0x34')]=qs['sort'](_0x4d2f15[_0x9f6f('0x2c')][_0x9f6f('0x35')]);_0x9c70af[_0x9f6f('0x36')]=qs[_0x9f6f('0x37')](_[_0x9f6f('0x38')](_0x4d2f15[_0x9f6f('0x2c')],_0x596cf9[_0x9f6f('0x37')]),_0x470791);if(_0x4d2f15[_0x9f6f('0x2c')][_0x9f6f('0x39')]){_0x9c70af['where']=_['merge'](_0x9c70af[_0x9f6f('0x36')],{'$or':_[_0x9f6f('0x2b')](_0x470791,function(_0x2e6ac7){if(_0x2e6ac7[_0x9f6f('0x28')]!==_0x9f6f('0x3a')){var _0x2db29e={};_0x2db29e[_0x2e6ac7[_0x9f6f('0x24')]]={'$like':'%'+_0x4d2f15['query']['filter']+'%'};return _0x2db29e;}})});}_0x9c70af=_[_0x9f6f('0x3b')]({},_0x9c70af,_0x4d2f15[_0x9f6f('0x3c')]);var _0x1610c8={'where':_0x9c70af[_0x9f6f('0x36')]};return db[_0x9f6f('0x27')][_0x9f6f('0x1a')](_0x1610c8)[_0x9f6f('0x21')](function(_0x2be4c9){_0x4c0b67[_0x9f6f('0x1a')]=_0x2be4c9;if(_0x4d2f15[_0x9f6f('0x2c')][_0x9f6f('0x3d')]){_0x9c70af[_0x9f6f('0x3e')]=[{'all':!![]}];}return db[_0x9f6f('0x27')][_0x9f6f('0x3f')](_0x9c70af);})[_0x9f6f('0x21')](function(_0x4a9f55){_0x4c0b67[_0x9f6f('0x40')]=_0x4a9f55;return _0x4c0b67;})[_0x9f6f('0x21')](respondWithFilteredResult(_0x452ae7,_0x9c70af))['catch'](handleError(_0x452ae7,null));};exports[_0x9f6f('0x41')]=function(_0x455643,_0x5f0fbe){var _0x197f14={'raw':![],'where':{'id':_0x455643[_0x9f6f('0x42')]['id']}},_0x2a7ef4={};_0x2a7ef4[_0x9f6f('0x2a')]=_['keys'](db[_0x9f6f('0x27')][_0x9f6f('0x43')]);_0x2a7ef4['query']=_['keys'](_0x455643['query']);_0x2a7ef4[_0x9f6f('0x37')]=_['intersection'](_0x2a7ef4['model'],_0x2a7ef4[_0x9f6f('0x2c')]);_0x197f14[_0x9f6f('0x2e')]=_[_0x9f6f('0x2f')](_0x2a7ef4[_0x9f6f('0x2a')],qs[_0x9f6f('0x30')](_0x455643[_0x9f6f('0x2c')][_0x9f6f('0x30')]));_0x197f14[_0x9f6f('0x2e')]=_0x197f14[_0x9f6f('0x2e')]['length']?_0x197f14['attributes']:_0x2a7ef4[_0x9f6f('0x2a')];if(_0x455643[_0x9f6f('0x2c')][_0x9f6f('0x3d')]){_0x197f14['include']=[{'all':!![]}];}_0x197f14=_[_0x9f6f('0x3b')]({},_0x197f14,_0x455643[_0x9f6f('0x3c')]);return db[_0x9f6f('0x27')][_0x9f6f('0x44')](_0x197f14)[_0x9f6f('0x21')](handleEntityNotFound(_0x5f0fbe,null))[_0x9f6f('0x21')](respondWithResult(_0x5f0fbe,null))['catch'](handleError(_0x5f0fbe,null));};exports[_0x9f6f('0x45')]=function(_0x32446c,_0xfe4c60){return db['SugarcrmAccount'][_0x9f6f('0x45')](_0x32446c['body'],{})[_0x9f6f('0x21')](respondWithResult(_0xfe4c60,0xc9))['catch'](handleError(_0xfe4c60,null));};exports[_0x9f6f('0x20')]=function(_0x35c035,_0xb73e7b){if(_0x35c035[_0x9f6f('0x46')]['id']){delete _0x35c035[_0x9f6f('0x46')]['id'];}return db[_0x9f6f('0x27')][_0x9f6f('0x44')]({'where':{'id':_0x35c035[_0x9f6f('0x42')]['id']}})[_0x9f6f('0x21')](handleEntityNotFound(_0xb73e7b,null))[_0x9f6f('0x21')](saveUpdates(_0x35c035[_0x9f6f('0x46')],null))[_0x9f6f('0x21')](respondWithResult(_0xb73e7b,null))[_0x9f6f('0x47')](handleError(_0xb73e7b,null));};exports[_0x9f6f('0x48')]=function(_0x58f6de,_0x1e5561){return db[_0x9f6f('0x27')][_0x9f6f('0x44')]({'where':{'id':_0x58f6de[_0x9f6f('0x42')]['id']}})['then'](handleEntityNotFound(_0x1e5561,null))['then'](removeEntity(_0x1e5561,null))[_0x9f6f('0x47')](handleError(_0x1e5561,null));};exports[_0x9f6f('0x49')]=function(_0x3b3c97,_0x4c630d,_0x235296){var _0x11de67={};var _0x3c0b02={};var _0x3a7e90;var _0x3fa053;return db[_0x9f6f('0x27')]['findOne']({'where':{'id':_0x3b3c97[_0x9f6f('0x42')]['id']}})['then'](handleEntityNotFound(_0x4c630d,null))[_0x9f6f('0x21')](function(_0x4d5198){if(_0x4d5198){_0x3a7e90=_0x4d5198;_0x3c0b02[_0x9f6f('0x2a')]=_[_0x9f6f('0x2d')](db[_0x9f6f('0x4a')][_0x9f6f('0x43')]);_0x3c0b02['query']=_[_0x9f6f('0x2d')](_0x3b3c97[_0x9f6f('0x2c')]);_0x3c0b02['filters']=_[_0x9f6f('0x2f')](_0x3c0b02[_0x9f6f('0x2a')],_0x3c0b02[_0x9f6f('0x2c')]);_0x11de67['attributes']=_['intersection'](_0x3c0b02['model'],qs[_0x9f6f('0x30')](_0x3b3c97[_0x9f6f('0x2c')][_0x9f6f('0x30')]));_0x11de67[_0x9f6f('0x2e')]=_0x11de67[_0x9f6f('0x2e')][_0x9f6f('0x31')]?_0x11de67[_0x9f6f('0x2e')]:_0x3c0b02['model'];_0x11de67[_0x9f6f('0x34')]=qs['sort'](_0x3b3c97[_0x9f6f('0x2c')]['sort']);_0x11de67[_0x9f6f('0x36')]=qs[_0x9f6f('0x37')](_[_0x9f6f('0x38')](_0x3b3c97['query'],_0x3c0b02['filters']));if(_0x3b3c97[_0x9f6f('0x2c')][_0x9f6f('0x39')]){_0x11de67[_0x9f6f('0x36')]=_[_0x9f6f('0x3b')](_0x11de67[_0x9f6f('0x36')],{'$or':_[_0x9f6f('0x2b')](_0x11de67[_0x9f6f('0x2e')],function(_0x18fae4){var _0x2e9207={};_0x2e9207[_0x18fae4]={'$like':'%'+_0x3b3c97[_0x9f6f('0x2c')][_0x9f6f('0x39')]+'%'};return _0x2e9207;})});}_0x11de67=_[_0x9f6f('0x3b')]({},_0x11de67,_0x3b3c97[_0x9f6f('0x3c')]);return _0x3a7e90[_0x9f6f('0x49')](_0x11de67);}})[_0x9f6f('0x21')](function(_0x4ff8f3){if(_0x4ff8f3){_0x3fa053=_0x4ff8f3[_0x9f6f('0x31')];if(!_0x3b3c97[_0x9f6f('0x2c')]['hasOwnProperty'](_0x9f6f('0x33'))){_0x11de67[_0x9f6f('0x19')]=qs[_0x9f6f('0x19')](_0x3b3c97['query'][_0x9f6f('0x19')]);_0x11de67[_0x9f6f('0x17')]=qs['offset'](_0x3b3c97[_0x9f6f('0x2c')][_0x9f6f('0x17')]);}return _0x3a7e90[_0x9f6f('0x49')](_0x11de67);}})[_0x9f6f('0x21')](function(_0x191844){if(_0x191844){return _0x191844?{'count':_0x3fa053,'rows':_0x191844}:null;}})[_0x9f6f('0x21')](respondWithResult(_0x4c630d,null))[_0x9f6f('0x47')](handleError(_0x4c630d,null));};exports[_0x9f6f('0x4b')]=function(_0x1ca480,_0x2e9077,_0x4f323b){if(_0x1ca480['body']['id']){delete _0x1ca480[_0x9f6f('0x46')]['id'];}return db['SugarcrmAccount'][_0x9f6f('0x4c')]({'where':{'id':_0x1ca480[_0x9f6f('0x42')]['id']}})[_0x9f6f('0x21')](handleEntityNotFound(_0x2e9077,null))['then'](function(_0x42a419){if(_0x42a419){_0x1ca480[_0x9f6f('0x46')][_0x9f6f('0x4d')]=_0x42a419['id'];_0x1ca480['body'][_0x9f6f('0x4e')]=integrations[_0x9f6f('0x4f')](_0x1ca480[_0x9f6f('0x46')][_0x9f6f('0x50')],_0x1ca480[_0x9f6f('0x46')][_0x9f6f('0x28')]);_0x1ca480[_0x9f6f('0x46')][_0x9f6f('0x51')]=integrations[_0x9f6f('0x52')](_0x1ca480[_0x9f6f('0x46')][_0x9f6f('0x50')],_0x1ca480['body'][_0x9f6f('0x28')]);return db['SugarcrmConfiguration'][_0x9f6f('0x45')](_0x1ca480['body'],{'include':[{'model':db[_0x9f6f('0x53')],'as':_0x9f6f('0x4e')},{'model':db[_0x9f6f('0x53')],'as':_0x9f6f('0x51')}]});}return null;})[_0x9f6f('0x21')](respondWithResult(_0x2e9077,null))[_0x9f6f('0x47')](handleError(_0x2e9077,null));};exports['getFields']=function(_0x5beb50,_0x229128,_0x5994df){var _0x3a9d95='';var _0x2d4a64=['id',_0x9f6f('0x24'),_0x9f6f('0x54'),_0x9f6f('0x55'),'description',_0x9f6f('0x56'),_0x9f6f('0x57'),_0x9f6f('0x58'),_0x9f6f('0x59'),_0x9f6f('0x5a'),_0x9f6f('0x5b'),_0x9f6f('0x5c')];return db[_0x9f6f('0x27')][_0x9f6f('0x4c')]({'where':{'id':_0x5beb50['params']['id']},'attributes':['id',_0x9f6f('0x5d'),_0x9f6f('0x5e'),_0x9f6f('0x5f')]})[_0x9f6f('0x21')](handleEntityNotFound(_0x229128,null))['then'](function(_0x240cae){if(_0x240cae){_0x3a9d95=_0x240cae['remoteUri'];var _0x4793db=_0x3a9d95[_0x9f6f('0x60')](-0x1);if(_0x4793db==='/'){_0x3a9d95=_0x3a9d95[_0x9f6f('0x61')](0x0,_0x3a9d95[_0x9f6f('0x62')](_0x4793db));}return rp({'method':_0x9f6f('0x63'),'uri':util[_0x9f6f('0x64')](_0x9f6f('0x65'),_0x3a9d95,'/service/v4_1/rest.php'),'json':!![],'form':{'method':_0x9f6f('0x66'),'input_type':_0x9f6f('0x67'),'response_type':_0x9f6f('0x67'),'rest_data':JSON[_0x9f6f('0x68')]({'user_auth':{'user_name':_0x240cae['username'],'password':_0x240cae[_0x9f6f('0x5e')],'encryption':'PLAIN'},'application':'xCALLY\x20Motion\x20Integration'})}});}})['then'](function(_0x43ac0d){if(_0x43ac0d&&_0x43ac0d[_0x9f6f('0x24')]!=='Invalid\x20Login'&&_0x43ac0d['name']!=='Password\x20Expired'){return rp({'method':'POST','uri':util[_0x9f6f('0x64')](_0x9f6f('0x65'),_0x3a9d95,_0x9f6f('0x69')),'json':!![],'form':{'method':'get_module_fields','input_type':_0x9f6f('0x67'),'response_type':'JSON','rest_data':JSON['stringify']({'session':_0x43ac0d['id'],'module_name':_0x9f6f('0x6a')})}})[_0x9f6f('0x21')](function(_0x930c3a){if(_0x930c3a){var _0x5db225=_['values'](_0x930c3a[_0x9f6f('0x6b')]);_[_0x9f6f('0x6c')](_0x5db225,function(_0x388232){return _0x2d4a64[_0x9f6f('0x6d')](_0x388232[_0x9f6f('0x24')]);});return{'count':_0x5db225[_0x9f6f('0x31')],'rows':_[_0x9f6f('0x2b')](_0x5db225,function(_0xfea823){return{'id':_0xfea823[_0x9f6f('0x24')],'name':_0xfea823[_0x9f6f('0x6e')],'custom':_[_0x9f6f('0x6f')](_0xfea823['name'],'_c')?!![]:![],'options':_0xfea823[_0x9f6f('0x3c')]?_[_0x9f6f('0x2b')](_[_0x9f6f('0x70')](_0xfea823[_0x9f6f('0x3c')]),function(_0xa9091c){return{'name':_0xa9091c[_0x9f6f('0x71')],'value':_0xa9091c[_0x9f6f('0x24')]};}):[]};})};}})[_0x9f6f('0x21')](respondWithResult(_0x229128,null))[_0x9f6f('0x47')](function(_0x517901){var _0x1859fa=_0x5beb50[_0x9f6f('0x2c')][_0x9f6f('0x72')]?0x1f4:_0x517901[_0x9f6f('0x73')]||0x1f4;logger['error'](_0x9f6f('0x74'),_0x9f6f('0x75'),_0x1859fa,JSON['stringify'](_0x517901));delete _0x517901['name'];if(_0x1859fa===0x191){_0x1859fa=0x190;}_0x229128[_0x9f6f('0x14')](_0x1859fa)['send'](_0x5beb50[_0x9f6f('0x2c')]['test']?{'message':'Wrong\x20credentials','statusCode':_0x517901[_0x9f6f('0x73')]}:_0x517901);});}else{var _0xd080f2=0x1f4;_0x229128[_0x9f6f('0x14')](_0xd080f2)[_0x9f6f('0x25')]({'message':'Wrong\x20credentials','statusCode':0x190});}});};
\ No newline at end of file