Built motion from commit c738b9ac.|2.6.25
[motion2.git] / server / api / intFreshsalesAccount / intFreshsalesAccount.controller.js
index c2a79e2..d9f706a 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0xa849=['fs-extra','lodash','squel','crypto','jsforce','desk.js','querystring','papaparse','ioredis','../../components/auth/service','../../components/parsers/qs','../../config/license/hardware','../../config/logger','../../config/environment','../../config/license/util','../../components/integrations/configuration','sendStatus','status','json','offset','undefined','count','limit','set','Content-Range','apply','save','then','destroy','end','error','stack','name','send','index','FreshsalesAccount','rawAttributes','fieldName','type','key','query','filters','intersection','model','fields','attributes','length','hasOwnProperty','nolimit','order','sort','where','pick','filter','VIRTUAL','merge','includeAll','findAll','catch','show','params','keys','include','options','find','create','body','update','getConfigurations','findOne','FreshsalesConfiguration','map','AccountId','Subjects','getSubjects','channel','Descriptions','getDescriptions','FreshsalesField','getFields','username','remoteUri','slice','substring','lastIndexOf','GET','format','%s%s','Token\x20token=','apiKey','users','Requested\x20Resource\x20not\x20Found','test','statusCode','getFields,\x20%s,\x20%s,\x20%s','stringify','eml-format','rimraf','zip-dir','request-promise','moment','mustache','util','path','sox','to-csv','ejs'];(function(_0x4b9efe,_0x40d72c){var _0x4bb144=function(_0x564032){while(--_0x564032){_0x4b9efe['push'](_0x4b9efe['shift']());}};_0x4bb144(++_0x40d72c);}(_0xa849,0xcb));var _0x9a84=function(_0x467366,_0x1eab75){_0x467366=_0x467366-0x0;var _0x564070=_0xa849[_0x467366];return _0x564070;};'use strict';var emlformat=require(_0x9a84('0x0'));var rimraf=require(_0x9a84('0x1'));var zipdir=require(_0x9a84('0x2'));var jsonpatch=require('fast-json-patch');var rp=require(_0x9a84('0x3'));var moment=require(_0x9a84('0x4'));var BPromise=require('bluebird');var Mustache=require(_0x9a84('0x5'));var util=require(_0x9a84('0x6'));var path=require(_0x9a84('0x7'));var sox=require(_0x9a84('0x8'));var csv=require(_0x9a84('0x9'));var ejs=require(_0x9a84('0xa'));var fs=require('fs');var fs_extra=require(_0x9a84('0xb'));var _=require(_0x9a84('0xc'));var squel=require(_0x9a84('0xd'));var crypto=require(_0x9a84('0xe'));var jsforce=require(_0x9a84('0xf'));var deskjs=require(_0x9a84('0x10'));var toCsv=require(_0x9a84('0x9'));var querystring=require(_0x9a84('0x11'));var Papa=require(_0x9a84('0x12'));var Redis=require(_0x9a84('0x13'));var authService=require(_0x9a84('0x14'));var qs=require(_0x9a84('0x15'));var as=require('../../components/parsers/advancedSearch');var hardwareService=require(_0x9a84('0x16'));var logger=require(_0x9a84('0x17'))('api');var utils=require('../../config/utils');var config=require(_0x9a84('0x18'));var licenseUtil=require(_0x9a84('0x19'));var db=require('../../mysqldb')['db'];var integrations=require(_0x9a84('0x1a'));function respondWithStatusCode(_0x2b9d6f,_0x10674f){_0x10674f=_0x10674f||0xcc;return function(_0x4a9c81){if(_0x4a9c81){return _0x2b9d6f[_0x9a84('0x1b')](_0x10674f);}return _0x2b9d6f[_0x9a84('0x1c')](_0x10674f)['end']();};}function respondWithResult(_0x53610c,_0x172869){_0x172869=_0x172869||0xc8;return function(_0x4b464a){if(_0x4b464a){return _0x53610c[_0x9a84('0x1c')](_0x172869)[_0x9a84('0x1d')](_0x4b464a);}};}function respondWithFilteredResult(_0x5b0a65,_0x274136){return function(_0x50d16e){if(_0x50d16e){var _0x33a788=typeof _0x274136[_0x9a84('0x1e')]===_0x9a84('0x1f')&&typeof _0x274136['limit']===_0x9a84('0x1f');var _0x29bc3c=_0x50d16e[_0x9a84('0x20')];var _0xeae8ed=_0x33a788?0x0:_0x274136[_0x9a84('0x1e')];var _0x2e0453=_0x33a788?_0x50d16e['count']:_0x274136[_0x9a84('0x1e')]+_0x274136[_0x9a84('0x21')];var _0xa59fd6;if(_0x2e0453>=_0x29bc3c){_0x2e0453=_0x29bc3c;_0xa59fd6=0xc8;}else{_0xa59fd6=0xce;}_0x5b0a65[_0x9a84('0x1c')](_0xa59fd6);return _0x5b0a65[_0x9a84('0x22')](_0x9a84('0x23'),_0xeae8ed+'-'+_0x2e0453+'/'+_0x29bc3c)[_0x9a84('0x1d')](_0x50d16e);}return null;};}function patchUpdates(_0x1b07b2){return function(_0x5c89a1){try{jsonpatch[_0x9a84('0x24')](_0x5c89a1,_0x1b07b2,!![]);}catch(_0x4291ae){return BPromise['reject'](_0x4291ae);}return _0x5c89a1[_0x9a84('0x25')]();};}function saveUpdates(_0x5e9ec0,_0x2b3728){return function(_0x4ab536){if(_0x4ab536){return _0x4ab536['update'](_0x5e9ec0)[_0x9a84('0x26')](function(_0x496f0d){return _0x496f0d;});}return null;};}function removeEntity(_0x4edcf4,_0x5bf3eb){return function(_0x36cb48){if(_0x36cb48){return _0x36cb48[_0x9a84('0x27')]()[_0x9a84('0x26')](function(){_0x4edcf4[_0x9a84('0x1c')](0xcc)[_0x9a84('0x28')]();});}};}function handleEntityNotFound(_0x5b51fb,_0x236ebd){return function(_0xcbc990){if(!_0xcbc990){_0x5b51fb[_0x9a84('0x1b')](0x194);}return _0xcbc990;};}function handleError(_0xf69d34,_0xac39b3){_0xac39b3=_0xac39b3||0x1f4;return function(_0x2f16f5){logger[_0x9a84('0x29')](_0x2f16f5[_0x9a84('0x2a')]);if(_0x2f16f5[_0x9a84('0x2b')]){delete _0x2f16f5['name'];}_0xf69d34['status'](_0xac39b3)[_0x9a84('0x2c')](_0x2f16f5);};}exports[_0x9a84('0x2d')]=function(_0x465a94,_0x1022bd){var _0x463128={},_0x1f70a0={},_0x39791a={'count':0x0,'rows':[]};var _0x47bf59=_['map'](db[_0x9a84('0x2e')][_0x9a84('0x2f')],function(_0x282d92){return{'name':_0x282d92[_0x9a84('0x30')],'type':_0x282d92[_0x9a84('0x31')][_0x9a84('0x32')]};});_0x1f70a0['model']=_['map'](_0x47bf59,'name');_0x1f70a0[_0x9a84('0x33')]=_['keys'](_0x465a94[_0x9a84('0x33')]);_0x1f70a0[_0x9a84('0x34')]=_['intersection'](_0x1f70a0['model'],_0x1f70a0[_0x9a84('0x33')]);_0x463128['attributes']=_[_0x9a84('0x35')](_0x1f70a0[_0x9a84('0x36')],qs[_0x9a84('0x37')](_0x465a94[_0x9a84('0x33')]['fields']));_0x463128[_0x9a84('0x38')]=_0x463128['attributes'][_0x9a84('0x39')]?_0x463128[_0x9a84('0x38')]:_0x1f70a0[_0x9a84('0x36')];if(!_0x465a94[_0x9a84('0x33')][_0x9a84('0x3a')](_0x9a84('0x3b'))){_0x463128['limit']=qs['limit'](_0x465a94['query']['limit']);_0x463128[_0x9a84('0x1e')]=qs['offset'](_0x465a94[_0x9a84('0x33')][_0x9a84('0x1e')]);}_0x463128[_0x9a84('0x3c')]=qs[_0x9a84('0x3d')](_0x465a94[_0x9a84('0x33')][_0x9a84('0x3d')]);_0x463128[_0x9a84('0x3e')]=qs[_0x9a84('0x34')](_[_0x9a84('0x3f')](_0x465a94[_0x9a84('0x33')],_0x1f70a0['filters']),_0x47bf59);if(_0x465a94[_0x9a84('0x33')][_0x9a84('0x40')]){_0x463128['where']=_['merge'](_0x463128[_0x9a84('0x3e')],{'$or':_['map'](_0x47bf59,function(_0x54a69e){if(_0x54a69e[_0x9a84('0x31')]!==_0x9a84('0x41')){var _0x1409d2={};_0x1409d2[_0x54a69e[_0x9a84('0x2b')]]={'$like':'%'+_0x465a94[_0x9a84('0x33')]['filter']+'%'};return _0x1409d2;}})});}_0x463128=_[_0x9a84('0x42')]({},_0x463128,_0x465a94['options']);var _0x49617b={'where':_0x463128[_0x9a84('0x3e')]};return db[_0x9a84('0x2e')]['count'](_0x49617b)[_0x9a84('0x26')](function(_0x4c63c7){_0x39791a['count']=_0x4c63c7;if(_0x465a94['query'][_0x9a84('0x43')]){_0x463128['include']=[{'all':!![]}];}return db[_0x9a84('0x2e')][_0x9a84('0x44')](_0x463128);})['then'](function(_0x487b4c){_0x39791a['rows']=_0x487b4c;return _0x39791a;})['then'](respondWithFilteredResult(_0x1022bd,_0x463128))[_0x9a84('0x45')](handleError(_0x1022bd,null));};exports[_0x9a84('0x46')]=function(_0x323fbd,_0x3a8bfb){var _0x498903={'raw':![],'where':{'id':_0x323fbd[_0x9a84('0x47')]['id']}},_0x10efa6={};_0x10efa6['model']=_['keys'](db['FreshsalesAccount'][_0x9a84('0x2f')]);_0x10efa6[_0x9a84('0x33')]=_[_0x9a84('0x48')](_0x323fbd[_0x9a84('0x33')]);_0x10efa6[_0x9a84('0x34')]=_['intersection'](_0x10efa6[_0x9a84('0x36')],_0x10efa6['query']);_0x498903[_0x9a84('0x38')]=_[_0x9a84('0x35')](_0x10efa6[_0x9a84('0x36')],qs['fields'](_0x323fbd[_0x9a84('0x33')][_0x9a84('0x37')]));_0x498903[_0x9a84('0x38')]=_0x498903[_0x9a84('0x38')][_0x9a84('0x39')]?_0x498903[_0x9a84('0x38')]:_0x10efa6['model'];if(_0x323fbd[_0x9a84('0x33')][_0x9a84('0x43')]){_0x498903[_0x9a84('0x49')]=[{'all':!![]}];}_0x498903=_['merge']({},_0x498903,_0x323fbd[_0x9a84('0x4a')]);return db[_0x9a84('0x2e')][_0x9a84('0x4b')](_0x498903)[_0x9a84('0x26')](handleEntityNotFound(_0x3a8bfb,null))[_0x9a84('0x26')](respondWithResult(_0x3a8bfb,null))['catch'](handleError(_0x3a8bfb,null));};exports[_0x9a84('0x4c')]=function(_0x5c9e43,_0x57137a){return db['FreshsalesAccount']['create'](_0x5c9e43[_0x9a84('0x4d')],{})[_0x9a84('0x26')](respondWithResult(_0x57137a,0xc9))['catch'](handleError(_0x57137a,null));};exports[_0x9a84('0x4e')]=function(_0x965721,_0x3047b6){if(_0x965721[_0x9a84('0x4d')]['id']){delete _0x965721[_0x9a84('0x4d')]['id'];}return db[_0x9a84('0x2e')][_0x9a84('0x4b')]({'where':{'id':_0x965721['params']['id']}})[_0x9a84('0x26')](handleEntityNotFound(_0x3047b6,null))[_0x9a84('0x26')](saveUpdates(_0x965721[_0x9a84('0x4d')],null))['then'](respondWithResult(_0x3047b6,null))[_0x9a84('0x45')](handleError(_0x3047b6,null));};exports[_0x9a84('0x27')]=function(_0x4d8021,_0x8144d9){return db[_0x9a84('0x2e')][_0x9a84('0x4b')]({'where':{'id':_0x4d8021[_0x9a84('0x47')]['id']}})[_0x9a84('0x26')](handleEntityNotFound(_0x8144d9,null))[_0x9a84('0x26')](removeEntity(_0x8144d9,null))[_0x9a84('0x45')](handleError(_0x8144d9,null));};exports[_0x9a84('0x4f')]=function(_0x4066c5,_0x23f4b2,_0x5d8386){var _0x175dc0={};var _0x5ca39a={};var _0x5a9694;var _0x173f86;return db['FreshsalesAccount'][_0x9a84('0x50')]({'where':{'id':_0x4066c5[_0x9a84('0x47')]['id']}})[_0x9a84('0x26')](handleEntityNotFound(_0x23f4b2,null))[_0x9a84('0x26')](function(_0x3f656e){if(_0x3f656e){_0x5a9694=_0x3f656e;_0x5ca39a[_0x9a84('0x36')]=_[_0x9a84('0x48')](db[_0x9a84('0x51')]['rawAttributes']);_0x5ca39a[_0x9a84('0x33')]=_['keys'](_0x4066c5[_0x9a84('0x33')]);_0x5ca39a[_0x9a84('0x34')]=_['intersection'](_0x5ca39a[_0x9a84('0x36')],_0x5ca39a[_0x9a84('0x33')]);_0x175dc0[_0x9a84('0x38')]=_['intersection'](_0x5ca39a[_0x9a84('0x36')],qs[_0x9a84('0x37')](_0x4066c5[_0x9a84('0x33')]['fields']));_0x175dc0[_0x9a84('0x38')]=_0x175dc0['attributes'][_0x9a84('0x39')]?_0x175dc0[_0x9a84('0x38')]:_0x5ca39a[_0x9a84('0x36')];_0x175dc0['order']=qs[_0x9a84('0x3d')](_0x4066c5[_0x9a84('0x33')][_0x9a84('0x3d')]);_0x175dc0['where']=qs['filters'](_['pick'](_0x4066c5[_0x9a84('0x33')],_0x5ca39a[_0x9a84('0x34')]));if(_0x4066c5[_0x9a84('0x33')][_0x9a84('0x40')]){_0x175dc0[_0x9a84('0x3e')]=_[_0x9a84('0x42')](_0x175dc0[_0x9a84('0x3e')],{'$or':_[_0x9a84('0x52')](_0x175dc0[_0x9a84('0x38')],function(_0x47dca9){var _0x2154fd={};_0x2154fd[_0x47dca9]={'$like':'%'+_0x4066c5['query'][_0x9a84('0x40')]+'%'};return _0x2154fd;})});}_0x175dc0=_[_0x9a84('0x42')]({},_0x175dc0,_0x4066c5[_0x9a84('0x4a')]);return _0x5a9694[_0x9a84('0x4f')](_0x175dc0);}})[_0x9a84('0x26')](function(_0x3c1684){if(_0x3c1684){_0x173f86=_0x3c1684[_0x9a84('0x39')];if(!_0x4066c5['query'][_0x9a84('0x3a')](_0x9a84('0x3b'))){_0x175dc0[_0x9a84('0x21')]=qs['limit'](_0x4066c5[_0x9a84('0x33')][_0x9a84('0x21')]);_0x175dc0['offset']=qs[_0x9a84('0x1e')](_0x4066c5[_0x9a84('0x33')][_0x9a84('0x1e')]);}return _0x5a9694['getConfigurations'](_0x175dc0);}})[_0x9a84('0x26')](function(_0x3e70cf){if(_0x3e70cf){return _0x3e70cf?{'count':_0x173f86,'rows':_0x3e70cf}:null;}})['then'](respondWithResult(_0x23f4b2,null))['catch'](handleError(_0x23f4b2,null));};exports['addConfiguration']=function(_0x56f8d8,_0x2f6c6e,_0x526b1e){if(_0x56f8d8[_0x9a84('0x4d')]['id']){delete _0x56f8d8[_0x9a84('0x4d')]['id'];}return db['FreshsalesAccount'][_0x9a84('0x50')]({'where':{'id':_0x56f8d8[_0x9a84('0x47')]['id']}})[_0x9a84('0x26')](handleEntityNotFound(_0x2f6c6e,null))['then'](function(_0x4f720a){if(_0x4f720a){_0x56f8d8[_0x9a84('0x4d')][_0x9a84('0x53')]=_0x4f720a['id'];_0x56f8d8[_0x9a84('0x4d')][_0x9a84('0x54')]=integrations[_0x9a84('0x55')](_0x56f8d8[_0x9a84('0x4d')][_0x9a84('0x56')],_0x56f8d8[_0x9a84('0x4d')][_0x9a84('0x31')]);_0x56f8d8[_0x9a84('0x4d')][_0x9a84('0x57')]=integrations[_0x9a84('0x58')](_0x56f8d8[_0x9a84('0x4d')]['channel'],_0x56f8d8[_0x9a84('0x4d')][_0x9a84('0x31')]);return db[_0x9a84('0x51')]['create'](_0x56f8d8[_0x9a84('0x4d')],{'include':[{'model':db[_0x9a84('0x59')],'as':_0x9a84('0x54')},{'model':db[_0x9a84('0x59')],'as':_0x9a84('0x57')}]});}return null;})[_0x9a84('0x26')](respondWithResult(_0x2f6c6e,null))[_0x9a84('0x45')](handleError(_0x2f6c6e,null));};exports[_0x9a84('0x5a')]=function(_0x56739d,_0x4a2b3f,_0x31868a){var _0x1f212e='';var _0x1834e5='';return db[_0x9a84('0x2e')]['findOne']({'where':{'id':_0x56739d['params']['id']},'attributes':['id',_0x9a84('0x5b'),'remoteUri','apiKey']})['then'](handleEntityNotFound(_0x4a2b3f,null))[_0x9a84('0x26')](function(_0x3dca66){if(_0x3dca66){_0x1834e5=_0x3dca66[_0x9a84('0x5b')];_0x1f212e=_0x3dca66[_0x9a84('0x5c')];var _0x4f60d5=_0x3dca66[_0x9a84('0x5c')][_0x9a84('0x5d')](-0x1);if(_0x4f60d5==='/'){_0x1f212e=_0x1f212e[_0x9a84('0x5e')](0x0,_0x1f212e[_0x9a84('0x5f')](_0x4f60d5));}return rp({'method':_0x9a84('0x60'),'uri':util[_0x9a84('0x61')](_0x9a84('0x62'),_0x1f212e,'/api/selector/owners'),'headers':{'Authorization':_0x9a84('0x63')+_0x3dca66[_0x9a84('0x64')]},'json':!![]});}})[_0x9a84('0x26')](function(_0xccb46a){if(_0xccb46a){var _0x2b1190=_0xccb46a[_0x9a84('0x65')];var _0x24b543=![];var _0x22f4bd=null;for(_0x22f4bd=0x0;_0x22f4bd<_0x2b1190['length'];_0x22f4bd++){if(_0x2b1190[_0x22f4bd]['email']===_0x1834e5){_0x24b543=!![];}}if(_0x24b543){return!![];}else{throw new Error({'statusCode':0x194,'message':_0x9a84('0x66')});}}})[_0x9a84('0x26')](respondWithResult(_0x4a2b3f,null))[_0x9a84('0x45')](function(_0x2b9217){var _0x450c8e=_0x56739d[_0x9a84('0x33')][_0x9a84('0x67')]?0x1f4:_0x2b9217[_0x9a84('0x68')]||0x1f4;logger[_0x9a84('0x29')](_0x9a84('0x69'),_0x9a84('0x5a'),_0x450c8e,JSON[_0x9a84('0x6a')](_0x2b9217));delete _0x2b9217[_0x9a84('0x2b')];if(_0x450c8e===0x191){_0x450c8e=0x190;}_0x4a2b3f['status'](_0x450c8e)[_0x9a84('0x2c')](_0x56739d['query'][_0x9a84('0x67')]?{'message':'Wrong\x20credentials','statusCode':_0x2b9217['statusCode']}:_0x2b9217);});};
\ No newline at end of file
+var _0x6b52=['FreshsalesConfiguration','username','remoteUri','apiKey','substring','%s%s','/api/selector/owners','users','Requested\x20Resource\x20not\x20Found','error','getFields','stringify','test','Wrong\x20credentials','statusCode','eml-format','rimraf','zip-dir','fast-json-patch','request-promise','moment','bluebird','mustache','util','path','to-csv','ejs','fs-extra','lodash','crypto','jsforce','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','offset','undefined','limit','count','Content-Range','apply','reject','save','then','destroy','end','sendStatus','stack','name','send','index','map','rawAttributes','fieldName','type','key','model','query','keys','intersection','fields','attributes','length','hasOwnProperty','nolimit','where','filters','pick','merge','VIRTUAL','options','FreshsalesAccount','includeAll','include','rows','catch','show','params','find','create','body','update','getConfigurations','findOne','sort','filter','addConfiguration','Subjects','getSubjects','channel','Descriptions','getDescriptions'];(function(_0xafdf61,_0x38bba3){var _0x42612e=function(_0x546e3c){while(--_0x546e3c){_0xafdf61['push'](_0xafdf61['shift']());}};_0x42612e(++_0x38bba3);}(_0x6b52,0xdf));var _0x26b5=function(_0x3fcfb9,_0x3ccab1){_0x3fcfb9=_0x3fcfb9-0x0;var _0x10384b=_0x6b52[_0x3fcfb9];return _0x10384b;};'use strict';var emlformat=require(_0x26b5('0x0'));var rimraf=require(_0x26b5('0x1'));var zipdir=require(_0x26b5('0x2'));var jsonpatch=require(_0x26b5('0x3'));var rp=require(_0x26b5('0x4'));var moment=require(_0x26b5('0x5'));var BPromise=require(_0x26b5('0x6'));var Mustache=require(_0x26b5('0x7'));var util=require(_0x26b5('0x8'));var path=require(_0x26b5('0x9'));var sox=require('sox');var csv=require(_0x26b5('0xa'));var ejs=require(_0x26b5('0xb'));var fs=require('fs');var fs_extra=require(_0x26b5('0xc'));var _=require(_0x26b5('0xd'));var squel=require('squel');var crypto=require(_0x26b5('0xe'));var jsforce=require(_0x26b5('0xf'));var deskjs=require(_0x26b5('0x10'));var toCsv=require('to-csv');var querystring=require(_0x26b5('0x11'));var Papa=require(_0x26b5('0x12'));var Redis=require(_0x26b5('0x13'));var authService=require(_0x26b5('0x14'));var qs=require(_0x26b5('0x15'));var as=require(_0x26b5('0x16'));var hardwareService=require(_0x26b5('0x17'));var logger=require(_0x26b5('0x18'))(_0x26b5('0x19'));var utils=require(_0x26b5('0x1a'));var config=require(_0x26b5('0x1b'));var licenseUtil=require(_0x26b5('0x1c'));var db=require('../../mysqldb')['db'];var integrations=require(_0x26b5('0x1d'));function respondWithStatusCode(_0x5e3f32,_0x17638b){_0x17638b=_0x17638b||0xcc;return function(_0x18fcc0){if(_0x18fcc0){return _0x5e3f32['sendStatus'](_0x17638b);}return _0x5e3f32[_0x26b5('0x1e')](_0x17638b)['end']();};}function respondWithResult(_0x1ed712,_0x249913){_0x249913=_0x249913||0xc8;return function(_0x19f765){if(_0x19f765){return _0x1ed712[_0x26b5('0x1e')](_0x249913)[_0x26b5('0x1f')](_0x19f765);}};}function respondWithFilteredResult(_0x3e5859,_0x1642dc){return function(_0x487de4){if(_0x487de4){var _0x150a31=typeof _0x1642dc[_0x26b5('0x20')]===_0x26b5('0x21')&&typeof _0x1642dc[_0x26b5('0x22')]===_0x26b5('0x21');var _0x316e56=_0x487de4[_0x26b5('0x23')];var _0x3872b6=_0x150a31?0x0:_0x1642dc[_0x26b5('0x20')];var _0x2ae701=_0x150a31?_0x487de4[_0x26b5('0x23')]:_0x1642dc['offset']+_0x1642dc[_0x26b5('0x22')];var _0x4ee52c;if(_0x2ae701>=_0x316e56){_0x2ae701=_0x316e56;_0x4ee52c=0xc8;}else{_0x4ee52c=0xce;}_0x3e5859['status'](_0x4ee52c);return _0x3e5859['set'](_0x26b5('0x24'),_0x3872b6+'-'+_0x2ae701+'/'+_0x316e56)['json'](_0x487de4);}return null;};}function patchUpdates(_0x16d67e){return function(_0x4f09b3){try{jsonpatch[_0x26b5('0x25')](_0x4f09b3,_0x16d67e,!![]);}catch(_0x170e56){return BPromise[_0x26b5('0x26')](_0x170e56);}return _0x4f09b3[_0x26b5('0x27')]();};}function saveUpdates(_0x3f6cd0,_0x57925f){return function(_0xad5fc5){if(_0xad5fc5){return _0xad5fc5['update'](_0x3f6cd0)[_0x26b5('0x28')](function(_0x7f02bd){return _0x7f02bd;});}return null;};}function removeEntity(_0x325f92,_0x2dbd95){return function(_0xb7b952){if(_0xb7b952){return _0xb7b952[_0x26b5('0x29')]()[_0x26b5('0x28')](function(){_0x325f92[_0x26b5('0x1e')](0xcc)[_0x26b5('0x2a')]();});}};}function handleEntityNotFound(_0x5a046f,_0x2372c5){return function(_0x1856e2){if(!_0x1856e2){_0x5a046f[_0x26b5('0x2b')](0x194);}return _0x1856e2;};}function handleError(_0x55341d,_0x5b4691){_0x5b4691=_0x5b4691||0x1f4;return function(_0xad7c7){logger['error'](_0xad7c7[_0x26b5('0x2c')]);if(_0xad7c7['name']){delete _0xad7c7[_0x26b5('0x2d')];}_0x55341d[_0x26b5('0x1e')](_0x5b4691)[_0x26b5('0x2e')](_0xad7c7);};}exports[_0x26b5('0x2f')]=function(_0x29374d,_0x307514){var _0x51d782={},_0x4489e6={},_0x465816={'count':0x0,'rows':[]};var _0x1ca763=_[_0x26b5('0x30')](db['FreshsalesAccount'][_0x26b5('0x31')],function(_0x5ba185){return{'name':_0x5ba185[_0x26b5('0x32')],'type':_0x5ba185[_0x26b5('0x33')][_0x26b5('0x34')]};});_0x4489e6[_0x26b5('0x35')]=_[_0x26b5('0x30')](_0x1ca763,'name');_0x4489e6[_0x26b5('0x36')]=_[_0x26b5('0x37')](_0x29374d[_0x26b5('0x36')]);_0x4489e6['filters']=_[_0x26b5('0x38')](_0x4489e6[_0x26b5('0x35')],_0x4489e6[_0x26b5('0x36')]);_0x51d782['attributes']=_[_0x26b5('0x38')](_0x4489e6['model'],qs['fields'](_0x29374d[_0x26b5('0x36')][_0x26b5('0x39')]));_0x51d782[_0x26b5('0x3a')]=_0x51d782['attributes'][_0x26b5('0x3b')]?_0x51d782[_0x26b5('0x3a')]:_0x4489e6[_0x26b5('0x35')];if(!_0x29374d[_0x26b5('0x36')][_0x26b5('0x3c')](_0x26b5('0x3d'))){_0x51d782[_0x26b5('0x22')]=qs[_0x26b5('0x22')](_0x29374d[_0x26b5('0x36')][_0x26b5('0x22')]);_0x51d782[_0x26b5('0x20')]=qs[_0x26b5('0x20')](_0x29374d[_0x26b5('0x36')][_0x26b5('0x20')]);}_0x51d782['order']=qs['sort'](_0x29374d[_0x26b5('0x36')]['sort']);_0x51d782[_0x26b5('0x3e')]=qs[_0x26b5('0x3f')](_[_0x26b5('0x40')](_0x29374d[_0x26b5('0x36')],_0x4489e6[_0x26b5('0x3f')]),_0x1ca763);if(_0x29374d[_0x26b5('0x36')]['filter']){_0x51d782[_0x26b5('0x3e')]=_[_0x26b5('0x41')](_0x51d782[_0x26b5('0x3e')],{'$or':_['map'](_0x1ca763,function(_0x5b911f){if(_0x5b911f[_0x26b5('0x33')]!==_0x26b5('0x42')){var _0x366769={};_0x366769[_0x5b911f[_0x26b5('0x2d')]]={'$like':'%'+_0x29374d['query']['filter']+'%'};return _0x366769;}})});}_0x51d782=_[_0x26b5('0x41')]({},_0x51d782,_0x29374d[_0x26b5('0x43')]);var _0x1aec9a={'where':_0x51d782[_0x26b5('0x3e')]};return db[_0x26b5('0x44')]['count'](_0x1aec9a)[_0x26b5('0x28')](function(_0xef5d14){_0x465816['count']=_0xef5d14;if(_0x29374d[_0x26b5('0x36')][_0x26b5('0x45')]){_0x51d782[_0x26b5('0x46')]=[{'all':!![]}];}return db[_0x26b5('0x44')]['findAll'](_0x51d782);})[_0x26b5('0x28')](function(_0xb5b763){_0x465816[_0x26b5('0x47')]=_0xb5b763;return _0x465816;})['then'](respondWithFilteredResult(_0x307514,_0x51d782))[_0x26b5('0x48')](handleError(_0x307514,null));};exports[_0x26b5('0x49')]=function(_0x435716,_0x323dce){var _0x3fae8c={'raw':![],'where':{'id':_0x435716[_0x26b5('0x4a')]['id']}},_0x53b935={};_0x53b935[_0x26b5('0x35')]=_[_0x26b5('0x37')](db[_0x26b5('0x44')][_0x26b5('0x31')]);_0x53b935[_0x26b5('0x36')]=_[_0x26b5('0x37')](_0x435716[_0x26b5('0x36')]);_0x53b935[_0x26b5('0x3f')]=_['intersection'](_0x53b935[_0x26b5('0x35')],_0x53b935[_0x26b5('0x36')]);_0x3fae8c[_0x26b5('0x3a')]=_['intersection'](_0x53b935['model'],qs['fields'](_0x435716[_0x26b5('0x36')][_0x26b5('0x39')]));_0x3fae8c['attributes']=_0x3fae8c[_0x26b5('0x3a')]['length']?_0x3fae8c[_0x26b5('0x3a')]:_0x53b935[_0x26b5('0x35')];if(_0x435716[_0x26b5('0x36')][_0x26b5('0x45')]){_0x3fae8c[_0x26b5('0x46')]=[{'all':!![]}];}_0x3fae8c=_[_0x26b5('0x41')]({},_0x3fae8c,_0x435716['options']);return db[_0x26b5('0x44')][_0x26b5('0x4b')](_0x3fae8c)['then'](handleEntityNotFound(_0x323dce,null))[_0x26b5('0x28')](respondWithResult(_0x323dce,null))[_0x26b5('0x48')](handleError(_0x323dce,null));};exports[_0x26b5('0x4c')]=function(_0x25048c,_0xe5e930){return db[_0x26b5('0x44')][_0x26b5('0x4c')](_0x25048c[_0x26b5('0x4d')],{})[_0x26b5('0x28')](respondWithResult(_0xe5e930,0xc9))[_0x26b5('0x48')](handleError(_0xe5e930,null));};exports[_0x26b5('0x4e')]=function(_0x3ef542,_0xb5d8d0){if(_0x3ef542[_0x26b5('0x4d')]['id']){delete _0x3ef542['body']['id'];}return db[_0x26b5('0x44')][_0x26b5('0x4b')]({'where':{'id':_0x3ef542[_0x26b5('0x4a')]['id']}})['then'](handleEntityNotFound(_0xb5d8d0,null))[_0x26b5('0x28')](saveUpdates(_0x3ef542['body'],null))['then'](respondWithResult(_0xb5d8d0,null))[_0x26b5('0x48')](handleError(_0xb5d8d0,null));};exports[_0x26b5('0x29')]=function(_0x2094f5,_0x31425d){return db[_0x26b5('0x44')][_0x26b5('0x4b')]({'where':{'id':_0x2094f5[_0x26b5('0x4a')]['id']}})[_0x26b5('0x28')](handleEntityNotFound(_0x31425d,null))['then'](removeEntity(_0x31425d,null))[_0x26b5('0x48')](handleError(_0x31425d,null));};exports[_0x26b5('0x4f')]=function(_0x17cace,_0x19a77c,_0x1c352d){var _0x2f27e4={};var _0x4985eb={};var _0x16c09d;var _0xb2085d;return db[_0x26b5('0x44')][_0x26b5('0x50')]({'where':{'id':_0x17cace[_0x26b5('0x4a')]['id']}})[_0x26b5('0x28')](handleEntityNotFound(_0x19a77c,null))[_0x26b5('0x28')](function(_0x2fdf9f){if(_0x2fdf9f){_0x16c09d=_0x2fdf9f;_0x4985eb[_0x26b5('0x35')]=_[_0x26b5('0x37')](db['FreshsalesConfiguration'][_0x26b5('0x31')]);_0x4985eb[_0x26b5('0x36')]=_[_0x26b5('0x37')](_0x17cace['query']);_0x4985eb[_0x26b5('0x3f')]=_[_0x26b5('0x38')](_0x4985eb[_0x26b5('0x35')],_0x4985eb[_0x26b5('0x36')]);_0x2f27e4[_0x26b5('0x3a')]=_[_0x26b5('0x38')](_0x4985eb[_0x26b5('0x35')],qs[_0x26b5('0x39')](_0x17cace['query'][_0x26b5('0x39')]));_0x2f27e4[_0x26b5('0x3a')]=_0x2f27e4[_0x26b5('0x3a')][_0x26b5('0x3b')]?_0x2f27e4['attributes']:_0x4985eb['model'];_0x2f27e4['order']=qs[_0x26b5('0x51')](_0x17cace[_0x26b5('0x36')][_0x26b5('0x51')]);_0x2f27e4['where']=qs[_0x26b5('0x3f')](_[_0x26b5('0x40')](_0x17cace[_0x26b5('0x36')],_0x4985eb[_0x26b5('0x3f')]));if(_0x17cace[_0x26b5('0x36')][_0x26b5('0x52')]){_0x2f27e4['where']=_[_0x26b5('0x41')](_0x2f27e4['where'],{'$or':_[_0x26b5('0x30')](_0x2f27e4[_0x26b5('0x3a')],function(_0x12dc24){var _0x319c50={};_0x319c50[_0x12dc24]={'$like':'%'+_0x17cace['query']['filter']+'%'};return _0x319c50;})});}_0x2f27e4=_[_0x26b5('0x41')]({},_0x2f27e4,_0x17cace['options']);return _0x16c09d[_0x26b5('0x4f')](_0x2f27e4);}})[_0x26b5('0x28')](function(_0x3d1229){if(_0x3d1229){_0xb2085d=_0x3d1229['length'];if(!_0x17cace['query']['hasOwnProperty']('nolimit')){_0x2f27e4[_0x26b5('0x22')]=qs[_0x26b5('0x22')](_0x17cace[_0x26b5('0x36')][_0x26b5('0x22')]);_0x2f27e4[_0x26b5('0x20')]=qs[_0x26b5('0x20')](_0x17cace['query'][_0x26b5('0x20')]);}return _0x16c09d[_0x26b5('0x4f')](_0x2f27e4);}})[_0x26b5('0x28')](function(_0x230d16){if(_0x230d16){return _0x230d16?{'count':_0xb2085d,'rows':_0x230d16}:null;}})[_0x26b5('0x28')](respondWithResult(_0x19a77c,null))['catch'](handleError(_0x19a77c,null));};exports[_0x26b5('0x53')]=function(_0x2b885b,_0x48c54b,_0x489ee2){if(_0x2b885b[_0x26b5('0x4d')]['id']){delete _0x2b885b[_0x26b5('0x4d')]['id'];}return db['FreshsalesAccount'][_0x26b5('0x50')]({'where':{'id':_0x2b885b[_0x26b5('0x4a')]['id']}})[_0x26b5('0x28')](handleEntityNotFound(_0x48c54b,null))[_0x26b5('0x28')](function(_0x6d59ca){if(_0x6d59ca){_0x2b885b[_0x26b5('0x4d')]['AccountId']=_0x6d59ca['id'];_0x2b885b[_0x26b5('0x4d')][_0x26b5('0x54')]=integrations[_0x26b5('0x55')](_0x2b885b[_0x26b5('0x4d')][_0x26b5('0x56')],_0x2b885b[_0x26b5('0x4d')][_0x26b5('0x33')]);_0x2b885b[_0x26b5('0x4d')][_0x26b5('0x57')]=integrations[_0x26b5('0x58')](_0x2b885b['body'][_0x26b5('0x56')],_0x2b885b[_0x26b5('0x4d')]['type']);return db[_0x26b5('0x59')][_0x26b5('0x4c')](_0x2b885b['body'],{'include':[{'model':db['FreshsalesField'],'as':_0x26b5('0x54')},{'model':db['FreshsalesField'],'as':_0x26b5('0x57')}]});}return null;})[_0x26b5('0x28')](respondWithResult(_0x48c54b,null))['catch'](handleError(_0x48c54b,null));};exports['getFields']=function(_0x4a73e7,_0x3cebdd,_0x57476a){var _0x510d3f='';var _0x99d4d0='';return db[_0x26b5('0x44')][_0x26b5('0x50')]({'where':{'id':_0x4a73e7[_0x26b5('0x4a')]['id']},'attributes':['id',_0x26b5('0x5a'),_0x26b5('0x5b'),_0x26b5('0x5c')]})[_0x26b5('0x28')](handleEntityNotFound(_0x3cebdd,null))[_0x26b5('0x28')](function(_0x448fd0){if(_0x448fd0){_0x99d4d0=_0x448fd0['username'];_0x510d3f=_0x448fd0['remoteUri'];var _0x422017=_0x448fd0[_0x26b5('0x5b')]['slice'](-0x1);if(_0x422017==='/'){_0x510d3f=_0x510d3f[_0x26b5('0x5d')](0x0,_0x510d3f['lastIndexOf'](_0x422017));}return rp({'method':'GET','uri':util['format'](_0x26b5('0x5e'),_0x510d3f,_0x26b5('0x5f')),'headers':{'Authorization':'Token\x20token='+_0x448fd0[_0x26b5('0x5c')]},'json':!![]});}})[_0x26b5('0x28')](function(_0x512a77){if(_0x512a77){var _0x45ed91=_0x512a77[_0x26b5('0x60')];var _0x4755f3=![];var _0x573277=null;for(_0x573277=0x0;_0x573277<_0x45ed91[_0x26b5('0x3b')];_0x573277++){if(_0x45ed91[_0x573277]['email']===_0x99d4d0){_0x4755f3=!![];}}if(_0x4755f3){return!![];}else{throw new Error({'statusCode':0x194,'message':_0x26b5('0x61')});}}})[_0x26b5('0x28')](respondWithResult(_0x3cebdd,null))['catch'](function(_0x520c1e){var _0x1f79ae=_0x4a73e7[_0x26b5('0x36')]['test']?0x1f4:_0x520c1e['statusCode']||0x1f4;logger[_0x26b5('0x62')]('getFields,\x20%s,\x20%s,\x20%s',_0x26b5('0x63'),_0x1f79ae,JSON[_0x26b5('0x64')](_0x520c1e));delete _0x520c1e['name'];if(_0x1f79ae===0x191){_0x1f79ae=0x190;}_0x3cebdd[_0x26b5('0x1e')](_0x1f79ae)[_0x26b5('0x2e')](_0x4a73e7[_0x26b5('0x36')][_0x26b5('0x65')]?{'message':_0x26b5('0x66'),'statusCode':_0x520c1e[_0x26b5('0x67')]}:_0x520c1e);});};
\ No newline at end of file