Built motion from commit 0900f080.|2.5.45
[motion2.git] / server / api / intSugarcrmAccount / intSugarcrmAccount.controller.js
index 23b4ced..a0e5e43 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0xafc4=['catch','sendStatus','status','json','count','offset','limit','Content-Range','apply','reject','update','destroy','end','stack','name','map','rawAttributes','fieldName','key','model','query','keys','filters','intersection','attributes','fields','length','hasOwnProperty','order','sort','pick','where','merge','type','VIRTUAL','filter','options','include','SugarcrmAccount','findAll','rows','show','params','includeAll','find','create','body','getConfigurations','findOne','SugarcrmConfiguration','nolimit','AccountId','Subjects','getSubjects','channel','getDescriptions','SugarcrmField','Descriptions','getFields','created_by','duration_minutes','parent_type','direction','remoteUri','POST','format','%s%s','JSON','password','PLAIN','xCALLY\x20Motion\x20Integration','Invalid\x20Login','Password\x20Expired','get_module_fields','Calls','module_fields','remove','includes','endsWith','values','test','send','statusCode','eml-format','rimraf','zip-dir','fast-json-patch','request-promise','moment','bluebird','mustache','sox','to-csv','ejs','crypto','jsforce','desk.js','querystring','papaparse','ioredis','../../components/auth/service','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','../../config/utils','../../config/environment','../../mysqldb','jayson/promise','client','http','ValidationError','The\x20password\x20must\x20be\x20at\x20least\x208\x20characters\x20long\x20and\x20have\x201\x20lowercase\x20character,\x201\x20uppercase\x20character,\x201\x20number\x20and\x201\x20special\x20character\x20~!@#$%^&-_=+[{]}.','request','then','info','SugarcrmAccount,\x20%s,\x20%s','request\x20sent','debug','SugarcrmAccount,\x20%s,\x20%s,\x20%s','stringify','error','message'];(function(_0x4b369d,_0x265eb8){var _0x571a98=function(_0x56341a){while(--_0x56341a){_0x4b369d['push'](_0x4b369d['shift']());}};_0x571a98(++_0x265eb8);}(_0xafc4,0x1c1));var _0x4afc=function(_0xc261a,_0x1880bf){_0xc261a=_0xc261a-0x0;var _0x4e1011=_0xafc4[_0xc261a];return _0x4e1011;};'use strict';var pdf=require('html-pdf');var emlformat=require(_0x4afc('0x0'));var rimraf=require(_0x4afc('0x1'));var zipdir=require(_0x4afc('0x2'));var jsonpatch=require(_0x4afc('0x3'));var rp=require(_0x4afc('0x4'));var moment=require(_0x4afc('0x5'));var BPromise=require(_0x4afc('0x6'));var Mustache=require(_0x4afc('0x7'));var util=require('util');var path=require('path');var sox=require(_0x4afc('0x8'));var csv=require(_0x4afc('0x9'));var ejs=require(_0x4afc('0xa'));var fs=require('fs');var _=require('lodash');var squel=require('squel');var crypto=require(_0x4afc('0xb'));var jsforce=require(_0x4afc('0xc'));var deskjs=require(_0x4afc('0xd'));var toCsv=require(_0x4afc('0x9'));var querystring=require(_0x4afc('0xe'));var Papa=require(_0x4afc('0xf'));var Redis=require(_0x4afc('0x10'));var authService=require(_0x4afc('0x11'));var qs=require('../../components/parsers/qs');var as=require(_0x4afc('0x12'));var hardwareService=require(_0x4afc('0x13'));var logger=require(_0x4afc('0x14'))('api');var utils=require(_0x4afc('0x15'));var config=require(_0x4afc('0x16'));var db=require(_0x4afc('0x17'))['db'];var integrations=require('../../components/integrations/configuration');var jayson=require(_0x4afc('0x18'));var client=jayson[_0x4afc('0x19')][_0x4afc('0x1a')]({'port':0x232a});function checkPasswordPattern(_0x27cb67,_0x15c782,_0x905cc1){if(_0x905cc1){var _0x2c25a4=new RegExp(/(?=.*[a-z])(?=.*[A-Z])(?=.*[0-9])(?=.*[?!@#\$%\^&\*~\-_=+[{\]\}])(?=.{8,})/);if(_0x2c25a4['test'](_0x15c782)){return _0x27cb67;}else{throw new db['Sequelize'][(_0x4afc('0x1b'))](_0x4afc('0x1c'));}}else{return _0x27cb67;}}function respondWithRpcPromise(_0x479088,_0x109fad,_0x1f1238,_0x44211c){return new BPromise(function(_0x3f3c9b,_0x45a2d5){var _0x280674=_0x44211c||client;return _0x280674[_0x4afc('0x1d')](_0x479088,_0x1f1238)[_0x4afc('0x1e')](function(_0x4a76d3){logger[_0x4afc('0x1f')](_0x4afc('0x20'),_0x109fad,_0x4afc('0x21'));logger[_0x4afc('0x22')](_0x4afc('0x23'),_0x109fad,'request\x20sent',JSON[_0x4afc('0x24')](_0x4a76d3));if(_0x4a76d3[_0x4afc('0x25')]){if(_0x4a76d3[_0x4afc('0x25')]['code']===0x1f4){logger[_0x4afc('0x25')](_0x4afc('0x20'),_0x109fad,_0x4a76d3[_0x4afc('0x25')][_0x4afc('0x26')]);return _0x45a2d5(_0x4a76d3[_0x4afc('0x25')][_0x4afc('0x26')]);}logger[_0x4afc('0x25')](_0x4afc('0x20'),_0x109fad,_0x4a76d3['error']['message']);return _0x3f3c9b(_0x4a76d3[_0x4afc('0x25')][_0x4afc('0x26')]);}else{logger[_0x4afc('0x1f')](_0x4afc('0x20'),_0x109fad,_0x4afc('0x21'));_0x3f3c9b(_0x4a76d3['result'][_0x4afc('0x26')]);}})[_0x4afc('0x27')](function(_0x22fad9){logger['error'](_0x4afc('0x20'),_0x109fad,_0x22fad9);_0x45a2d5(_0x22fad9);});});}function respondWithStatusCode(_0x6b8ce8,_0xaacdc0){_0xaacdc0=_0xaacdc0||0xcc;return function(_0x912b16){if(_0x912b16){return _0x6b8ce8[_0x4afc('0x28')](_0xaacdc0);}return _0x6b8ce8[_0x4afc('0x29')](_0xaacdc0)['end']();};}function respondWithResult(_0x485b5d,_0x401245){_0x401245=_0x401245||0xc8;return function(_0x517c01){if(_0x517c01){return _0x485b5d['status'](_0x401245)[_0x4afc('0x2a')](_0x517c01);}};}function respondWithFilteredResult(_0x1e39b4,_0x4e581a){return function(_0x16ec69){if(_0x16ec69){var _0x2b22db=_0x16ec69[_0x4afc('0x2b')],_0x244936=_0x4e581a['offset'],_0x31052a=_0x4e581a[_0x4afc('0x2c')]+_0x4e581a[_0x4afc('0x2d')],_0xc8878a;if(_0x31052a>=_0x2b22db){_0x31052a=_0x2b22db;_0xc8878a=0xc8;}else{_0xc8878a=0xce;}_0x1e39b4[_0x4afc('0x29')](_0xc8878a);return _0x1e39b4['set'](_0x4afc('0x2e'),_0x244936+'-'+_0x31052a+'/'+_0x2b22db)[_0x4afc('0x2a')](_0x16ec69);}return null;};}function patchUpdates(_0x1904ac){return function(_0x5a69c4){try{jsonpatch[_0x4afc('0x2f')](_0x5a69c4,_0x1904ac,!![]);}catch(_0x54e272){return BPromise[_0x4afc('0x30')](_0x54e272);}return _0x5a69c4['save']();};}function saveUpdates(_0x3d0287,_0x16d9c4){return function(_0xd27604){if(_0xd27604){return _0xd27604[_0x4afc('0x31')](_0x3d0287)[_0x4afc('0x1e')](function(_0x3f0c6e){return _0x3f0c6e;});}return null;};}function removeEntity(_0x488b5e,_0x488cf3){return function(_0x28ec81){if(_0x28ec81){return _0x28ec81[_0x4afc('0x32')]()['then'](function(){_0x488b5e[_0x4afc('0x29')](0xcc)[_0x4afc('0x33')]();});}};}function handleEntityNotFound(_0x146025,_0x3b3139){return function(_0x45a279){if(!_0x45a279){_0x146025[_0x4afc('0x28')](0x194);}return _0x45a279;};}function handleError(_0x21e41a,_0x1db67f){_0x1db67f=_0x1db67f||0x1f4;return function(_0x3e6f60){logger[_0x4afc('0x25')](_0x3e6f60[_0x4afc('0x34')]);if(_0x3e6f60[_0x4afc('0x35')]){delete _0x3e6f60[_0x4afc('0x35')];}_0x21e41a[_0x4afc('0x29')](_0x1db67f)['send'](_0x3e6f60);};}exports['index']=function(_0xbcb70c,_0x260948){var _0x325704={},_0x10e132={},_0x5abec5={'count':0x0,'rows':[]};var _0x2ab1e3=_[_0x4afc('0x36')](db['SugarcrmAccount'][_0x4afc('0x37')],function(_0x153971){return{'name':_0x153971[_0x4afc('0x38')],'type':_0x153971['type'][_0x4afc('0x39')]};});_0x10e132[_0x4afc('0x3a')]=_[_0x4afc('0x36')](_0x2ab1e3,_0x4afc('0x35'));_0x10e132[_0x4afc('0x3b')]=_[_0x4afc('0x3c')](_0xbcb70c[_0x4afc('0x3b')]);_0x10e132[_0x4afc('0x3d')]=_[_0x4afc('0x3e')](_0x10e132[_0x4afc('0x3a')],_0x10e132[_0x4afc('0x3b')]);_0x325704[_0x4afc('0x3f')]=_[_0x4afc('0x3e')](_0x10e132[_0x4afc('0x3a')],qs['fields'](_0xbcb70c[_0x4afc('0x3b')][_0x4afc('0x40')]));_0x325704[_0x4afc('0x3f')]=_0x325704['attributes'][_0x4afc('0x41')]?_0x325704['attributes']:_0x10e132[_0x4afc('0x3a')];if(!_0xbcb70c[_0x4afc('0x3b')][_0x4afc('0x42')]('nolimit')){_0x325704[_0x4afc('0x2d')]=qs['limit'](_0xbcb70c[_0x4afc('0x3b')]['limit']);_0x325704[_0x4afc('0x2c')]=qs['offset'](_0xbcb70c['query'][_0x4afc('0x2c')]);}_0x325704[_0x4afc('0x43')]=qs['sort'](_0xbcb70c[_0x4afc('0x3b')][_0x4afc('0x44')]);_0x325704['where']=qs[_0x4afc('0x3d')](_[_0x4afc('0x45')](_0xbcb70c[_0x4afc('0x3b')],_0x10e132[_0x4afc('0x3d')]),_0x2ab1e3);if(_0xbcb70c['query']['filter']){_0x325704[_0x4afc('0x46')]=_[_0x4afc('0x47')](_0x325704[_0x4afc('0x46')],{'$or':_[_0x4afc('0x36')](_0x2ab1e3,function(_0xa073ff){if(_0xa073ff[_0x4afc('0x48')]!==_0x4afc('0x49')){var _0x4cc578={};_0x4cc578[_0xa073ff['name']]={'$like':'%'+_0xbcb70c[_0x4afc('0x3b')][_0x4afc('0x4a')]+'%'};return _0x4cc578;}})});}_0x325704=_[_0x4afc('0x47')]({},_0x325704,_0xbcb70c[_0x4afc('0x4b')]);var _0x253522={'where':_0x325704[_0x4afc('0x46')]};return db['SugarcrmAccount'][_0x4afc('0x2b')](_0x253522)[_0x4afc('0x1e')](function(_0x16def4){_0x5abec5[_0x4afc('0x2b')]=_0x16def4;if(_0xbcb70c[_0x4afc('0x3b')]['includeAll']){_0x325704[_0x4afc('0x4c')]=[{'all':!![]}];}return db[_0x4afc('0x4d')][_0x4afc('0x4e')](_0x325704);})['then'](function(_0x366358){_0x5abec5[_0x4afc('0x4f')]=_0x366358;return _0x5abec5;})[_0x4afc('0x1e')](respondWithFilteredResult(_0x260948,_0x325704))['catch'](handleError(_0x260948,null));};exports[_0x4afc('0x50')]=function(_0x21c89e,_0x93bae5){var _0x55f963={'raw':![],'where':{'id':_0x21c89e[_0x4afc('0x51')]['id']}},_0x27d53a={};_0x27d53a['model']=_[_0x4afc('0x3c')](db['SugarcrmAccount'][_0x4afc('0x37')]);_0x27d53a[_0x4afc('0x3b')]=_['keys'](_0x21c89e[_0x4afc('0x3b')]);_0x27d53a[_0x4afc('0x3d')]=_[_0x4afc('0x3e')](_0x27d53a['model'],_0x27d53a[_0x4afc('0x3b')]);_0x55f963[_0x4afc('0x3f')]=_[_0x4afc('0x3e')](_0x27d53a['model'],qs[_0x4afc('0x40')](_0x21c89e[_0x4afc('0x3b')][_0x4afc('0x40')]));_0x55f963[_0x4afc('0x3f')]=_0x55f963[_0x4afc('0x3f')][_0x4afc('0x41')]?_0x55f963[_0x4afc('0x3f')]:_0x27d53a[_0x4afc('0x3a')];if(_0x21c89e['query'][_0x4afc('0x52')]){_0x55f963[_0x4afc('0x4c')]=[{'all':!![]}];}_0x55f963=_[_0x4afc('0x47')]({},_0x55f963,_0x21c89e['options']);return db['SugarcrmAccount'][_0x4afc('0x53')](_0x55f963)['then'](handleEntityNotFound(_0x93bae5,null))[_0x4afc('0x1e')](respondWithResult(_0x93bae5,null))[_0x4afc('0x27')](handleError(_0x93bae5,null));};exports[_0x4afc('0x54')]=function(_0x17af37,_0x9fc877){return db[_0x4afc('0x4d')][_0x4afc('0x54')](_0x17af37[_0x4afc('0x55')],{})['then'](respondWithResult(_0x9fc877,0xc9))[_0x4afc('0x27')](handleError(_0x9fc877,null));};exports['update']=function(_0x273343,_0x21019b){if(_0x273343[_0x4afc('0x55')]['id']){delete _0x273343[_0x4afc('0x55')]['id'];}return db[_0x4afc('0x4d')][_0x4afc('0x53')]({'where':{'id':_0x273343[_0x4afc('0x51')]['id']}})[_0x4afc('0x1e')](handleEntityNotFound(_0x21019b,null))[_0x4afc('0x1e')](saveUpdates(_0x273343[_0x4afc('0x55')],null))[_0x4afc('0x1e')](respondWithResult(_0x21019b,null))[_0x4afc('0x27')](handleError(_0x21019b,null));};exports[_0x4afc('0x32')]=function(_0x4642e4,_0x350457){return db['SugarcrmAccount'][_0x4afc('0x53')]({'where':{'id':_0x4642e4[_0x4afc('0x51')]['id']}})[_0x4afc('0x1e')](handleEntityNotFound(_0x350457,null))[_0x4afc('0x1e')](removeEntity(_0x350457,null))[_0x4afc('0x27')](handleError(_0x350457,null));};exports[_0x4afc('0x56')]=function(_0x4e296e,_0x59f1a9,_0x48da73){var _0x30c6fc={};var _0x14eb07={};var _0x1fb2ca;var _0x150468;return db[_0x4afc('0x4d')][_0x4afc('0x57')]({'where':{'id':_0x4e296e[_0x4afc('0x51')]['id']}})[_0x4afc('0x1e')](handleEntityNotFound(_0x59f1a9,null))['then'](function(_0x340d85){if(_0x340d85){_0x1fb2ca=_0x340d85;_0x14eb07['model']=_['keys'](db[_0x4afc('0x58')]['rawAttributes']);_0x14eb07[_0x4afc('0x3b')]=_[_0x4afc('0x3c')](_0x4e296e['query']);_0x14eb07[_0x4afc('0x3d')]=_[_0x4afc('0x3e')](_0x14eb07[_0x4afc('0x3a')],_0x14eb07[_0x4afc('0x3b')]);_0x30c6fc['attributes']=_[_0x4afc('0x3e')](_0x14eb07[_0x4afc('0x3a')],qs[_0x4afc('0x40')](_0x4e296e[_0x4afc('0x3b')]['fields']));_0x30c6fc[_0x4afc('0x3f')]=_0x30c6fc['attributes'][_0x4afc('0x41')]?_0x30c6fc[_0x4afc('0x3f')]:_0x14eb07['model'];_0x30c6fc['order']=qs['sort'](_0x4e296e['query'][_0x4afc('0x44')]);_0x30c6fc[_0x4afc('0x46')]=qs['filters'](_[_0x4afc('0x45')](_0x4e296e[_0x4afc('0x3b')],_0x14eb07[_0x4afc('0x3d')]));if(_0x4e296e[_0x4afc('0x3b')][_0x4afc('0x4a')]){_0x30c6fc[_0x4afc('0x46')]=_[_0x4afc('0x47')](_0x30c6fc['where'],{'$or':_[_0x4afc('0x36')](_0x30c6fc[_0x4afc('0x3f')],function(_0x1f425c){var _0x47f858={};_0x47f858[_0x1f425c]={'$like':'%'+_0x4e296e[_0x4afc('0x3b')]['filter']+'%'};return _0x47f858;})});}_0x30c6fc=_[_0x4afc('0x47')]({},_0x30c6fc,_0x4e296e[_0x4afc('0x4b')]);return _0x1fb2ca[_0x4afc('0x56')](_0x30c6fc);}})['then'](function(_0x33ca23){if(_0x33ca23){_0x150468=_0x33ca23[_0x4afc('0x41')];if(!_0x4e296e[_0x4afc('0x3b')][_0x4afc('0x42')](_0x4afc('0x59'))){_0x30c6fc['limit']=qs[_0x4afc('0x2d')](_0x4e296e['query'][_0x4afc('0x2d')]);_0x30c6fc[_0x4afc('0x2c')]=qs[_0x4afc('0x2c')](_0x4e296e[_0x4afc('0x3b')][_0x4afc('0x2c')]);}return _0x1fb2ca[_0x4afc('0x56')](_0x30c6fc);}})['then'](function(_0x18b098){if(_0x18b098){return _0x18b098?{'count':_0x150468,'rows':_0x18b098}:null;}})[_0x4afc('0x1e')](respondWithResult(_0x59f1a9,null))[_0x4afc('0x27')](handleError(_0x59f1a9,null));};exports['addConfiguration']=function(_0xb587b0,_0x2ff6f0,_0x10fd11){if(_0xb587b0['body']['id']){delete _0xb587b0[_0x4afc('0x55')]['id'];}return db[_0x4afc('0x4d')]['findOne']({'where':{'id':_0xb587b0[_0x4afc('0x51')]['id']}})[_0x4afc('0x1e')](handleEntityNotFound(_0x2ff6f0,null))['then'](function(_0x2d144d){if(_0x2d144d){_0xb587b0['body'][_0x4afc('0x5a')]=_0x2d144d['id'];_0xb587b0[_0x4afc('0x55')][_0x4afc('0x5b')]=integrations[_0x4afc('0x5c')](_0xb587b0[_0x4afc('0x55')][_0x4afc('0x5d')],_0xb587b0[_0x4afc('0x55')]['type']);_0xb587b0['body']['Descriptions']=integrations[_0x4afc('0x5e')](_0xb587b0['body'][_0x4afc('0x5d')],_0xb587b0[_0x4afc('0x55')]['type']);return db[_0x4afc('0x58')][_0x4afc('0x54')](_0xb587b0[_0x4afc('0x55')],{'include':[{'model':db[_0x4afc('0x5f')],'as':_0x4afc('0x5b')},{'model':db['SugarcrmField'],'as':_0x4afc('0x60')}]});}return null;})[_0x4afc('0x1e')](respondWithResult(_0x2ff6f0,null))['catch'](handleError(_0x2ff6f0,null));};exports[_0x4afc('0x61')]=function(_0x2eeed4,_0x529a62,_0x3ceabc){var _0x32f35b='';var _0x4ecaef=['id',_0x4afc('0x35'),'assigned_user_id',_0x4afc('0x62'),'description','date_start','duration_hours',_0x4afc('0x63'),'parent_id',_0x4afc('0x64'),'parent_name',_0x4afc('0x65')];return db[_0x4afc('0x4d')][_0x4afc('0x57')]({'where':{'id':_0x2eeed4['params']['id']},'attributes':['id','username','password',_0x4afc('0x66')]})['then'](handleEntityNotFound(_0x529a62,null))[_0x4afc('0x1e')](function(_0x58e435){if(_0x58e435){_0x32f35b=_0x58e435[_0x4afc('0x66')];var _0x31b5aa=_0x32f35b['slice'](-0x1);if(_0x31b5aa==='/'){_0x32f35b=_0x32f35b['substring'](0x0,_0x32f35b['lastIndexOf'](_0x31b5aa));}return rp({'method':_0x4afc('0x67'),'uri':util[_0x4afc('0x68')](_0x4afc('0x69'),_0x32f35b,'/service/v4_1/rest.php'),'json':!![],'form':{'method':'login','input_type':'JSON','response_type':_0x4afc('0x6a'),'rest_data':JSON['stringify']({'user_auth':{'user_name':_0x58e435['username'],'password':_0x58e435[_0x4afc('0x6b')],'encryption':_0x4afc('0x6c')},'application':_0x4afc('0x6d')})}});}})[_0x4afc('0x1e')](function(_0xdd531f){if(_0xdd531f&&_0xdd531f[_0x4afc('0x35')]!==_0x4afc('0x6e')&&_0xdd531f['name']!==_0x4afc('0x6f')){return rp({'method':'POST','uri':util[_0x4afc('0x68')]('%s%s',_0x32f35b,'/service/v4_1/rest.php'),'json':!![],'form':{'method':_0x4afc('0x70'),'input_type':_0x4afc('0x6a'),'response_type':_0x4afc('0x6a'),'rest_data':JSON[_0x4afc('0x24')]({'session':_0xdd531f['id'],'module_name':_0x4afc('0x71')})}})[_0x4afc('0x1e')](function(_0x3c7f24){if(_0x3c7f24){var _0x322a53=_['values'](_0x3c7f24[_0x4afc('0x72')]);_[_0x4afc('0x73')](_0x322a53,function(_0x245e1c){return _0x4ecaef[_0x4afc('0x74')](_0x245e1c[_0x4afc('0x35')]);});return{'count':_0x322a53[_0x4afc('0x41')],'rows':_['map'](_0x322a53,function(_0x2c7ea8){return{'id':_0x2c7ea8[_0x4afc('0x35')],'name':_0x2c7ea8['label'],'custom':_[_0x4afc('0x75')](_0x2c7ea8[_0x4afc('0x35')],'_c')?!![]:![],'options':_0x2c7ea8[_0x4afc('0x4b')]?_['map'](_[_0x4afc('0x76')](_0x2c7ea8[_0x4afc('0x4b')]),function(_0x1332b3){return{'name':_0x1332b3['value'],'value':_0x1332b3[_0x4afc('0x35')]};}):[]};})};}})[_0x4afc('0x1e')](respondWithResult(_0x529a62,null))[_0x4afc('0x27')](function(_0x5bf2df){var _0x5a4278=_0x2eeed4[_0x4afc('0x3b')][_0x4afc('0x77')]?0x1f4:_0x5bf2df['statusCode']||0x1f4;logger[_0x4afc('0x25')]('getFields,\x20%s,\x20%s,\x20%s',_0x4afc('0x61'),_0x5a4278,JSON['stringify'](_0x5bf2df));delete _0x5bf2df[_0x4afc('0x35')];if(_0x5a4278===0x191){_0x5a4278=0x190;}_0x529a62[_0x4afc('0x29')](_0x5a4278)[_0x4afc('0x78')](_0x2eeed4[_0x4afc('0x3b')]['test']?{'message':'Wrong\x20credentials','statusCode':_0x5bf2df[_0x4afc('0x79')]}:_0x5bf2df);});}else{var _0x498cf9=0x1f4;_0x529a62[_0x4afc('0x29')](_0x498cf9)['send']({'message':'Wrong\x20credentials','statusCode':0x190});}});};
\ No newline at end of file
+var _0x9c18=['destroy','status','end','error','stack','name','index','map','rawAttributes','fieldName','type','key','model','query','keys','filters','intersection','attributes','fields','length','hasOwnProperty','nolimit','order','sort','where','pick','merge','VIRTUAL','filter','SugarcrmAccount','includeAll','include','findAll','rows','catch','show','params','options','find','create','body','update','getConfigurations','addConfiguration','Subjects','getSubjects','channel','Descriptions','getDescriptions','SugarcrmConfiguration','SugarcrmField','getFields','assigned_user_id','created_by','description','duration_hours','duration_minutes','parent_type','parent_name','direction','findOne','password','slice','lastIndexOf','POST','format','%s%s','/service/v4_1/rest.php','login','stringify','username','PLAIN','xCALLY\x20Motion\x20Integration','Invalid\x20Login','Password\x20Expired','get_module_fields','JSON','Calls','module_fields','remove','includes','label','endsWith','values','getFields,\x20%s,\x20%s,\x20%s','test','Wrong\x20credentials','statusCode','send','eml-format','rimraf','zip-dir','fast-json-patch','moment','bluebird','mustache','util','sox','to-csv','ejs','fs-extra','lodash','squel','desk.js','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','../../config/utils','../../config/environment','../../config/license/util','../../mysqldb','../../components/integrations/configuration','sendStatus','json','offset','count','limit','Content-Range','apply','reject','save','then'];(function(_0x30d618,_0x590668){var _0x39731a=function(_0x53e0fe){while(--_0x53e0fe){_0x30d618['push'](_0x30d618['shift']());}};_0x39731a(++_0x590668);}(_0x9c18,0x153));var _0x89c1=function(_0x28d18d,_0x55896b){_0x28d18d=_0x28d18d-0x0;var _0x470640=_0x9c18[_0x28d18d];return _0x470640;};'use strict';var emlformat=require(_0x89c1('0x0'));var rimraf=require(_0x89c1('0x1'));var zipdir=require(_0x89c1('0x2'));var jsonpatch=require(_0x89c1('0x3'));var rp=require('request-promise');var moment=require(_0x89c1('0x4'));var BPromise=require(_0x89c1('0x5'));var Mustache=require(_0x89c1('0x6'));var util=require(_0x89c1('0x7'));var path=require('path');var sox=require(_0x89c1('0x8'));var csv=require(_0x89c1('0x9'));var ejs=require(_0x89c1('0xa'));var fs=require('fs');var fs_extra=require(_0x89c1('0xb'));var _=require(_0x89c1('0xc'));var squel=require(_0x89c1('0xd'));var crypto=require('crypto');var jsforce=require('jsforce');var deskjs=require(_0x89c1('0xe'));var toCsv=require(_0x89c1('0x9'));var querystring=require('querystring');var Papa=require('papaparse');var Redis=require(_0x89c1('0xf'));var authService=require(_0x89c1('0x10'));var qs=require(_0x89c1('0x11'));var as=require(_0x89c1('0x12'));var hardwareService=require(_0x89c1('0x13'));var logger=require(_0x89c1('0x14'))('api');var utils=require(_0x89c1('0x15'));var config=require(_0x89c1('0x16'));var licenseUtil=require(_0x89c1('0x17'));var db=require(_0x89c1('0x18'))['db'];var integrations=require(_0x89c1('0x19'));function respondWithStatusCode(_0x31fd1e,_0x502424){_0x502424=_0x502424||0xcc;return function(_0x1e6de7){if(_0x1e6de7){return _0x31fd1e[_0x89c1('0x1a')](_0x502424);}return _0x31fd1e['status'](_0x502424)['end']();};}function respondWithResult(_0x2daac1,_0x322986){_0x322986=_0x322986||0xc8;return function(_0x20bd4c){if(_0x20bd4c){return _0x2daac1['status'](_0x322986)[_0x89c1('0x1b')](_0x20bd4c);}};}function respondWithFilteredResult(_0x553f52,_0x5a6a39){return function(_0x14685a){if(_0x14685a){var _0x100bae=typeof _0x5a6a39[_0x89c1('0x1c')]==='undefined'&&typeof _0x5a6a39['limit']==='undefined';var _0xdc49ac=_0x14685a[_0x89c1('0x1d')];var _0x301115=_0x100bae?0x0:_0x5a6a39['offset'];var _0x350070=_0x100bae?_0x14685a['count']:_0x5a6a39[_0x89c1('0x1c')]+_0x5a6a39[_0x89c1('0x1e')];var _0x2b0592;if(_0x350070>=_0xdc49ac){_0x350070=_0xdc49ac;_0x2b0592=0xc8;}else{_0x2b0592=0xce;}_0x553f52['status'](_0x2b0592);return _0x553f52['set'](_0x89c1('0x1f'),_0x301115+'-'+_0x350070+'/'+_0xdc49ac)[_0x89c1('0x1b')](_0x14685a);}return null;};}function patchUpdates(_0x2a3dbc){return function(_0x2eacb4){try{jsonpatch[_0x89c1('0x20')](_0x2eacb4,_0x2a3dbc,!![]);}catch(_0x709778){return BPromise[_0x89c1('0x21')](_0x709778);}return _0x2eacb4[_0x89c1('0x22')]();};}function saveUpdates(_0x377d7c,_0x381327){return function(_0x1bc842){if(_0x1bc842){return _0x1bc842['update'](_0x377d7c)[_0x89c1('0x23')](function(_0x387f06){return _0x387f06;});}return null;};}function removeEntity(_0x42f5ff,_0x4e571b){return function(_0x15053f){if(_0x15053f){return _0x15053f[_0x89c1('0x24')]()[_0x89c1('0x23')](function(){_0x42f5ff[_0x89c1('0x25')](0xcc)[_0x89c1('0x26')]();});}};}function handleEntityNotFound(_0x579f3e,_0x33376c){return function(_0xc1917e){if(!_0xc1917e){_0x579f3e['sendStatus'](0x194);}return _0xc1917e;};}function handleError(_0x47c7c8,_0xb74115){_0xb74115=_0xb74115||0x1f4;return function(_0x548e7d){logger[_0x89c1('0x27')](_0x548e7d[_0x89c1('0x28')]);if(_0x548e7d[_0x89c1('0x29')]){delete _0x548e7d['name'];}_0x47c7c8[_0x89c1('0x25')](_0xb74115)['send'](_0x548e7d);};}exports[_0x89c1('0x2a')]=function(_0x442042,_0xb7f9b7){var _0x543749={},_0x1f7bc7={},_0x429cfa={'count':0x0,'rows':[]};var _0x4b18ee=_[_0x89c1('0x2b')](db['SugarcrmAccount'][_0x89c1('0x2c')],function(_0x290eef){return{'name':_0x290eef[_0x89c1('0x2d')],'type':_0x290eef[_0x89c1('0x2e')][_0x89c1('0x2f')]};});_0x1f7bc7[_0x89c1('0x30')]=_[_0x89c1('0x2b')](_0x4b18ee,_0x89c1('0x29'));_0x1f7bc7[_0x89c1('0x31')]=_[_0x89c1('0x32')](_0x442042['query']);_0x1f7bc7[_0x89c1('0x33')]=_[_0x89c1('0x34')](_0x1f7bc7['model'],_0x1f7bc7[_0x89c1('0x31')]);_0x543749[_0x89c1('0x35')]=_[_0x89c1('0x34')](_0x1f7bc7[_0x89c1('0x30')],qs['fields'](_0x442042[_0x89c1('0x31')][_0x89c1('0x36')]));_0x543749['attributes']=_0x543749[_0x89c1('0x35')][_0x89c1('0x37')]?_0x543749[_0x89c1('0x35')]:_0x1f7bc7['model'];if(!_0x442042[_0x89c1('0x31')][_0x89c1('0x38')](_0x89c1('0x39'))){_0x543749['limit']=qs[_0x89c1('0x1e')](_0x442042[_0x89c1('0x31')][_0x89c1('0x1e')]);_0x543749[_0x89c1('0x1c')]=qs[_0x89c1('0x1c')](_0x442042[_0x89c1('0x31')]['offset']);}_0x543749[_0x89c1('0x3a')]=qs[_0x89c1('0x3b')](_0x442042[_0x89c1('0x31')][_0x89c1('0x3b')]);_0x543749[_0x89c1('0x3c')]=qs[_0x89c1('0x33')](_[_0x89c1('0x3d')](_0x442042['query'],_0x1f7bc7[_0x89c1('0x33')]),_0x4b18ee);if(_0x442042[_0x89c1('0x31')]['filter']){_0x543749['where']=_[_0x89c1('0x3e')](_0x543749[_0x89c1('0x3c')],{'$or':_[_0x89c1('0x2b')](_0x4b18ee,function(_0x335808){if(_0x335808[_0x89c1('0x2e')]!==_0x89c1('0x3f')){var _0x4b04b5={};_0x4b04b5[_0x335808[_0x89c1('0x29')]]={'$like':'%'+_0x442042[_0x89c1('0x31')][_0x89c1('0x40')]+'%'};return _0x4b04b5;}})});}_0x543749=_[_0x89c1('0x3e')]({},_0x543749,_0x442042['options']);var _0x1c0f3c={'where':_0x543749['where']};return db[_0x89c1('0x41')][_0x89c1('0x1d')](_0x1c0f3c)[_0x89c1('0x23')](function(_0x2b1f55){_0x429cfa[_0x89c1('0x1d')]=_0x2b1f55;if(_0x442042[_0x89c1('0x31')][_0x89c1('0x42')]){_0x543749[_0x89c1('0x43')]=[{'all':!![]}];}return db[_0x89c1('0x41')][_0x89c1('0x44')](_0x543749);})['then'](function(_0x2a8dd0){_0x429cfa[_0x89c1('0x45')]=_0x2a8dd0;return _0x429cfa;})[_0x89c1('0x23')](respondWithFilteredResult(_0xb7f9b7,_0x543749))[_0x89c1('0x46')](handleError(_0xb7f9b7,null));};exports[_0x89c1('0x47')]=function(_0x3ffdcb,_0x5d7b96){var _0x14cb8e={'raw':![],'where':{'id':_0x3ffdcb[_0x89c1('0x48')]['id']}},_0x4f569c={};_0x4f569c[_0x89c1('0x30')]=_[_0x89c1('0x32')](db[_0x89c1('0x41')][_0x89c1('0x2c')]);_0x4f569c['query']=_['keys'](_0x3ffdcb[_0x89c1('0x31')]);_0x4f569c[_0x89c1('0x33')]=_[_0x89c1('0x34')](_0x4f569c[_0x89c1('0x30')],_0x4f569c[_0x89c1('0x31')]);_0x14cb8e[_0x89c1('0x35')]=_[_0x89c1('0x34')](_0x4f569c[_0x89c1('0x30')],qs[_0x89c1('0x36')](_0x3ffdcb[_0x89c1('0x31')][_0x89c1('0x36')]));_0x14cb8e[_0x89c1('0x35')]=_0x14cb8e['attributes'][_0x89c1('0x37')]?_0x14cb8e[_0x89c1('0x35')]:_0x4f569c['model'];if(_0x3ffdcb[_0x89c1('0x31')][_0x89c1('0x42')]){_0x14cb8e['include']=[{'all':!![]}];}_0x14cb8e=_[_0x89c1('0x3e')]({},_0x14cb8e,_0x3ffdcb[_0x89c1('0x49')]);return db[_0x89c1('0x41')][_0x89c1('0x4a')](_0x14cb8e)['then'](handleEntityNotFound(_0x5d7b96,null))[_0x89c1('0x23')](respondWithResult(_0x5d7b96,null))['catch'](handleError(_0x5d7b96,null));};exports[_0x89c1('0x4b')]=function(_0x396e31,_0x40f918){return db['SugarcrmAccount'][_0x89c1('0x4b')](_0x396e31[_0x89c1('0x4c')],{})['then'](respondWithResult(_0x40f918,0xc9))[_0x89c1('0x46')](handleError(_0x40f918,null));};exports[_0x89c1('0x4d')]=function(_0x1f9f89,_0x1d6d20){if(_0x1f9f89[_0x89c1('0x4c')]['id']){delete _0x1f9f89[_0x89c1('0x4c')]['id'];}return db[_0x89c1('0x41')][_0x89c1('0x4a')]({'where':{'id':_0x1f9f89[_0x89c1('0x48')]['id']}})[_0x89c1('0x23')](handleEntityNotFound(_0x1d6d20,null))[_0x89c1('0x23')](saveUpdates(_0x1f9f89[_0x89c1('0x4c')],null))[_0x89c1('0x23')](respondWithResult(_0x1d6d20,null))[_0x89c1('0x46')](handleError(_0x1d6d20,null));};exports['destroy']=function(_0x516740,_0x5d5c33){return db[_0x89c1('0x41')][_0x89c1('0x4a')]({'where':{'id':_0x516740[_0x89c1('0x48')]['id']}})[_0x89c1('0x23')](handleEntityNotFound(_0x5d5c33,null))[_0x89c1('0x23')](removeEntity(_0x5d5c33,null))[_0x89c1('0x46')](handleError(_0x5d5c33,null));};exports[_0x89c1('0x4e')]=function(_0x347261,_0x4ece4b,_0x369871){var _0x559a73={};var _0x142415={};var _0x3d50b2;var _0x120b6c;return db[_0x89c1('0x41')]['findOne']({'where':{'id':_0x347261[_0x89c1('0x48')]['id']}})[_0x89c1('0x23')](handleEntityNotFound(_0x4ece4b,null))[_0x89c1('0x23')](function(_0x196b23){if(_0x196b23){_0x3d50b2=_0x196b23;_0x142415['model']=_[_0x89c1('0x32')](db['SugarcrmConfiguration'][_0x89c1('0x2c')]);_0x142415[_0x89c1('0x31')]=_[_0x89c1('0x32')](_0x347261[_0x89c1('0x31')]);_0x142415[_0x89c1('0x33')]=_[_0x89c1('0x34')](_0x142415[_0x89c1('0x30')],_0x142415[_0x89c1('0x31')]);_0x559a73[_0x89c1('0x35')]=_[_0x89c1('0x34')](_0x142415[_0x89c1('0x30')],qs[_0x89c1('0x36')](_0x347261[_0x89c1('0x31')][_0x89c1('0x36')]));_0x559a73[_0x89c1('0x35')]=_0x559a73[_0x89c1('0x35')][_0x89c1('0x37')]?_0x559a73[_0x89c1('0x35')]:_0x142415[_0x89c1('0x30')];_0x559a73[_0x89c1('0x3a')]=qs[_0x89c1('0x3b')](_0x347261['query'][_0x89c1('0x3b')]);_0x559a73[_0x89c1('0x3c')]=qs['filters'](_[_0x89c1('0x3d')](_0x347261['query'],_0x142415['filters']));if(_0x347261['query'][_0x89c1('0x40')]){_0x559a73['where']=_['merge'](_0x559a73['where'],{'$or':_[_0x89c1('0x2b')](_0x559a73[_0x89c1('0x35')],function(_0x82a11a){var _0x184025={};_0x184025[_0x82a11a]={'$like':'%'+_0x347261[_0x89c1('0x31')][_0x89c1('0x40')]+'%'};return _0x184025;})});}_0x559a73=_[_0x89c1('0x3e')]({},_0x559a73,_0x347261['options']);return _0x3d50b2[_0x89c1('0x4e')](_0x559a73);}})[_0x89c1('0x23')](function(_0x5c9aa1){if(_0x5c9aa1){_0x120b6c=_0x5c9aa1[_0x89c1('0x37')];if(!_0x347261[_0x89c1('0x31')][_0x89c1('0x38')](_0x89c1('0x39'))){_0x559a73['limit']=qs[_0x89c1('0x1e')](_0x347261['query'][_0x89c1('0x1e')]);_0x559a73['offset']=qs['offset'](_0x347261[_0x89c1('0x31')][_0x89c1('0x1c')]);}return _0x3d50b2[_0x89c1('0x4e')](_0x559a73);}})[_0x89c1('0x23')](function(_0x20b570){if(_0x20b570){return _0x20b570?{'count':_0x120b6c,'rows':_0x20b570}:null;}})[_0x89c1('0x23')](respondWithResult(_0x4ece4b,null))[_0x89c1('0x46')](handleError(_0x4ece4b,null));};exports[_0x89c1('0x4f')]=function(_0x288eeb,_0x12cf0e,_0x312dad){if(_0x288eeb[_0x89c1('0x4c')]['id']){delete _0x288eeb['body']['id'];}return db[_0x89c1('0x41')]['findOne']({'where':{'id':_0x288eeb[_0x89c1('0x48')]['id']}})[_0x89c1('0x23')](handleEntityNotFound(_0x12cf0e,null))[_0x89c1('0x23')](function(_0x372122){if(_0x372122){_0x288eeb[_0x89c1('0x4c')]['AccountId']=_0x372122['id'];_0x288eeb['body'][_0x89c1('0x50')]=integrations[_0x89c1('0x51')](_0x288eeb[_0x89c1('0x4c')][_0x89c1('0x52')],_0x288eeb[_0x89c1('0x4c')][_0x89c1('0x2e')]);_0x288eeb['body'][_0x89c1('0x53')]=integrations[_0x89c1('0x54')](_0x288eeb['body']['channel'],_0x288eeb[_0x89c1('0x4c')][_0x89c1('0x2e')]);return db[_0x89c1('0x55')]['create'](_0x288eeb[_0x89c1('0x4c')],{'include':[{'model':db['SugarcrmField'],'as':_0x89c1('0x50')},{'model':db[_0x89c1('0x56')],'as':_0x89c1('0x53')}]});}return null;})['then'](respondWithResult(_0x12cf0e,null))[_0x89c1('0x46')](handleError(_0x12cf0e,null));};exports[_0x89c1('0x57')]=function(_0x55200e,_0x370ced,_0x52fea7){var _0x4d38a6='';var _0x3ed40a=['id',_0x89c1('0x29'),_0x89c1('0x58'),_0x89c1('0x59'),_0x89c1('0x5a'),'date_start',_0x89c1('0x5b'),_0x89c1('0x5c'),'parent_id',_0x89c1('0x5d'),_0x89c1('0x5e'),_0x89c1('0x5f')];return db[_0x89c1('0x41')][_0x89c1('0x60')]({'where':{'id':_0x55200e['params']['id']},'attributes':['id','username',_0x89c1('0x61'),'remoteUri']})[_0x89c1('0x23')](handleEntityNotFound(_0x370ced,null))[_0x89c1('0x23')](function(_0x3d6134){if(_0x3d6134){_0x4d38a6=_0x3d6134['remoteUri'];var _0x9b2d09=_0x4d38a6[_0x89c1('0x62')](-0x1);if(_0x9b2d09==='/'){_0x4d38a6=_0x4d38a6['substring'](0x0,_0x4d38a6[_0x89c1('0x63')](_0x9b2d09));}return rp({'method':_0x89c1('0x64'),'uri':util[_0x89c1('0x65')](_0x89c1('0x66'),_0x4d38a6,_0x89c1('0x67')),'json':!![],'form':{'method':_0x89c1('0x68'),'input_type':'JSON','response_type':'JSON','rest_data':JSON[_0x89c1('0x69')]({'user_auth':{'user_name':_0x3d6134[_0x89c1('0x6a')],'password':_0x3d6134[_0x89c1('0x61')],'encryption':_0x89c1('0x6b')},'application':_0x89c1('0x6c')})}});}})[_0x89c1('0x23')](function(_0x4b81f2){if(_0x4b81f2&&_0x4b81f2[_0x89c1('0x29')]!==_0x89c1('0x6d')&&_0x4b81f2[_0x89c1('0x29')]!==_0x89c1('0x6e')){return rp({'method':_0x89c1('0x64'),'uri':util['format']('%s%s',_0x4d38a6,'/service/v4_1/rest.php'),'json':!![],'form':{'method':_0x89c1('0x6f'),'input_type':_0x89c1('0x70'),'response_type':_0x89c1('0x70'),'rest_data':JSON[_0x89c1('0x69')]({'session':_0x4b81f2['id'],'module_name':_0x89c1('0x71')})}})[_0x89c1('0x23')](function(_0x779244){if(_0x779244){var _0x528c1c=_['values'](_0x779244[_0x89c1('0x72')]);_[_0x89c1('0x73')](_0x528c1c,function(_0x4d2524){return _0x3ed40a[_0x89c1('0x74')](_0x4d2524[_0x89c1('0x29')]);});return{'count':_0x528c1c[_0x89c1('0x37')],'rows':_[_0x89c1('0x2b')](_0x528c1c,function(_0x96f302){return{'id':_0x96f302[_0x89c1('0x29')],'name':_0x96f302[_0x89c1('0x75')],'custom':_[_0x89c1('0x76')](_0x96f302[_0x89c1('0x29')],'_c')?!![]:![],'options':_0x96f302['options']?_[_0x89c1('0x2b')](_[_0x89c1('0x77')](_0x96f302[_0x89c1('0x49')]),function(_0x3fdc6e){return{'name':_0x3fdc6e['value'],'value':_0x3fdc6e[_0x89c1('0x29')]};}):[]};})};}})['then'](respondWithResult(_0x370ced,null))[_0x89c1('0x46')](function(_0x23306a){var _0x21a48b=_0x55200e[_0x89c1('0x31')]['test']?0x1f4:_0x23306a['statusCode']||0x1f4;logger[_0x89c1('0x27')](_0x89c1('0x78'),_0x89c1('0x57'),_0x21a48b,JSON[_0x89c1('0x69')](_0x23306a));delete _0x23306a[_0x89c1('0x29')];if(_0x21a48b===0x191){_0x21a48b=0x190;}_0x370ced[_0x89c1('0x25')](_0x21a48b)['send'](_0x55200e[_0x89c1('0x31')][_0x89c1('0x79')]?{'message':_0x89c1('0x7a'),'statusCode':_0x23306a[_0x89c1('0x7b')]}:_0x23306a);});}else{var _0x103a0a=0x1f4;_0x370ced[_0x89c1('0x25')](_0x103a0a)[_0x89c1('0x7c')]({'message':_0x89c1('0x7a'),'statusCode':0x190});}});};
\ No newline at end of file