Built motion from commit b0a9a629.|2.6.33
[motion2.git] / server / api / intFreshsalesAccount / intFreshsalesAccount.controller.js
index fd8f5e8..294baa0 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0xf4f6=['type','key','model','query','keys','filters','intersection','attributes','fields','length','hasOwnProperty','nolimit','order','sort','where','pick','filter','VIRTUAL','merge','options','include','rows','catch','show','params','includeAll','create','body','find','getConfigurations','findOne','FreshsalesConfiguration','addConfiguration','getSubjects','channel','Descriptions','getDescriptions','FreshsalesField','Subjects','username','remoteUri','GET','format','/api/selector/owners','apiKey','users','test','statusCode','getFields,\x20%s,\x20%s,\x20%s','getFields','stringify','send','eml-format','rimraf','zip-dir','fast-json-patch','request-promise','moment','bluebird','mustache','util','path','ejs','fs-extra','lodash','squel','crypto','desk.js','to-csv','querystring','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','api','../../config/utils','../../config/license/util','../../mysqldb','../../components/integrations/configuration','sendStatus','status','end','json','offset','undefined','count','limit','set','Content-Range','apply','reject','save','update','then','destroy','error','stack','name','index','map','FreshsalesAccount','rawAttributes','fieldName'];(function(_0x4d578c,_0x4d2ed2){var _0xf41cac=function(_0x4edde3){while(--_0x4edde3){_0x4d578c['push'](_0x4d578c['shift']());}};_0xf41cac(++_0x4d2ed2);}(_0xf4f6,0x16c));var _0x6f4f=function(_0xa148b7,_0x2f3eb2){_0xa148b7=_0xa148b7-0x0;var _0x51efd3=_0xf4f6[_0xa148b7];return _0x51efd3;};'use strict';var emlformat=require(_0x6f4f('0x0'));var rimraf=require(_0x6f4f('0x1'));var zipdir=require(_0x6f4f('0x2'));var jsonpatch=require(_0x6f4f('0x3'));var rp=require(_0x6f4f('0x4'));var moment=require(_0x6f4f('0x5'));var BPromise=require(_0x6f4f('0x6'));var Mustache=require(_0x6f4f('0x7'));var util=require(_0x6f4f('0x8'));var path=require(_0x6f4f('0x9'));var sox=require('sox');var csv=require('to-csv');var ejs=require(_0x6f4f('0xa'));var fs=require('fs');var fs_extra=require(_0x6f4f('0xb'));var _=require(_0x6f4f('0xc'));var squel=require(_0x6f4f('0xd'));var crypto=require(_0x6f4f('0xe'));var jsforce=require('jsforce');var deskjs=require(_0x6f4f('0xf'));var toCsv=require(_0x6f4f('0x10'));var querystring=require(_0x6f4f('0x11'));var Papa=require('papaparse');var Redis=require('ioredis');var authService=require(_0x6f4f('0x12'));var qs=require(_0x6f4f('0x13'));var as=require(_0x6f4f('0x14'));var hardwareService=require(_0x6f4f('0x15'));var logger=require(_0x6f4f('0x16'))(_0x6f4f('0x17'));var utils=require(_0x6f4f('0x18'));var config=require('../../config/environment');var licenseUtil=require(_0x6f4f('0x19'));var db=require(_0x6f4f('0x1a'))['db'];var integrations=require(_0x6f4f('0x1b'));function respondWithStatusCode(_0x363391,_0x2b12f8){_0x2b12f8=_0x2b12f8||0xcc;return function(_0x1c5f0d){if(_0x1c5f0d){return _0x363391[_0x6f4f('0x1c')](_0x2b12f8);}return _0x363391[_0x6f4f('0x1d')](_0x2b12f8)[_0x6f4f('0x1e')]();};}function respondWithResult(_0x4fa903,_0x44342a){_0x44342a=_0x44342a||0xc8;return function(_0x36607b){if(_0x36607b){return _0x4fa903[_0x6f4f('0x1d')](_0x44342a)[_0x6f4f('0x1f')](_0x36607b);}};}function respondWithFilteredResult(_0xf65e08,_0x114e61){return function(_0x24f619){if(_0x24f619){var _0xf3b4af=typeof _0x114e61[_0x6f4f('0x20')]==='undefined'&&typeof _0x114e61['limit']===_0x6f4f('0x21');var _0x1c243a=_0x24f619['count'];var _0x4a3e11=_0xf3b4af?0x0:_0x114e61[_0x6f4f('0x20')];var _0x3a831d=_0xf3b4af?_0x24f619[_0x6f4f('0x22')]:_0x114e61['offset']+_0x114e61[_0x6f4f('0x23')];var _0x262861;if(_0x3a831d>=_0x1c243a){_0x3a831d=_0x1c243a;_0x262861=0xc8;}else{_0x262861=0xce;}_0xf65e08['status'](_0x262861);return _0xf65e08[_0x6f4f('0x24')](_0x6f4f('0x25'),_0x4a3e11+'-'+_0x3a831d+'/'+_0x1c243a)[_0x6f4f('0x1f')](_0x24f619);}return null;};}function patchUpdates(_0x4a00d9){return function(_0x3b76f5){try{jsonpatch[_0x6f4f('0x26')](_0x3b76f5,_0x4a00d9,!![]);}catch(_0x2642f1){return BPromise[_0x6f4f('0x27')](_0x2642f1);}return _0x3b76f5[_0x6f4f('0x28')]();};}function saveUpdates(_0x266d3a,_0x40a497){return function(_0x392d53){if(_0x392d53){return _0x392d53[_0x6f4f('0x29')](_0x266d3a)[_0x6f4f('0x2a')](function(_0x2d3c35){return _0x2d3c35;});}return null;};}function removeEntity(_0x89f23d,_0x2f43d4){return function(_0x22c90a){if(_0x22c90a){return _0x22c90a[_0x6f4f('0x2b')]()[_0x6f4f('0x2a')](function(){_0x89f23d['status'](0xcc)[_0x6f4f('0x1e')]();});}};}function handleEntityNotFound(_0x2540d2,_0xc59bf7){return function(_0x1dded){if(!_0x1dded){_0x2540d2[_0x6f4f('0x1c')](0x194);}return _0x1dded;};}function handleError(_0x700f1d,_0x1b6016){_0x1b6016=_0x1b6016||0x1f4;return function(_0xa89e95){logger[_0x6f4f('0x2c')](_0xa89e95[_0x6f4f('0x2d')]);if(_0xa89e95[_0x6f4f('0x2e')]){delete _0xa89e95['name'];}_0x700f1d[_0x6f4f('0x1d')](_0x1b6016)['send'](_0xa89e95);};}exports[_0x6f4f('0x2f')]=function(_0x521cdc,_0x436ed6){var _0x190e5e={},_0x30ea67={},_0x1caf71={'count':0x0,'rows':[]};var _0x59b276=_[_0x6f4f('0x30')](db[_0x6f4f('0x31')][_0x6f4f('0x32')],function(_0x47e1ad){return{'name':_0x47e1ad[_0x6f4f('0x33')],'type':_0x47e1ad[_0x6f4f('0x34')][_0x6f4f('0x35')]};});_0x30ea67[_0x6f4f('0x36')]=_[_0x6f4f('0x30')](_0x59b276,_0x6f4f('0x2e'));_0x30ea67[_0x6f4f('0x37')]=_[_0x6f4f('0x38')](_0x521cdc[_0x6f4f('0x37')]);_0x30ea67[_0x6f4f('0x39')]=_[_0x6f4f('0x3a')](_0x30ea67[_0x6f4f('0x36')],_0x30ea67[_0x6f4f('0x37')]);_0x190e5e[_0x6f4f('0x3b')]=_[_0x6f4f('0x3a')](_0x30ea67[_0x6f4f('0x36')],qs[_0x6f4f('0x3c')](_0x521cdc[_0x6f4f('0x37')][_0x6f4f('0x3c')]));_0x190e5e[_0x6f4f('0x3b')]=_0x190e5e[_0x6f4f('0x3b')][_0x6f4f('0x3d')]?_0x190e5e[_0x6f4f('0x3b')]:_0x30ea67[_0x6f4f('0x36')];if(!_0x521cdc[_0x6f4f('0x37')][_0x6f4f('0x3e')](_0x6f4f('0x3f'))){_0x190e5e[_0x6f4f('0x23')]=qs[_0x6f4f('0x23')](_0x521cdc['query'][_0x6f4f('0x23')]);_0x190e5e[_0x6f4f('0x20')]=qs[_0x6f4f('0x20')](_0x521cdc[_0x6f4f('0x37')][_0x6f4f('0x20')]);}_0x190e5e[_0x6f4f('0x40')]=qs[_0x6f4f('0x41')](_0x521cdc[_0x6f4f('0x37')][_0x6f4f('0x41')]);_0x190e5e[_0x6f4f('0x42')]=qs[_0x6f4f('0x39')](_[_0x6f4f('0x43')](_0x521cdc[_0x6f4f('0x37')],_0x30ea67[_0x6f4f('0x39')]),_0x59b276);if(_0x521cdc[_0x6f4f('0x37')][_0x6f4f('0x44')]){_0x190e5e[_0x6f4f('0x42')]=_['merge'](_0x190e5e[_0x6f4f('0x42')],{'$or':_[_0x6f4f('0x30')](_0x59b276,function(_0x57a7e8){if(_0x57a7e8[_0x6f4f('0x34')]!==_0x6f4f('0x45')){var _0x41c2ec={};_0x41c2ec[_0x57a7e8[_0x6f4f('0x2e')]]={'$like':'%'+_0x521cdc[_0x6f4f('0x37')][_0x6f4f('0x44')]+'%'};return _0x41c2ec;}})});}_0x190e5e=_[_0x6f4f('0x46')]({},_0x190e5e,_0x521cdc[_0x6f4f('0x47')]);var _0x5c7e8a={'where':_0x190e5e['where']};return db[_0x6f4f('0x31')][_0x6f4f('0x22')](_0x5c7e8a)[_0x6f4f('0x2a')](function(_0x281aaf){_0x1caf71['count']=_0x281aaf;if(_0x521cdc[_0x6f4f('0x37')]['includeAll']){_0x190e5e[_0x6f4f('0x48')]=[{'all':!![]}];}return db[_0x6f4f('0x31')]['findAll'](_0x190e5e);})[_0x6f4f('0x2a')](function(_0x10e969){_0x1caf71[_0x6f4f('0x49')]=_0x10e969;return _0x1caf71;})['then'](respondWithFilteredResult(_0x436ed6,_0x190e5e))[_0x6f4f('0x4a')](handleError(_0x436ed6,null));};exports[_0x6f4f('0x4b')]=function(_0x532a85,_0x59d080){var _0x106df9={'raw':![],'where':{'id':_0x532a85[_0x6f4f('0x4c')]['id']}},_0x3e8bb5={};_0x3e8bb5[_0x6f4f('0x36')]=_['keys'](db[_0x6f4f('0x31')][_0x6f4f('0x32')]);_0x3e8bb5[_0x6f4f('0x37')]=_['keys'](_0x532a85[_0x6f4f('0x37')]);_0x3e8bb5[_0x6f4f('0x39')]=_['intersection'](_0x3e8bb5['model'],_0x3e8bb5[_0x6f4f('0x37')]);_0x106df9[_0x6f4f('0x3b')]=_[_0x6f4f('0x3a')](_0x3e8bb5[_0x6f4f('0x36')],qs[_0x6f4f('0x3c')](_0x532a85[_0x6f4f('0x37')]['fields']));_0x106df9[_0x6f4f('0x3b')]=_0x106df9[_0x6f4f('0x3b')][_0x6f4f('0x3d')]?_0x106df9[_0x6f4f('0x3b')]:_0x3e8bb5[_0x6f4f('0x36')];if(_0x532a85[_0x6f4f('0x37')][_0x6f4f('0x4d')]){_0x106df9[_0x6f4f('0x48')]=[{'all':!![]}];}_0x106df9=_['merge']({},_0x106df9,_0x532a85['options']);return db[_0x6f4f('0x31')]['find'](_0x106df9)[_0x6f4f('0x2a')](handleEntityNotFound(_0x59d080,null))[_0x6f4f('0x2a')](respondWithResult(_0x59d080,null))[_0x6f4f('0x4a')](handleError(_0x59d080,null));};exports[_0x6f4f('0x4e')]=function(_0x280b7e,_0x334a8e){return db['FreshsalesAccount'][_0x6f4f('0x4e')](_0x280b7e[_0x6f4f('0x4f')],{})[_0x6f4f('0x2a')](respondWithResult(_0x334a8e,0xc9))['catch'](handleError(_0x334a8e,null));};exports[_0x6f4f('0x29')]=function(_0x1f5282,_0xbe5eb5){if(_0x1f5282[_0x6f4f('0x4f')]['id']){delete _0x1f5282[_0x6f4f('0x4f')]['id'];}return db[_0x6f4f('0x31')][_0x6f4f('0x50')]({'where':{'id':_0x1f5282[_0x6f4f('0x4c')]['id']}})[_0x6f4f('0x2a')](handleEntityNotFound(_0xbe5eb5,null))[_0x6f4f('0x2a')](saveUpdates(_0x1f5282[_0x6f4f('0x4f')],null))[_0x6f4f('0x2a')](respondWithResult(_0xbe5eb5,null))['catch'](handleError(_0xbe5eb5,null));};exports['destroy']=function(_0x571f4b,_0x5bb21e){return db['FreshsalesAccount']['find']({'where':{'id':_0x571f4b['params']['id']}})[_0x6f4f('0x2a')](handleEntityNotFound(_0x5bb21e,null))[_0x6f4f('0x2a')](removeEntity(_0x5bb21e,null))[_0x6f4f('0x4a')](handleError(_0x5bb21e,null));};exports[_0x6f4f('0x51')]=function(_0x5b06a2,_0x47be5a,_0x54c5c2){var _0x14a1cb={};var _0x2ddff2={};var _0x465833;var _0x469931;return db[_0x6f4f('0x31')][_0x6f4f('0x52')]({'where':{'id':_0x5b06a2[_0x6f4f('0x4c')]['id']}})[_0x6f4f('0x2a')](handleEntityNotFound(_0x47be5a,null))[_0x6f4f('0x2a')](function(_0x4cdb0c){if(_0x4cdb0c){_0x465833=_0x4cdb0c;_0x2ddff2[_0x6f4f('0x36')]=_[_0x6f4f('0x38')](db[_0x6f4f('0x53')][_0x6f4f('0x32')]);_0x2ddff2[_0x6f4f('0x37')]=_[_0x6f4f('0x38')](_0x5b06a2[_0x6f4f('0x37')]);_0x2ddff2[_0x6f4f('0x39')]=_[_0x6f4f('0x3a')](_0x2ddff2[_0x6f4f('0x36')],_0x2ddff2[_0x6f4f('0x37')]);_0x14a1cb[_0x6f4f('0x3b')]=_[_0x6f4f('0x3a')](_0x2ddff2[_0x6f4f('0x36')],qs['fields'](_0x5b06a2[_0x6f4f('0x37')][_0x6f4f('0x3c')]));_0x14a1cb[_0x6f4f('0x3b')]=_0x14a1cb[_0x6f4f('0x3b')][_0x6f4f('0x3d')]?_0x14a1cb[_0x6f4f('0x3b')]:_0x2ddff2[_0x6f4f('0x36')];_0x14a1cb[_0x6f4f('0x40')]=qs['sort'](_0x5b06a2[_0x6f4f('0x37')][_0x6f4f('0x41')]);_0x14a1cb[_0x6f4f('0x42')]=qs['filters'](_['pick'](_0x5b06a2[_0x6f4f('0x37')],_0x2ddff2['filters']));if(_0x5b06a2['query'][_0x6f4f('0x44')]){_0x14a1cb[_0x6f4f('0x42')]=_['merge'](_0x14a1cb[_0x6f4f('0x42')],{'$or':_[_0x6f4f('0x30')](_0x14a1cb[_0x6f4f('0x3b')],function(_0x192b81){var _0x275ce4={};_0x275ce4[_0x192b81]={'$like':'%'+_0x5b06a2['query'][_0x6f4f('0x44')]+'%'};return _0x275ce4;})});}_0x14a1cb=_[_0x6f4f('0x46')]({},_0x14a1cb,_0x5b06a2[_0x6f4f('0x47')]);return _0x465833[_0x6f4f('0x51')](_0x14a1cb);}})[_0x6f4f('0x2a')](function(_0x3f6e44){if(_0x3f6e44){_0x469931=_0x3f6e44[_0x6f4f('0x3d')];if(!_0x5b06a2[_0x6f4f('0x37')]['hasOwnProperty'](_0x6f4f('0x3f'))){_0x14a1cb[_0x6f4f('0x23')]=qs[_0x6f4f('0x23')](_0x5b06a2['query'][_0x6f4f('0x23')]);_0x14a1cb[_0x6f4f('0x20')]=qs[_0x6f4f('0x20')](_0x5b06a2[_0x6f4f('0x37')][_0x6f4f('0x20')]);}return _0x465833[_0x6f4f('0x51')](_0x14a1cb);}})[_0x6f4f('0x2a')](function(_0x445557){if(_0x445557){return _0x445557?{'count':_0x469931,'rows':_0x445557}:null;}})['then'](respondWithResult(_0x47be5a,null))[_0x6f4f('0x4a')](handleError(_0x47be5a,null));};exports[_0x6f4f('0x54')]=function(_0x5f0f0c,_0xc4fa66,_0x459d64){if(_0x5f0f0c[_0x6f4f('0x4f')]['id']){delete _0x5f0f0c[_0x6f4f('0x4f')]['id'];}return db[_0x6f4f('0x31')]['findOne']({'where':{'id':_0x5f0f0c[_0x6f4f('0x4c')]['id']}})[_0x6f4f('0x2a')](handleEntityNotFound(_0xc4fa66,null))[_0x6f4f('0x2a')](function(_0x46fb1){if(_0x46fb1){_0x5f0f0c['body']['AccountId']=_0x46fb1['id'];_0x5f0f0c['body']['Subjects']=integrations[_0x6f4f('0x55')](_0x5f0f0c[_0x6f4f('0x4f')][_0x6f4f('0x56')],_0x5f0f0c[_0x6f4f('0x4f')][_0x6f4f('0x34')]);_0x5f0f0c[_0x6f4f('0x4f')][_0x6f4f('0x57')]=integrations[_0x6f4f('0x58')](_0x5f0f0c[_0x6f4f('0x4f')]['channel'],_0x5f0f0c[_0x6f4f('0x4f')]['type']);return db[_0x6f4f('0x53')][_0x6f4f('0x4e')](_0x5f0f0c[_0x6f4f('0x4f')],{'include':[{'model':db[_0x6f4f('0x59')],'as':_0x6f4f('0x5a')},{'model':db['FreshsalesField'],'as':_0x6f4f('0x57')}]});}return null;})[_0x6f4f('0x2a')](respondWithResult(_0xc4fa66,null))['catch'](handleError(_0xc4fa66,null));};exports['getFields']=function(_0x2d2b35,_0x319726,_0x276148){var _0x6af37e='';var _0x1fd2ed='';return db['FreshsalesAccount'][_0x6f4f('0x52')]({'where':{'id':_0x2d2b35[_0x6f4f('0x4c')]['id']},'attributes':['id',_0x6f4f('0x5b'),_0x6f4f('0x5c'),'apiKey']})['then'](handleEntityNotFound(_0x319726,null))['then'](function(_0x36f34d){if(_0x36f34d){_0x1fd2ed=_0x36f34d['username'];_0x6af37e=_0x36f34d['remoteUri'];var _0x2f4e7a=_0x36f34d[_0x6f4f('0x5c')]['slice'](-0x1);if(_0x2f4e7a==='/'){_0x6af37e=_0x6af37e['substring'](0x0,_0x6af37e['lastIndexOf'](_0x2f4e7a));}return rp({'method':_0x6f4f('0x5d'),'uri':util[_0x6f4f('0x5e')]('%s%s',_0x6af37e,_0x6f4f('0x5f')),'headers':{'Authorization':'Token\x20token='+_0x36f34d[_0x6f4f('0x60')]},'json':!![]});}})[_0x6f4f('0x2a')](function(_0x1594cf){if(_0x1594cf){var _0x47aafc=_0x1594cf[_0x6f4f('0x61')];var _0x32212f=![];var _0x46ece2=null;for(_0x46ece2=0x0;_0x46ece2<_0x47aafc[_0x6f4f('0x3d')];_0x46ece2++){if(_0x47aafc[_0x46ece2]['email']===_0x1fd2ed){_0x32212f=!![];}}if(_0x32212f){return!![];}else{throw new Error({'statusCode':0x194,'message':'Requested\x20Resource\x20not\x20Found'});}}})[_0x6f4f('0x2a')](respondWithResult(_0x319726,null))[_0x6f4f('0x4a')](function(_0x2dc0fb){var _0x2fd50b=_0x2d2b35['query'][_0x6f4f('0x62')]?0x1f4:_0x2dc0fb[_0x6f4f('0x63')]||0x1f4;logger['error'](_0x6f4f('0x64'),_0x6f4f('0x65'),_0x2fd50b,JSON[_0x6f4f('0x66')](_0x2dc0fb));delete _0x2dc0fb[_0x6f4f('0x2e')];if(_0x2fd50b===0x191){_0x2fd50b=0x190;}_0x319726[_0x6f4f('0x1d')](_0x2fd50b)[_0x6f4f('0x67')](_0x2d2b35[_0x6f4f('0x37')][_0x6f4f('0x62')]?{'message':'Wrong\x20credentials','statusCode':_0x2dc0fb[_0x6f4f('0x63')]}:_0x2dc0fb);});};
\ No newline at end of file
+var _0x8980=['hasOwnProperty','addConfiguration','AccountId','getSubjects','channel','getDescriptions','FreshsalesField','Subjects','Descriptions','getFields','username','remoteUri','apiKey','slice','lastIndexOf','format','/api/selector/owners','users','Requested\x20Resource\x20not\x20Found','statusCode','error','getFields,\x20%s,\x20%s,\x20%s','stringify','test','Wrong\x20credentials','eml-format','rimraf','fast-json-patch','request-promise','moment','bluebird','mustache','util','path','sox','to-csv','ejs','fs-extra','lodash','squel','crypto','desk.js','querystring','papaparse','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','api','../../config/utils','../../config/environment','../../config/license/util','../../components/integrations/configuration','status','json','undefined','count','offset','limit','set','reject','save','update','then','destroy','end','sendStatus','name','send','index','FreshsalesAccount','rawAttributes','type','model','map','query','keys','filters','intersection','attributes','fields','length','nolimit','sort','where','pick','filter','merge','VIRTUAL','options','include','findAll','rows','catch','show','params','includeAll','find','create','body','findOne','order','getConfigurations'];(function(_0x20a584,_0xe384a5){var _0x4b41a8=function(_0x2127c6){while(--_0x2127c6){_0x20a584['push'](_0x20a584['shift']());}};_0x4b41a8(++_0xe384a5);}(_0x8980,0x82));var _0x0898=function(_0x1d4aa8,_0x177c03){_0x1d4aa8=_0x1d4aa8-0x0;var _0x1d9b0f=_0x8980[_0x1d4aa8];return _0x1d9b0f;};'use strict';var emlformat=require(_0x0898('0x0'));var rimraf=require(_0x0898('0x1'));var zipdir=require('zip-dir');var jsonpatch=require(_0x0898('0x2'));var rp=require(_0x0898('0x3'));var moment=require(_0x0898('0x4'));var BPromise=require(_0x0898('0x5'));var Mustache=require(_0x0898('0x6'));var util=require(_0x0898('0x7'));var path=require(_0x0898('0x8'));var sox=require(_0x0898('0x9'));var csv=require(_0x0898('0xa'));var ejs=require(_0x0898('0xb'));var fs=require('fs');var fs_extra=require(_0x0898('0xc'));var _=require(_0x0898('0xd'));var squel=require(_0x0898('0xe'));var crypto=require(_0x0898('0xf'));var jsforce=require('jsforce');var deskjs=require(_0x0898('0x10'));var toCsv=require(_0x0898('0xa'));var querystring=require(_0x0898('0x11'));var Papa=require(_0x0898('0x12'));var Redis=require(_0x0898('0x13'));var authService=require(_0x0898('0x14'));var qs=require(_0x0898('0x15'));var as=require(_0x0898('0x16'));var hardwareService=require(_0x0898('0x17'));var logger=require(_0x0898('0x18'))(_0x0898('0x19'));var utils=require(_0x0898('0x1a'));var config=require(_0x0898('0x1b'));var licenseUtil=require(_0x0898('0x1c'));var db=require('../../mysqldb')['db'];var integrations=require(_0x0898('0x1d'));function respondWithStatusCode(_0x2b5047,_0x55681f){_0x55681f=_0x55681f||0xcc;return function(_0x159d76){if(_0x159d76){return _0x2b5047['sendStatus'](_0x55681f);}return _0x2b5047[_0x0898('0x1e')](_0x55681f)['end']();};}function respondWithResult(_0x2e95fd,_0x200800){_0x200800=_0x200800||0xc8;return function(_0x4c4294){if(_0x4c4294){return _0x2e95fd[_0x0898('0x1e')](_0x200800)[_0x0898('0x1f')](_0x4c4294);}};}function respondWithFilteredResult(_0x2e9c68,_0x3d9b81){return function(_0x30be4e){if(_0x30be4e){var _0x5195fa=typeof _0x3d9b81['offset']==='undefined'&&typeof _0x3d9b81['limit']===_0x0898('0x20');var _0x36a195=_0x30be4e[_0x0898('0x21')];var _0x1686f3=_0x5195fa?0x0:_0x3d9b81[_0x0898('0x22')];var _0x41c42d=_0x5195fa?_0x30be4e[_0x0898('0x21')]:_0x3d9b81['offset']+_0x3d9b81[_0x0898('0x23')];var _0x468c53;if(_0x41c42d>=_0x36a195){_0x41c42d=_0x36a195;_0x468c53=0xc8;}else{_0x468c53=0xce;}_0x2e9c68[_0x0898('0x1e')](_0x468c53);return _0x2e9c68[_0x0898('0x24')]('Content-Range',_0x1686f3+'-'+_0x41c42d+'/'+_0x36a195)[_0x0898('0x1f')](_0x30be4e);}return null;};}function patchUpdates(_0x4471eb){return function(_0x5034c1){try{jsonpatch['apply'](_0x5034c1,_0x4471eb,!![]);}catch(_0x51a04e){return BPromise[_0x0898('0x25')](_0x51a04e);}return _0x5034c1[_0x0898('0x26')]();};}function saveUpdates(_0x5b36d9,_0x14bfc4){return function(_0x56fcae){if(_0x56fcae){return _0x56fcae[_0x0898('0x27')](_0x5b36d9)[_0x0898('0x28')](function(_0xffcb33){return _0xffcb33;});}return null;};}function removeEntity(_0x550d08,_0x5d6e6f){return function(_0x4f8c4d){if(_0x4f8c4d){return _0x4f8c4d[_0x0898('0x29')]()[_0x0898('0x28')](function(){_0x550d08[_0x0898('0x1e')](0xcc)[_0x0898('0x2a')]();});}};}function handleEntityNotFound(_0x3f49e9,_0x5e7bdb){return function(_0x45999b){if(!_0x45999b){_0x3f49e9[_0x0898('0x2b')](0x194);}return _0x45999b;};}function handleError(_0x1f967d,_0x358c34){_0x358c34=_0x358c34||0x1f4;return function(_0x5973b1){logger['error'](_0x5973b1['stack']);if(_0x5973b1[_0x0898('0x2c')]){delete _0x5973b1[_0x0898('0x2c')];}_0x1f967d[_0x0898('0x1e')](_0x358c34)[_0x0898('0x2d')](_0x5973b1);};}exports[_0x0898('0x2e')]=function(_0x2ddbdb,_0x5e57d8){var _0x1a611c={},_0x5f01cf={},_0x38be48={'count':0x0,'rows':[]};var _0x3aedb1=_['map'](db[_0x0898('0x2f')][_0x0898('0x30')],function(_0x2fa9cb){return{'name':_0x2fa9cb['fieldName'],'type':_0x2fa9cb[_0x0898('0x31')]['key']};});_0x5f01cf[_0x0898('0x32')]=_[_0x0898('0x33')](_0x3aedb1,'name');_0x5f01cf[_0x0898('0x34')]=_[_0x0898('0x35')](_0x2ddbdb[_0x0898('0x34')]);_0x5f01cf[_0x0898('0x36')]=_[_0x0898('0x37')](_0x5f01cf[_0x0898('0x32')],_0x5f01cf['query']);_0x1a611c[_0x0898('0x38')]=_[_0x0898('0x37')](_0x5f01cf['model'],qs['fields'](_0x2ddbdb[_0x0898('0x34')][_0x0898('0x39')]));_0x1a611c['attributes']=_0x1a611c['attributes'][_0x0898('0x3a')]?_0x1a611c[_0x0898('0x38')]:_0x5f01cf['model'];if(!_0x2ddbdb[_0x0898('0x34')]['hasOwnProperty'](_0x0898('0x3b'))){_0x1a611c[_0x0898('0x23')]=qs['limit'](_0x2ddbdb[_0x0898('0x34')]['limit']);_0x1a611c['offset']=qs[_0x0898('0x22')](_0x2ddbdb['query'][_0x0898('0x22')]);}_0x1a611c['order']=qs[_0x0898('0x3c')](_0x2ddbdb['query'][_0x0898('0x3c')]);_0x1a611c[_0x0898('0x3d')]=qs['filters'](_[_0x0898('0x3e')](_0x2ddbdb['query'],_0x5f01cf[_0x0898('0x36')]),_0x3aedb1);if(_0x2ddbdb[_0x0898('0x34')][_0x0898('0x3f')]){_0x1a611c[_0x0898('0x3d')]=_[_0x0898('0x40')](_0x1a611c[_0x0898('0x3d')],{'$or':_[_0x0898('0x33')](_0x3aedb1,function(_0x604a75){if(_0x604a75['type']!==_0x0898('0x41')){var _0x1b0d4c={};_0x1b0d4c[_0x604a75['name']]={'$like':'%'+_0x2ddbdb[_0x0898('0x34')][_0x0898('0x3f')]+'%'};return _0x1b0d4c;}})});}_0x1a611c=_[_0x0898('0x40')]({},_0x1a611c,_0x2ddbdb[_0x0898('0x42')]);var _0x42f0b6={'where':_0x1a611c['where']};return db[_0x0898('0x2f')][_0x0898('0x21')](_0x42f0b6)[_0x0898('0x28')](function(_0x4c089a){_0x38be48[_0x0898('0x21')]=_0x4c089a;if(_0x2ddbdb[_0x0898('0x34')]['includeAll']){_0x1a611c[_0x0898('0x43')]=[{'all':!![]}];}return db['FreshsalesAccount'][_0x0898('0x44')](_0x1a611c);})[_0x0898('0x28')](function(_0x8c1f07){_0x38be48[_0x0898('0x45')]=_0x8c1f07;return _0x38be48;})['then'](respondWithFilteredResult(_0x5e57d8,_0x1a611c))[_0x0898('0x46')](handleError(_0x5e57d8,null));};exports[_0x0898('0x47')]=function(_0x1b035c,_0x4c44d3){var _0x29e311={'raw':![],'where':{'id':_0x1b035c[_0x0898('0x48')]['id']}},_0xc2d88={};_0xc2d88[_0x0898('0x32')]=_[_0x0898('0x35')](db['FreshsalesAccount']['rawAttributes']);_0xc2d88[_0x0898('0x34')]=_['keys'](_0x1b035c[_0x0898('0x34')]);_0xc2d88[_0x0898('0x36')]=_[_0x0898('0x37')](_0xc2d88[_0x0898('0x32')],_0xc2d88[_0x0898('0x34')]);_0x29e311[_0x0898('0x38')]=_['intersection'](_0xc2d88[_0x0898('0x32')],qs['fields'](_0x1b035c[_0x0898('0x34')][_0x0898('0x39')]));_0x29e311[_0x0898('0x38')]=_0x29e311[_0x0898('0x38')][_0x0898('0x3a')]?_0x29e311['attributes']:_0xc2d88['model'];if(_0x1b035c[_0x0898('0x34')][_0x0898('0x49')]){_0x29e311['include']=[{'all':!![]}];}_0x29e311=_[_0x0898('0x40')]({},_0x29e311,_0x1b035c[_0x0898('0x42')]);return db['FreshsalesAccount'][_0x0898('0x4a')](_0x29e311)['then'](handleEntityNotFound(_0x4c44d3,null))['then'](respondWithResult(_0x4c44d3,null))[_0x0898('0x46')](handleError(_0x4c44d3,null));};exports['create']=function(_0x50d610,_0x492013){return db[_0x0898('0x2f')][_0x0898('0x4b')](_0x50d610[_0x0898('0x4c')],{})['then'](respondWithResult(_0x492013,0xc9))[_0x0898('0x46')](handleError(_0x492013,null));};exports[_0x0898('0x27')]=function(_0x272d1a,_0x271ad6){if(_0x272d1a[_0x0898('0x4c')]['id']){delete _0x272d1a[_0x0898('0x4c')]['id'];}return db[_0x0898('0x2f')][_0x0898('0x4a')]({'where':{'id':_0x272d1a[_0x0898('0x48')]['id']}})[_0x0898('0x28')](handleEntityNotFound(_0x271ad6,null))[_0x0898('0x28')](saveUpdates(_0x272d1a[_0x0898('0x4c')],null))[_0x0898('0x28')](respondWithResult(_0x271ad6,null))[_0x0898('0x46')](handleError(_0x271ad6,null));};exports['destroy']=function(_0x1a190a,_0x157219){return db[_0x0898('0x2f')][_0x0898('0x4a')]({'where':{'id':_0x1a190a[_0x0898('0x48')]['id']}})[_0x0898('0x28')](handleEntityNotFound(_0x157219,null))[_0x0898('0x28')](removeEntity(_0x157219,null))[_0x0898('0x46')](handleError(_0x157219,null));};exports['getConfigurations']=function(_0x4bfd98,_0xe17121,_0x5e1fdf){var _0xd819ba={};var _0x4f2af4={};var _0x2670c;var _0x4d94ec;return db['FreshsalesAccount'][_0x0898('0x4d')]({'where':{'id':_0x4bfd98[_0x0898('0x48')]['id']}})['then'](handleEntityNotFound(_0xe17121,null))[_0x0898('0x28')](function(_0x5532ec){if(_0x5532ec){_0x2670c=_0x5532ec;_0x4f2af4['model']=_['keys'](db['FreshsalesConfiguration']['rawAttributes']);_0x4f2af4[_0x0898('0x34')]=_['keys'](_0x4bfd98[_0x0898('0x34')]);_0x4f2af4[_0x0898('0x36')]=_[_0x0898('0x37')](_0x4f2af4[_0x0898('0x32')],_0x4f2af4[_0x0898('0x34')]);_0xd819ba['attributes']=_[_0x0898('0x37')](_0x4f2af4[_0x0898('0x32')],qs[_0x0898('0x39')](_0x4bfd98['query']['fields']));_0xd819ba[_0x0898('0x38')]=_0xd819ba[_0x0898('0x38')][_0x0898('0x3a')]?_0xd819ba['attributes']:_0x4f2af4['model'];_0xd819ba[_0x0898('0x4e')]=qs[_0x0898('0x3c')](_0x4bfd98[_0x0898('0x34')][_0x0898('0x3c')]);_0xd819ba['where']=qs[_0x0898('0x36')](_[_0x0898('0x3e')](_0x4bfd98[_0x0898('0x34')],_0x4f2af4[_0x0898('0x36')]));if(_0x4bfd98[_0x0898('0x34')][_0x0898('0x3f')]){_0xd819ba[_0x0898('0x3d')]=_['merge'](_0xd819ba[_0x0898('0x3d')],{'$or':_[_0x0898('0x33')](_0xd819ba[_0x0898('0x38')],function(_0xa19c44){var _0x23bd39={};_0x23bd39[_0xa19c44]={'$like':'%'+_0x4bfd98['query'][_0x0898('0x3f')]+'%'};return _0x23bd39;})});}_0xd819ba=_[_0x0898('0x40')]({},_0xd819ba,_0x4bfd98[_0x0898('0x42')]);return _0x2670c[_0x0898('0x4f')](_0xd819ba);}})[_0x0898('0x28')](function(_0x4667d8){if(_0x4667d8){_0x4d94ec=_0x4667d8[_0x0898('0x3a')];if(!_0x4bfd98[_0x0898('0x34')][_0x0898('0x50')]('nolimit')){_0xd819ba[_0x0898('0x23')]=qs[_0x0898('0x23')](_0x4bfd98[_0x0898('0x34')][_0x0898('0x23')]);_0xd819ba[_0x0898('0x22')]=qs[_0x0898('0x22')](_0x4bfd98[_0x0898('0x34')]['offset']);}return _0x2670c[_0x0898('0x4f')](_0xd819ba);}})[_0x0898('0x28')](function(_0x14c82b){if(_0x14c82b){return _0x14c82b?{'count':_0x4d94ec,'rows':_0x14c82b}:null;}})[_0x0898('0x28')](respondWithResult(_0xe17121,null))[_0x0898('0x46')](handleError(_0xe17121,null));};exports[_0x0898('0x51')]=function(_0x303fdd,_0x5dadde,_0x5caeae){if(_0x303fdd['body']['id']){delete _0x303fdd['body']['id'];}return db[_0x0898('0x2f')]['findOne']({'where':{'id':_0x303fdd[_0x0898('0x48')]['id']}})[_0x0898('0x28')](handleEntityNotFound(_0x5dadde,null))[_0x0898('0x28')](function(_0x44ebcf){if(_0x44ebcf){_0x303fdd['body'][_0x0898('0x52')]=_0x44ebcf['id'];_0x303fdd[_0x0898('0x4c')]['Subjects']=integrations[_0x0898('0x53')](_0x303fdd[_0x0898('0x4c')][_0x0898('0x54')],_0x303fdd[_0x0898('0x4c')][_0x0898('0x31')]);_0x303fdd[_0x0898('0x4c')]['Descriptions']=integrations[_0x0898('0x55')](_0x303fdd[_0x0898('0x4c')][_0x0898('0x54')],_0x303fdd[_0x0898('0x4c')]['type']);return db['FreshsalesConfiguration'][_0x0898('0x4b')](_0x303fdd['body'],{'include':[{'model':db[_0x0898('0x56')],'as':_0x0898('0x57')},{'model':db['FreshsalesField'],'as':_0x0898('0x58')}]});}return null;})[_0x0898('0x28')](respondWithResult(_0x5dadde,null))['catch'](handleError(_0x5dadde,null));};exports[_0x0898('0x59')]=function(_0x1eeba6,_0x4eb902,_0x287368){var _0x130b04='';var _0x32dfa1='';return db[_0x0898('0x2f')][_0x0898('0x4d')]({'where':{'id':_0x1eeba6['params']['id']},'attributes':['id',_0x0898('0x5a'),_0x0898('0x5b'),_0x0898('0x5c')]})[_0x0898('0x28')](handleEntityNotFound(_0x4eb902,null))[_0x0898('0x28')](function(_0x18f6a7){if(_0x18f6a7){_0x32dfa1=_0x18f6a7['username'];_0x130b04=_0x18f6a7[_0x0898('0x5b')];var _0x7ff982=_0x18f6a7[_0x0898('0x5b')][_0x0898('0x5d')](-0x1);if(_0x7ff982==='/'){_0x130b04=_0x130b04['substring'](0x0,_0x130b04[_0x0898('0x5e')](_0x7ff982));}return rp({'method':'GET','uri':util[_0x0898('0x5f')]('%s%s',_0x130b04,_0x0898('0x60')),'headers':{'Authorization':'Token\x20token='+_0x18f6a7['apiKey']},'json':!![]});}})[_0x0898('0x28')](function(_0x1bc4b4){if(_0x1bc4b4){var _0x318424=_0x1bc4b4[_0x0898('0x61')];var _0x21cbf9=![];var _0x52ed10=null;for(_0x52ed10=0x0;_0x52ed10<_0x318424[_0x0898('0x3a')];_0x52ed10++){if(_0x318424[_0x52ed10]['email']===_0x32dfa1){_0x21cbf9=!![];}}if(_0x21cbf9){return!![];}else{throw new Error({'statusCode':0x194,'message':_0x0898('0x62')});}}})[_0x0898('0x28')](respondWithResult(_0x4eb902,null))['catch'](function(_0x56df69){var _0x225a3a=_0x1eeba6[_0x0898('0x34')]['test']?0x1f4:_0x56df69[_0x0898('0x63')]||0x1f4;logger[_0x0898('0x64')](_0x0898('0x65'),_0x0898('0x59'),_0x225a3a,JSON[_0x0898('0x66')](_0x56df69));delete _0x56df69[_0x0898('0x2c')];if(_0x225a3a===0x191){_0x225a3a=0x190;}_0x4eb902[_0x0898('0x1e')](_0x225a3a)['send'](_0x1eeba6[_0x0898('0x34')][_0x0898('0x67')]?{'message':_0x0898('0x68'),'statusCode':_0x56df69[_0x0898('0x63')]}:_0x56df69);});};
\ No newline at end of file