Built motion from commit da617fac.|2.6.6
[motion2.git] / server / api / intFreshsalesAccount / intFreshsalesAccount.controller.js
index 93fb1dd..f17183f 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0x5ffa=['info','FreshsalesAccount,\x20%s,\x20%s','debug','FreshsalesAccount,\x20%s,\x20%s,\x20%s','stringify','error','code','message','request\x20sent','result','catch','status','end','json','count','offset','limit','Content-Range','apply','reject','update','destroy','sendStatus','stack','send','index','map','rawAttributes','fieldName','key','model','name','query','keys','filters','intersection','fields','attributes','hasOwnProperty','nolimit','order','sort','where','merge','type','VIRTUAL','filter','options','FreshsalesAccount','includeAll','include','show','params','find','create','body','findOne','FreshsalesConfiguration','length','pick','getConfigurations','addConfiguration','AccountId','channel','Descriptions','getDescriptions','FreshsalesField','Subjects','username','remoteUri','apiKey','slice','substring','GET','format','/api/selector/owners','Token\x20token=','users','statusCode','getFields,\x20%s,\x20%s,\x20%s','getFields','Wrong\x20credentials','html-pdf','eml-format','rimraf','zip-dir','fast-json-patch','bluebird','mustache','path','sox','lodash','crypto','jsforce','desk.js','querystring','papaparse','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/logger','api','../../config/utils','../../config/environment','../../config/license/util','../../mysqldb','../../components/integrations/configuration','jayson/promise','client','http','then'];(function(_0x4872fd,_0x586430){var _0xaae5ad=function(_0x271564){while(--_0x271564){_0x4872fd['push'](_0x4872fd['shift']());}};_0xaae5ad(++_0x586430);}(_0x5ffa,0x130));var _0xa5ff=function(_0x2e037e,_0x45d57c){_0x2e037e=_0x2e037e-0x0;var _0x22106c=_0x5ffa[_0x2e037e];return _0x22106c;};'use strict';var pdf=require(_0xa5ff('0x0'));var emlformat=require(_0xa5ff('0x1'));var rimraf=require(_0xa5ff('0x2'));var zipdir=require(_0xa5ff('0x3'));var jsonpatch=require(_0xa5ff('0x4'));var rp=require('request-promise');var moment=require('moment');var BPromise=require(_0xa5ff('0x5'));var Mustache=require(_0xa5ff('0x6'));var util=require('util');var path=require(_0xa5ff('0x7'));var sox=require(_0xa5ff('0x8'));var csv=require('to-csv');var ejs=require('ejs');var fs=require('fs');var _=require(_0xa5ff('0x9'));var squel=require('squel');var crypto=require(_0xa5ff('0xa'));var jsforce=require(_0xa5ff('0xb'));var deskjs=require(_0xa5ff('0xc'));var toCsv=require('to-csv');var querystring=require(_0xa5ff('0xd'));var Papa=require(_0xa5ff('0xe'));var Redis=require('ioredis');var authService=require(_0xa5ff('0xf'));var qs=require(_0xa5ff('0x10'));var as=require(_0xa5ff('0x11'));var hardwareService=require('../../config/license/hardware');var logger=require(_0xa5ff('0x12'))(_0xa5ff('0x13'));var utils=require(_0xa5ff('0x14'));var config=require(_0xa5ff('0x15'));var licenseUtil=require(_0xa5ff('0x16'));var db=require(_0xa5ff('0x17'))['db'];var integrations=require(_0xa5ff('0x18'));var jayson=require(_0xa5ff('0x19'));var client=jayson[_0xa5ff('0x1a')][_0xa5ff('0x1b')]({'port':0x232a});function respondWithRpcPromise(_0x16b9db,_0x36e13f,_0x208803,_0x477c1a){return new BPromise(function(_0x47c00e,_0xd75c68){var _0x580e39=_0x477c1a||client;return _0x580e39['request'](_0x16b9db,_0x208803)[_0xa5ff('0x1c')](function(_0x2415bd){logger[_0xa5ff('0x1d')](_0xa5ff('0x1e'),_0x36e13f,'request\x20sent');logger[_0xa5ff('0x1f')](_0xa5ff('0x20'),_0x36e13f,'request\x20sent',JSON[_0xa5ff('0x21')](_0x2415bd));if(_0x2415bd[_0xa5ff('0x22')]){if(_0x2415bd['error'][_0xa5ff('0x23')]===0x1f4){logger[_0xa5ff('0x22')](_0xa5ff('0x1e'),_0x36e13f,_0x2415bd['error'][_0xa5ff('0x24')]);return _0xd75c68(_0x2415bd[_0xa5ff('0x22')]['message']);}logger[_0xa5ff('0x22')](_0xa5ff('0x1e'),_0x36e13f,_0x2415bd['error'][_0xa5ff('0x24')]);return _0x47c00e(_0x2415bd[_0xa5ff('0x22')][_0xa5ff('0x24')]);}else{logger['info'](_0xa5ff('0x1e'),_0x36e13f,_0xa5ff('0x25'));_0x47c00e(_0x2415bd[_0xa5ff('0x26')]['message']);}})[_0xa5ff('0x27')](function(_0x4ee6e3){logger['error']('FreshsalesAccount,\x20%s,\x20%s',_0x36e13f,_0x4ee6e3);_0xd75c68(_0x4ee6e3);});});}function respondWithStatusCode(_0x22391a,_0x50c9e8){_0x50c9e8=_0x50c9e8||0xcc;return function(_0x2a4368){if(_0x2a4368){return _0x22391a['sendStatus'](_0x50c9e8);}return _0x22391a[_0xa5ff('0x28')](_0x50c9e8)[_0xa5ff('0x29')]();};}function respondWithResult(_0x40c6e0,_0x2a00a7){_0x2a00a7=_0x2a00a7||0xc8;return function(_0x26ad57){if(_0x26ad57){return _0x40c6e0['status'](_0x2a00a7)[_0xa5ff('0x2a')](_0x26ad57);}};}function respondWithFilteredResult(_0x58c2c5,_0x38a007){return function(_0x2a3caa){if(_0x2a3caa){var _0x580e25=_0x2a3caa[_0xa5ff('0x2b')],_0x3a2c8a=_0x38a007['offset'],_0x1a6190=_0x38a007[_0xa5ff('0x2c')]+_0x38a007[_0xa5ff('0x2d')],_0x2116c5;if(_0x1a6190>=_0x580e25){_0x1a6190=_0x580e25;_0x2116c5=0xc8;}else{_0x2116c5=0xce;}_0x58c2c5[_0xa5ff('0x28')](_0x2116c5);return _0x58c2c5['set'](_0xa5ff('0x2e'),_0x3a2c8a+'-'+_0x1a6190+'/'+_0x580e25)[_0xa5ff('0x2a')](_0x2a3caa);}return null;};}function patchUpdates(_0x52fedc){return function(_0x171395){try{jsonpatch[_0xa5ff('0x2f')](_0x171395,_0x52fedc,!![]);}catch(_0x28cce2){return BPromise[_0xa5ff('0x30')](_0x28cce2);}return _0x171395['save']();};}function saveUpdates(_0x1c78c5,_0x507963){return function(_0x281ea3){if(_0x281ea3){return _0x281ea3[_0xa5ff('0x31')](_0x1c78c5)[_0xa5ff('0x1c')](function(_0x1414a0){return _0x1414a0;});}return null;};}function removeEntity(_0x3c5e3d,_0x47de94){return function(_0x1f6317){if(_0x1f6317){return _0x1f6317[_0xa5ff('0x32')]()['then'](function(){_0x3c5e3d['status'](0xcc)['end']();});}};}function handleEntityNotFound(_0x258d26,_0x1569e5){return function(_0x4c16d9){if(!_0x4c16d9){_0x258d26[_0xa5ff('0x33')](0x194);}return _0x4c16d9;};}function handleError(_0x96d14e,_0x3e720f){_0x3e720f=_0x3e720f||0x1f4;return function(_0x25e2aa){logger[_0xa5ff('0x22')](_0x25e2aa[_0xa5ff('0x34')]);if(_0x25e2aa['name']){delete _0x25e2aa['name'];}_0x96d14e[_0xa5ff('0x28')](_0x3e720f)[_0xa5ff('0x35')](_0x25e2aa);};}exports[_0xa5ff('0x36')]=function(_0x32aa5e,_0x3eb48b){var _0x16356b={},_0x37dca9={},_0x14aa91={'count':0x0,'rows':[]};var _0x33f10b=_[_0xa5ff('0x37')](db['FreshsalesAccount'][_0xa5ff('0x38')],function(_0x41e104){return{'name':_0x41e104[_0xa5ff('0x39')],'type':_0x41e104['type'][_0xa5ff('0x3a')]};});_0x37dca9[_0xa5ff('0x3b')]=_[_0xa5ff('0x37')](_0x33f10b,_0xa5ff('0x3c'));_0x37dca9[_0xa5ff('0x3d')]=_[_0xa5ff('0x3e')](_0x32aa5e['query']);_0x37dca9[_0xa5ff('0x3f')]=_[_0xa5ff('0x40')](_0x37dca9['model'],_0x37dca9['query']);_0x16356b['attributes']=_['intersection'](_0x37dca9[_0xa5ff('0x3b')],qs[_0xa5ff('0x41')](_0x32aa5e['query']['fields']));_0x16356b['attributes']=_0x16356b['attributes']['length']?_0x16356b[_0xa5ff('0x42')]:_0x37dca9[_0xa5ff('0x3b')];if(!_0x32aa5e[_0xa5ff('0x3d')][_0xa5ff('0x43')](_0xa5ff('0x44'))){_0x16356b[_0xa5ff('0x2d')]=qs[_0xa5ff('0x2d')](_0x32aa5e['query']['limit']);_0x16356b['offset']=qs['offset'](_0x32aa5e[_0xa5ff('0x3d')][_0xa5ff('0x2c')]);}_0x16356b[_0xa5ff('0x45')]=qs[_0xa5ff('0x46')](_0x32aa5e[_0xa5ff('0x3d')]['sort']);_0x16356b[_0xa5ff('0x47')]=qs[_0xa5ff('0x3f')](_['pick'](_0x32aa5e['query'],_0x37dca9[_0xa5ff('0x3f')]),_0x33f10b);if(_0x32aa5e[_0xa5ff('0x3d')]['filter']){_0x16356b[_0xa5ff('0x47')]=_[_0xa5ff('0x48')](_0x16356b['where'],{'$or':_['map'](_0x33f10b,function(_0x25b9a4){if(_0x25b9a4[_0xa5ff('0x49')]!==_0xa5ff('0x4a')){var _0x317dca={};_0x317dca[_0x25b9a4[_0xa5ff('0x3c')]]={'$like':'%'+_0x32aa5e[_0xa5ff('0x3d')][_0xa5ff('0x4b')]+'%'};return _0x317dca;}})});}_0x16356b=_[_0xa5ff('0x48')]({},_0x16356b,_0x32aa5e[_0xa5ff('0x4c')]);var _0x6d1b15={'where':_0x16356b[_0xa5ff('0x47')]};return db[_0xa5ff('0x4d')][_0xa5ff('0x2b')](_0x6d1b15)['then'](function(_0x4dfebd){_0x14aa91['count']=_0x4dfebd;if(_0x32aa5e[_0xa5ff('0x3d')][_0xa5ff('0x4e')]){_0x16356b[_0xa5ff('0x4f')]=[{'all':!![]}];}return db[_0xa5ff('0x4d')]['findAll'](_0x16356b);})[_0xa5ff('0x1c')](function(_0x1ef977){_0x14aa91['rows']=_0x1ef977;return _0x14aa91;})[_0xa5ff('0x1c')](respondWithFilteredResult(_0x3eb48b,_0x16356b))[_0xa5ff('0x27')](handleError(_0x3eb48b,null));};exports[_0xa5ff('0x50')]=function(_0x157d71,_0x4bfc05){var _0x48038a={'raw':![],'where':{'id':_0x157d71[_0xa5ff('0x51')]['id']}},_0x472a9a={};_0x472a9a['model']=_[_0xa5ff('0x3e')](db['FreshsalesAccount'][_0xa5ff('0x38')]);_0x472a9a[_0xa5ff('0x3d')]=_['keys'](_0x157d71[_0xa5ff('0x3d')]);_0x472a9a[_0xa5ff('0x3f')]=_[_0xa5ff('0x40')](_0x472a9a[_0xa5ff('0x3b')],_0x472a9a[_0xa5ff('0x3d')]);_0x48038a[_0xa5ff('0x42')]=_[_0xa5ff('0x40')](_0x472a9a[_0xa5ff('0x3b')],qs[_0xa5ff('0x41')](_0x157d71[_0xa5ff('0x3d')][_0xa5ff('0x41')]));_0x48038a[_0xa5ff('0x42')]=_0x48038a['attributes']['length']?_0x48038a[_0xa5ff('0x42')]:_0x472a9a[_0xa5ff('0x3b')];if(_0x157d71[_0xa5ff('0x3d')][_0xa5ff('0x4e')]){_0x48038a[_0xa5ff('0x4f')]=[{'all':!![]}];}_0x48038a=_[_0xa5ff('0x48')]({},_0x48038a,_0x157d71[_0xa5ff('0x4c')]);return db[_0xa5ff('0x4d')][_0xa5ff('0x52')](_0x48038a)[_0xa5ff('0x1c')](handleEntityNotFound(_0x4bfc05,null))[_0xa5ff('0x1c')](respondWithResult(_0x4bfc05,null))['catch'](handleError(_0x4bfc05,null));};exports[_0xa5ff('0x53')]=function(_0x310396,_0x4889e3){return db[_0xa5ff('0x4d')][_0xa5ff('0x53')](_0x310396[_0xa5ff('0x54')],{})[_0xa5ff('0x1c')](respondWithResult(_0x4889e3,0xc9))[_0xa5ff('0x27')](handleError(_0x4889e3,null));};exports[_0xa5ff('0x31')]=function(_0x31eae2,_0x4b4eeb){if(_0x31eae2[_0xa5ff('0x54')]['id']){delete _0x31eae2['body']['id'];}return db[_0xa5ff('0x4d')][_0xa5ff('0x52')]({'where':{'id':_0x31eae2[_0xa5ff('0x51')]['id']}})[_0xa5ff('0x1c')](handleEntityNotFound(_0x4b4eeb,null))[_0xa5ff('0x1c')](saveUpdates(_0x31eae2[_0xa5ff('0x54')],null))[_0xa5ff('0x1c')](respondWithResult(_0x4b4eeb,null))[_0xa5ff('0x27')](handleError(_0x4b4eeb,null));};exports['destroy']=function(_0x1d9477,_0x490c04){return db[_0xa5ff('0x4d')][_0xa5ff('0x52')]({'where':{'id':_0x1d9477[_0xa5ff('0x51')]['id']}})[_0xa5ff('0x1c')](handleEntityNotFound(_0x490c04,null))[_0xa5ff('0x1c')](removeEntity(_0x490c04,null))[_0xa5ff('0x27')](handleError(_0x490c04,null));};exports['getConfigurations']=function(_0x504f78,_0x51d3d3,_0x290d11){var _0x282976={};var _0x38450e={};var _0x17abce;var _0x5bd90b;return db[_0xa5ff('0x4d')][_0xa5ff('0x55')]({'where':{'id':_0x504f78['params']['id']}})['then'](handleEntityNotFound(_0x51d3d3,null))['then'](function(_0x28d310){if(_0x28d310){_0x17abce=_0x28d310;_0x38450e[_0xa5ff('0x3b')]=_[_0xa5ff('0x3e')](db[_0xa5ff('0x56')][_0xa5ff('0x38')]);_0x38450e[_0xa5ff('0x3d')]=_[_0xa5ff('0x3e')](_0x504f78[_0xa5ff('0x3d')]);_0x38450e['filters']=_[_0xa5ff('0x40')](_0x38450e['model'],_0x38450e['query']);_0x282976[_0xa5ff('0x42')]=_[_0xa5ff('0x40')](_0x38450e['model'],qs[_0xa5ff('0x41')](_0x504f78[_0xa5ff('0x3d')][_0xa5ff('0x41')]));_0x282976[_0xa5ff('0x42')]=_0x282976[_0xa5ff('0x42')][_0xa5ff('0x57')]?_0x282976['attributes']:_0x38450e[_0xa5ff('0x3b')];_0x282976[_0xa5ff('0x45')]=qs[_0xa5ff('0x46')](_0x504f78['query'][_0xa5ff('0x46')]);_0x282976[_0xa5ff('0x47')]=qs[_0xa5ff('0x3f')](_[_0xa5ff('0x58')](_0x504f78[_0xa5ff('0x3d')],_0x38450e[_0xa5ff('0x3f')]));if(_0x504f78[_0xa5ff('0x3d')][_0xa5ff('0x4b')]){_0x282976['where']=_[_0xa5ff('0x48')](_0x282976[_0xa5ff('0x47')],{'$or':_['map'](_0x282976['attributes'],function(_0x3fec6b){var _0x1bc5b0={};_0x1bc5b0[_0x3fec6b]={'$like':'%'+_0x504f78[_0xa5ff('0x3d')][_0xa5ff('0x4b')]+'%'};return _0x1bc5b0;})});}_0x282976=_[_0xa5ff('0x48')]({},_0x282976,_0x504f78[_0xa5ff('0x4c')]);return _0x17abce[_0xa5ff('0x59')](_0x282976);}})[_0xa5ff('0x1c')](function(_0x353df1){if(_0x353df1){_0x5bd90b=_0x353df1[_0xa5ff('0x57')];if(!_0x504f78['query']['hasOwnProperty'](_0xa5ff('0x44'))){_0x282976[_0xa5ff('0x2d')]=qs['limit'](_0x504f78[_0xa5ff('0x3d')]['limit']);_0x282976[_0xa5ff('0x2c')]=qs['offset'](_0x504f78[_0xa5ff('0x3d')][_0xa5ff('0x2c')]);}return _0x17abce[_0xa5ff('0x59')](_0x282976);}})[_0xa5ff('0x1c')](function(_0x13b678){if(_0x13b678){return _0x13b678?{'count':_0x5bd90b,'rows':_0x13b678}:null;}})[_0xa5ff('0x1c')](respondWithResult(_0x51d3d3,null))[_0xa5ff('0x27')](handleError(_0x51d3d3,null));};exports[_0xa5ff('0x5a')]=function(_0x36c569,_0x50c0f2,_0x2ceda4){if(_0x36c569[_0xa5ff('0x54')]['id']){delete _0x36c569[_0xa5ff('0x54')]['id'];}return db[_0xa5ff('0x4d')][_0xa5ff('0x55')]({'where':{'id':_0x36c569[_0xa5ff('0x51')]['id']}})[_0xa5ff('0x1c')](handleEntityNotFound(_0x50c0f2,null))[_0xa5ff('0x1c')](function(_0x36ad02){if(_0x36ad02){_0x36c569[_0xa5ff('0x54')][_0xa5ff('0x5b')]=_0x36ad02['id'];_0x36c569['body']['Subjects']=integrations['getSubjects'](_0x36c569[_0xa5ff('0x54')][_0xa5ff('0x5c')],_0x36c569[_0xa5ff('0x54')][_0xa5ff('0x49')]);_0x36c569[_0xa5ff('0x54')][_0xa5ff('0x5d')]=integrations[_0xa5ff('0x5e')](_0x36c569['body'][_0xa5ff('0x5c')],_0x36c569[_0xa5ff('0x54')][_0xa5ff('0x49')]);return db[_0xa5ff('0x56')]['create'](_0x36c569[_0xa5ff('0x54')],{'include':[{'model':db[_0xa5ff('0x5f')],'as':_0xa5ff('0x60')},{'model':db[_0xa5ff('0x5f')],'as':_0xa5ff('0x5d')}]});}return null;})[_0xa5ff('0x1c')](respondWithResult(_0x50c0f2,null))[_0xa5ff('0x27')](handleError(_0x50c0f2,null));};exports['getFields']=function(_0x531b1b,_0x26e571,_0x1a2039){var _0x4629b7='';var _0x5aff61='';return db[_0xa5ff('0x4d')][_0xa5ff('0x55')]({'where':{'id':_0x531b1b[_0xa5ff('0x51')]['id']},'attributes':['id',_0xa5ff('0x61'),_0xa5ff('0x62'),_0xa5ff('0x63')]})['then'](handleEntityNotFound(_0x26e571,null))[_0xa5ff('0x1c')](function(_0x4362bc){if(_0x4362bc){_0x5aff61=_0x4362bc[_0xa5ff('0x61')];_0x4629b7=_0x4362bc[_0xa5ff('0x62')];var _0x20fece=_0x4362bc['remoteUri'][_0xa5ff('0x64')](-0x1);if(_0x20fece==='/'){_0x4629b7=_0x4629b7[_0xa5ff('0x65')](0x0,_0x4629b7['lastIndexOf'](_0x20fece));}return rp({'method':_0xa5ff('0x66'),'uri':util[_0xa5ff('0x67')]('%s%s',_0x4629b7,_0xa5ff('0x68')),'headers':{'Authorization':_0xa5ff('0x69')+_0x4362bc[_0xa5ff('0x63')]},'json':!![]});}})['then'](function(_0x4e9dd8){if(_0x4e9dd8){var _0x2da261=_0x4e9dd8[_0xa5ff('0x6a')];var _0x53850e=![];var _0x39531f=null;for(_0x39531f=0x0;_0x39531f<_0x2da261['length'];_0x39531f++){if(_0x2da261[_0x39531f]['email']===_0x5aff61){_0x53850e=!![];}}if(_0x53850e){return!![];}else{throw new Error({'statusCode':0x194,'message':'Requested\x20Resource\x20not\x20Found'});}}})['then'](respondWithResult(_0x26e571,null))[_0xa5ff('0x27')](function(_0x510797){var _0x7186ed=_0x531b1b[_0xa5ff('0x3d')]['test']?0x1f4:_0x510797[_0xa5ff('0x6b')]||0x1f4;logger['error'](_0xa5ff('0x6c'),_0xa5ff('0x6d'),_0x7186ed,JSON[_0xa5ff('0x21')](_0x510797));delete _0x510797[_0xa5ff('0x3c')];if(_0x7186ed===0x191){_0x7186ed=0x190;}_0x26e571[_0xa5ff('0x28')](_0x7186ed)['send'](_0x531b1b['query']['test']?{'message':_0xa5ff('0x6e'),'statusCode':_0x510797[_0xa5ff('0x6b')]}:_0x510797);});};
\ No newline at end of file
+var _0xac3e=['undefined','count','set','apply','save','then','destroy','error','name','send','index','FreshsalesAccount','rawAttributes','fieldName','type','model','map','query','keys','intersection','attributes','fields','nolimit','order','sort','filters','pick','where','filter','merge','includeAll','include','findAll','show','params','length','options','find','catch','create','body','update','getConfigurations','findOne','FreshsalesConfiguration','hasOwnProperty','addConfiguration','AccountId','Subjects','channel','Descriptions','getDescriptions','FreshsalesField','username','remoteUri','apiKey','slice','substring','lastIndexOf','GET','%s%s','Token\x20token=','users','Requested\x20Resource\x20not\x20Found','test','statusCode','stringify','Wrong\x20credentials','eml-format','rimraf','zip-dir','fast-json-patch','moment','mustache','ejs','lodash','squel','crypto','jsforce','desk.js','to-csv','querystring','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','api','../../config/environment','../../config/license/util','../../mysqldb','sendStatus','status','end','json','offset','limit'];(function(_0x4fbdc0,_0x5bf025){var _0x2ed5b4=function(_0x1d87f0){while(--_0x1d87f0){_0x4fbdc0['push'](_0x4fbdc0['shift']());}};_0x2ed5b4(++_0x5bf025);}(_0xac3e,0x164));var _0xeac3=function(_0x5db99b,_0xdee23a){_0x5db99b=_0x5db99b-0x0;var _0x4b2d0e=_0xac3e[_0x5db99b];return _0x4b2d0e;};'use strict';var emlformat=require(_0xeac3('0x0'));var rimraf=require(_0xeac3('0x1'));var zipdir=require(_0xeac3('0x2'));var jsonpatch=require(_0xeac3('0x3'));var rp=require('request-promise');var moment=require(_0xeac3('0x4'));var BPromise=require('bluebird');var Mustache=require(_0xeac3('0x5'));var util=require('util');var path=require('path');var sox=require('sox');var csv=require('to-csv');var ejs=require(_0xeac3('0x6'));var fs=require('fs');var fs_extra=require('fs-extra');var _=require(_0xeac3('0x7'));var squel=require(_0xeac3('0x8'));var crypto=require(_0xeac3('0x9'));var jsforce=require(_0xeac3('0xa'));var deskjs=require(_0xeac3('0xb'));var toCsv=require(_0xeac3('0xc'));var querystring=require(_0xeac3('0xd'));var Papa=require('papaparse');var Redis=require('ioredis');var authService=require(_0xeac3('0xe'));var qs=require(_0xeac3('0xf'));var as=require(_0xeac3('0x10'));var hardwareService=require(_0xeac3('0x11'));var logger=require('../../config/logger')(_0xeac3('0x12'));var utils=require('../../config/utils');var config=require(_0xeac3('0x13'));var licenseUtil=require(_0xeac3('0x14'));var db=require(_0xeac3('0x15'))['db'];var integrations=require('../../components/integrations/configuration');function respondWithStatusCode(_0x2c381f,_0x502d92){_0x502d92=_0x502d92||0xcc;return function(_0x31d63d){if(_0x31d63d){return _0x2c381f[_0xeac3('0x16')](_0x502d92);}return _0x2c381f[_0xeac3('0x17')](_0x502d92)[_0xeac3('0x18')]();};}function respondWithResult(_0x58c186,_0xcf2ac4){_0xcf2ac4=_0xcf2ac4||0xc8;return function(_0x4285b8){if(_0x4285b8){return _0x58c186['status'](_0xcf2ac4)[_0xeac3('0x19')](_0x4285b8);}};}function respondWithFilteredResult(_0x444ded,_0x2e4daa){return function(_0x44b082){if(_0x44b082){var _0x10152b=typeof _0x2e4daa[_0xeac3('0x1a')]==='undefined'&&typeof _0x2e4daa[_0xeac3('0x1b')]===_0xeac3('0x1c');var _0x199108=_0x44b082[_0xeac3('0x1d')];var _0x3404ed=_0x10152b?0x0:_0x2e4daa[_0xeac3('0x1a')];var _0x2267a8=_0x10152b?_0x44b082[_0xeac3('0x1d')]:_0x2e4daa[_0xeac3('0x1a')]+_0x2e4daa['limit'];var _0x43c321;if(_0x2267a8>=_0x199108){_0x2267a8=_0x199108;_0x43c321=0xc8;}else{_0x43c321=0xce;}_0x444ded[_0xeac3('0x17')](_0x43c321);return _0x444ded[_0xeac3('0x1e')]('Content-Range',_0x3404ed+'-'+_0x2267a8+'/'+_0x199108)[_0xeac3('0x19')](_0x44b082);}return null;};}function patchUpdates(_0x269d2c){return function(_0x4d2e66){try{jsonpatch[_0xeac3('0x1f')](_0x4d2e66,_0x269d2c,!![]);}catch(_0xf4a0c3){return BPromise['reject'](_0xf4a0c3);}return _0x4d2e66[_0xeac3('0x20')]();};}function saveUpdates(_0x20e3c2,_0x5efa9e){return function(_0x3ee41e){if(_0x3ee41e){return _0x3ee41e['update'](_0x20e3c2)[_0xeac3('0x21')](function(_0xa82d4b){return _0xa82d4b;});}return null;};}function removeEntity(_0x2a6df0,_0xa66171){return function(_0x3c85a7){if(_0x3c85a7){return _0x3c85a7[_0xeac3('0x22')]()[_0xeac3('0x21')](function(){_0x2a6df0[_0xeac3('0x17')](0xcc)['end']();});}};}function handleEntityNotFound(_0x5c8172,_0x15813e){return function(_0x163f7d){if(!_0x163f7d){_0x5c8172[_0xeac3('0x16')](0x194);}return _0x163f7d;};}function handleError(_0x2fd0a9,_0x28340e){_0x28340e=_0x28340e||0x1f4;return function(_0x34ad48){logger[_0xeac3('0x23')](_0x34ad48['stack']);if(_0x34ad48['name']){delete _0x34ad48[_0xeac3('0x24')];}_0x2fd0a9['status'](_0x28340e)[_0xeac3('0x25')](_0x34ad48);};}exports[_0xeac3('0x26')]=function(_0x30aea,_0x1218a7){var _0x67ec2e={},_0x1d3df3={},_0x213374={'count':0x0,'rows':[]};var _0x53fc59=_['map'](db[_0xeac3('0x27')][_0xeac3('0x28')],function(_0x57d89f){return{'name':_0x57d89f[_0xeac3('0x29')],'type':_0x57d89f[_0xeac3('0x2a')]['key']};});_0x1d3df3[_0xeac3('0x2b')]=_[_0xeac3('0x2c')](_0x53fc59,_0xeac3('0x24'));_0x1d3df3[_0xeac3('0x2d')]=_[_0xeac3('0x2e')](_0x30aea[_0xeac3('0x2d')]);_0x1d3df3['filters']=_[_0xeac3('0x2f')](_0x1d3df3[_0xeac3('0x2b')],_0x1d3df3['query']);_0x67ec2e[_0xeac3('0x30')]=_[_0xeac3('0x2f')](_0x1d3df3[_0xeac3('0x2b')],qs[_0xeac3('0x31')](_0x30aea[_0xeac3('0x2d')][_0xeac3('0x31')]));_0x67ec2e['attributes']=_0x67ec2e[_0xeac3('0x30')]['length']?_0x67ec2e[_0xeac3('0x30')]:_0x1d3df3['model'];if(!_0x30aea['query']['hasOwnProperty'](_0xeac3('0x32'))){_0x67ec2e[_0xeac3('0x1b')]=qs[_0xeac3('0x1b')](_0x30aea[_0xeac3('0x2d')][_0xeac3('0x1b')]);_0x67ec2e[_0xeac3('0x1a')]=qs[_0xeac3('0x1a')](_0x30aea[_0xeac3('0x2d')][_0xeac3('0x1a')]);}_0x67ec2e[_0xeac3('0x33')]=qs[_0xeac3('0x34')](_0x30aea[_0xeac3('0x2d')][_0xeac3('0x34')]);_0x67ec2e['where']=qs[_0xeac3('0x35')](_[_0xeac3('0x36')](_0x30aea[_0xeac3('0x2d')],_0x1d3df3[_0xeac3('0x35')]),_0x53fc59);if(_0x30aea[_0xeac3('0x2d')]['filter']){_0x67ec2e[_0xeac3('0x37')]=_['merge'](_0x67ec2e['where'],{'$or':_[_0xeac3('0x2c')](_0x53fc59,function(_0x1ea804){if(_0x1ea804['type']!=='VIRTUAL'){var _0x30f0d7={};_0x30f0d7[_0x1ea804[_0xeac3('0x24')]]={'$like':'%'+_0x30aea['query'][_0xeac3('0x38')]+'%'};return _0x30f0d7;}})});}_0x67ec2e=_[_0xeac3('0x39')]({},_0x67ec2e,_0x30aea['options']);var _0x150875={'where':_0x67ec2e[_0xeac3('0x37')]};return db['FreshsalesAccount']['count'](_0x150875)[_0xeac3('0x21')](function(_0x83a7fe){_0x213374[_0xeac3('0x1d')]=_0x83a7fe;if(_0x30aea[_0xeac3('0x2d')][_0xeac3('0x3a')]){_0x67ec2e[_0xeac3('0x3b')]=[{'all':!![]}];}return db[_0xeac3('0x27')][_0xeac3('0x3c')](_0x67ec2e);})['then'](function(_0x20295f){_0x213374['rows']=_0x20295f;return _0x213374;})[_0xeac3('0x21')](respondWithFilteredResult(_0x1218a7,_0x67ec2e))['catch'](handleError(_0x1218a7,null));};exports[_0xeac3('0x3d')]=function(_0x51e9ad,_0x248ba1){var _0xbb6c4e={'raw':![],'where':{'id':_0x51e9ad[_0xeac3('0x3e')]['id']}},_0x52be66={};_0x52be66[_0xeac3('0x2b')]=_['keys'](db[_0xeac3('0x27')][_0xeac3('0x28')]);_0x52be66[_0xeac3('0x2d')]=_[_0xeac3('0x2e')](_0x51e9ad[_0xeac3('0x2d')]);_0x52be66[_0xeac3('0x35')]=_['intersection'](_0x52be66[_0xeac3('0x2b')],_0x52be66[_0xeac3('0x2d')]);_0xbb6c4e['attributes']=_[_0xeac3('0x2f')](_0x52be66[_0xeac3('0x2b')],qs[_0xeac3('0x31')](_0x51e9ad[_0xeac3('0x2d')][_0xeac3('0x31')]));_0xbb6c4e['attributes']=_0xbb6c4e[_0xeac3('0x30')][_0xeac3('0x3f')]?_0xbb6c4e[_0xeac3('0x30')]:_0x52be66[_0xeac3('0x2b')];if(_0x51e9ad[_0xeac3('0x2d')][_0xeac3('0x3a')]){_0xbb6c4e[_0xeac3('0x3b')]=[{'all':!![]}];}_0xbb6c4e=_['merge']({},_0xbb6c4e,_0x51e9ad[_0xeac3('0x40')]);return db['FreshsalesAccount'][_0xeac3('0x41')](_0xbb6c4e)[_0xeac3('0x21')](handleEntityNotFound(_0x248ba1,null))[_0xeac3('0x21')](respondWithResult(_0x248ba1,null))[_0xeac3('0x42')](handleError(_0x248ba1,null));};exports['create']=function(_0x319a79,_0x3d9b73){return db[_0xeac3('0x27')][_0xeac3('0x43')](_0x319a79[_0xeac3('0x44')],{})[_0xeac3('0x21')](respondWithResult(_0x3d9b73,0xc9))[_0xeac3('0x42')](handleError(_0x3d9b73,null));};exports[_0xeac3('0x45')]=function(_0x18eac7,_0x343a58){if(_0x18eac7[_0xeac3('0x44')]['id']){delete _0x18eac7[_0xeac3('0x44')]['id'];}return db[_0xeac3('0x27')][_0xeac3('0x41')]({'where':{'id':_0x18eac7[_0xeac3('0x3e')]['id']}})[_0xeac3('0x21')](handleEntityNotFound(_0x343a58,null))[_0xeac3('0x21')](saveUpdates(_0x18eac7[_0xeac3('0x44')],null))[_0xeac3('0x21')](respondWithResult(_0x343a58,null))['catch'](handleError(_0x343a58,null));};exports['destroy']=function(_0x1b4691,_0x21ab1e){return db[_0xeac3('0x27')][_0xeac3('0x41')]({'where':{'id':_0x1b4691[_0xeac3('0x3e')]['id']}})['then'](handleEntityNotFound(_0x21ab1e,null))[_0xeac3('0x21')](removeEntity(_0x21ab1e,null))[_0xeac3('0x42')](handleError(_0x21ab1e,null));};exports[_0xeac3('0x46')]=function(_0x36f83c,_0x8796e5,_0x27c7b2){var _0x1c8852={};var _0x520c66={};var _0x1243ec;var _0x3f3f50;return db['FreshsalesAccount'][_0xeac3('0x47')]({'where':{'id':_0x36f83c[_0xeac3('0x3e')]['id']}})[_0xeac3('0x21')](handleEntityNotFound(_0x8796e5,null))['then'](function(_0x263b6b){if(_0x263b6b){_0x1243ec=_0x263b6b;_0x520c66[_0xeac3('0x2b')]=_[_0xeac3('0x2e')](db[_0xeac3('0x48')]['rawAttributes']);_0x520c66[_0xeac3('0x2d')]=_[_0xeac3('0x2e')](_0x36f83c[_0xeac3('0x2d')]);_0x520c66[_0xeac3('0x35')]=_[_0xeac3('0x2f')](_0x520c66[_0xeac3('0x2b')],_0x520c66['query']);_0x1c8852[_0xeac3('0x30')]=_[_0xeac3('0x2f')](_0x520c66[_0xeac3('0x2b')],qs[_0xeac3('0x31')](_0x36f83c[_0xeac3('0x2d')][_0xeac3('0x31')]));_0x1c8852[_0xeac3('0x30')]=_0x1c8852['attributes'][_0xeac3('0x3f')]?_0x1c8852[_0xeac3('0x30')]:_0x520c66[_0xeac3('0x2b')];_0x1c8852[_0xeac3('0x33')]=qs[_0xeac3('0x34')](_0x36f83c['query'][_0xeac3('0x34')]);_0x1c8852[_0xeac3('0x37')]=qs[_0xeac3('0x35')](_['pick'](_0x36f83c[_0xeac3('0x2d')],_0x520c66[_0xeac3('0x35')]));if(_0x36f83c['query']['filter']){_0x1c8852[_0xeac3('0x37')]=_[_0xeac3('0x39')](_0x1c8852[_0xeac3('0x37')],{'$or':_['map'](_0x1c8852[_0xeac3('0x30')],function(_0x526755){var _0x3fb593={};_0x3fb593[_0x526755]={'$like':'%'+_0x36f83c[_0xeac3('0x2d')]['filter']+'%'};return _0x3fb593;})});}_0x1c8852=_[_0xeac3('0x39')]({},_0x1c8852,_0x36f83c[_0xeac3('0x40')]);return _0x1243ec[_0xeac3('0x46')](_0x1c8852);}})[_0xeac3('0x21')](function(_0x266afe){if(_0x266afe){_0x3f3f50=_0x266afe[_0xeac3('0x3f')];if(!_0x36f83c[_0xeac3('0x2d')][_0xeac3('0x49')](_0xeac3('0x32'))){_0x1c8852['limit']=qs[_0xeac3('0x1b')](_0x36f83c[_0xeac3('0x2d')]['limit']);_0x1c8852[_0xeac3('0x1a')]=qs[_0xeac3('0x1a')](_0x36f83c[_0xeac3('0x2d')]['offset']);}return _0x1243ec[_0xeac3('0x46')](_0x1c8852);}})[_0xeac3('0x21')](function(_0x5d2972){if(_0x5d2972){return _0x5d2972?{'count':_0x3f3f50,'rows':_0x5d2972}:null;}})[_0xeac3('0x21')](respondWithResult(_0x8796e5,null))['catch'](handleError(_0x8796e5,null));};exports[_0xeac3('0x4a')]=function(_0x407de9,_0x4b3f71,_0x47eb58){if(_0x407de9['body']['id']){delete _0x407de9[_0xeac3('0x44')]['id'];}return db[_0xeac3('0x27')][_0xeac3('0x47')]({'where':{'id':_0x407de9[_0xeac3('0x3e')]['id']}})['then'](handleEntityNotFound(_0x4b3f71,null))[_0xeac3('0x21')](function(_0x18bc03){if(_0x18bc03){_0x407de9['body'][_0xeac3('0x4b')]=_0x18bc03['id'];_0x407de9[_0xeac3('0x44')][_0xeac3('0x4c')]=integrations['getSubjects'](_0x407de9[_0xeac3('0x44')][_0xeac3('0x4d')],_0x407de9[_0xeac3('0x44')]['type']);_0x407de9[_0xeac3('0x44')][_0xeac3('0x4e')]=integrations[_0xeac3('0x4f')](_0x407de9[_0xeac3('0x44')][_0xeac3('0x4d')],_0x407de9['body'][_0xeac3('0x2a')]);return db[_0xeac3('0x48')][_0xeac3('0x43')](_0x407de9[_0xeac3('0x44')],{'include':[{'model':db[_0xeac3('0x50')],'as':'Subjects'},{'model':db['FreshsalesField'],'as':'Descriptions'}]});}return null;})[_0xeac3('0x21')](respondWithResult(_0x4b3f71,null))[_0xeac3('0x42')](handleError(_0x4b3f71,null));};exports['getFields']=function(_0x501314,_0x488ff3,_0x5c1002){var _0x398eae='';var _0x4e8a96='';return db[_0xeac3('0x27')][_0xeac3('0x47')]({'where':{'id':_0x501314[_0xeac3('0x3e')]['id']},'attributes':['id',_0xeac3('0x51'),_0xeac3('0x52'),_0xeac3('0x53')]})[_0xeac3('0x21')](handleEntityNotFound(_0x488ff3,null))['then'](function(_0x3e0852){if(_0x3e0852){_0x4e8a96=_0x3e0852[_0xeac3('0x51')];_0x398eae=_0x3e0852[_0xeac3('0x52')];var _0x1c8cfa=_0x3e0852[_0xeac3('0x52')][_0xeac3('0x54')](-0x1);if(_0x1c8cfa==='/'){_0x398eae=_0x398eae[_0xeac3('0x55')](0x0,_0x398eae[_0xeac3('0x56')](_0x1c8cfa));}return rp({'method':_0xeac3('0x57'),'uri':util['format'](_0xeac3('0x58'),_0x398eae,'/api/selector/owners'),'headers':{'Authorization':_0xeac3('0x59')+_0x3e0852[_0xeac3('0x53')]},'json':!![]});}})[_0xeac3('0x21')](function(_0x566f03){if(_0x566f03){var _0x2a970f=_0x566f03[_0xeac3('0x5a')];var _0x580584=![];var _0x445fcb=null;for(_0x445fcb=0x0;_0x445fcb<_0x2a970f['length'];_0x445fcb++){if(_0x2a970f[_0x445fcb]['email']===_0x4e8a96){_0x580584=!![];}}if(_0x580584){return!![];}else{throw new Error({'statusCode':0x194,'message':_0xeac3('0x5b')});}}})[_0xeac3('0x21')](respondWithResult(_0x488ff3,null))[_0xeac3('0x42')](function(_0x312a10){var _0x4cbefc=_0x501314[_0xeac3('0x2d')][_0xeac3('0x5c')]?0x1f4:_0x312a10[_0xeac3('0x5d')]||0x1f4;logger[_0xeac3('0x23')]('getFields,\x20%s,\x20%s,\x20%s','getFields',_0x4cbefc,JSON[_0xeac3('0x5e')](_0x312a10));delete _0x312a10['name'];if(_0x4cbefc===0x191){_0x4cbefc=0x190;}_0x488ff3['status'](_0x4cbefc)[_0xeac3('0x25')](_0x501314[_0xeac3('0x2d')][_0xeac3('0x5c')]?{'message':_0xeac3('0x5f'),'statusCode':_0x312a10[_0xeac3('0x5d')]}:_0x312a10);});};
\ No newline at end of file