Built motion from commit d5e4af8c.|2.6.23
[motion2.git] / server / api / intSugarcrmAccount / intSugarcrmAccount.controller.js
index ec4475b..f17bbe4 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0x65f6=['catch','sendStatus','status','end','json','limit','set','Content-Range','apply','reject','save','then','stack','name','index','map','rawAttributes','fieldName','key','model','query','filters','intersection','attributes','fields','length','hasOwnProperty','nolimit','offset','order','sort','where','pick','merge','type','VIRTUAL','options','SugarcrmAccount','count','includeAll','include','findAll','rows','show','params','keys','find','create','body','update','destroy','getConfigurations','findOne','SugarcrmConfiguration','filter','addConfiguration','channel','Descriptions','getDescriptions','SugarcrmField','getFields','created_by','date_start','parent_id','direction','password','remoteUri','slice','substring','lastIndexOf','/service/v4_1/rest.php','login','JSON','username','PLAIN','xCALLY\x20Motion\x20Integration','Password\x20Expired','POST','format','%s%s','get_module_fields','Calls','values','module_fields','remove','label','endsWith','value','send','test','Wrong\x20credentials','statusCode','html-pdf','zip-dir','fast-json-patch','request-promise','moment','bluebird','util','to-csv','lodash','squel','jsforce','querystring','../../components/auth/service','../../components/parsers/qs','../../config/license/hardware','../../config/logger','../../config/utils','../../config/environment','../../config/license/util','../../mysqldb','../../components/integrations/configuration','jayson/promise','client','http','request','SugarcrmAccount,\x20%s,\x20%s','request\x20sent','debug','SugarcrmAccount,\x20%s,\x20%s,\x20%s','stringify','error','code','message','info','result'];(function(_0x3872b4,_0x4d6083){var _0x27a63d=function(_0x7d4be5){while(--_0x7d4be5){_0x3872b4['push'](_0x3872b4['shift']());}};_0x27a63d(++_0x4d6083);}(_0x65f6,0xdb));var _0x665f=function(_0x523d34,_0x5e8c35){_0x523d34=_0x523d34-0x0;var _0x1d044a=_0x65f6[_0x523d34];return _0x1d044a;};'use strict';var pdf=require(_0x665f('0x0'));var emlformat=require('eml-format');var rimraf=require('rimraf');var zipdir=require(_0x665f('0x1'));var jsonpatch=require(_0x665f('0x2'));var rp=require(_0x665f('0x3'));var moment=require(_0x665f('0x4'));var BPromise=require(_0x665f('0x5'));var Mustache=require('mustache');var util=require(_0x665f('0x6'));var path=require('path');var sox=require('sox');var csv=require(_0x665f('0x7'));var ejs=require('ejs');var fs=require('fs');var _=require(_0x665f('0x8'));var squel=require(_0x665f('0x9'));var crypto=require('crypto');var jsforce=require(_0x665f('0xa'));var deskjs=require('desk.js');var toCsv=require('to-csv');var querystring=require(_0x665f('0xb'));var Papa=require('papaparse');var Redis=require('ioredis');var authService=require(_0x665f('0xc'));var qs=require(_0x665f('0xd'));var as=require('../../components/parsers/advancedSearch');var hardwareService=require(_0x665f('0xe'));var logger=require(_0x665f('0xf'))('api');var utils=require(_0x665f('0x10'));var config=require(_0x665f('0x11'));var licenseUtil=require(_0x665f('0x12'));var db=require(_0x665f('0x13'))['db'];var integrations=require(_0x665f('0x14'));var jayson=require(_0x665f('0x15'));var client=jayson[_0x665f('0x16')][_0x665f('0x17')]({'port':0x232a});function respondWithRpcPromise(_0x1d587b,_0x263830,_0x169fb8,_0x2525b0){return new BPromise(function(_0x5681d3,_0x3c8ae2){var _0x551e1c=_0x2525b0||client;return _0x551e1c[_0x665f('0x18')](_0x1d587b,_0x169fb8)['then'](function(_0x24f3b1){logger['info'](_0x665f('0x19'),_0x263830,_0x665f('0x1a'));logger[_0x665f('0x1b')](_0x665f('0x1c'),_0x263830,_0x665f('0x1a'),JSON[_0x665f('0x1d')](_0x24f3b1));if(_0x24f3b1[_0x665f('0x1e')]){if(_0x24f3b1[_0x665f('0x1e')][_0x665f('0x1f')]===0x1f4){logger[_0x665f('0x1e')](_0x665f('0x19'),_0x263830,_0x24f3b1[_0x665f('0x1e')][_0x665f('0x20')]);return _0x3c8ae2(_0x24f3b1[_0x665f('0x1e')][_0x665f('0x20')]);}logger[_0x665f('0x1e')](_0x665f('0x19'),_0x263830,_0x24f3b1[_0x665f('0x1e')][_0x665f('0x20')]);return _0x5681d3(_0x24f3b1[_0x665f('0x1e')][_0x665f('0x20')]);}else{logger[_0x665f('0x21')](_0x665f('0x19'),_0x263830,_0x665f('0x1a'));_0x5681d3(_0x24f3b1[_0x665f('0x22')]['message']);}})[_0x665f('0x23')](function(_0x450cb1){logger[_0x665f('0x1e')](_0x665f('0x19'),_0x263830,_0x450cb1);_0x3c8ae2(_0x450cb1);});});}function respondWithStatusCode(_0x54b1ad,_0x13546c){_0x13546c=_0x13546c||0xcc;return function(_0x504b98){if(_0x504b98){return _0x54b1ad[_0x665f('0x24')](_0x13546c);}return _0x54b1ad[_0x665f('0x25')](_0x13546c)[_0x665f('0x26')]();};}function respondWithResult(_0x5aca4d,_0x259425){_0x259425=_0x259425||0xc8;return function(_0x227e0f){if(_0x227e0f){return _0x5aca4d['status'](_0x259425)[_0x665f('0x27')](_0x227e0f);}};}function respondWithFilteredResult(_0x451fb7,_0x439b5a){return function(_0x3f74eb){if(_0x3f74eb){var _0x390558=_0x3f74eb['count'],_0x1c5fe9=_0x439b5a['offset'],_0x48dae9=_0x439b5a['offset']+_0x439b5a[_0x665f('0x28')],_0xb69e72;if(_0x48dae9>=_0x390558){_0x48dae9=_0x390558;_0xb69e72=0xc8;}else{_0xb69e72=0xce;}_0x451fb7['status'](_0xb69e72);return _0x451fb7[_0x665f('0x29')](_0x665f('0x2a'),_0x1c5fe9+'-'+_0x48dae9+'/'+_0x390558)['json'](_0x3f74eb);}return null;};}function patchUpdates(_0x24f37d){return function(_0x2b5c47){try{jsonpatch[_0x665f('0x2b')](_0x2b5c47,_0x24f37d,!![]);}catch(_0x2a85b7){return BPromise[_0x665f('0x2c')](_0x2a85b7);}return _0x2b5c47[_0x665f('0x2d')]();};}function saveUpdates(_0x142432,_0x1ad384){return function(_0x37bb2d){if(_0x37bb2d){return _0x37bb2d['update'](_0x142432)['then'](function(_0x151742){return _0x151742;});}return null;};}function removeEntity(_0x4eee83,_0x3e1b0c){return function(_0x358e65){if(_0x358e65){return _0x358e65['destroy']()[_0x665f('0x2e')](function(){_0x4eee83[_0x665f('0x25')](0xcc)[_0x665f('0x26')]();});}};}function handleEntityNotFound(_0x541409,_0x281a00){return function(_0x5e891c){if(!_0x5e891c){_0x541409[_0x665f('0x24')](0x194);}return _0x5e891c;};}function handleError(_0x3ce6a7,_0x402973){_0x402973=_0x402973||0x1f4;return function(_0x154619){logger[_0x665f('0x1e')](_0x154619[_0x665f('0x2f')]);if(_0x154619['name']){delete _0x154619[_0x665f('0x30')];}_0x3ce6a7[_0x665f('0x25')](_0x402973)['send'](_0x154619);};}exports[_0x665f('0x31')]=function(_0x5717f7,_0x4b5ba5){var _0x2dbcf4={},_0x1a8a5a={},_0x2fd2de={'count':0x0,'rows':[]};var _0xb62f06=_[_0x665f('0x32')](db['SugarcrmAccount'][_0x665f('0x33')],function(_0x1d47bc){return{'name':_0x1d47bc[_0x665f('0x34')],'type':_0x1d47bc['type'][_0x665f('0x35')]};});_0x1a8a5a[_0x665f('0x36')]=_[_0x665f('0x32')](_0xb62f06,_0x665f('0x30'));_0x1a8a5a['query']=_['keys'](_0x5717f7[_0x665f('0x37')]);_0x1a8a5a[_0x665f('0x38')]=_[_0x665f('0x39')](_0x1a8a5a['model'],_0x1a8a5a[_0x665f('0x37')]);_0x2dbcf4[_0x665f('0x3a')]=_[_0x665f('0x39')](_0x1a8a5a[_0x665f('0x36')],qs[_0x665f('0x3b')](_0x5717f7[_0x665f('0x37')][_0x665f('0x3b')]));_0x2dbcf4[_0x665f('0x3a')]=_0x2dbcf4[_0x665f('0x3a')][_0x665f('0x3c')]?_0x2dbcf4[_0x665f('0x3a')]:_0x1a8a5a[_0x665f('0x36')];if(!_0x5717f7[_0x665f('0x37')][_0x665f('0x3d')](_0x665f('0x3e'))){_0x2dbcf4[_0x665f('0x28')]=qs[_0x665f('0x28')](_0x5717f7[_0x665f('0x37')][_0x665f('0x28')]);_0x2dbcf4[_0x665f('0x3f')]=qs[_0x665f('0x3f')](_0x5717f7[_0x665f('0x37')][_0x665f('0x3f')]);}_0x2dbcf4[_0x665f('0x40')]=qs[_0x665f('0x41')](_0x5717f7[_0x665f('0x37')][_0x665f('0x41')]);_0x2dbcf4[_0x665f('0x42')]=qs['filters'](_[_0x665f('0x43')](_0x5717f7['query'],_0x1a8a5a[_0x665f('0x38')]),_0xb62f06);if(_0x5717f7[_0x665f('0x37')]['filter']){_0x2dbcf4[_0x665f('0x42')]=_[_0x665f('0x44')](_0x2dbcf4['where'],{'$or':_[_0x665f('0x32')](_0xb62f06,function(_0x40b213){if(_0x40b213[_0x665f('0x45')]!==_0x665f('0x46')){var _0x252fdb={};_0x252fdb[_0x40b213[_0x665f('0x30')]]={'$like':'%'+_0x5717f7['query']['filter']+'%'};return _0x252fdb;}})});}_0x2dbcf4=_[_0x665f('0x44')]({},_0x2dbcf4,_0x5717f7[_0x665f('0x47')]);var _0x3db9b9={'where':_0x2dbcf4[_0x665f('0x42')]};return db[_0x665f('0x48')][_0x665f('0x49')](_0x3db9b9)[_0x665f('0x2e')](function(_0x55bd26){_0x2fd2de[_0x665f('0x49')]=_0x55bd26;if(_0x5717f7[_0x665f('0x37')][_0x665f('0x4a')]){_0x2dbcf4[_0x665f('0x4b')]=[{'all':!![]}];}return db[_0x665f('0x48')][_0x665f('0x4c')](_0x2dbcf4);})[_0x665f('0x2e')](function(_0x3bd074){_0x2fd2de[_0x665f('0x4d')]=_0x3bd074;return _0x2fd2de;})[_0x665f('0x2e')](respondWithFilteredResult(_0x4b5ba5,_0x2dbcf4))[_0x665f('0x23')](handleError(_0x4b5ba5,null));};exports[_0x665f('0x4e')]=function(_0x1b4c73,_0x4a27c9){var _0x2dbde7={'raw':![],'where':{'id':_0x1b4c73[_0x665f('0x4f')]['id']}},_0x300c41={};_0x300c41[_0x665f('0x36')]=_[_0x665f('0x50')](db[_0x665f('0x48')][_0x665f('0x33')]);_0x300c41['query']=_[_0x665f('0x50')](_0x1b4c73[_0x665f('0x37')]);_0x300c41[_0x665f('0x38')]=_['intersection'](_0x300c41[_0x665f('0x36')],_0x300c41[_0x665f('0x37')]);_0x2dbde7[_0x665f('0x3a')]=_[_0x665f('0x39')](_0x300c41[_0x665f('0x36')],qs[_0x665f('0x3b')](_0x1b4c73['query']['fields']));_0x2dbde7[_0x665f('0x3a')]=_0x2dbde7['attributes']['length']?_0x2dbde7[_0x665f('0x3a')]:_0x300c41[_0x665f('0x36')];if(_0x1b4c73[_0x665f('0x37')][_0x665f('0x4a')]){_0x2dbde7[_0x665f('0x4b')]=[{'all':!![]}];}_0x2dbde7=_[_0x665f('0x44')]({},_0x2dbde7,_0x1b4c73['options']);return db[_0x665f('0x48')][_0x665f('0x51')](_0x2dbde7)[_0x665f('0x2e')](handleEntityNotFound(_0x4a27c9,null))['then'](respondWithResult(_0x4a27c9,null))[_0x665f('0x23')](handleError(_0x4a27c9,null));};exports[_0x665f('0x52')]=function(_0x3d503e,_0x16a91e){return db['SugarcrmAccount'][_0x665f('0x52')](_0x3d503e[_0x665f('0x53')],{})[_0x665f('0x2e')](respondWithResult(_0x16a91e,0xc9))[_0x665f('0x23')](handleError(_0x16a91e,null));};exports[_0x665f('0x54')]=function(_0x2e6d49,_0x1316c6){if(_0x2e6d49[_0x665f('0x53')]['id']){delete _0x2e6d49[_0x665f('0x53')]['id'];}return db[_0x665f('0x48')][_0x665f('0x51')]({'where':{'id':_0x2e6d49['params']['id']}})[_0x665f('0x2e')](handleEntityNotFound(_0x1316c6,null))[_0x665f('0x2e')](saveUpdates(_0x2e6d49[_0x665f('0x53')],null))[_0x665f('0x2e')](respondWithResult(_0x1316c6,null))[_0x665f('0x23')](handleError(_0x1316c6,null));};exports[_0x665f('0x55')]=function(_0x313fd7,_0x55c0be){return db[_0x665f('0x48')]['find']({'where':{'id':_0x313fd7[_0x665f('0x4f')]['id']}})[_0x665f('0x2e')](handleEntityNotFound(_0x55c0be,null))[_0x665f('0x2e')](removeEntity(_0x55c0be,null))[_0x665f('0x23')](handleError(_0x55c0be,null));};exports[_0x665f('0x56')]=function(_0x4b415b,_0x18a76f,_0x5a4a05){var _0x443508={};var _0x5105b5={};var _0x383d64;var _0x5c5ca3;return db[_0x665f('0x48')][_0x665f('0x57')]({'where':{'id':_0x4b415b['params']['id']}})['then'](handleEntityNotFound(_0x18a76f,null))['then'](function(_0x39a5be){if(_0x39a5be){_0x383d64=_0x39a5be;_0x5105b5[_0x665f('0x36')]=_[_0x665f('0x50')](db[_0x665f('0x58')][_0x665f('0x33')]);_0x5105b5['query']=_[_0x665f('0x50')](_0x4b415b[_0x665f('0x37')]);_0x5105b5[_0x665f('0x38')]=_[_0x665f('0x39')](_0x5105b5['model'],_0x5105b5[_0x665f('0x37')]);_0x443508['attributes']=_[_0x665f('0x39')](_0x5105b5[_0x665f('0x36')],qs[_0x665f('0x3b')](_0x4b415b['query'][_0x665f('0x3b')]));_0x443508[_0x665f('0x3a')]=_0x443508[_0x665f('0x3a')]['length']?_0x443508[_0x665f('0x3a')]:_0x5105b5['model'];_0x443508['order']=qs['sort'](_0x4b415b[_0x665f('0x37')]['sort']);_0x443508['where']=qs[_0x665f('0x38')](_['pick'](_0x4b415b[_0x665f('0x37')],_0x5105b5[_0x665f('0x38')]));if(_0x4b415b[_0x665f('0x37')][_0x665f('0x59')]){_0x443508[_0x665f('0x42')]=_[_0x665f('0x44')](_0x443508['where'],{'$or':_[_0x665f('0x32')](_0x443508[_0x665f('0x3a')],function(_0x704dc2){var _0x2aa11a={};_0x2aa11a[_0x704dc2]={'$like':'%'+_0x4b415b[_0x665f('0x37')][_0x665f('0x59')]+'%'};return _0x2aa11a;})});}_0x443508=_[_0x665f('0x44')]({},_0x443508,_0x4b415b[_0x665f('0x47')]);return _0x383d64[_0x665f('0x56')](_0x443508);}})['then'](function(_0x46882b){if(_0x46882b){_0x5c5ca3=_0x46882b['length'];if(!_0x4b415b[_0x665f('0x37')][_0x665f('0x3d')](_0x665f('0x3e'))){_0x443508[_0x665f('0x28')]=qs[_0x665f('0x28')](_0x4b415b[_0x665f('0x37')]['limit']);_0x443508[_0x665f('0x3f')]=qs[_0x665f('0x3f')](_0x4b415b[_0x665f('0x37')]['offset']);}return _0x383d64['getConfigurations'](_0x443508);}})[_0x665f('0x2e')](function(_0x51075a){if(_0x51075a){return _0x51075a?{'count':_0x5c5ca3,'rows':_0x51075a}:null;}})[_0x665f('0x2e')](respondWithResult(_0x18a76f,null))[_0x665f('0x23')](handleError(_0x18a76f,null));};exports[_0x665f('0x5a')]=function(_0x3c833c,_0x4b3917,_0x35e739){if(_0x3c833c[_0x665f('0x53')]['id']){delete _0x3c833c[_0x665f('0x53')]['id'];}return db[_0x665f('0x48')]['findOne']({'where':{'id':_0x3c833c[_0x665f('0x4f')]['id']}})[_0x665f('0x2e')](handleEntityNotFound(_0x4b3917,null))[_0x665f('0x2e')](function(_0x4a512a){if(_0x4a512a){_0x3c833c[_0x665f('0x53')]['AccountId']=_0x4a512a['id'];_0x3c833c[_0x665f('0x53')]['Subjects']=integrations['getSubjects'](_0x3c833c[_0x665f('0x53')][_0x665f('0x5b')],_0x3c833c[_0x665f('0x53')]['type']);_0x3c833c[_0x665f('0x53')][_0x665f('0x5c')]=integrations[_0x665f('0x5d')](_0x3c833c[_0x665f('0x53')]['channel'],_0x3c833c[_0x665f('0x53')][_0x665f('0x45')]);return db[_0x665f('0x58')][_0x665f('0x52')](_0x3c833c[_0x665f('0x53')],{'include':[{'model':db[_0x665f('0x5e')],'as':'Subjects'},{'model':db[_0x665f('0x5e')],'as':_0x665f('0x5c')}]});}return null;})[_0x665f('0x2e')](respondWithResult(_0x4b3917,null))['catch'](handleError(_0x4b3917,null));};exports[_0x665f('0x5f')]=function(_0x3110ca,_0x3a2634,_0x3934df){var _0x37407a='';var _0x169ab1=['id',_0x665f('0x30'),'assigned_user_id',_0x665f('0x60'),'description',_0x665f('0x61'),'duration_hours','duration_minutes',_0x665f('0x62'),'parent_type','parent_name',_0x665f('0x63')];return db['SugarcrmAccount'][_0x665f('0x57')]({'where':{'id':_0x3110ca[_0x665f('0x4f')]['id']},'attributes':['id','username',_0x665f('0x64'),'remoteUri']})[_0x665f('0x2e')](handleEntityNotFound(_0x3a2634,null))[_0x665f('0x2e')](function(_0x3b988d){if(_0x3b988d){_0x37407a=_0x3b988d[_0x665f('0x65')];var _0x29e6f8=_0x37407a[_0x665f('0x66')](-0x1);if(_0x29e6f8==='/'){_0x37407a=_0x37407a[_0x665f('0x67')](0x0,_0x37407a[_0x665f('0x68')](_0x29e6f8));}return rp({'method':'POST','uri':util['format']('%s%s',_0x37407a,_0x665f('0x69')),'json':!![],'form':{'method':_0x665f('0x6a'),'input_type':_0x665f('0x6b'),'response_type':'JSON','rest_data':JSON[_0x665f('0x1d')]({'user_auth':{'user_name':_0x3b988d[_0x665f('0x6c')],'password':_0x3b988d['password'],'encryption':_0x665f('0x6d')},'application':_0x665f('0x6e')})}});}})[_0x665f('0x2e')](function(_0x1d82ff){if(_0x1d82ff&&_0x1d82ff[_0x665f('0x30')]!=='Invalid\x20Login'&&_0x1d82ff[_0x665f('0x30')]!==_0x665f('0x6f')){return rp({'method':_0x665f('0x70'),'uri':util[_0x665f('0x71')](_0x665f('0x72'),_0x37407a,'/service/v4_1/rest.php'),'json':!![],'form':{'method':_0x665f('0x73'),'input_type':_0x665f('0x6b'),'response_type':_0x665f('0x6b'),'rest_data':JSON['stringify']({'session':_0x1d82ff['id'],'module_name':_0x665f('0x74')})}})[_0x665f('0x2e')](function(_0x267d48){if(_0x267d48){var _0x5b5868=_[_0x665f('0x75')](_0x267d48[_0x665f('0x76')]);_[_0x665f('0x77')](_0x5b5868,function(_0x27e0c8){return _0x169ab1['includes'](_0x27e0c8[_0x665f('0x30')]);});return{'count':_0x5b5868[_0x665f('0x3c')],'rows':_[_0x665f('0x32')](_0x5b5868,function(_0x4554d2){return{'id':_0x4554d2[_0x665f('0x30')],'name':_0x4554d2[_0x665f('0x78')],'custom':_[_0x665f('0x79')](_0x4554d2[_0x665f('0x30')],'_c')?!![]:![],'options':_0x4554d2[_0x665f('0x47')]?_[_0x665f('0x32')](_[_0x665f('0x75')](_0x4554d2['options']),function(_0x37b855){return{'name':_0x37b855[_0x665f('0x7a')],'value':_0x37b855['name']};}):[]};})};}})[_0x665f('0x2e')](respondWithResult(_0x3a2634,null))[_0x665f('0x23')](function(_0x5d87b8){var _0xa14a08=_0x3110ca[_0x665f('0x37')]['test']?0x1f4:_0x5d87b8['statusCode']||0x1f4;logger['error']('getFields,\x20%s,\x20%s,\x20%s','getFields',_0xa14a08,JSON[_0x665f('0x1d')](_0x5d87b8));delete _0x5d87b8['name'];if(_0xa14a08===0x191){_0xa14a08=0x190;}_0x3a2634['status'](_0xa14a08)[_0x665f('0x7b')](_0x3110ca[_0x665f('0x37')][_0x665f('0x7c')]?{'message':_0x665f('0x7d'),'statusCode':_0x5d87b8[_0x665f('0x7e')]}:_0x5d87b8);});}else{var _0x1d631d=0x1f4;_0x3a2634[_0x665f('0x25')](_0x1d631d)['send']({'message':_0x665f('0x7d'),'statusCode':0x190});}});};
\ No newline at end of file
+var _0x6c77=['status','json','offset','limit','count','set','apply','reject','then','destroy','end','sendStatus','error','stack','name','send','index','map','SugarcrmAccount','rawAttributes','fieldName','type','key','model','keys','filters','intersection','query','fields','attributes','hasOwnProperty','nolimit','order','sort','where','pick','merge','VIRTUAL','options','includeAll','include','rows','catch','show','length','create','body','find','params','SugarcrmConfiguration','filter','getConfigurations','addConfiguration','findOne','AccountId','Subjects','getSubjects','Descriptions','channel','SugarcrmField','getFields','assigned_user_id','description','date_start','duration_hours','duration_minutes','parent_id','parent_type','username','remoteUri','slice','lastIndexOf','POST','format','%s%s','login','JSON','stringify','password','PLAIN','Invalid\x20Login','/service/v4_1/rest.php','get_module_fields','module_fields','remove','includes','label','values','value','statusCode','Wrong\x20credentials','rimraf','zip-dir','fast-json-patch','request-promise','bluebird','mustache','util','to-csv','ejs','fs-extra','lodash','squel','crypto','jsforce','desk.js','querystring','papaparse','ioredis','../../components/auth/service','../../components/parsers/qs','../../config/logger','../../config/utils','../../config/environment','../../config/license/util','../../components/integrations/configuration'];(function(_0x1fbb69,_0x541d33){var _0x4bb876=function(_0x499882){while(--_0x499882){_0x1fbb69['push'](_0x1fbb69['shift']());}};_0x4bb876(++_0x541d33);}(_0x6c77,0x143));var _0x76c7=function(_0x1c47b0,_0x19e61c){_0x1c47b0=_0x1c47b0-0x0;var _0x5ae2e3=_0x6c77[_0x1c47b0];return _0x5ae2e3;};'use strict';var emlformat=require('eml-format');var rimraf=require(_0x76c7('0x0'));var zipdir=require(_0x76c7('0x1'));var jsonpatch=require(_0x76c7('0x2'));var rp=require(_0x76c7('0x3'));var moment=require('moment');var BPromise=require(_0x76c7('0x4'));var Mustache=require(_0x76c7('0x5'));var util=require(_0x76c7('0x6'));var path=require('path');var sox=require('sox');var csv=require(_0x76c7('0x7'));var ejs=require(_0x76c7('0x8'));var fs=require('fs');var fs_extra=require(_0x76c7('0x9'));var _=require(_0x76c7('0xa'));var squel=require(_0x76c7('0xb'));var crypto=require(_0x76c7('0xc'));var jsforce=require(_0x76c7('0xd'));var deskjs=require(_0x76c7('0xe'));var toCsv=require(_0x76c7('0x7'));var querystring=require(_0x76c7('0xf'));var Papa=require(_0x76c7('0x10'));var Redis=require(_0x76c7('0x11'));var authService=require(_0x76c7('0x12'));var qs=require(_0x76c7('0x13'));var as=require('../../components/parsers/advancedSearch');var hardwareService=require('../../config/license/hardware');var logger=require(_0x76c7('0x14'))('api');var utils=require(_0x76c7('0x15'));var config=require(_0x76c7('0x16'));var licenseUtil=require(_0x76c7('0x17'));var db=require('../../mysqldb')['db'];var integrations=require(_0x76c7('0x18'));function respondWithStatusCode(_0x166c2e,_0x1842bc){_0x1842bc=_0x1842bc||0xcc;return function(_0x3a4cf1){if(_0x3a4cf1){return _0x166c2e['sendStatus'](_0x1842bc);}return _0x166c2e['status'](_0x1842bc)['end']();};}function respondWithResult(_0x19d239,_0x4d7a40){_0x4d7a40=_0x4d7a40||0xc8;return function(_0x439507){if(_0x439507){return _0x19d239[_0x76c7('0x19')](_0x4d7a40)[_0x76c7('0x1a')](_0x439507);}};}function respondWithFilteredResult(_0x2ba6e1,_0x39dfc9){return function(_0xd2f189){if(_0xd2f189){var _0x544bf6=typeof _0x39dfc9[_0x76c7('0x1b')]==='undefined'&&typeof _0x39dfc9[_0x76c7('0x1c')]==='undefined';var _0xcabbd8=_0xd2f189[_0x76c7('0x1d')];var _0x3a630e=_0x544bf6?0x0:_0x39dfc9['offset'];var _0x1062e6=_0x544bf6?_0xd2f189[_0x76c7('0x1d')]:_0x39dfc9[_0x76c7('0x1b')]+_0x39dfc9[_0x76c7('0x1c')];var _0x2763e4;if(_0x1062e6>=_0xcabbd8){_0x1062e6=_0xcabbd8;_0x2763e4=0xc8;}else{_0x2763e4=0xce;}_0x2ba6e1['status'](_0x2763e4);return _0x2ba6e1[_0x76c7('0x1e')]('Content-Range',_0x3a630e+'-'+_0x1062e6+'/'+_0xcabbd8)[_0x76c7('0x1a')](_0xd2f189);}return null;};}function patchUpdates(_0x435986){return function(_0x3cd65b){try{jsonpatch[_0x76c7('0x1f')](_0x3cd65b,_0x435986,!![]);}catch(_0x30ed83){return BPromise[_0x76c7('0x20')](_0x30ed83);}return _0x3cd65b['save']();};}function saveUpdates(_0x301998,_0x47b101){return function(_0x2f6bc1){if(_0x2f6bc1){return _0x2f6bc1['update'](_0x301998)[_0x76c7('0x21')](function(_0x443c8d){return _0x443c8d;});}return null;};}function removeEntity(_0x1a38a9,_0x4e9d53){return function(_0x147a9f){if(_0x147a9f){return _0x147a9f[_0x76c7('0x22')]()[_0x76c7('0x21')](function(){_0x1a38a9[_0x76c7('0x19')](0xcc)[_0x76c7('0x23')]();});}};}function handleEntityNotFound(_0x1de46c,_0x2c2638){return function(_0x4a8991){if(!_0x4a8991){_0x1de46c[_0x76c7('0x24')](0x194);}return _0x4a8991;};}function handleError(_0x8e8569,_0x38dcd5){_0x38dcd5=_0x38dcd5||0x1f4;return function(_0x54950f){logger[_0x76c7('0x25')](_0x54950f[_0x76c7('0x26')]);if(_0x54950f[_0x76c7('0x27')]){delete _0x54950f[_0x76c7('0x27')];}_0x8e8569[_0x76c7('0x19')](_0x38dcd5)[_0x76c7('0x28')](_0x54950f);};}exports[_0x76c7('0x29')]=function(_0xa0a3c9,_0x3729dd){var _0x5a7e14={},_0x13db2c={},_0x3d3ffb={'count':0x0,'rows':[]};var _0x2d158d=_[_0x76c7('0x2a')](db[_0x76c7('0x2b')][_0x76c7('0x2c')],function(_0x74a30e){return{'name':_0x74a30e[_0x76c7('0x2d')],'type':_0x74a30e[_0x76c7('0x2e')][_0x76c7('0x2f')]};});_0x13db2c[_0x76c7('0x30')]=_[_0x76c7('0x2a')](_0x2d158d,_0x76c7('0x27'));_0x13db2c['query']=_[_0x76c7('0x31')](_0xa0a3c9['query']);_0x13db2c[_0x76c7('0x32')]=_[_0x76c7('0x33')](_0x13db2c[_0x76c7('0x30')],_0x13db2c[_0x76c7('0x34')]);_0x5a7e14['attributes']=_[_0x76c7('0x33')](_0x13db2c['model'],qs[_0x76c7('0x35')](_0xa0a3c9[_0x76c7('0x34')][_0x76c7('0x35')]));_0x5a7e14[_0x76c7('0x36')]=_0x5a7e14[_0x76c7('0x36')]['length']?_0x5a7e14[_0x76c7('0x36')]:_0x13db2c[_0x76c7('0x30')];if(!_0xa0a3c9[_0x76c7('0x34')][_0x76c7('0x37')](_0x76c7('0x38'))){_0x5a7e14[_0x76c7('0x1c')]=qs[_0x76c7('0x1c')](_0xa0a3c9[_0x76c7('0x34')]['limit']);_0x5a7e14['offset']=qs[_0x76c7('0x1b')](_0xa0a3c9[_0x76c7('0x34')][_0x76c7('0x1b')]);}_0x5a7e14[_0x76c7('0x39')]=qs[_0x76c7('0x3a')](_0xa0a3c9[_0x76c7('0x34')][_0x76c7('0x3a')]);_0x5a7e14[_0x76c7('0x3b')]=qs[_0x76c7('0x32')](_[_0x76c7('0x3c')](_0xa0a3c9[_0x76c7('0x34')],_0x13db2c[_0x76c7('0x32')]),_0x2d158d);if(_0xa0a3c9['query']['filter']){_0x5a7e14[_0x76c7('0x3b')]=_[_0x76c7('0x3d')](_0x5a7e14[_0x76c7('0x3b')],{'$or':_[_0x76c7('0x2a')](_0x2d158d,function(_0x4e1565){if(_0x4e1565[_0x76c7('0x2e')]!==_0x76c7('0x3e')){var _0x524fb6={};_0x524fb6[_0x4e1565[_0x76c7('0x27')]]={'$like':'%'+_0xa0a3c9[_0x76c7('0x34')]['filter']+'%'};return _0x524fb6;}})});}_0x5a7e14=_[_0x76c7('0x3d')]({},_0x5a7e14,_0xa0a3c9[_0x76c7('0x3f')]);var _0x55a284={'where':_0x5a7e14[_0x76c7('0x3b')]};return db[_0x76c7('0x2b')][_0x76c7('0x1d')](_0x55a284)[_0x76c7('0x21')](function(_0x39aad1){_0x3d3ffb[_0x76c7('0x1d')]=_0x39aad1;if(_0xa0a3c9[_0x76c7('0x34')][_0x76c7('0x40')]){_0x5a7e14[_0x76c7('0x41')]=[{'all':!![]}];}return db[_0x76c7('0x2b')]['findAll'](_0x5a7e14);})[_0x76c7('0x21')](function(_0x241c6c){_0x3d3ffb[_0x76c7('0x42')]=_0x241c6c;return _0x3d3ffb;})[_0x76c7('0x21')](respondWithFilteredResult(_0x3729dd,_0x5a7e14))[_0x76c7('0x43')](handleError(_0x3729dd,null));};exports[_0x76c7('0x44')]=function(_0x1ec193,_0x532666){var _0x3ad283={'raw':![],'where':{'id':_0x1ec193['params']['id']}},_0x170373={};_0x170373[_0x76c7('0x30')]=_[_0x76c7('0x31')](db[_0x76c7('0x2b')]['rawAttributes']);_0x170373[_0x76c7('0x34')]=_[_0x76c7('0x31')](_0x1ec193['query']);_0x170373[_0x76c7('0x32')]=_['intersection'](_0x170373[_0x76c7('0x30')],_0x170373['query']);_0x3ad283[_0x76c7('0x36')]=_[_0x76c7('0x33')](_0x170373[_0x76c7('0x30')],qs[_0x76c7('0x35')](_0x1ec193[_0x76c7('0x34')][_0x76c7('0x35')]));_0x3ad283[_0x76c7('0x36')]=_0x3ad283['attributes'][_0x76c7('0x45')]?_0x3ad283[_0x76c7('0x36')]:_0x170373[_0x76c7('0x30')];if(_0x1ec193[_0x76c7('0x34')][_0x76c7('0x40')]){_0x3ad283[_0x76c7('0x41')]=[{'all':!![]}];}_0x3ad283=_[_0x76c7('0x3d')]({},_0x3ad283,_0x1ec193['options']);return db[_0x76c7('0x2b')]['find'](_0x3ad283)[_0x76c7('0x21')](handleEntityNotFound(_0x532666,null))[_0x76c7('0x21')](respondWithResult(_0x532666,null))[_0x76c7('0x43')](handleError(_0x532666,null));};exports[_0x76c7('0x46')]=function(_0x50c5a0,_0x48aa31){return db[_0x76c7('0x2b')]['create'](_0x50c5a0[_0x76c7('0x47')],{})[_0x76c7('0x21')](respondWithResult(_0x48aa31,0xc9))['catch'](handleError(_0x48aa31,null));};exports['update']=function(_0x5d0788,_0x1aa61c){if(_0x5d0788['body']['id']){delete _0x5d0788[_0x76c7('0x47')]['id'];}return db[_0x76c7('0x2b')][_0x76c7('0x48')]({'where':{'id':_0x5d0788['params']['id']}})[_0x76c7('0x21')](handleEntityNotFound(_0x1aa61c,null))[_0x76c7('0x21')](saveUpdates(_0x5d0788[_0x76c7('0x47')],null))[_0x76c7('0x21')](respondWithResult(_0x1aa61c,null))[_0x76c7('0x43')](handleError(_0x1aa61c,null));};exports[_0x76c7('0x22')]=function(_0x533bfc,_0x1b3616){return db['SugarcrmAccount'][_0x76c7('0x48')]({'where':{'id':_0x533bfc[_0x76c7('0x49')]['id']}})[_0x76c7('0x21')](handleEntityNotFound(_0x1b3616,null))[_0x76c7('0x21')](removeEntity(_0x1b3616,null))[_0x76c7('0x43')](handleError(_0x1b3616,null));};exports['getConfigurations']=function(_0x1bf53c,_0x4f5a21,_0x16ba57){var _0x4782da={};var _0x496e7d={};var _0x1e950d;var _0x465cf1;return db[_0x76c7('0x2b')]['findOne']({'where':{'id':_0x1bf53c[_0x76c7('0x49')]['id']}})['then'](handleEntityNotFound(_0x4f5a21,null))['then'](function(_0x1bb9f7){if(_0x1bb9f7){_0x1e950d=_0x1bb9f7;_0x496e7d[_0x76c7('0x30')]=_[_0x76c7('0x31')](db[_0x76c7('0x4a')][_0x76c7('0x2c')]);_0x496e7d['query']=_[_0x76c7('0x31')](_0x1bf53c[_0x76c7('0x34')]);_0x496e7d[_0x76c7('0x32')]=_[_0x76c7('0x33')](_0x496e7d['model'],_0x496e7d[_0x76c7('0x34')]);_0x4782da[_0x76c7('0x36')]=_[_0x76c7('0x33')](_0x496e7d[_0x76c7('0x30')],qs[_0x76c7('0x35')](_0x1bf53c[_0x76c7('0x34')][_0x76c7('0x35')]));_0x4782da[_0x76c7('0x36')]=_0x4782da[_0x76c7('0x36')]['length']?_0x4782da[_0x76c7('0x36')]:_0x496e7d[_0x76c7('0x30')];_0x4782da[_0x76c7('0x39')]=qs[_0x76c7('0x3a')](_0x1bf53c[_0x76c7('0x34')][_0x76c7('0x3a')]);_0x4782da[_0x76c7('0x3b')]=qs[_0x76c7('0x32')](_[_0x76c7('0x3c')](_0x1bf53c[_0x76c7('0x34')],_0x496e7d['filters']));if(_0x1bf53c[_0x76c7('0x34')][_0x76c7('0x4b')]){_0x4782da[_0x76c7('0x3b')]=_[_0x76c7('0x3d')](_0x4782da[_0x76c7('0x3b')],{'$or':_[_0x76c7('0x2a')](_0x4782da['attributes'],function(_0x58280d){var _0x368465={};_0x368465[_0x58280d]={'$like':'%'+_0x1bf53c[_0x76c7('0x34')][_0x76c7('0x4b')]+'%'};return _0x368465;})});}_0x4782da=_[_0x76c7('0x3d')]({},_0x4782da,_0x1bf53c[_0x76c7('0x3f')]);return _0x1e950d[_0x76c7('0x4c')](_0x4782da);}})[_0x76c7('0x21')](function(_0x1ddfd2){if(_0x1ddfd2){_0x465cf1=_0x1ddfd2[_0x76c7('0x45')];if(!_0x1bf53c[_0x76c7('0x34')][_0x76c7('0x37')]('nolimit')){_0x4782da[_0x76c7('0x1c')]=qs['limit'](_0x1bf53c[_0x76c7('0x34')][_0x76c7('0x1c')]);_0x4782da[_0x76c7('0x1b')]=qs[_0x76c7('0x1b')](_0x1bf53c[_0x76c7('0x34')][_0x76c7('0x1b')]);}return _0x1e950d[_0x76c7('0x4c')](_0x4782da);}})[_0x76c7('0x21')](function(_0x3ba835){if(_0x3ba835){return _0x3ba835?{'count':_0x465cf1,'rows':_0x3ba835}:null;}})[_0x76c7('0x21')](respondWithResult(_0x4f5a21,null))[_0x76c7('0x43')](handleError(_0x4f5a21,null));};exports[_0x76c7('0x4d')]=function(_0x3a6e83,_0x39c0a4,_0x549b8c){if(_0x3a6e83[_0x76c7('0x47')]['id']){delete _0x3a6e83['body']['id'];}return db[_0x76c7('0x2b')][_0x76c7('0x4e')]({'where':{'id':_0x3a6e83[_0x76c7('0x49')]['id']}})[_0x76c7('0x21')](handleEntityNotFound(_0x39c0a4,null))[_0x76c7('0x21')](function(_0x91b6f2){if(_0x91b6f2){_0x3a6e83[_0x76c7('0x47')][_0x76c7('0x4f')]=_0x91b6f2['id'];_0x3a6e83[_0x76c7('0x47')][_0x76c7('0x50')]=integrations[_0x76c7('0x51')](_0x3a6e83[_0x76c7('0x47')]['channel'],_0x3a6e83['body'][_0x76c7('0x2e')]);_0x3a6e83[_0x76c7('0x47')][_0x76c7('0x52')]=integrations['getDescriptions'](_0x3a6e83[_0x76c7('0x47')][_0x76c7('0x53')],_0x3a6e83[_0x76c7('0x47')]['type']);return db['SugarcrmConfiguration']['create'](_0x3a6e83[_0x76c7('0x47')],{'include':[{'model':db['SugarcrmField'],'as':_0x76c7('0x50')},{'model':db[_0x76c7('0x54')],'as':_0x76c7('0x52')}]});}return null;})[_0x76c7('0x21')](respondWithResult(_0x39c0a4,null))['catch'](handleError(_0x39c0a4,null));};exports[_0x76c7('0x55')]=function(_0x34abcc,_0x2a3d10,_0x12e57d){var _0x748a5f='';var _0x186c2f=['id','name',_0x76c7('0x56'),'created_by',_0x76c7('0x57'),_0x76c7('0x58'),_0x76c7('0x59'),_0x76c7('0x5a'),_0x76c7('0x5b'),_0x76c7('0x5c'),'parent_name','direction'];return db[_0x76c7('0x2b')][_0x76c7('0x4e')]({'where':{'id':_0x34abcc[_0x76c7('0x49')]['id']},'attributes':['id',_0x76c7('0x5d'),'password','remoteUri']})[_0x76c7('0x21')](handleEntityNotFound(_0x2a3d10,null))[_0x76c7('0x21')](function(_0x3dcf88){if(_0x3dcf88){_0x748a5f=_0x3dcf88[_0x76c7('0x5e')];var _0x2efa62=_0x748a5f[_0x76c7('0x5f')](-0x1);if(_0x2efa62==='/'){_0x748a5f=_0x748a5f['substring'](0x0,_0x748a5f[_0x76c7('0x60')](_0x2efa62));}return rp({'method':_0x76c7('0x61'),'uri':util[_0x76c7('0x62')](_0x76c7('0x63'),_0x748a5f,'/service/v4_1/rest.php'),'json':!![],'form':{'method':_0x76c7('0x64'),'input_type':'JSON','response_type':_0x76c7('0x65'),'rest_data':JSON[_0x76c7('0x66')]({'user_auth':{'user_name':_0x3dcf88[_0x76c7('0x5d')],'password':_0x3dcf88[_0x76c7('0x67')],'encryption':_0x76c7('0x68')},'application':'xCALLY\x20Motion\x20Integration'})}});}})[_0x76c7('0x21')](function(_0x16e5f0){if(_0x16e5f0&&_0x16e5f0['name']!==_0x76c7('0x69')&&_0x16e5f0[_0x76c7('0x27')]!=='Password\x20Expired'){return rp({'method':_0x76c7('0x61'),'uri':util[_0x76c7('0x62')](_0x76c7('0x63'),_0x748a5f,_0x76c7('0x6a')),'json':!![],'form':{'method':_0x76c7('0x6b'),'input_type':_0x76c7('0x65'),'response_type':'JSON','rest_data':JSON[_0x76c7('0x66')]({'session':_0x16e5f0['id'],'module_name':'Calls'})}})[_0x76c7('0x21')](function(_0x1fd3f7){if(_0x1fd3f7){var _0x4801dd=_['values'](_0x1fd3f7[_0x76c7('0x6c')]);_[_0x76c7('0x6d')](_0x4801dd,function(_0x4ff97d){return _0x186c2f[_0x76c7('0x6e')](_0x4ff97d[_0x76c7('0x27')]);});return{'count':_0x4801dd['length'],'rows':_['map'](_0x4801dd,function(_0x23eaea){return{'id':_0x23eaea[_0x76c7('0x27')],'name':_0x23eaea[_0x76c7('0x6f')],'custom':_['endsWith'](_0x23eaea['name'],'_c')?!![]:![],'options':_0x23eaea['options']?_[_0x76c7('0x2a')](_[_0x76c7('0x70')](_0x23eaea[_0x76c7('0x3f')]),function(_0x1738cc){return{'name':_0x1738cc[_0x76c7('0x71')],'value':_0x1738cc[_0x76c7('0x27')]};}):[]};})};}})[_0x76c7('0x21')](respondWithResult(_0x2a3d10,null))[_0x76c7('0x43')](function(_0x64b780){var _0xd77d9d=_0x34abcc[_0x76c7('0x34')]['test']?0x1f4:_0x64b780[_0x76c7('0x72')]||0x1f4;logger['error']('getFields,\x20%s,\x20%s,\x20%s',_0x76c7('0x55'),_0xd77d9d,JSON[_0x76c7('0x66')](_0x64b780));delete _0x64b780[_0x76c7('0x27')];if(_0xd77d9d===0x191){_0xd77d9d=0x190;}_0x2a3d10['status'](_0xd77d9d)[_0x76c7('0x28')](_0x34abcc[_0x76c7('0x34')]['test']?{'message':_0x76c7('0x73'),'statusCode':_0x64b780[_0x76c7('0x72')]}:_0x64b780);});}else{var _0x512c76=0x1f4;_0x2a3d10[_0x76c7('0x19')](_0x512c76)[_0x76c7('0x28')]({'message':_0x76c7('0x73'),'statusCode':0x190});}});};
\ No newline at end of file