Built motion from commit 10af8726.|2.6.34
[motion2.git] / server / api / intFreshsalesAccount / intFreshsalesAccount.controller.js
index 7993b9c..4297925 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0xe13a=['order','where','pick','filter','type','VIRTUAL','merge','includeAll','findAll','rows','show','options','create','body','params','find','getConfigurations','findOne','FreshsalesConfiguration','sort','addConfiguration','getSubjects','Descriptions','getDescriptions','channel','FreshsalesField','Subjects','getFields','username','apiKey','remoteUri','substring','format','/api/selector/owners','users','email','getFields,\x20%s,\x20%s,\x20%s','test','Wrong\x20credentials','statusCode','eml-format','rimraf','zip-dir','fast-json-patch','moment','bluebird','mustache','util','path','sox','to-csv','ejs','lodash','crypto','jsforce','desk.js','querystring','papaparse','ioredis','../../components/auth/service','../../components/parsers/qs','../../config/license/hardware','../../config/logger','api','../../config/utils','../../config/environment','../../config/license/util','../../mysqldb','jayson/promise','client','request','then','FreshsalesAccount,\x20%s,\x20%s','debug','FreshsalesAccount,\x20%s,\x20%s,\x20%s','request\x20sent','stringify','error','code','message','info','catch','json','count','offset','status','set','Content-Range','apply','reject','update','destroy','end','sendStatus','stack','name','map','FreshsalesAccount','rawAttributes','fieldName','key','model','keys','query','filters','intersection','attributes','fields','length','hasOwnProperty','nolimit','limit'];(function(_0x150551,_0x6cbe68){var _0x19f9fc=function(_0x36cfda){while(--_0x36cfda){_0x150551['push'](_0x150551['shift']());}};_0x19f9fc(++_0x6cbe68);}(_0xe13a,0x178));var _0xae13=function(_0x1686bf,_0xb62804){_0x1686bf=_0x1686bf-0x0;var _0x1adf78=_0xe13a[_0x1686bf];return _0x1adf78;};'use strict';var pdf=require('html-pdf');var emlformat=require(_0xae13('0x0'));var rimraf=require(_0xae13('0x1'));var zipdir=require(_0xae13('0x2'));var jsonpatch=require(_0xae13('0x3'));var rp=require('request-promise');var moment=require(_0xae13('0x4'));var BPromise=require(_0xae13('0x5'));var Mustache=require(_0xae13('0x6'));var util=require(_0xae13('0x7'));var path=require(_0xae13('0x8'));var sox=require(_0xae13('0x9'));var csv=require(_0xae13('0xa'));var ejs=require(_0xae13('0xb'));var fs=require('fs');var _=require(_0xae13('0xc'));var squel=require('squel');var crypto=require(_0xae13('0xd'));var jsforce=require(_0xae13('0xe'));var deskjs=require(_0xae13('0xf'));var toCsv=require(_0xae13('0xa'));var querystring=require(_0xae13('0x10'));var Papa=require(_0xae13('0x11'));var Redis=require(_0xae13('0x12'));var authService=require(_0xae13('0x13'));var qs=require(_0xae13('0x14'));var as=require('../../components/parsers/advancedSearch');var hardwareService=require(_0xae13('0x15'));var logger=require(_0xae13('0x16'))(_0xae13('0x17'));var utils=require(_0xae13('0x18'));var config=require(_0xae13('0x19'));var licenseUtil=require(_0xae13('0x1a'));var db=require(_0xae13('0x1b'))['db'];var integrations=require('../../components/integrations/configuration');var jayson=require(_0xae13('0x1c'));var client=jayson[_0xae13('0x1d')]['http']({'port':0x232a});function respondWithRpcPromise(_0x589803,_0x506411,_0x50f7c4,_0x52484b){return new BPromise(function(_0x26ff3e,_0x148186){var _0x44e141=_0x52484b||client;return _0x44e141[_0xae13('0x1e')](_0x589803,_0x50f7c4)[_0xae13('0x1f')](function(_0x2912a2){logger['info'](_0xae13('0x20'),_0x506411,'request\x20sent');logger[_0xae13('0x21')](_0xae13('0x22'),_0x506411,_0xae13('0x23'),JSON[_0xae13('0x24')](_0x2912a2));if(_0x2912a2[_0xae13('0x25')]){if(_0x2912a2[_0xae13('0x25')][_0xae13('0x26')]===0x1f4){logger[_0xae13('0x25')](_0xae13('0x20'),_0x506411,_0x2912a2['error'][_0xae13('0x27')]);return _0x148186(_0x2912a2['error'][_0xae13('0x27')]);}logger[_0xae13('0x25')]('FreshsalesAccount,\x20%s,\x20%s',_0x506411,_0x2912a2[_0xae13('0x25')][_0xae13('0x27')]);return _0x26ff3e(_0x2912a2[_0xae13('0x25')][_0xae13('0x27')]);}else{logger[_0xae13('0x28')](_0xae13('0x20'),_0x506411,'request\x20sent');_0x26ff3e(_0x2912a2['result'][_0xae13('0x27')]);}})[_0xae13('0x29')](function(_0x51205e){logger[_0xae13('0x25')]('FreshsalesAccount,\x20%s,\x20%s',_0x506411,_0x51205e);_0x148186(_0x51205e);});});}function respondWithStatusCode(_0x13c2de,_0x194437){_0x194437=_0x194437||0xcc;return function(_0x3f12b0){if(_0x3f12b0){return _0x13c2de['sendStatus'](_0x194437);}return _0x13c2de['status'](_0x194437)['end']();};}function respondWithResult(_0x4edb8c,_0xc5e6a7){_0xc5e6a7=_0xc5e6a7||0xc8;return function(_0x17ce58){if(_0x17ce58){return _0x4edb8c['status'](_0xc5e6a7)[_0xae13('0x2a')](_0x17ce58);}};}function respondWithFilteredResult(_0x517e71,_0x3d0d60){return function(_0x5de054){if(_0x5de054){var _0xbeda8d=_0x5de054[_0xae13('0x2b')],_0x3117c2=_0x3d0d60[_0xae13('0x2c')],_0x526e4e=_0x3d0d60[_0xae13('0x2c')]+_0x3d0d60['limit'],_0xa98d6c;if(_0x526e4e>=_0xbeda8d){_0x526e4e=_0xbeda8d;_0xa98d6c=0xc8;}else{_0xa98d6c=0xce;}_0x517e71[_0xae13('0x2d')](_0xa98d6c);return _0x517e71[_0xae13('0x2e')](_0xae13('0x2f'),_0x3117c2+'-'+_0x526e4e+'/'+_0xbeda8d)[_0xae13('0x2a')](_0x5de054);}return null;};}function patchUpdates(_0x742759){return function(_0x27bcf3){try{jsonpatch[_0xae13('0x30')](_0x27bcf3,_0x742759,!![]);}catch(_0x5bd0ee){return BPromise[_0xae13('0x31')](_0x5bd0ee);}return _0x27bcf3['save']();};}function saveUpdates(_0xf6289c,_0x100df1){return function(_0x2dc2af){if(_0x2dc2af){return _0x2dc2af[_0xae13('0x32')](_0xf6289c)[_0xae13('0x1f')](function(_0x39718f){return _0x39718f;});}return null;};}function removeEntity(_0x11c2ba,_0x48f0f6){return function(_0x4a3deb){if(_0x4a3deb){return _0x4a3deb[_0xae13('0x33')]()[_0xae13('0x1f')](function(){_0x11c2ba[_0xae13('0x2d')](0xcc)[_0xae13('0x34')]();});}};}function handleEntityNotFound(_0x3d4ffd,_0xfac8e7){return function(_0x126686){if(!_0x126686){_0x3d4ffd[_0xae13('0x35')](0x194);}return _0x126686;};}function handleError(_0x1fda10,_0x23f9d7){_0x23f9d7=_0x23f9d7||0x1f4;return function(_0x5f1aeb){logger[_0xae13('0x25')](_0x5f1aeb[_0xae13('0x36')]);if(_0x5f1aeb[_0xae13('0x37')]){delete _0x5f1aeb['name'];}_0x1fda10['status'](_0x23f9d7)['send'](_0x5f1aeb);};}exports['index']=function(_0x5b4060,_0x5ee151){var _0x6e91ea={},_0x2e9a97={},_0x34a801={'count':0x0,'rows':[]};var _0x5bb32a=_[_0xae13('0x38')](db[_0xae13('0x39')][_0xae13('0x3a')],function(_0x1f5587){return{'name':_0x1f5587[_0xae13('0x3b')],'type':_0x1f5587['type'][_0xae13('0x3c')]};});_0x2e9a97[_0xae13('0x3d')]=_[_0xae13('0x38')](_0x5bb32a,'name');_0x2e9a97['query']=_[_0xae13('0x3e')](_0x5b4060[_0xae13('0x3f')]);_0x2e9a97[_0xae13('0x40')]=_[_0xae13('0x41')](_0x2e9a97['model'],_0x2e9a97[_0xae13('0x3f')]);_0x6e91ea[_0xae13('0x42')]=_['intersection'](_0x2e9a97[_0xae13('0x3d')],qs[_0xae13('0x43')](_0x5b4060['query'][_0xae13('0x43')]));_0x6e91ea[_0xae13('0x42')]=_0x6e91ea[_0xae13('0x42')][_0xae13('0x44')]?_0x6e91ea['attributes']:_0x2e9a97[_0xae13('0x3d')];if(!_0x5b4060[_0xae13('0x3f')][_0xae13('0x45')](_0xae13('0x46'))){_0x6e91ea['limit']=qs[_0xae13('0x47')](_0x5b4060[_0xae13('0x3f')][_0xae13('0x47')]);_0x6e91ea[_0xae13('0x2c')]=qs['offset'](_0x5b4060['query'][_0xae13('0x2c')]);}_0x6e91ea[_0xae13('0x48')]=qs['sort'](_0x5b4060[_0xae13('0x3f')]['sort']);_0x6e91ea[_0xae13('0x49')]=qs[_0xae13('0x40')](_[_0xae13('0x4a')](_0x5b4060['query'],_0x2e9a97[_0xae13('0x40')]),_0x5bb32a);if(_0x5b4060[_0xae13('0x3f')][_0xae13('0x4b')]){_0x6e91ea[_0xae13('0x49')]=_['merge'](_0x6e91ea[_0xae13('0x49')],{'$or':_[_0xae13('0x38')](_0x5bb32a,function(_0x133f00){if(_0x133f00[_0xae13('0x4c')]!==_0xae13('0x4d')){var _0x74e6b3={};_0x74e6b3[_0x133f00[_0xae13('0x37')]]={'$like':'%'+_0x5b4060[_0xae13('0x3f')]['filter']+'%'};return _0x74e6b3;}})});}_0x6e91ea=_[_0xae13('0x4e')]({},_0x6e91ea,_0x5b4060['options']);var _0x2a8d56={'where':_0x6e91ea[_0xae13('0x49')]};return db[_0xae13('0x39')][_0xae13('0x2b')](_0x2a8d56)['then'](function(_0x2fd0c8){_0x34a801['count']=_0x2fd0c8;if(_0x5b4060[_0xae13('0x3f')][_0xae13('0x4f')]){_0x6e91ea['include']=[{'all':!![]}];}return db[_0xae13('0x39')][_0xae13('0x50')](_0x6e91ea);})[_0xae13('0x1f')](function(_0x432a49){_0x34a801[_0xae13('0x51')]=_0x432a49;return _0x34a801;})[_0xae13('0x1f')](respondWithFilteredResult(_0x5ee151,_0x6e91ea))['catch'](handleError(_0x5ee151,null));};exports[_0xae13('0x52')]=function(_0x26dcbb,_0xd15aa7){var _0x3dbfb7={'raw':![],'where':{'id':_0x26dcbb['params']['id']}},_0x29ba1={};_0x29ba1[_0xae13('0x3d')]=_[_0xae13('0x3e')](db[_0xae13('0x39')]['rawAttributes']);_0x29ba1['query']=_['keys'](_0x26dcbb['query']);_0x29ba1[_0xae13('0x40')]=_['intersection'](_0x29ba1[_0xae13('0x3d')],_0x29ba1['query']);_0x3dbfb7[_0xae13('0x42')]=_[_0xae13('0x41')](_0x29ba1[_0xae13('0x3d')],qs[_0xae13('0x43')](_0x26dcbb[_0xae13('0x3f')]['fields']));_0x3dbfb7[_0xae13('0x42')]=_0x3dbfb7[_0xae13('0x42')]['length']?_0x3dbfb7[_0xae13('0x42')]:_0x29ba1[_0xae13('0x3d')];if(_0x26dcbb['query']['includeAll']){_0x3dbfb7['include']=[{'all':!![]}];}_0x3dbfb7=_['merge']({},_0x3dbfb7,_0x26dcbb[_0xae13('0x53')]);return db[_0xae13('0x39')]['find'](_0x3dbfb7)[_0xae13('0x1f')](handleEntityNotFound(_0xd15aa7,null))[_0xae13('0x1f')](respondWithResult(_0xd15aa7,null))['catch'](handleError(_0xd15aa7,null));};exports[_0xae13('0x54')]=function(_0x277213,_0x231a76){return db[_0xae13('0x39')][_0xae13('0x54')](_0x277213[_0xae13('0x55')],{})[_0xae13('0x1f')](respondWithResult(_0x231a76,0xc9))[_0xae13('0x29')](handleError(_0x231a76,null));};exports[_0xae13('0x32')]=function(_0x2ec943,_0x4990ec){if(_0x2ec943[_0xae13('0x55')]['id']){delete _0x2ec943[_0xae13('0x55')]['id'];}return db[_0xae13('0x39')]['find']({'where':{'id':_0x2ec943[_0xae13('0x56')]['id']}})['then'](handleEntityNotFound(_0x4990ec,null))[_0xae13('0x1f')](saveUpdates(_0x2ec943[_0xae13('0x55')],null))[_0xae13('0x1f')](respondWithResult(_0x4990ec,null))['catch'](handleError(_0x4990ec,null));};exports['destroy']=function(_0x1a9ca4,_0x3fa6e4){return db[_0xae13('0x39')][_0xae13('0x57')]({'where':{'id':_0x1a9ca4[_0xae13('0x56')]['id']}})[_0xae13('0x1f')](handleEntityNotFound(_0x3fa6e4,null))[_0xae13('0x1f')](removeEntity(_0x3fa6e4,null))['catch'](handleError(_0x3fa6e4,null));};exports[_0xae13('0x58')]=function(_0x155fe7,_0x1cf135,_0x346fdd){var _0xcbac5b={};var _0x67e5d3={};var _0x14f543;var _0x54c748;return db[_0xae13('0x39')][_0xae13('0x59')]({'where':{'id':_0x155fe7['params']['id']}})[_0xae13('0x1f')](handleEntityNotFound(_0x1cf135,null))[_0xae13('0x1f')](function(_0xe6b279){if(_0xe6b279){_0x14f543=_0xe6b279;_0x67e5d3['model']=_[_0xae13('0x3e')](db[_0xae13('0x5a')]['rawAttributes']);_0x67e5d3[_0xae13('0x3f')]=_[_0xae13('0x3e')](_0x155fe7[_0xae13('0x3f')]);_0x67e5d3[_0xae13('0x40')]=_[_0xae13('0x41')](_0x67e5d3[_0xae13('0x3d')],_0x67e5d3['query']);_0xcbac5b['attributes']=_[_0xae13('0x41')](_0x67e5d3[_0xae13('0x3d')],qs[_0xae13('0x43')](_0x155fe7[_0xae13('0x3f')][_0xae13('0x43')]));_0xcbac5b[_0xae13('0x42')]=_0xcbac5b['attributes'][_0xae13('0x44')]?_0xcbac5b[_0xae13('0x42')]:_0x67e5d3['model'];_0xcbac5b['order']=qs['sort'](_0x155fe7[_0xae13('0x3f')][_0xae13('0x5b')]);_0xcbac5b[_0xae13('0x49')]=qs[_0xae13('0x40')](_[_0xae13('0x4a')](_0x155fe7[_0xae13('0x3f')],_0x67e5d3[_0xae13('0x40')]));if(_0x155fe7[_0xae13('0x3f')][_0xae13('0x4b')]){_0xcbac5b[_0xae13('0x49')]=_[_0xae13('0x4e')](_0xcbac5b[_0xae13('0x49')],{'$or':_[_0xae13('0x38')](_0xcbac5b[_0xae13('0x42')],function(_0xc3ef7d){var _0x4e623b={};_0x4e623b[_0xc3ef7d]={'$like':'%'+_0x155fe7[_0xae13('0x3f')][_0xae13('0x4b')]+'%'};return _0x4e623b;})});}_0xcbac5b=_['merge']({},_0xcbac5b,_0x155fe7[_0xae13('0x53')]);return _0x14f543['getConfigurations'](_0xcbac5b);}})['then'](function(_0x20b8e5){if(_0x20b8e5){_0x54c748=_0x20b8e5[_0xae13('0x44')];if(!_0x155fe7[_0xae13('0x3f')][_0xae13('0x45')](_0xae13('0x46'))){_0xcbac5b[_0xae13('0x47')]=qs['limit'](_0x155fe7['query'][_0xae13('0x47')]);_0xcbac5b[_0xae13('0x2c')]=qs[_0xae13('0x2c')](_0x155fe7['query'][_0xae13('0x2c')]);}return _0x14f543['getConfigurations'](_0xcbac5b);}})[_0xae13('0x1f')](function(_0xb29110){if(_0xb29110){return _0xb29110?{'count':_0x54c748,'rows':_0xb29110}:null;}})[_0xae13('0x1f')](respondWithResult(_0x1cf135,null))[_0xae13('0x29')](handleError(_0x1cf135,null));};exports[_0xae13('0x5c')]=function(_0x5e8e4f,_0x3ff1a5,_0x39b2e5){if(_0x5e8e4f['body']['id']){delete _0x5e8e4f[_0xae13('0x55')]['id'];}return db[_0xae13('0x39')][_0xae13('0x59')]({'where':{'id':_0x5e8e4f[_0xae13('0x56')]['id']}})[_0xae13('0x1f')](handleEntityNotFound(_0x3ff1a5,null))[_0xae13('0x1f')](function(_0x519134){if(_0x519134){_0x5e8e4f[_0xae13('0x55')]['AccountId']=_0x519134['id'];_0x5e8e4f[_0xae13('0x55')]['Subjects']=integrations[_0xae13('0x5d')](_0x5e8e4f[_0xae13('0x55')]['channel'],_0x5e8e4f[_0xae13('0x55')][_0xae13('0x4c')]);_0x5e8e4f[_0xae13('0x55')][_0xae13('0x5e')]=integrations[_0xae13('0x5f')](_0x5e8e4f[_0xae13('0x55')][_0xae13('0x60')],_0x5e8e4f[_0xae13('0x55')]['type']);return db[_0xae13('0x5a')][_0xae13('0x54')](_0x5e8e4f[_0xae13('0x55')],{'include':[{'model':db[_0xae13('0x61')],'as':_0xae13('0x62')},{'model':db[_0xae13('0x61')],'as':_0xae13('0x5e')}]});}return null;})[_0xae13('0x1f')](respondWithResult(_0x3ff1a5,null))[_0xae13('0x29')](handleError(_0x3ff1a5,null));};exports[_0xae13('0x63')]=function(_0x491f7f,_0x40844e,_0x490754){var _0x4b51f4='';var _0x2b6ce2='';return db[_0xae13('0x39')][_0xae13('0x59')]({'where':{'id':_0x491f7f['params']['id']},'attributes':['id',_0xae13('0x64'),'remoteUri',_0xae13('0x65')]})['then'](handleEntityNotFound(_0x40844e,null))[_0xae13('0x1f')](function(_0x22685d){if(_0x22685d){_0x2b6ce2=_0x22685d['username'];_0x4b51f4=_0x22685d[_0xae13('0x66')];var _0x415abb=_0x22685d['remoteUri']['slice'](-0x1);if(_0x415abb==='/'){_0x4b51f4=_0x4b51f4[_0xae13('0x67')](0x0,_0x4b51f4['lastIndexOf'](_0x415abb));}return rp({'method':'GET','uri':util[_0xae13('0x68')]('%s%s',_0x4b51f4,_0xae13('0x69')),'headers':{'Authorization':'Token\x20token='+_0x22685d[_0xae13('0x65')]},'json':!![]});}})[_0xae13('0x1f')](function(_0x35333f){if(_0x35333f){var _0x88d31=_0x35333f[_0xae13('0x6a')];var _0x31c15e=![];var _0x5ceb04=null;for(_0x5ceb04=0x0;_0x5ceb04<_0x88d31[_0xae13('0x44')];_0x5ceb04++){if(_0x88d31[_0x5ceb04][_0xae13('0x6b')]===_0x2b6ce2){_0x31c15e=!![];}}if(_0x31c15e){return!![];}else{throw new Error({'statusCode':0x194,'message':'Requested\x20Resource\x20not\x20Found'});}}})['then'](respondWithResult(_0x40844e,null))['catch'](function(_0x30ca46){var _0x4b5808=_0x491f7f[_0xae13('0x3f')]['test']?0x1f4:_0x30ca46['statusCode']||0x1f4;logger[_0xae13('0x25')](_0xae13('0x6c'),_0xae13('0x63'),_0x4b5808,JSON[_0xae13('0x24')](_0x30ca46));delete _0x30ca46[_0xae13('0x37')];if(_0x4b5808===0x191){_0x4b5808=0x190;}_0x40844e[_0xae13('0x2d')](_0x4b5808)['send'](_0x491f7f[_0xae13('0x3f')][_0xae13('0x6d')]?{'message':_0xae13('0x6e'),'statusCode':_0x30ca46[_0xae13('0x6f')]}:_0x30ca46);});};
\ No newline at end of file
+var _0x4c6f=['options','findAll','rows','catch','show','params','includeAll','find','create','body','findOne','FreshsalesConfiguration','order','getConfigurations','addConfiguration','AccountId','Subjects','getSubjects','channel','Descriptions','FreshsalesField','username','apiKey','remoteUri','slice','substring','lastIndexOf','format','/api/selector/owners','Token\x20token=','users','email','test','statusCode','getFields,\x20%s,\x20%s,\x20%s','getFields','stringify','rimraf','zip-dir','request-promise','moment','bluebird','mustache','util','path','to-csv','ejs','fs-extra','lodash','squel','jsforce','desk.js','papaparse','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','api','../../config/utils','../../config/environment','../../config/license/util','../../mysqldb','../../components/integrations/configuration','status','json','offset','undefined','limit','count','apply','reject','save','update','destroy','then','sendStatus','error','stack','name','send','index','map','FreshsalesAccount','rawAttributes','type','key','model','keys','query','filters','attributes','intersection','fields','length','hasOwnProperty','nolimit','sort','where','pick','filter','merge','VIRTUAL'];(function(_0x47df54,_0x1aeb61){var _0x261b87=function(_0x54bc77){while(--_0x54bc77){_0x47df54['push'](_0x47df54['shift']());}};_0x261b87(++_0x1aeb61);}(_0x4c6f,0x157));var _0xf4c6=function(_0x5e1e25,_0xdc1421){_0x5e1e25=_0x5e1e25-0x0;var _0x548e5f=_0x4c6f[_0x5e1e25];return _0x548e5f;};'use strict';var emlformat=require('eml-format');var rimraf=require(_0xf4c6('0x0'));var zipdir=require(_0xf4c6('0x1'));var jsonpatch=require('fast-json-patch');var rp=require(_0xf4c6('0x2'));var moment=require(_0xf4c6('0x3'));var BPromise=require(_0xf4c6('0x4'));var Mustache=require(_0xf4c6('0x5'));var util=require(_0xf4c6('0x6'));var path=require(_0xf4c6('0x7'));var sox=require('sox');var csv=require(_0xf4c6('0x8'));var ejs=require(_0xf4c6('0x9'));var fs=require('fs');var fs_extra=require(_0xf4c6('0xa'));var _=require(_0xf4c6('0xb'));var squel=require(_0xf4c6('0xc'));var crypto=require('crypto');var jsforce=require(_0xf4c6('0xd'));var deskjs=require(_0xf4c6('0xe'));var toCsv=require(_0xf4c6('0x8'));var querystring=require('querystring');var Papa=require(_0xf4c6('0xf'));var Redis=require(_0xf4c6('0x10'));var authService=require(_0xf4c6('0x11'));var qs=require(_0xf4c6('0x12'));var as=require(_0xf4c6('0x13'));var hardwareService=require('../../config/license/hardware');var logger=require('../../config/logger')(_0xf4c6('0x14'));var utils=require(_0xf4c6('0x15'));var config=require(_0xf4c6('0x16'));var licenseUtil=require(_0xf4c6('0x17'));var db=require(_0xf4c6('0x18'))['db'];var integrations=require(_0xf4c6('0x19'));function respondWithStatusCode(_0x2b3fc5,_0x391c8f){_0x391c8f=_0x391c8f||0xcc;return function(_0x13fd11){if(_0x13fd11){return _0x2b3fc5['sendStatus'](_0x391c8f);}return _0x2b3fc5[_0xf4c6('0x1a')](_0x391c8f)['end']();};}function respondWithResult(_0xe0f86b,_0x5edec9){_0x5edec9=_0x5edec9||0xc8;return function(_0x5cde4a){if(_0x5cde4a){return _0xe0f86b[_0xf4c6('0x1a')](_0x5edec9)[_0xf4c6('0x1b')](_0x5cde4a);}};}function respondWithFilteredResult(_0x466a66,_0x30fd34){return function(_0x290b98){if(_0x290b98){var _0x5582fa=typeof _0x30fd34[_0xf4c6('0x1c')]===_0xf4c6('0x1d')&&typeof _0x30fd34[_0xf4c6('0x1e')]==='undefined';var _0x180003=_0x290b98[_0xf4c6('0x1f')];var _0x271c45=_0x5582fa?0x0:_0x30fd34['offset'];var _0x3740b3=_0x5582fa?_0x290b98[_0xf4c6('0x1f')]:_0x30fd34[_0xf4c6('0x1c')]+_0x30fd34[_0xf4c6('0x1e')];var _0x1b9279;if(_0x3740b3>=_0x180003){_0x3740b3=_0x180003;_0x1b9279=0xc8;}else{_0x1b9279=0xce;}_0x466a66[_0xf4c6('0x1a')](_0x1b9279);return _0x466a66['set']('Content-Range',_0x271c45+'-'+_0x3740b3+'/'+_0x180003)['json'](_0x290b98);}return null;};}function patchUpdates(_0x24e5f4){return function(_0x160394){try{jsonpatch[_0xf4c6('0x20')](_0x160394,_0x24e5f4,!![]);}catch(_0x4dc258){return BPromise[_0xf4c6('0x21')](_0x4dc258);}return _0x160394[_0xf4c6('0x22')]();};}function saveUpdates(_0x5e79ab,_0x6b20b){return function(_0xd5691a){if(_0xd5691a){return _0xd5691a[_0xf4c6('0x23')](_0x5e79ab)['then'](function(_0x5c7fbd){return _0x5c7fbd;});}return null;};}function removeEntity(_0x1453c,_0x126c33){return function(_0x3ac0e9){if(_0x3ac0e9){return _0x3ac0e9[_0xf4c6('0x24')]()[_0xf4c6('0x25')](function(){_0x1453c[_0xf4c6('0x1a')](0xcc)['end']();});}};}function handleEntityNotFound(_0x21d260,_0x45f678){return function(_0x50f16f){if(!_0x50f16f){_0x21d260[_0xf4c6('0x26')](0x194);}return _0x50f16f;};}function handleError(_0x31874d,_0x30f0db){_0x30f0db=_0x30f0db||0x1f4;return function(_0xde436a){logger[_0xf4c6('0x27')](_0xde436a[_0xf4c6('0x28')]);if(_0xde436a[_0xf4c6('0x29')]){delete _0xde436a[_0xf4c6('0x29')];}_0x31874d[_0xf4c6('0x1a')](_0x30f0db)[_0xf4c6('0x2a')](_0xde436a);};}exports[_0xf4c6('0x2b')]=function(_0x18ac4c,_0xdde7d8){var _0x1d03e2={},_0x1a6235={},_0x2dc0b1={'count':0x0,'rows':[]};var _0x4afc82=_[_0xf4c6('0x2c')](db[_0xf4c6('0x2d')][_0xf4c6('0x2e')],function(_0x339762){return{'name':_0x339762['fieldName'],'type':_0x339762[_0xf4c6('0x2f')][_0xf4c6('0x30')]};});_0x1a6235[_0xf4c6('0x31')]=_[_0xf4c6('0x2c')](_0x4afc82,_0xf4c6('0x29'));_0x1a6235['query']=_[_0xf4c6('0x32')](_0x18ac4c[_0xf4c6('0x33')]);_0x1a6235[_0xf4c6('0x34')]=_['intersection'](_0x1a6235[_0xf4c6('0x31')],_0x1a6235[_0xf4c6('0x33')]);_0x1d03e2[_0xf4c6('0x35')]=_[_0xf4c6('0x36')](_0x1a6235[_0xf4c6('0x31')],qs['fields'](_0x18ac4c['query'][_0xf4c6('0x37')]));_0x1d03e2[_0xf4c6('0x35')]=_0x1d03e2[_0xf4c6('0x35')][_0xf4c6('0x38')]?_0x1d03e2[_0xf4c6('0x35')]:_0x1a6235['model'];if(!_0x18ac4c[_0xf4c6('0x33')][_0xf4c6('0x39')](_0xf4c6('0x3a'))){_0x1d03e2['limit']=qs['limit'](_0x18ac4c[_0xf4c6('0x33')][_0xf4c6('0x1e')]);_0x1d03e2[_0xf4c6('0x1c')]=qs[_0xf4c6('0x1c')](_0x18ac4c[_0xf4c6('0x33')]['offset']);}_0x1d03e2['order']=qs[_0xf4c6('0x3b')](_0x18ac4c[_0xf4c6('0x33')]['sort']);_0x1d03e2[_0xf4c6('0x3c')]=qs[_0xf4c6('0x34')](_[_0xf4c6('0x3d')](_0x18ac4c['query'],_0x1a6235[_0xf4c6('0x34')]),_0x4afc82);if(_0x18ac4c['query'][_0xf4c6('0x3e')]){_0x1d03e2[_0xf4c6('0x3c')]=_[_0xf4c6('0x3f')](_0x1d03e2[_0xf4c6('0x3c')],{'$or':_[_0xf4c6('0x2c')](_0x4afc82,function(_0x14f3e6){if(_0x14f3e6[_0xf4c6('0x2f')]!==_0xf4c6('0x40')){var _0x216017={};_0x216017[_0x14f3e6[_0xf4c6('0x29')]]={'$like':'%'+_0x18ac4c[_0xf4c6('0x33')][_0xf4c6('0x3e')]+'%'};return _0x216017;}})});}_0x1d03e2=_[_0xf4c6('0x3f')]({},_0x1d03e2,_0x18ac4c[_0xf4c6('0x41')]);var _0x301417={'where':_0x1d03e2[_0xf4c6('0x3c')]};return db[_0xf4c6('0x2d')][_0xf4c6('0x1f')](_0x301417)[_0xf4c6('0x25')](function(_0xe6773b){_0x2dc0b1[_0xf4c6('0x1f')]=_0xe6773b;if(_0x18ac4c[_0xf4c6('0x33')]['includeAll']){_0x1d03e2['include']=[{'all':!![]}];}return db[_0xf4c6('0x2d')][_0xf4c6('0x42')](_0x1d03e2);})['then'](function(_0x3f18b0){_0x2dc0b1[_0xf4c6('0x43')]=_0x3f18b0;return _0x2dc0b1;})['then'](respondWithFilteredResult(_0xdde7d8,_0x1d03e2))[_0xf4c6('0x44')](handleError(_0xdde7d8,null));};exports[_0xf4c6('0x45')]=function(_0x355bcc,_0x38329a){var _0x33b292={'raw':![],'where':{'id':_0x355bcc[_0xf4c6('0x46')]['id']}},_0x2ef48f={};_0x2ef48f[_0xf4c6('0x31')]=_[_0xf4c6('0x32')](db[_0xf4c6('0x2d')][_0xf4c6('0x2e')]);_0x2ef48f['query']=_['keys'](_0x355bcc['query']);_0x2ef48f[_0xf4c6('0x34')]=_['intersection'](_0x2ef48f[_0xf4c6('0x31')],_0x2ef48f[_0xf4c6('0x33')]);_0x33b292[_0xf4c6('0x35')]=_[_0xf4c6('0x36')](_0x2ef48f[_0xf4c6('0x31')],qs[_0xf4c6('0x37')](_0x355bcc[_0xf4c6('0x33')]['fields']));_0x33b292[_0xf4c6('0x35')]=_0x33b292[_0xf4c6('0x35')][_0xf4c6('0x38')]?_0x33b292[_0xf4c6('0x35')]:_0x2ef48f[_0xf4c6('0x31')];if(_0x355bcc[_0xf4c6('0x33')][_0xf4c6('0x47')]){_0x33b292['include']=[{'all':!![]}];}_0x33b292=_[_0xf4c6('0x3f')]({},_0x33b292,_0x355bcc[_0xf4c6('0x41')]);return db[_0xf4c6('0x2d')][_0xf4c6('0x48')](_0x33b292)[_0xf4c6('0x25')](handleEntityNotFound(_0x38329a,null))[_0xf4c6('0x25')](respondWithResult(_0x38329a,null))[_0xf4c6('0x44')](handleError(_0x38329a,null));};exports['create']=function(_0x34a7c0,_0x59b09){return db[_0xf4c6('0x2d')][_0xf4c6('0x49')](_0x34a7c0['body'],{})['then'](respondWithResult(_0x59b09,0xc9))[_0xf4c6('0x44')](handleError(_0x59b09,null));};exports[_0xf4c6('0x23')]=function(_0x128e34,_0x10ecd6){if(_0x128e34[_0xf4c6('0x4a')]['id']){delete _0x128e34['body']['id'];}return db['FreshsalesAccount'][_0xf4c6('0x48')]({'where':{'id':_0x128e34[_0xf4c6('0x46')]['id']}})[_0xf4c6('0x25')](handleEntityNotFound(_0x10ecd6,null))['then'](saveUpdates(_0x128e34[_0xf4c6('0x4a')],null))[_0xf4c6('0x25')](respondWithResult(_0x10ecd6,null))[_0xf4c6('0x44')](handleError(_0x10ecd6,null));};exports['destroy']=function(_0x17469f,_0x5b607c){return db[_0xf4c6('0x2d')][_0xf4c6('0x48')]({'where':{'id':_0x17469f['params']['id']}})[_0xf4c6('0x25')](handleEntityNotFound(_0x5b607c,null))['then'](removeEntity(_0x5b607c,null))[_0xf4c6('0x44')](handleError(_0x5b607c,null));};exports['getConfigurations']=function(_0xc1651d,_0x26b971,_0x362d05){var _0x1c37c0={};var _0x264085={};var _0x313e94;var _0x154f7c;return db['FreshsalesAccount'][_0xf4c6('0x4b')]({'where':{'id':_0xc1651d[_0xf4c6('0x46')]['id']}})[_0xf4c6('0x25')](handleEntityNotFound(_0x26b971,null))[_0xf4c6('0x25')](function(_0x1e7fdb){if(_0x1e7fdb){_0x313e94=_0x1e7fdb;_0x264085['model']=_['keys'](db[_0xf4c6('0x4c')][_0xf4c6('0x2e')]);_0x264085[_0xf4c6('0x33')]=_['keys'](_0xc1651d[_0xf4c6('0x33')]);_0x264085[_0xf4c6('0x34')]=_['intersection'](_0x264085[_0xf4c6('0x31')],_0x264085[_0xf4c6('0x33')]);_0x1c37c0['attributes']=_[_0xf4c6('0x36')](_0x264085[_0xf4c6('0x31')],qs[_0xf4c6('0x37')](_0xc1651d['query']['fields']));_0x1c37c0['attributes']=_0x1c37c0[_0xf4c6('0x35')][_0xf4c6('0x38')]?_0x1c37c0[_0xf4c6('0x35')]:_0x264085[_0xf4c6('0x31')];_0x1c37c0[_0xf4c6('0x4d')]=qs[_0xf4c6('0x3b')](_0xc1651d[_0xf4c6('0x33')][_0xf4c6('0x3b')]);_0x1c37c0[_0xf4c6('0x3c')]=qs[_0xf4c6('0x34')](_[_0xf4c6('0x3d')](_0xc1651d[_0xf4c6('0x33')],_0x264085['filters']));if(_0xc1651d[_0xf4c6('0x33')][_0xf4c6('0x3e')]){_0x1c37c0[_0xf4c6('0x3c')]=_[_0xf4c6('0x3f')](_0x1c37c0[_0xf4c6('0x3c')],{'$or':_[_0xf4c6('0x2c')](_0x1c37c0[_0xf4c6('0x35')],function(_0x804bfa){var _0x119235={};_0x119235[_0x804bfa]={'$like':'%'+_0xc1651d['query'][_0xf4c6('0x3e')]+'%'};return _0x119235;})});}_0x1c37c0=_[_0xf4c6('0x3f')]({},_0x1c37c0,_0xc1651d[_0xf4c6('0x41')]);return _0x313e94['getConfigurations'](_0x1c37c0);}})[_0xf4c6('0x25')](function(_0x233417){if(_0x233417){_0x154f7c=_0x233417['length'];if(!_0xc1651d[_0xf4c6('0x33')][_0xf4c6('0x39')](_0xf4c6('0x3a'))){_0x1c37c0[_0xf4c6('0x1e')]=qs['limit'](_0xc1651d['query'][_0xf4c6('0x1e')]);_0x1c37c0['offset']=qs[_0xf4c6('0x1c')](_0xc1651d['query'][_0xf4c6('0x1c')]);}return _0x313e94[_0xf4c6('0x4e')](_0x1c37c0);}})['then'](function(_0x5ca79a){if(_0x5ca79a){return _0x5ca79a?{'count':_0x154f7c,'rows':_0x5ca79a}:null;}})['then'](respondWithResult(_0x26b971,null))[_0xf4c6('0x44')](handleError(_0x26b971,null));};exports[_0xf4c6('0x4f')]=function(_0x47a5b9,_0x51609f,_0x473aad){if(_0x47a5b9[_0xf4c6('0x4a')]['id']){delete _0x47a5b9[_0xf4c6('0x4a')]['id'];}return db[_0xf4c6('0x2d')][_0xf4c6('0x4b')]({'where':{'id':_0x47a5b9[_0xf4c6('0x46')]['id']}})['then'](handleEntityNotFound(_0x51609f,null))[_0xf4c6('0x25')](function(_0x452bdf){if(_0x452bdf){_0x47a5b9[_0xf4c6('0x4a')][_0xf4c6('0x50')]=_0x452bdf['id'];_0x47a5b9[_0xf4c6('0x4a')][_0xf4c6('0x51')]=integrations[_0xf4c6('0x52')](_0x47a5b9[_0xf4c6('0x4a')][_0xf4c6('0x53')],_0x47a5b9['body'][_0xf4c6('0x2f')]);_0x47a5b9[_0xf4c6('0x4a')][_0xf4c6('0x54')]=integrations['getDescriptions'](_0x47a5b9[_0xf4c6('0x4a')]['channel'],_0x47a5b9['body'][_0xf4c6('0x2f')]);return db[_0xf4c6('0x4c')][_0xf4c6('0x49')](_0x47a5b9['body'],{'include':[{'model':db['FreshsalesField'],'as':_0xf4c6('0x51')},{'model':db[_0xf4c6('0x55')],'as':_0xf4c6('0x54')}]});}return null;})[_0xf4c6('0x25')](respondWithResult(_0x51609f,null))['catch'](handleError(_0x51609f,null));};exports['getFields']=function(_0x79a3b2,_0x3b7599,_0x4a476b){var _0xa5df3c='';var _0x2da35a='';return db[_0xf4c6('0x2d')][_0xf4c6('0x4b')]({'where':{'id':_0x79a3b2[_0xf4c6('0x46')]['id']},'attributes':['id',_0xf4c6('0x56'),'remoteUri',_0xf4c6('0x57')]})[_0xf4c6('0x25')](handleEntityNotFound(_0x3b7599,null))[_0xf4c6('0x25')](function(_0x3694b3){if(_0x3694b3){_0x2da35a=_0x3694b3['username'];_0xa5df3c=_0x3694b3[_0xf4c6('0x58')];var _0x1e9e92=_0x3694b3[_0xf4c6('0x58')][_0xf4c6('0x59')](-0x1);if(_0x1e9e92==='/'){_0xa5df3c=_0xa5df3c[_0xf4c6('0x5a')](0x0,_0xa5df3c[_0xf4c6('0x5b')](_0x1e9e92));}return rp({'method':'GET','uri':util[_0xf4c6('0x5c')]('%s%s',_0xa5df3c,_0xf4c6('0x5d')),'headers':{'Authorization':_0xf4c6('0x5e')+_0x3694b3[_0xf4c6('0x57')]},'json':!![]});}})[_0xf4c6('0x25')](function(_0x291894){if(_0x291894){var _0x5bbfb7=_0x291894[_0xf4c6('0x5f')];var _0x463ae1=![];var _0x18f8ac=null;for(_0x18f8ac=0x0;_0x18f8ac<_0x5bbfb7[_0xf4c6('0x38')];_0x18f8ac++){if(_0x5bbfb7[_0x18f8ac][_0xf4c6('0x60')]===_0x2da35a){_0x463ae1=!![];}}if(_0x463ae1){return!![];}else{throw new Error({'statusCode':0x194,'message':'Requested\x20Resource\x20not\x20Found'});}}})['then'](respondWithResult(_0x3b7599,null))[_0xf4c6('0x44')](function(_0x20753f){var _0x38d4ca=_0x79a3b2[_0xf4c6('0x33')][_0xf4c6('0x61')]?0x1f4:_0x20753f[_0xf4c6('0x62')]||0x1f4;logger['error'](_0xf4c6('0x63'),_0xf4c6('0x64'),_0x38d4ca,JSON[_0xf4c6('0x65')](_0x20753f));delete _0x20753f[_0xf4c6('0x29')];if(_0x38d4ca===0x191){_0x38d4ca=0x190;}_0x3b7599[_0xf4c6('0x1a')](_0x38d4ca)['send'](_0x79a3b2[_0xf4c6('0x33')][_0xf4c6('0x61')]?{'message':'Wrong\x20credentials','statusCode':_0x20753f[_0xf4c6('0x62')]}:_0x20753f);});};
\ No newline at end of file