Built motion from commit 616d3211.|2.6.4
[motion2.git] / server / api / intVtigerAccount / intVtigerAccount.controller.js
index 7b24a8b..42ce7e7 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0x768f=['json','offset','limit','undefined','count','apply','reject','save','update','destroy','then','end','error','name','send','index','map','rawAttributes','fieldName','model','keys','query','intersection','attributes','fields','length','hasOwnProperty','nolimit','order','sort','where','pick','filters','filter','merge','type','VIRTUAL','options','includeAll','include','VtigerAccount','findAll','rows','find','catch','create','body','findOne','params','VtigerConfiguration','getConfigurations','addConfiguration','AccountId','getSubjects','channel','Descriptions','getDescriptions','Subjects','md5','getFields','username','remoteUri','accessKey','moduleName','slice','substring','format','%s/webservice.php','GET','getchallenge','login','token','success','result','sessionName','reference','owner','remove','includes','false','label','startsWith','picklist','picklistValues','value','test','statusCode','getFields,\x20%s,\x20%s,\x20%s','stringify','rimraf','zip-dir','request-promise','moment','mustache','util','sox','ejs','fs-extra','lodash','squel','crypto','desk.js','to-csv','querystring','papaparse','ioredis','../../components/auth/service','../../config/license/hardware','../../config/logger','api','../../config/utils','../../config/environment','../../config/license/util','../../mysqldb','sendStatus','status'];(function(_0x113a6c,_0x10df30){var _0x1ac632=function(_0xbd4fb9){while(--_0xbd4fb9){_0x113a6c['push'](_0x113a6c['shift']());}};_0x1ac632(++_0x10df30);}(_0x768f,0x141));var _0xf768=function(_0x415c5e,_0x4a854c){_0x415c5e=_0x415c5e-0x0;var _0x1e09c7=_0x768f[_0x415c5e];return _0x1e09c7;};'use strict';var emlformat=require('eml-format');var rimraf=require(_0xf768('0x0'));var zipdir=require(_0xf768('0x1'));var jsonpatch=require('fast-json-patch');var rp=require(_0xf768('0x2'));var moment=require(_0xf768('0x3'));var BPromise=require('bluebird');var Mustache=require(_0xf768('0x4'));var util=require(_0xf768('0x5'));var path=require('path');var sox=require(_0xf768('0x6'));var csv=require('to-csv');var ejs=require(_0xf768('0x7'));var fs=require('fs');var fs_extra=require(_0xf768('0x8'));var _=require(_0xf768('0x9'));var squel=require(_0xf768('0xa'));var crypto=require(_0xf768('0xb'));var jsforce=require('jsforce');var deskjs=require(_0xf768('0xc'));var toCsv=require(_0xf768('0xd'));var querystring=require(_0xf768('0xe'));var Papa=require(_0xf768('0xf'));var Redis=require(_0xf768('0x10'));var authService=require(_0xf768('0x11'));var qs=require('../../components/parsers/qs');var as=require('../../components/parsers/advancedSearch');var hardwareService=require(_0xf768('0x12'));var logger=require(_0xf768('0x13'))(_0xf768('0x14'));var utils=require(_0xf768('0x15'));var config=require(_0xf768('0x16'));var licenseUtil=require(_0xf768('0x17'));var db=require(_0xf768('0x18'))['db'];var integrations=require('../../components/integrations/configuration');function respondWithStatusCode(_0x567e58,_0x574b5b){_0x574b5b=_0x574b5b||0xcc;return function(_0x3253d0){if(_0x3253d0){return _0x567e58[_0xf768('0x19')](_0x574b5b);}return _0x567e58['status'](_0x574b5b)['end']();};}function respondWithResult(_0x2ace86,_0x24dd24){_0x24dd24=_0x24dd24||0xc8;return function(_0x4481c7){if(_0x4481c7){return _0x2ace86[_0xf768('0x1a')](_0x24dd24)[_0xf768('0x1b')](_0x4481c7);}};}function respondWithFilteredResult(_0x2fdeab,_0x10fa1c){return function(_0x21591c){if(_0x21591c){var _0x2e2877=typeof _0x10fa1c[_0xf768('0x1c')]==='undefined'&&typeof _0x10fa1c[_0xf768('0x1d')]===_0xf768('0x1e');var _0x12e6e4=_0x21591c[_0xf768('0x1f')];var _0x52cfbe=_0x2e2877?0x0:_0x10fa1c[_0xf768('0x1c')];var _0xf31e90=_0x2e2877?_0x21591c[_0xf768('0x1f')]:_0x10fa1c[_0xf768('0x1c')]+_0x10fa1c[_0xf768('0x1d')];var _0x3da99b;if(_0xf31e90>=_0x12e6e4){_0xf31e90=_0x12e6e4;_0x3da99b=0xc8;}else{_0x3da99b=0xce;}_0x2fdeab[_0xf768('0x1a')](_0x3da99b);return _0x2fdeab['set']('Content-Range',_0x52cfbe+'-'+_0xf31e90+'/'+_0x12e6e4)[_0xf768('0x1b')](_0x21591c);}return null;};}function patchUpdates(_0x369994){return function(_0x34e66c){try{jsonpatch[_0xf768('0x20')](_0x34e66c,_0x369994,!![]);}catch(_0x2c49ca){return BPromise[_0xf768('0x21')](_0x2c49ca);}return _0x34e66c[_0xf768('0x22')]();};}function saveUpdates(_0x5b34c1,_0x285a3a){return function(_0x182e40){if(_0x182e40){return _0x182e40[_0xf768('0x23')](_0x5b34c1)['then'](function(_0x223881){return _0x223881;});}return null;};}function removeEntity(_0x18fbc5,_0x31f95e){return function(_0x12907b){if(_0x12907b){return _0x12907b[_0xf768('0x24')]()[_0xf768('0x25')](function(){_0x18fbc5[_0xf768('0x1a')](0xcc)[_0xf768('0x26')]();});}};}function handleEntityNotFound(_0x2a8544,_0x22f05a){return function(_0x28ae0a){if(!_0x28ae0a){_0x2a8544[_0xf768('0x19')](0x194);}return _0x28ae0a;};}function handleError(_0x3b9f4a,_0x4559c7){_0x4559c7=_0x4559c7||0x1f4;return function(_0x3c07f2){logger[_0xf768('0x27')](_0x3c07f2['stack']);if(_0x3c07f2[_0xf768('0x28')]){delete _0x3c07f2[_0xf768('0x28')];}_0x3b9f4a[_0xf768('0x1a')](_0x4559c7)[_0xf768('0x29')](_0x3c07f2);};}exports[_0xf768('0x2a')]=function(_0x1926f0,_0x120a3a){var _0x256133={},_0x3e250f={},_0x206f2f={'count':0x0,'rows':[]};var _0x119f4c=_[_0xf768('0x2b')](db['VtigerAccount'][_0xf768('0x2c')],function(_0x5f25b8){return{'name':_0x5f25b8[_0xf768('0x2d')],'type':_0x5f25b8['type']['key']};});_0x3e250f[_0xf768('0x2e')]=_[_0xf768('0x2b')](_0x119f4c,_0xf768('0x28'));_0x3e250f['query']=_[_0xf768('0x2f')](_0x1926f0[_0xf768('0x30')]);_0x3e250f['filters']=_[_0xf768('0x31')](_0x3e250f[_0xf768('0x2e')],_0x3e250f[_0xf768('0x30')]);_0x256133[_0xf768('0x32')]=_['intersection'](_0x3e250f[_0xf768('0x2e')],qs[_0xf768('0x33')](_0x1926f0[_0xf768('0x30')][_0xf768('0x33')]));_0x256133[_0xf768('0x32')]=_0x256133[_0xf768('0x32')][_0xf768('0x34')]?_0x256133[_0xf768('0x32')]:_0x3e250f['model'];if(!_0x1926f0[_0xf768('0x30')][_0xf768('0x35')](_0xf768('0x36'))){_0x256133[_0xf768('0x1d')]=qs[_0xf768('0x1d')](_0x1926f0['query'][_0xf768('0x1d')]);_0x256133[_0xf768('0x1c')]=qs[_0xf768('0x1c')](_0x1926f0[_0xf768('0x30')][_0xf768('0x1c')]);}_0x256133[_0xf768('0x37')]=qs[_0xf768('0x38')](_0x1926f0[_0xf768('0x30')]['sort']);_0x256133[_0xf768('0x39')]=qs['filters'](_[_0xf768('0x3a')](_0x1926f0['query'],_0x3e250f[_0xf768('0x3b')]),_0x119f4c);if(_0x1926f0[_0xf768('0x30')][_0xf768('0x3c')]){_0x256133[_0xf768('0x39')]=_[_0xf768('0x3d')](_0x256133[_0xf768('0x39')],{'$or':_[_0xf768('0x2b')](_0x119f4c,function(_0x55bd57){if(_0x55bd57[_0xf768('0x3e')]!==_0xf768('0x3f')){var _0x1774c1={};_0x1774c1[_0x55bd57[_0xf768('0x28')]]={'$like':'%'+_0x1926f0['query'][_0xf768('0x3c')]+'%'};return _0x1774c1;}})});}_0x256133=_[_0xf768('0x3d')]({},_0x256133,_0x1926f0[_0xf768('0x40')]);var _0x3e59a6={'where':_0x256133['where']};return db['VtigerAccount'][_0xf768('0x1f')](_0x3e59a6)['then'](function(_0xeebea8){_0x206f2f[_0xf768('0x1f')]=_0xeebea8;if(_0x1926f0[_0xf768('0x30')][_0xf768('0x41')]){_0x256133[_0xf768('0x42')]=[{'all':!![]}];}return db[_0xf768('0x43')][_0xf768('0x44')](_0x256133);})['then'](function(_0x29f1ef){_0x206f2f[_0xf768('0x45')]=_0x29f1ef;return _0x206f2f;})[_0xf768('0x25')](respondWithFilteredResult(_0x120a3a,_0x256133))['catch'](handleError(_0x120a3a,null));};exports['show']=function(_0x2ccd91,_0xe18684){var _0x216063={'raw':![],'where':{'id':_0x2ccd91['params']['id']}},_0x2742c1={};_0x2742c1[_0xf768('0x2e')]=_[_0xf768('0x2f')](db[_0xf768('0x43')]['rawAttributes']);_0x2742c1['query']=_['keys'](_0x2ccd91['query']);_0x2742c1['filters']=_[_0xf768('0x31')](_0x2742c1['model'],_0x2742c1['query']);_0x216063[_0xf768('0x32')]=_[_0xf768('0x31')](_0x2742c1['model'],qs[_0xf768('0x33')](_0x2ccd91[_0xf768('0x30')][_0xf768('0x33')]));_0x216063[_0xf768('0x32')]=_0x216063[_0xf768('0x32')]['length']?_0x216063[_0xf768('0x32')]:_0x2742c1[_0xf768('0x2e')];if(_0x2ccd91['query'][_0xf768('0x41')]){_0x216063[_0xf768('0x42')]=[{'all':!![]}];}_0x216063=_['merge']({},_0x216063,_0x2ccd91[_0xf768('0x40')]);return db['VtigerAccount'][_0xf768('0x46')](_0x216063)['then'](handleEntityNotFound(_0xe18684,null))[_0xf768('0x25')](respondWithResult(_0xe18684,null))[_0xf768('0x47')](handleError(_0xe18684,null));};exports[_0xf768('0x48')]=function(_0x197883,_0x4c08e4){return db[_0xf768('0x43')][_0xf768('0x48')](_0x197883[_0xf768('0x49')],{})[_0xf768('0x25')](respondWithResult(_0x4c08e4,0xc9))[_0xf768('0x47')](handleError(_0x4c08e4,null));};exports[_0xf768('0x23')]=function(_0x498c52,_0xbe2957){if(_0x498c52[_0xf768('0x49')]['id']){delete _0x498c52[_0xf768('0x49')]['id'];}return db[_0xf768('0x43')][_0xf768('0x46')]({'where':{'id':_0x498c52['params']['id']}})[_0xf768('0x25')](handleEntityNotFound(_0xbe2957,null))[_0xf768('0x25')](saveUpdates(_0x498c52[_0xf768('0x49')],null))['then'](respondWithResult(_0xbe2957,null))['catch'](handleError(_0xbe2957,null));};exports['destroy']=function(_0x389705,_0x4c3fdd){return db[_0xf768('0x43')][_0xf768('0x46')]({'where':{'id':_0x389705['params']['id']}})[_0xf768('0x25')](handleEntityNotFound(_0x4c3fdd,null))[_0xf768('0x25')](removeEntity(_0x4c3fdd,null))[_0xf768('0x47')](handleError(_0x4c3fdd,null));};exports['getConfigurations']=function(_0x21593a,_0x5062dc,_0x5f14e9){var _0x6f5889={};var _0x7b57e1={};var _0x5cae26;var _0x51361d;return db['VtigerAccount'][_0xf768('0x4a')]({'where':{'id':_0x21593a[_0xf768('0x4b')]['id']}})[_0xf768('0x25')](handleEntityNotFound(_0x5062dc,null))[_0xf768('0x25')](function(_0x1ff1a6){if(_0x1ff1a6){_0x5cae26=_0x1ff1a6;_0x7b57e1[_0xf768('0x2e')]=_[_0xf768('0x2f')](db[_0xf768('0x4c')][_0xf768('0x2c')]);_0x7b57e1[_0xf768('0x30')]=_[_0xf768('0x2f')](_0x21593a[_0xf768('0x30')]);_0x7b57e1[_0xf768('0x3b')]=_[_0xf768('0x31')](_0x7b57e1[_0xf768('0x2e')],_0x7b57e1['query']);_0x6f5889[_0xf768('0x32')]=_[_0xf768('0x31')](_0x7b57e1['model'],qs['fields'](_0x21593a[_0xf768('0x30')][_0xf768('0x33')]));_0x6f5889['attributes']=_0x6f5889[_0xf768('0x32')][_0xf768('0x34')]?_0x6f5889[_0xf768('0x32')]:_0x7b57e1['model'];_0x6f5889[_0xf768('0x37')]=qs[_0xf768('0x38')](_0x21593a[_0xf768('0x30')]['sort']);_0x6f5889[_0xf768('0x39')]=qs[_0xf768('0x3b')](_[_0xf768('0x3a')](_0x21593a[_0xf768('0x30')],_0x7b57e1[_0xf768('0x3b')]));if(_0x21593a[_0xf768('0x30')][_0xf768('0x3c')]){_0x6f5889[_0xf768('0x39')]=_[_0xf768('0x3d')](_0x6f5889[_0xf768('0x39')],{'$or':_[_0xf768('0x2b')](_0x6f5889[_0xf768('0x32')],function(_0xe341d2){var _0x560909={};_0x560909[_0xe341d2]={'$like':'%'+_0x21593a[_0xf768('0x30')][_0xf768('0x3c')]+'%'};return _0x560909;})});}_0x6f5889=_[_0xf768('0x3d')]({},_0x6f5889,_0x21593a[_0xf768('0x40')]);return _0x5cae26[_0xf768('0x4d')](_0x6f5889);}})['then'](function(_0x11352c){if(_0x11352c){_0x51361d=_0x11352c[_0xf768('0x34')];if(!_0x21593a['query'][_0xf768('0x35')](_0xf768('0x36'))){_0x6f5889[_0xf768('0x1d')]=qs[_0xf768('0x1d')](_0x21593a[_0xf768('0x30')][_0xf768('0x1d')]);_0x6f5889['offset']=qs[_0xf768('0x1c')](_0x21593a[_0xf768('0x30')]['offset']);}return _0x5cae26['getConfigurations'](_0x6f5889);}})[_0xf768('0x25')](function(_0x11d597){if(_0x11d597){return _0x11d597?{'count':_0x51361d,'rows':_0x11d597}:null;}})[_0xf768('0x25')](respondWithResult(_0x5062dc,null))[_0xf768('0x47')](handleError(_0x5062dc,null));};exports[_0xf768('0x4e')]=function(_0x35847f,_0x474df2,_0x10d3c5){if(_0x35847f[_0xf768('0x49')]['id']){delete _0x35847f['body']['id'];}return db['VtigerAccount'][_0xf768('0x4a')]({'where':{'id':_0x35847f[_0xf768('0x4b')]['id']}})[_0xf768('0x25')](handleEntityNotFound(_0x474df2,null))[_0xf768('0x25')](function(_0x17b508){if(_0x17b508){_0x35847f['body'][_0xf768('0x4f')]=_0x17b508['id'];_0x35847f[_0xf768('0x49')]['Subjects']=integrations[_0xf768('0x50')](_0x35847f[_0xf768('0x49')][_0xf768('0x51')],_0x35847f[_0xf768('0x49')][_0xf768('0x3e')]);_0x35847f[_0xf768('0x49')][_0xf768('0x52')]=integrations[_0xf768('0x53')](_0x35847f[_0xf768('0x49')][_0xf768('0x51')],_0x35847f[_0xf768('0x49')][_0xf768('0x3e')]);return db['VtigerConfiguration']['create'](_0x35847f['body'],{'include':[{'model':db['VtigerField'],'as':_0xf768('0x54')},{'model':db['VtigerField'],'as':'Descriptions'}]});}return null;})['then'](respondWithResult(_0x474df2,null))[_0xf768('0x47')](handleError(_0x474df2,null));};var md5=require(_0xf768('0x55'));exports[_0xf768('0x56')]=function(_0x203837,_0x231efb,_0x4ba9b7){var _0x4a92ce=null;var _0x1ed7b0=null;var _0x3b1d90=null;var _0x215e55=null;var _0x39b350='';return db[_0xf768('0x43')][_0xf768('0x4a')]({'where':{'id':_0x203837['params']['id']},'attributes':['id','name',_0xf768('0x57'),'description','moduleName',_0xf768('0x58'),'serverUrl',_0xf768('0x59')]})['then'](handleEntityNotFound(_0x231efb,null))[_0xf768('0x25')](function(_0xb1308c){if(_0xb1308c){_0x4a92ce=_0xb1308c['username'];_0x1ed7b0=_0xb1308c['accessKey'];_0x3b1d90=_0xb1308c[_0xf768('0x5a')];_0x39b350=_0xb1308c['remoteUri'];var _0x37f0b6=_0x39b350[_0xf768('0x5b')](-0x1);if(_0x37f0b6==='/'){_0x39b350=_0x39b350[_0xf768('0x5c')](0x0,_0x39b350['lastIndexOf'](_0x37f0b6));}_0x215e55=util[_0xf768('0x5d')](_0xf768('0x5e'),_0x39b350);var _0xd3a3f6={'method':_0xf768('0x5f'),'uri':_0x215e55,'qs':{'operation':_0xf768('0x60'),'username':_0xb1308c[_0xf768('0x57')]},'json':!![]};return rp(_0xd3a3f6);}})['then'](function(_0x384863){if(_0x384863['success']){var _0x15fe19={'method':'POST','uri':_0x215e55,'form':{'operation':_0xf768('0x61'),'username':_0x4a92ce,'accessKey':md5(_0x384863['result'][_0xf768('0x62')]+_0x1ed7b0)},'json':!![]};return rp(_0x15fe19);}})[_0xf768('0x25')](function(_0x7788f3){if(_0x7788f3[_0xf768('0x63')]){var _0x30986a={'method':'GET','uri':_0x215e55,'qs':{'operation':'describe','username':_0x4a92ce,'sessionName':_0x7788f3[_0xf768('0x64')][_0xf768('0x65')],'elementType':_0x3b1d90},'json':!![]};return rp(_0x30986a);}})['then'](function(_0x4088e7){if(_0x4088e7[_0xf768('0x63')]){var _0x5d63dd=['autogenerated',_0xf768('0x66'),_0xf768('0x67')];_[_0xf768('0x68')](_0x4088e7[_0xf768('0x64')][_0xf768('0x33')],function(_0x56b035){return _0x5d63dd[_0xf768('0x69')](_0x56b035[_0xf768('0x3e')][_0xf768('0x28')]);});_[_0xf768('0x68')](_0x4088e7[_0xf768('0x64')][_0xf768('0x33')],function(_0x15df9b){return _0x15df9b['editable']===_0xf768('0x6a');});return{'count':_0x4088e7['result'][_0xf768('0x33')][_0xf768('0x34')],'rows':_[_0xf768('0x2b')](_0x4088e7['result'][_0xf768('0x33')],function(_0x16ef37){return{'id':_0x16ef37[_0xf768('0x28')],'name':_0x16ef37[_0xf768('0x6b')],'custom':_[_0xf768('0x6c')](_0x16ef37[_0xf768('0x28')],'cf_')?!![]:![],'options':_0x16ef37[_0xf768('0x3e')][_0xf768('0x28')]===_0xf768('0x6d')&&_0x16ef37[_0xf768('0x3e')][_0xf768('0x6e')][_0xf768('0x34')]>0x0?_[_0xf768('0x2b')](_0x16ef37[_0xf768('0x3e')][_0xf768('0x6e')],function(_0x34371b){return{'name':_0x34371b[_0xf768('0x6b')],'value':_0x34371b[_0xf768('0x6f')]};}):[]};})};}})[_0xf768('0x25')](respondWithResult(_0x231efb,null))['catch'](function(_0x18f14f){console['log']('vTiger\x20error:\x20'+_0x18f14f);var _0x9c612a=_0x203837['query'][_0xf768('0x70')]?0x1f4:_0x18f14f[_0xf768('0x71')]||0x1f4;logger['error'](_0xf768('0x72'),_0xf768('0x56'),_0x9c612a,JSON[_0xf768('0x73')](_0x18f14f));delete _0x18f14f[_0xf768('0x28')];if(_0x9c612a===0x191){_0x9c612a=0x190;}_0x231efb[_0xf768('0x1a')](_0x9c612a)[_0xf768('0x29')](_0x203837[_0xf768('0x30')][_0xf768('0x70')]?{'message':'Wrong\x20credentials','statusCode':_0x18f14f[_0xf768('0x71')]}:_0x18f14f);});};
\ No newline at end of file
+var _0x1b34=['remoteUri','serverUrl','accessKey','username','slice','substring','lastIndexOf','%s/webservice.php','GET','getchallenge','success','POST','login','result','token','sessionName','autogenerated','reference','owner','remove','editable','false','label','startsWith','cf_','picklist','picklistValues','value','log','vTiger\x20error:\x20','getFields','stringify','Wrong\x20credentials','statusCode','rimraf','zip-dir','request-promise','moment','bluebird','mustache','util','path','to-csv','ejs','fs-extra','lodash','jsforce','desk.js','ioredis','../../config/license/hardware','../../config/logger','api','../../config/utils','../../config/environment','../../config/license/util','../../mysqldb','../../components/integrations/configuration','status','json','limit','undefined','count','Content-Range','apply','reject','then','destroy','sendStatus','error','name','send','map','VtigerAccount','rawAttributes','fieldName','key','model','query','keys','intersection','attributes','fields','length','hasOwnProperty','nolimit','offset','order','sort','filters','pick','filter','merge','VIRTUAL','options','where','includeAll','include','findAll','catch','show','params','find','create','update','body','getConfigurations','VtigerConfiguration','addConfiguration','findOne','AccountId','getSubjects','Descriptions','getDescriptions','channel','type','VtigerField','md5','description','moduleName'];(function(_0x1b97f3,_0xce63f3){var _0x32d818=function(_0x9671b7){while(--_0x9671b7){_0x1b97f3['push'](_0x1b97f3['shift']());}};_0x32d818(++_0xce63f3);}(_0x1b34,0x99));var _0x41b3=function(_0x2b27a0,_0x2ee33){_0x2b27a0=_0x2b27a0-0x0;var _0x44ec6b=_0x1b34[_0x2b27a0];return _0x44ec6b;};'use strict';var emlformat=require('eml-format');var rimraf=require(_0x41b3('0x0'));var zipdir=require(_0x41b3('0x1'));var jsonpatch=require('fast-json-patch');var rp=require(_0x41b3('0x2'));var moment=require(_0x41b3('0x3'));var BPromise=require(_0x41b3('0x4'));var Mustache=require(_0x41b3('0x5'));var util=require(_0x41b3('0x6'));var path=require(_0x41b3('0x7'));var sox=require('sox');var csv=require(_0x41b3('0x8'));var ejs=require(_0x41b3('0x9'));var fs=require('fs');var fs_extra=require(_0x41b3('0xa'));var _=require(_0x41b3('0xb'));var squel=require('squel');var crypto=require('crypto');var jsforce=require(_0x41b3('0xc'));var deskjs=require(_0x41b3('0xd'));var toCsv=require('to-csv');var querystring=require('querystring');var Papa=require('papaparse');var Redis=require(_0x41b3('0xe'));var authService=require('../../components/auth/service');var qs=require('../../components/parsers/qs');var as=require('../../components/parsers/advancedSearch');var hardwareService=require(_0x41b3('0xf'));var logger=require(_0x41b3('0x10'))(_0x41b3('0x11'));var utils=require(_0x41b3('0x12'));var config=require(_0x41b3('0x13'));var licenseUtil=require(_0x41b3('0x14'));var db=require(_0x41b3('0x15'))['db'];var integrations=require(_0x41b3('0x16'));function respondWithStatusCode(_0x2ca7ea,_0x431811){_0x431811=_0x431811||0xcc;return function(_0x4e7552){if(_0x4e7552){return _0x2ca7ea['sendStatus'](_0x431811);}return _0x2ca7ea[_0x41b3('0x17')](_0x431811)['end']();};}function respondWithResult(_0x1cdb03,_0x43caa4){_0x43caa4=_0x43caa4||0xc8;return function(_0x7283b1){if(_0x7283b1){return _0x1cdb03[_0x41b3('0x17')](_0x43caa4)[_0x41b3('0x18')](_0x7283b1);}};}function respondWithFilteredResult(_0x2aedd7,_0x2a6a52){return function(_0x55b1bf){if(_0x55b1bf){var _0x4511c9=typeof _0x2a6a52['offset']==='undefined'&&typeof _0x2a6a52[_0x41b3('0x19')]===_0x41b3('0x1a');var _0x104190=_0x55b1bf[_0x41b3('0x1b')];var _0x2d4325=_0x4511c9?0x0:_0x2a6a52['offset'];var _0x4684a7=_0x4511c9?_0x55b1bf[_0x41b3('0x1b')]:_0x2a6a52['offset']+_0x2a6a52[_0x41b3('0x19')];var _0x35f777;if(_0x4684a7>=_0x104190){_0x4684a7=_0x104190;_0x35f777=0xc8;}else{_0x35f777=0xce;}_0x2aedd7[_0x41b3('0x17')](_0x35f777);return _0x2aedd7['set'](_0x41b3('0x1c'),_0x2d4325+'-'+_0x4684a7+'/'+_0x104190)[_0x41b3('0x18')](_0x55b1bf);}return null;};}function patchUpdates(_0x6a2959){return function(_0x368daf){try{jsonpatch[_0x41b3('0x1d')](_0x368daf,_0x6a2959,!![]);}catch(_0x3c8367){return BPromise[_0x41b3('0x1e')](_0x3c8367);}return _0x368daf['save']();};}function saveUpdates(_0x4f0c08,_0x413cd8){return function(_0xc80638){if(_0xc80638){return _0xc80638['update'](_0x4f0c08)[_0x41b3('0x1f')](function(_0x45e79b){return _0x45e79b;});}return null;};}function removeEntity(_0x3c0e81,_0x3a4ac6){return function(_0x365003){if(_0x365003){return _0x365003[_0x41b3('0x20')]()['then'](function(){_0x3c0e81[_0x41b3('0x17')](0xcc)['end']();});}};}function handleEntityNotFound(_0x333ebb,_0x2d5191){return function(_0x377086){if(!_0x377086){_0x333ebb[_0x41b3('0x21')](0x194);}return _0x377086;};}function handleError(_0x5b9a57,_0x20b51a){_0x20b51a=_0x20b51a||0x1f4;return function(_0x1e1637){logger[_0x41b3('0x22')](_0x1e1637['stack']);if(_0x1e1637[_0x41b3('0x23')]){delete _0x1e1637[_0x41b3('0x23')];}_0x5b9a57['status'](_0x20b51a)[_0x41b3('0x24')](_0x1e1637);};}exports['index']=function(_0x24e8e9,_0x4cc510){var _0x3fa2b4={},_0x500d63={},_0x1ed919={'count':0x0,'rows':[]};var _0x39f931=_[_0x41b3('0x25')](db[_0x41b3('0x26')][_0x41b3('0x27')],function(_0xc028a){return{'name':_0xc028a[_0x41b3('0x28')],'type':_0xc028a['type'][_0x41b3('0x29')]};});_0x500d63[_0x41b3('0x2a')]=_['map'](_0x39f931,_0x41b3('0x23'));_0x500d63[_0x41b3('0x2b')]=_[_0x41b3('0x2c')](_0x24e8e9[_0x41b3('0x2b')]);_0x500d63['filters']=_[_0x41b3('0x2d')](_0x500d63['model'],_0x500d63[_0x41b3('0x2b')]);_0x3fa2b4[_0x41b3('0x2e')]=_[_0x41b3('0x2d')](_0x500d63[_0x41b3('0x2a')],qs[_0x41b3('0x2f')](_0x24e8e9[_0x41b3('0x2b')][_0x41b3('0x2f')]));_0x3fa2b4[_0x41b3('0x2e')]=_0x3fa2b4[_0x41b3('0x2e')][_0x41b3('0x30')]?_0x3fa2b4[_0x41b3('0x2e')]:_0x500d63[_0x41b3('0x2a')];if(!_0x24e8e9[_0x41b3('0x2b')][_0x41b3('0x31')](_0x41b3('0x32'))){_0x3fa2b4[_0x41b3('0x19')]=qs[_0x41b3('0x19')](_0x24e8e9[_0x41b3('0x2b')][_0x41b3('0x19')]);_0x3fa2b4[_0x41b3('0x33')]=qs[_0x41b3('0x33')](_0x24e8e9[_0x41b3('0x2b')][_0x41b3('0x33')]);}_0x3fa2b4[_0x41b3('0x34')]=qs[_0x41b3('0x35')](_0x24e8e9[_0x41b3('0x2b')][_0x41b3('0x35')]);_0x3fa2b4['where']=qs[_0x41b3('0x36')](_[_0x41b3('0x37')](_0x24e8e9[_0x41b3('0x2b')],_0x500d63[_0x41b3('0x36')]),_0x39f931);if(_0x24e8e9[_0x41b3('0x2b')][_0x41b3('0x38')]){_0x3fa2b4['where']=_[_0x41b3('0x39')](_0x3fa2b4['where'],{'$or':_['map'](_0x39f931,function(_0x57f142){if(_0x57f142['type']!==_0x41b3('0x3a')){var _0x1a101b={};_0x1a101b[_0x57f142[_0x41b3('0x23')]]={'$like':'%'+_0x24e8e9[_0x41b3('0x2b')]['filter']+'%'};return _0x1a101b;}})});}_0x3fa2b4=_[_0x41b3('0x39')]({},_0x3fa2b4,_0x24e8e9[_0x41b3('0x3b')]);var _0x4d51ca={'where':_0x3fa2b4[_0x41b3('0x3c')]};return db[_0x41b3('0x26')]['count'](_0x4d51ca)[_0x41b3('0x1f')](function(_0x2b7fd5){_0x1ed919[_0x41b3('0x1b')]=_0x2b7fd5;if(_0x24e8e9['query'][_0x41b3('0x3d')]){_0x3fa2b4[_0x41b3('0x3e')]=[{'all':!![]}];}return db[_0x41b3('0x26')][_0x41b3('0x3f')](_0x3fa2b4);})[_0x41b3('0x1f')](function(_0x1c17a2){_0x1ed919['rows']=_0x1c17a2;return _0x1ed919;})[_0x41b3('0x1f')](respondWithFilteredResult(_0x4cc510,_0x3fa2b4))[_0x41b3('0x40')](handleError(_0x4cc510,null));};exports[_0x41b3('0x41')]=function(_0x3fe1d9,_0x8f01fe){var _0x1bf59a={'raw':![],'where':{'id':_0x3fe1d9[_0x41b3('0x42')]['id']}},_0x199f78={};_0x199f78[_0x41b3('0x2a')]=_['keys'](db['VtigerAccount'][_0x41b3('0x27')]);_0x199f78[_0x41b3('0x2b')]=_[_0x41b3('0x2c')](_0x3fe1d9[_0x41b3('0x2b')]);_0x199f78[_0x41b3('0x36')]=_['intersection'](_0x199f78['model'],_0x199f78[_0x41b3('0x2b')]);_0x1bf59a['attributes']=_[_0x41b3('0x2d')](_0x199f78['model'],qs[_0x41b3('0x2f')](_0x3fe1d9[_0x41b3('0x2b')][_0x41b3('0x2f')]));_0x1bf59a[_0x41b3('0x2e')]=_0x1bf59a[_0x41b3('0x2e')][_0x41b3('0x30')]?_0x1bf59a[_0x41b3('0x2e')]:_0x199f78[_0x41b3('0x2a')];if(_0x3fe1d9[_0x41b3('0x2b')][_0x41b3('0x3d')]){_0x1bf59a[_0x41b3('0x3e')]=[{'all':!![]}];}_0x1bf59a=_[_0x41b3('0x39')]({},_0x1bf59a,_0x3fe1d9[_0x41b3('0x3b')]);return db[_0x41b3('0x26')][_0x41b3('0x43')](_0x1bf59a)['then'](handleEntityNotFound(_0x8f01fe,null))['then'](respondWithResult(_0x8f01fe,null))[_0x41b3('0x40')](handleError(_0x8f01fe,null));};exports[_0x41b3('0x44')]=function(_0x38360a,_0x17cb8a){return db[_0x41b3('0x26')][_0x41b3('0x44')](_0x38360a['body'],{})[_0x41b3('0x1f')](respondWithResult(_0x17cb8a,0xc9))[_0x41b3('0x40')](handleError(_0x17cb8a,null));};exports[_0x41b3('0x45')]=function(_0x33732f,_0x88528b){if(_0x33732f[_0x41b3('0x46')]['id']){delete _0x33732f[_0x41b3('0x46')]['id'];}return db['VtigerAccount'][_0x41b3('0x43')]({'where':{'id':_0x33732f['params']['id']}})[_0x41b3('0x1f')](handleEntityNotFound(_0x88528b,null))[_0x41b3('0x1f')](saveUpdates(_0x33732f['body'],null))[_0x41b3('0x1f')](respondWithResult(_0x88528b,null))[_0x41b3('0x40')](handleError(_0x88528b,null));};exports[_0x41b3('0x20')]=function(_0x5298d1,_0x19dfd7){return db[_0x41b3('0x26')][_0x41b3('0x43')]({'where':{'id':_0x5298d1[_0x41b3('0x42')]['id']}})[_0x41b3('0x1f')](handleEntityNotFound(_0x19dfd7,null))[_0x41b3('0x1f')](removeEntity(_0x19dfd7,null))[_0x41b3('0x40')](handleError(_0x19dfd7,null));};exports[_0x41b3('0x47')]=function(_0x51c2f4,_0x53364e,_0x577469){var _0x5044fb={};var _0x3d17cf={};var _0x38fdd8;var _0x343598;return db[_0x41b3('0x26')]['findOne']({'where':{'id':_0x51c2f4['params']['id']}})['then'](handleEntityNotFound(_0x53364e,null))[_0x41b3('0x1f')](function(_0x3a57cb){if(_0x3a57cb){_0x38fdd8=_0x3a57cb;_0x3d17cf[_0x41b3('0x2a')]=_[_0x41b3('0x2c')](db[_0x41b3('0x48')][_0x41b3('0x27')]);_0x3d17cf[_0x41b3('0x2b')]=_[_0x41b3('0x2c')](_0x51c2f4['query']);_0x3d17cf[_0x41b3('0x36')]=_[_0x41b3('0x2d')](_0x3d17cf['model'],_0x3d17cf[_0x41b3('0x2b')]);_0x5044fb[_0x41b3('0x2e')]=_['intersection'](_0x3d17cf[_0x41b3('0x2a')],qs[_0x41b3('0x2f')](_0x51c2f4[_0x41b3('0x2b')][_0x41b3('0x2f')]));_0x5044fb[_0x41b3('0x2e')]=_0x5044fb['attributes']['length']?_0x5044fb[_0x41b3('0x2e')]:_0x3d17cf[_0x41b3('0x2a')];_0x5044fb[_0x41b3('0x34')]=qs['sort'](_0x51c2f4[_0x41b3('0x2b')][_0x41b3('0x35')]);_0x5044fb[_0x41b3('0x3c')]=qs[_0x41b3('0x36')](_['pick'](_0x51c2f4['query'],_0x3d17cf[_0x41b3('0x36')]));if(_0x51c2f4[_0x41b3('0x2b')]['filter']){_0x5044fb[_0x41b3('0x3c')]=_[_0x41b3('0x39')](_0x5044fb['where'],{'$or':_[_0x41b3('0x25')](_0x5044fb[_0x41b3('0x2e')],function(_0x336968){var _0x418c43={};_0x418c43[_0x336968]={'$like':'%'+_0x51c2f4[_0x41b3('0x2b')]['filter']+'%'};return _0x418c43;})});}_0x5044fb=_[_0x41b3('0x39')]({},_0x5044fb,_0x51c2f4[_0x41b3('0x3b')]);return _0x38fdd8['getConfigurations'](_0x5044fb);}})[_0x41b3('0x1f')](function(_0x166ea2){if(_0x166ea2){_0x343598=_0x166ea2[_0x41b3('0x30')];if(!_0x51c2f4[_0x41b3('0x2b')][_0x41b3('0x31')](_0x41b3('0x32'))){_0x5044fb[_0x41b3('0x19')]=qs[_0x41b3('0x19')](_0x51c2f4[_0x41b3('0x2b')][_0x41b3('0x19')]);_0x5044fb[_0x41b3('0x33')]=qs[_0x41b3('0x33')](_0x51c2f4[_0x41b3('0x2b')][_0x41b3('0x33')]);}return _0x38fdd8[_0x41b3('0x47')](_0x5044fb);}})[_0x41b3('0x1f')](function(_0x1aa3ad){if(_0x1aa3ad){return _0x1aa3ad?{'count':_0x343598,'rows':_0x1aa3ad}:null;}})[_0x41b3('0x1f')](respondWithResult(_0x53364e,null))['catch'](handleError(_0x53364e,null));};exports[_0x41b3('0x49')]=function(_0x42d61d,_0x4d4bcb,_0x47bc54){if(_0x42d61d[_0x41b3('0x46')]['id']){delete _0x42d61d[_0x41b3('0x46')]['id'];}return db[_0x41b3('0x26')][_0x41b3('0x4a')]({'where':{'id':_0x42d61d[_0x41b3('0x42')]['id']}})[_0x41b3('0x1f')](handleEntityNotFound(_0x4d4bcb,null))[_0x41b3('0x1f')](function(_0x5c2cac){if(_0x5c2cac){_0x42d61d['body'][_0x41b3('0x4b')]=_0x5c2cac['id'];_0x42d61d[_0x41b3('0x46')]['Subjects']=integrations[_0x41b3('0x4c')](_0x42d61d[_0x41b3('0x46')]['channel'],_0x42d61d[_0x41b3('0x46')]['type']);_0x42d61d[_0x41b3('0x46')][_0x41b3('0x4d')]=integrations[_0x41b3('0x4e')](_0x42d61d['body'][_0x41b3('0x4f')],_0x42d61d['body'][_0x41b3('0x50')]);return db[_0x41b3('0x48')]['create'](_0x42d61d[_0x41b3('0x46')],{'include':[{'model':db[_0x41b3('0x51')],'as':'Subjects'},{'model':db[_0x41b3('0x51')],'as':'Descriptions'}]});}return null;})[_0x41b3('0x1f')](respondWithResult(_0x4d4bcb,null))[_0x41b3('0x40')](handleError(_0x4d4bcb,null));};var md5=require(_0x41b3('0x52'));exports['getFields']=function(_0x28f1e2,_0x1b6544,_0x44ef32){var _0x1e5a2=null;var _0x13267a=null;var _0x256d54=null;var _0x52db06=null;var _0x3ac1e3='';return db[_0x41b3('0x26')][_0x41b3('0x4a')]({'where':{'id':_0x28f1e2['params']['id']},'attributes':['id','name','username',_0x41b3('0x53'),_0x41b3('0x54'),_0x41b3('0x55'),_0x41b3('0x56'),_0x41b3('0x57')]})['then'](handleEntityNotFound(_0x1b6544,null))['then'](function(_0x166669){if(_0x166669){_0x1e5a2=_0x166669[_0x41b3('0x58')];_0x13267a=_0x166669[_0x41b3('0x57')];_0x256d54=_0x166669[_0x41b3('0x54')];_0x3ac1e3=_0x166669[_0x41b3('0x55')];var _0x541874=_0x3ac1e3[_0x41b3('0x59')](-0x1);if(_0x541874==='/'){_0x3ac1e3=_0x3ac1e3[_0x41b3('0x5a')](0x0,_0x3ac1e3[_0x41b3('0x5b')](_0x541874));}_0x52db06=util['format'](_0x41b3('0x5c'),_0x3ac1e3);var _0x57c0c6={'method':_0x41b3('0x5d'),'uri':_0x52db06,'qs':{'operation':_0x41b3('0x5e'),'username':_0x166669[_0x41b3('0x58')]},'json':!![]};return rp(_0x57c0c6);}})[_0x41b3('0x1f')](function(_0x4a194a){if(_0x4a194a[_0x41b3('0x5f')]){var _0x5d4ab9={'method':_0x41b3('0x60'),'uri':_0x52db06,'form':{'operation':_0x41b3('0x61'),'username':_0x1e5a2,'accessKey':md5(_0x4a194a[_0x41b3('0x62')][_0x41b3('0x63')]+_0x13267a)},'json':!![]};return rp(_0x5d4ab9);}})['then'](function(_0x13e9e4){if(_0x13e9e4['success']){var _0x17aa59={'method':_0x41b3('0x5d'),'uri':_0x52db06,'qs':{'operation':'describe','username':_0x1e5a2,'sessionName':_0x13e9e4[_0x41b3('0x62')][_0x41b3('0x64')],'elementType':_0x256d54},'json':!![]};return rp(_0x17aa59);}})[_0x41b3('0x1f')](function(_0xccafa9){if(_0xccafa9[_0x41b3('0x5f')]){var _0x1d02b3=[_0x41b3('0x65'),_0x41b3('0x66'),_0x41b3('0x67')];_[_0x41b3('0x68')](_0xccafa9[_0x41b3('0x62')][_0x41b3('0x2f')],function(_0x52afd4){return _0x1d02b3['includes'](_0x52afd4[_0x41b3('0x50')][_0x41b3('0x23')]);});_[_0x41b3('0x68')](_0xccafa9[_0x41b3('0x62')][_0x41b3('0x2f')],function(_0x5702a6){return _0x5702a6[_0x41b3('0x69')]===_0x41b3('0x6a');});return{'count':_0xccafa9[_0x41b3('0x62')][_0x41b3('0x2f')][_0x41b3('0x30')],'rows':_[_0x41b3('0x25')](_0xccafa9[_0x41b3('0x62')][_0x41b3('0x2f')],function(_0xe91bc6){return{'id':_0xe91bc6[_0x41b3('0x23')],'name':_0xe91bc6[_0x41b3('0x6b')],'custom':_[_0x41b3('0x6c')](_0xe91bc6[_0x41b3('0x23')],_0x41b3('0x6d'))?!![]:![],'options':_0xe91bc6[_0x41b3('0x50')][_0x41b3('0x23')]===_0x41b3('0x6e')&&_0xe91bc6[_0x41b3('0x50')][_0x41b3('0x6f')]['length']>0x0?_[_0x41b3('0x25')](_0xe91bc6[_0x41b3('0x50')][_0x41b3('0x6f')],function(_0x4ddca0){return{'name':_0x4ddca0[_0x41b3('0x6b')],'value':_0x4ddca0[_0x41b3('0x70')]};}):[]};})};}})[_0x41b3('0x1f')](respondWithResult(_0x1b6544,null))['catch'](function(_0x5591f0){console[_0x41b3('0x71')](_0x41b3('0x72')+_0x5591f0);var _0x1fc1ab=_0x28f1e2[_0x41b3('0x2b')]['test']?0x1f4:_0x5591f0['statusCode']||0x1f4;logger[_0x41b3('0x22')]('getFields,\x20%s,\x20%s,\x20%s',_0x41b3('0x73'),_0x1fc1ab,JSON[_0x41b3('0x74')](_0x5591f0));delete _0x5591f0[_0x41b3('0x23')];if(_0x1fc1ab===0x191){_0x1fc1ab=0x190;}_0x1b6544[_0x41b3('0x17')](_0x1fc1ab)['send'](_0x28f1e2[_0x41b3('0x2b')]['test']?{'message':_0x41b3('0x75'),'statusCode':_0x5591f0[_0x41b3('0x76')]}:_0x5591f0);});};
\ No newline at end of file