Built motion from commit ffdca78c.|2.6.24
[motion2.git] / server / api / intVtigerAccount / intVtigerAccount.controller.js
index 6b0ceb5..f01feac 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0x6444=['rows','show','intersection','includeAll','merge','catch','create','body','find','params','getConfigurations','VtigerConfiguration','rawAttributes','order','nolimit','addConfiguration','findOne','AccountId','Subjects','getSubjects','channel','getDescriptions','VtigerField','Descriptions','username','description','moduleName','remoteUri','serverUrl','accessKey','slice','substring','format','%s/webservice.php','getchallenge','success','POST','login','result','token','GET','sessionName','reference','owner','remove','includes','editable','false','label','startsWith','cf_','picklist','picklistValues','value','log','vTiger\x20error:\x20','test','statusCode','error','getFields,\x20%s,\x20%s,\x20%s','getFields','Wrong\x20credentials','rimraf','fast-json-patch','request-promise','bluebird','mustache','util','sox','to-csv','fs-extra','lodash','squel','crypto','desk.js','querystring','papaparse','ioredis','../../components/parsers/qs','../../config/license/hardware','../../config/logger','api','../../config/utils','../../config/environment','../../mysqldb','sendStatus','undefined','limit','count','offset','status','Content-Range','json','reject','save','update','destroy','then','end','stack','name','send','index','map','fieldName','type','key','model','query','keys','filters','fields','attributes','length','hasOwnProperty','sort','pick','filter','where','options','VtigerAccount','include','findAll'];(function(_0x1dcdca,_0x3544cf){var _0x27ec22=function(_0x4089e6){while(--_0x4089e6){_0x1dcdca['push'](_0x1dcdca['shift']());}};_0x27ec22(++_0x3544cf);}(_0x6444,0x1af));var _0x4644=function(_0x52ec0e,_0x10a03c){_0x52ec0e=_0x52ec0e-0x0;var _0x2d649c=_0x6444[_0x52ec0e];return _0x2d649c;};'use strict';var emlformat=require('eml-format');var rimraf=require(_0x4644('0x0'));var zipdir=require('zip-dir');var jsonpatch=require(_0x4644('0x1'));var rp=require(_0x4644('0x2'));var moment=require('moment');var BPromise=require(_0x4644('0x3'));var Mustache=require(_0x4644('0x4'));var util=require(_0x4644('0x5'));var path=require('path');var sox=require(_0x4644('0x6'));var csv=require(_0x4644('0x7'));var ejs=require('ejs');var fs=require('fs');var fs_extra=require(_0x4644('0x8'));var _=require(_0x4644('0x9'));var squel=require(_0x4644('0xa'));var crypto=require(_0x4644('0xb'));var jsforce=require('jsforce');var deskjs=require(_0x4644('0xc'));var toCsv=require(_0x4644('0x7'));var querystring=require(_0x4644('0xd'));var Papa=require(_0x4644('0xe'));var Redis=require(_0x4644('0xf'));var authService=require('../../components/auth/service');var qs=require(_0x4644('0x10'));var as=require('../../components/parsers/advancedSearch');var hardwareService=require(_0x4644('0x11'));var logger=require(_0x4644('0x12'))(_0x4644('0x13'));var utils=require(_0x4644('0x14'));var config=require(_0x4644('0x15'));var licenseUtil=require('../../config/license/util');var db=require(_0x4644('0x16'))['db'];var integrations=require('../../components/integrations/configuration');function respondWithStatusCode(_0x35d351,_0x2b0716){_0x2b0716=_0x2b0716||0xcc;return function(_0x65a0fe){if(_0x65a0fe){return _0x35d351[_0x4644('0x17')](_0x2b0716);}return _0x35d351['status'](_0x2b0716)['end']();};}function respondWithResult(_0x28e82b,_0x591dda){_0x591dda=_0x591dda||0xc8;return function(_0x266d1f){if(_0x266d1f){return _0x28e82b['status'](_0x591dda)['json'](_0x266d1f);}};}function respondWithFilteredResult(_0x52933b,_0x28fa03){return function(_0x5339f9){if(_0x5339f9){var _0x3b4688=typeof _0x28fa03['offset']===_0x4644('0x18')&&typeof _0x28fa03[_0x4644('0x19')]===_0x4644('0x18');var _0x243efc=_0x5339f9[_0x4644('0x1a')];var _0x1f0b18=_0x3b4688?0x0:_0x28fa03[_0x4644('0x1b')];var _0x34318b=_0x3b4688?_0x5339f9[_0x4644('0x1a')]:_0x28fa03[_0x4644('0x1b')]+_0x28fa03[_0x4644('0x19')];var _0x510cda;if(_0x34318b>=_0x243efc){_0x34318b=_0x243efc;_0x510cda=0xc8;}else{_0x510cda=0xce;}_0x52933b[_0x4644('0x1c')](_0x510cda);return _0x52933b['set'](_0x4644('0x1d'),_0x1f0b18+'-'+_0x34318b+'/'+_0x243efc)[_0x4644('0x1e')](_0x5339f9);}return null;};}function patchUpdates(_0x28ab10){return function(_0x1915c4){try{jsonpatch['apply'](_0x1915c4,_0x28ab10,!![]);}catch(_0x389ea9){return BPromise[_0x4644('0x1f')](_0x389ea9);}return _0x1915c4[_0x4644('0x20')]();};}function saveUpdates(_0x44b82b,_0x376856){return function(_0x369f93){if(_0x369f93){return _0x369f93[_0x4644('0x21')](_0x44b82b)['then'](function(_0x560b81){return _0x560b81;});}return null;};}function removeEntity(_0x41d574,_0x36a253){return function(_0x422b5a){if(_0x422b5a){return _0x422b5a[_0x4644('0x22')]()[_0x4644('0x23')](function(){_0x41d574[_0x4644('0x1c')](0xcc)[_0x4644('0x24')]();});}};}function handleEntityNotFound(_0x15cae7,_0x489abe){return function(_0x26940f){if(!_0x26940f){_0x15cae7[_0x4644('0x17')](0x194);}return _0x26940f;};}function handleError(_0x44a0fe,_0x5ab938){_0x5ab938=_0x5ab938||0x1f4;return function(_0x4fd7c3){logger['error'](_0x4fd7c3[_0x4644('0x25')]);if(_0x4fd7c3[_0x4644('0x26')]){delete _0x4fd7c3['name'];}_0x44a0fe[_0x4644('0x1c')](_0x5ab938)[_0x4644('0x27')](_0x4fd7c3);};}exports[_0x4644('0x28')]=function(_0x297dfc,_0x2fd086){var _0x221dc2={},_0x1558cb={},_0x33eb52={'count':0x0,'rows':[]};var _0x23fc1a=_[_0x4644('0x29')](db['VtigerAccount']['rawAttributes'],function(_0x1a10fa){return{'name':_0x1a10fa[_0x4644('0x2a')],'type':_0x1a10fa[_0x4644('0x2b')][_0x4644('0x2c')]};});_0x1558cb[_0x4644('0x2d')]=_[_0x4644('0x29')](_0x23fc1a,_0x4644('0x26'));_0x1558cb[_0x4644('0x2e')]=_[_0x4644('0x2f')](_0x297dfc[_0x4644('0x2e')]);_0x1558cb[_0x4644('0x30')]=_['intersection'](_0x1558cb[_0x4644('0x2d')],_0x1558cb[_0x4644('0x2e')]);_0x221dc2['attributes']=_['intersection'](_0x1558cb[_0x4644('0x2d')],qs['fields'](_0x297dfc[_0x4644('0x2e')][_0x4644('0x31')]));_0x221dc2[_0x4644('0x32')]=_0x221dc2[_0x4644('0x32')][_0x4644('0x33')]?_0x221dc2[_0x4644('0x32')]:_0x1558cb[_0x4644('0x2d')];if(!_0x297dfc[_0x4644('0x2e')][_0x4644('0x34')]('nolimit')){_0x221dc2[_0x4644('0x19')]=qs[_0x4644('0x19')](_0x297dfc[_0x4644('0x2e')][_0x4644('0x19')]);_0x221dc2[_0x4644('0x1b')]=qs[_0x4644('0x1b')](_0x297dfc[_0x4644('0x2e')][_0x4644('0x1b')]);}_0x221dc2['order']=qs['sort'](_0x297dfc[_0x4644('0x2e')][_0x4644('0x35')]);_0x221dc2['where']=qs[_0x4644('0x30')](_[_0x4644('0x36')](_0x297dfc['query'],_0x1558cb['filters']),_0x23fc1a);if(_0x297dfc['query'][_0x4644('0x37')]){_0x221dc2[_0x4644('0x38')]=_['merge'](_0x221dc2[_0x4644('0x38')],{'$or':_[_0x4644('0x29')](_0x23fc1a,function(_0x291db8){if(_0x291db8['type']!=='VIRTUAL'){var _0x22a35a={};_0x22a35a[_0x291db8[_0x4644('0x26')]]={'$like':'%'+_0x297dfc[_0x4644('0x2e')][_0x4644('0x37')]+'%'};return _0x22a35a;}})});}_0x221dc2=_['merge']({},_0x221dc2,_0x297dfc[_0x4644('0x39')]);var _0x120ff5={'where':_0x221dc2['where']};return db[_0x4644('0x3a')][_0x4644('0x1a')](_0x120ff5)[_0x4644('0x23')](function(_0xfa6aa1){_0x33eb52[_0x4644('0x1a')]=_0xfa6aa1;if(_0x297dfc[_0x4644('0x2e')]['includeAll']){_0x221dc2[_0x4644('0x3b')]=[{'all':!![]}];}return db[_0x4644('0x3a')][_0x4644('0x3c')](_0x221dc2);})[_0x4644('0x23')](function(_0x178482){_0x33eb52[_0x4644('0x3d')]=_0x178482;return _0x33eb52;})[_0x4644('0x23')](respondWithFilteredResult(_0x2fd086,_0x221dc2))['catch'](handleError(_0x2fd086,null));};exports[_0x4644('0x3e')]=function(_0x45c2b3,_0xe7f70d){var _0x2e3470={'raw':![],'where':{'id':_0x45c2b3['params']['id']}},_0x3dfab5={};_0x3dfab5[_0x4644('0x2d')]=_[_0x4644('0x2f')](db[_0x4644('0x3a')]['rawAttributes']);_0x3dfab5[_0x4644('0x2e')]=_[_0x4644('0x2f')](_0x45c2b3[_0x4644('0x2e')]);_0x3dfab5['filters']=_[_0x4644('0x3f')](_0x3dfab5[_0x4644('0x2d')],_0x3dfab5[_0x4644('0x2e')]);_0x2e3470[_0x4644('0x32')]=_[_0x4644('0x3f')](_0x3dfab5[_0x4644('0x2d')],qs[_0x4644('0x31')](_0x45c2b3[_0x4644('0x2e')][_0x4644('0x31')]));_0x2e3470[_0x4644('0x32')]=_0x2e3470[_0x4644('0x32')]['length']?_0x2e3470['attributes']:_0x3dfab5[_0x4644('0x2d')];if(_0x45c2b3[_0x4644('0x2e')][_0x4644('0x40')]){_0x2e3470['include']=[{'all':!![]}];}_0x2e3470=_[_0x4644('0x41')]({},_0x2e3470,_0x45c2b3['options']);return db[_0x4644('0x3a')]['find'](_0x2e3470)[_0x4644('0x23')](handleEntityNotFound(_0xe7f70d,null))[_0x4644('0x23')](respondWithResult(_0xe7f70d,null))[_0x4644('0x42')](handleError(_0xe7f70d,null));};exports['create']=function(_0x5b21a6,_0x37fd7b){return db['VtigerAccount'][_0x4644('0x43')](_0x5b21a6[_0x4644('0x44')],{})[_0x4644('0x23')](respondWithResult(_0x37fd7b,0xc9))[_0x4644('0x42')](handleError(_0x37fd7b,null));};exports[_0x4644('0x21')]=function(_0x222c65,_0x2d7ddb){if(_0x222c65[_0x4644('0x44')]['id']){delete _0x222c65[_0x4644('0x44')]['id'];}return db['VtigerAccount'][_0x4644('0x45')]({'where':{'id':_0x222c65[_0x4644('0x46')]['id']}})[_0x4644('0x23')](handleEntityNotFound(_0x2d7ddb,null))['then'](saveUpdates(_0x222c65[_0x4644('0x44')],null))[_0x4644('0x23')](respondWithResult(_0x2d7ddb,null))['catch'](handleError(_0x2d7ddb,null));};exports[_0x4644('0x22')]=function(_0x449a18,_0x5680cd){return db['VtigerAccount'][_0x4644('0x45')]({'where':{'id':_0x449a18[_0x4644('0x46')]['id']}})[_0x4644('0x23')](handleEntityNotFound(_0x5680cd,null))['then'](removeEntity(_0x5680cd,null))[_0x4644('0x42')](handleError(_0x5680cd,null));};exports[_0x4644('0x47')]=function(_0x16b911,_0x2da394,_0x4ad28c){var _0x371149={};var _0x32220b={};var _0xaec0b7;var _0x3efccf;return db['VtigerAccount']['findOne']({'where':{'id':_0x16b911['params']['id']}})['then'](handleEntityNotFound(_0x2da394,null))[_0x4644('0x23')](function(_0x103a5c){if(_0x103a5c){_0xaec0b7=_0x103a5c;_0x32220b[_0x4644('0x2d')]=_[_0x4644('0x2f')](db[_0x4644('0x48')][_0x4644('0x49')]);_0x32220b[_0x4644('0x2e')]=_[_0x4644('0x2f')](_0x16b911['query']);_0x32220b[_0x4644('0x30')]=_[_0x4644('0x3f')](_0x32220b[_0x4644('0x2d')],_0x32220b['query']);_0x371149[_0x4644('0x32')]=_[_0x4644('0x3f')](_0x32220b[_0x4644('0x2d')],qs[_0x4644('0x31')](_0x16b911[_0x4644('0x2e')]['fields']));_0x371149[_0x4644('0x32')]=_0x371149['attributes'][_0x4644('0x33')]?_0x371149['attributes']:_0x32220b[_0x4644('0x2d')];_0x371149[_0x4644('0x4a')]=qs['sort'](_0x16b911[_0x4644('0x2e')][_0x4644('0x35')]);_0x371149['where']=qs[_0x4644('0x30')](_['pick'](_0x16b911['query'],_0x32220b[_0x4644('0x30')]));if(_0x16b911['query'][_0x4644('0x37')]){_0x371149[_0x4644('0x38')]=_[_0x4644('0x41')](_0x371149[_0x4644('0x38')],{'$or':_['map'](_0x371149[_0x4644('0x32')],function(_0x7eb656){var _0x4fff7c={};_0x4fff7c[_0x7eb656]={'$like':'%'+_0x16b911[_0x4644('0x2e')]['filter']+'%'};return _0x4fff7c;})});}_0x371149=_['merge']({},_0x371149,_0x16b911[_0x4644('0x39')]);return _0xaec0b7[_0x4644('0x47')](_0x371149);}})['then'](function(_0x42a590){if(_0x42a590){_0x3efccf=_0x42a590['length'];if(!_0x16b911[_0x4644('0x2e')][_0x4644('0x34')](_0x4644('0x4b'))){_0x371149[_0x4644('0x19')]=qs[_0x4644('0x19')](_0x16b911[_0x4644('0x2e')]['limit']);_0x371149[_0x4644('0x1b')]=qs[_0x4644('0x1b')](_0x16b911[_0x4644('0x2e')][_0x4644('0x1b')]);}return _0xaec0b7[_0x4644('0x47')](_0x371149);}})[_0x4644('0x23')](function(_0x218453){if(_0x218453){return _0x218453?{'count':_0x3efccf,'rows':_0x218453}:null;}})[_0x4644('0x23')](respondWithResult(_0x2da394,null))[_0x4644('0x42')](handleError(_0x2da394,null));};exports[_0x4644('0x4c')]=function(_0x53387f,_0x5b1656,_0x349b88){if(_0x53387f[_0x4644('0x44')]['id']){delete _0x53387f['body']['id'];}return db[_0x4644('0x3a')][_0x4644('0x4d')]({'where':{'id':_0x53387f[_0x4644('0x46')]['id']}})['then'](handleEntityNotFound(_0x5b1656,null))[_0x4644('0x23')](function(_0x598c57){if(_0x598c57){_0x53387f['body'][_0x4644('0x4e')]=_0x598c57['id'];_0x53387f[_0x4644('0x44')][_0x4644('0x4f')]=integrations[_0x4644('0x50')](_0x53387f[_0x4644('0x44')][_0x4644('0x51')],_0x53387f['body']['type']);_0x53387f[_0x4644('0x44')]['Descriptions']=integrations[_0x4644('0x52')](_0x53387f[_0x4644('0x44')][_0x4644('0x51')],_0x53387f['body'][_0x4644('0x2b')]);return db[_0x4644('0x48')][_0x4644('0x43')](_0x53387f[_0x4644('0x44')],{'include':[{'model':db['VtigerField'],'as':_0x4644('0x4f')},{'model':db[_0x4644('0x53')],'as':_0x4644('0x54')}]});}return null;})['then'](respondWithResult(_0x5b1656,null))[_0x4644('0x42')](handleError(_0x5b1656,null));};var md5=require('md5');exports['getFields']=function(_0x860cbf,_0x32c71b,_0x4184b3){var _0x1a4b15=null;var _0x609ad2=null;var _0x2084fa=null;var _0x535550=null;var _0x506f97='';return db[_0x4644('0x3a')]['findOne']({'where':{'id':_0x860cbf[_0x4644('0x46')]['id']},'attributes':['id',_0x4644('0x26'),_0x4644('0x55'),_0x4644('0x56'),_0x4644('0x57'),_0x4644('0x58'),_0x4644('0x59'),_0x4644('0x5a')]})['then'](handleEntityNotFound(_0x32c71b,null))[_0x4644('0x23')](function(_0x2f33fd){if(_0x2f33fd){_0x1a4b15=_0x2f33fd[_0x4644('0x55')];_0x609ad2=_0x2f33fd['accessKey'];_0x2084fa=_0x2f33fd['moduleName'];_0x506f97=_0x2f33fd[_0x4644('0x58')];var _0x3da835=_0x506f97[_0x4644('0x5b')](-0x1);if(_0x3da835==='/'){_0x506f97=_0x506f97[_0x4644('0x5c')](0x0,_0x506f97['lastIndexOf'](_0x3da835));}_0x535550=util[_0x4644('0x5d')](_0x4644('0x5e'),_0x506f97);var _0x39fb36={'method':'GET','uri':_0x535550,'qs':{'operation':_0x4644('0x5f'),'username':_0x2f33fd[_0x4644('0x55')]},'json':!![]};return rp(_0x39fb36);}})[_0x4644('0x23')](function(_0x4ff5d9){if(_0x4ff5d9[_0x4644('0x60')]){var _0x3dde9a={'method':_0x4644('0x61'),'uri':_0x535550,'form':{'operation':_0x4644('0x62'),'username':_0x1a4b15,'accessKey':md5(_0x4ff5d9[_0x4644('0x63')][_0x4644('0x64')]+_0x609ad2)},'json':!![]};return rp(_0x3dde9a);}})[_0x4644('0x23')](function(_0x212da7){if(_0x212da7['success']){var _0xed1c6={'method':_0x4644('0x65'),'uri':_0x535550,'qs':{'operation':'describe','username':_0x1a4b15,'sessionName':_0x212da7['result'][_0x4644('0x66')],'elementType':_0x2084fa},'json':!![]};return rp(_0xed1c6);}})[_0x4644('0x23')](function(_0x1a2edd){if(_0x1a2edd['success']){var _0x5d2d2d=['autogenerated',_0x4644('0x67'),_0x4644('0x68')];_[_0x4644('0x69')](_0x1a2edd[_0x4644('0x63')][_0x4644('0x31')],function(_0x554d56){return _0x5d2d2d[_0x4644('0x6a')](_0x554d56[_0x4644('0x2b')][_0x4644('0x26')]);});_[_0x4644('0x69')](_0x1a2edd['result']['fields'],function(_0x28b833){return _0x28b833[_0x4644('0x6b')]===_0x4644('0x6c');});return{'count':_0x1a2edd[_0x4644('0x63')][_0x4644('0x31')][_0x4644('0x33')],'rows':_[_0x4644('0x29')](_0x1a2edd[_0x4644('0x63')]['fields'],function(_0x3458b6){return{'id':_0x3458b6[_0x4644('0x26')],'name':_0x3458b6[_0x4644('0x6d')],'custom':_[_0x4644('0x6e')](_0x3458b6[_0x4644('0x26')],_0x4644('0x6f'))?!![]:![],'options':_0x3458b6['type']['name']===_0x4644('0x70')&&_0x3458b6[_0x4644('0x2b')][_0x4644('0x71')][_0x4644('0x33')]>0x0?_['map'](_0x3458b6[_0x4644('0x2b')][_0x4644('0x71')],function(_0x4f1aa4){return{'name':_0x4f1aa4[_0x4644('0x6d')],'value':_0x4f1aa4[_0x4644('0x72')]};}):[]};})};}})['then'](respondWithResult(_0x32c71b,null))[_0x4644('0x42')](function(_0x7180c1){console[_0x4644('0x73')](_0x4644('0x74')+_0x7180c1);var _0x10d9fe=_0x860cbf[_0x4644('0x2e')][_0x4644('0x75')]?0x1f4:_0x7180c1[_0x4644('0x76')]||0x1f4;logger[_0x4644('0x77')](_0x4644('0x78'),_0x4644('0x79'),_0x10d9fe,JSON['stringify'](_0x7180c1));delete _0x7180c1[_0x4644('0x26')];if(_0x10d9fe===0x191){_0x10d9fe=0x190;}_0x32c71b[_0x4644('0x1c')](_0x10d9fe)[_0x4644('0x27')](_0x860cbf['query']['test']?{'message':_0x4644('0x7a'),'statusCode':_0x7180c1['statusCode']}:_0x7180c1);});};
\ No newline at end of file
+var _0x6c12=['VtigerConfiguration','VtigerField','Subjects','md5','username','moduleName','remoteUri','serverUrl','accessKey','slice','lastIndexOf','format','%s/webservice.php','GET','getchallenge','success','POST','login','result','token','describe','owner','remove','includes','false','startsWith','cf_','picklist','picklistValues','label','value','vTiger\x20error:\x20','test','getFields,\x20%s,\x20%s,\x20%s','getFields','Wrong\x20credentials','statusCode','eml-format','rimraf','fast-json-patch','request-promise','moment','bluebird','mustache','util','sox','to-csv','ejs','squel','crypto','jsforce','querystring','papaparse','ioredis','../../components/auth/service','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','api','../../config/utils','../../config/environment','../../config/license/util','../../mysqldb','../../components/integrations/configuration','status','end','offset','undefined','limit','count','set','Content-Range','json','apply','reject','save','then','destroy','sendStatus','error','stack','name','index','VtigerAccount','rawAttributes','key','model','query','keys','filters','intersection','attributes','fields','hasOwnProperty','order','sort','where','pick','filter','merge','map','type','VIRTUAL','options','include','findAll','rows','show','params','find','catch','body','update','getConfigurations','findOne','length','nolimit','addConfiguration','AccountId','channel','Descriptions'];(function(_0x197185,_0x251145){var _0x2c8af1=function(_0x1dbcfd){while(--_0x1dbcfd){_0x197185['push'](_0x197185['shift']());}};_0x2c8af1(++_0x251145);}(_0x6c12,0x117));var _0x26c1=function(_0x3f6b1b,_0x58d3d6){_0x3f6b1b=_0x3f6b1b-0x0;var _0x4a3d2b=_0x6c12[_0x3f6b1b];return _0x4a3d2b;};'use strict';var emlformat=require(_0x26c1('0x0'));var rimraf=require(_0x26c1('0x1'));var zipdir=require('zip-dir');var jsonpatch=require(_0x26c1('0x2'));var rp=require(_0x26c1('0x3'));var moment=require(_0x26c1('0x4'));var BPromise=require(_0x26c1('0x5'));var Mustache=require(_0x26c1('0x6'));var util=require(_0x26c1('0x7'));var path=require('path');var sox=require(_0x26c1('0x8'));var csv=require(_0x26c1('0x9'));var ejs=require(_0x26c1('0xa'));var fs=require('fs');var fs_extra=require('fs-extra');var _=require('lodash');var squel=require(_0x26c1('0xb'));var crypto=require(_0x26c1('0xc'));var jsforce=require(_0x26c1('0xd'));var deskjs=require('desk.js');var toCsv=require(_0x26c1('0x9'));var querystring=require(_0x26c1('0xe'));var Papa=require(_0x26c1('0xf'));var Redis=require(_0x26c1('0x10'));var authService=require(_0x26c1('0x11'));var qs=require('../../components/parsers/qs');var as=require(_0x26c1('0x12'));var hardwareService=require(_0x26c1('0x13'));var logger=require(_0x26c1('0x14'))(_0x26c1('0x15'));var utils=require(_0x26c1('0x16'));var config=require(_0x26c1('0x17'));var licenseUtil=require(_0x26c1('0x18'));var db=require(_0x26c1('0x19'))['db'];var integrations=require(_0x26c1('0x1a'));function respondWithStatusCode(_0x1bda53,_0x34d0af){_0x34d0af=_0x34d0af||0xcc;return function(_0x24428b){if(_0x24428b){return _0x1bda53['sendStatus'](_0x34d0af);}return _0x1bda53[_0x26c1('0x1b')](_0x34d0af)[_0x26c1('0x1c')]();};}function respondWithResult(_0x24239d,_0x5459c7){_0x5459c7=_0x5459c7||0xc8;return function(_0x5a8c88){if(_0x5a8c88){return _0x24239d['status'](_0x5459c7)['json'](_0x5a8c88);}};}function respondWithFilteredResult(_0x15b4ce,_0x49e836){return function(_0x11bba5){if(_0x11bba5){var _0x45ed30=typeof _0x49e836[_0x26c1('0x1d')]===_0x26c1('0x1e')&&typeof _0x49e836[_0x26c1('0x1f')]===_0x26c1('0x1e');var _0x2d57a6=_0x11bba5[_0x26c1('0x20')];var _0x1445a6=_0x45ed30?0x0:_0x49e836[_0x26c1('0x1d')];var _0x46249d=_0x45ed30?_0x11bba5[_0x26c1('0x20')]:_0x49e836[_0x26c1('0x1d')]+_0x49e836[_0x26c1('0x1f')];var _0xfd2139;if(_0x46249d>=_0x2d57a6){_0x46249d=_0x2d57a6;_0xfd2139=0xc8;}else{_0xfd2139=0xce;}_0x15b4ce[_0x26c1('0x1b')](_0xfd2139);return _0x15b4ce[_0x26c1('0x21')](_0x26c1('0x22'),_0x1445a6+'-'+_0x46249d+'/'+_0x2d57a6)[_0x26c1('0x23')](_0x11bba5);}return null;};}function patchUpdates(_0x50cbfb){return function(_0x1f9b9b){try{jsonpatch[_0x26c1('0x24')](_0x1f9b9b,_0x50cbfb,!![]);}catch(_0x251766){return BPromise[_0x26c1('0x25')](_0x251766);}return _0x1f9b9b[_0x26c1('0x26')]();};}function saveUpdates(_0x4c64f5,_0x4cdac6){return function(_0x49d872){if(_0x49d872){return _0x49d872['update'](_0x4c64f5)[_0x26c1('0x27')](function(_0x869bf9){return _0x869bf9;});}return null;};}function removeEntity(_0x5e2112,_0xdb428d){return function(_0x143cbf){if(_0x143cbf){return _0x143cbf[_0x26c1('0x28')]()[_0x26c1('0x27')](function(){_0x5e2112[_0x26c1('0x1b')](0xcc)[_0x26c1('0x1c')]();});}};}function handleEntityNotFound(_0x5ea3b6,_0x213854){return function(_0x34646f){if(!_0x34646f){_0x5ea3b6[_0x26c1('0x29')](0x194);}return _0x34646f;};}function handleError(_0x17f955,_0x48aa84){_0x48aa84=_0x48aa84||0x1f4;return function(_0x5e4e3c){logger[_0x26c1('0x2a')](_0x5e4e3c[_0x26c1('0x2b')]);if(_0x5e4e3c[_0x26c1('0x2c')]){delete _0x5e4e3c[_0x26c1('0x2c')];}_0x17f955[_0x26c1('0x1b')](_0x48aa84)['send'](_0x5e4e3c);};}exports[_0x26c1('0x2d')]=function(_0x2c40fa,_0x16dc39){var _0x478f51={},_0x2d2757={},_0x5f0c05={'count':0x0,'rows':[]};var _0x3d4c0d=_['map'](db[_0x26c1('0x2e')][_0x26c1('0x2f')],function(_0x10a48a){return{'name':_0x10a48a['fieldName'],'type':_0x10a48a['type'][_0x26c1('0x30')]};});_0x2d2757[_0x26c1('0x31')]=_['map'](_0x3d4c0d,_0x26c1('0x2c'));_0x2d2757[_0x26c1('0x32')]=_[_0x26c1('0x33')](_0x2c40fa['query']);_0x2d2757[_0x26c1('0x34')]=_[_0x26c1('0x35')](_0x2d2757[_0x26c1('0x31')],_0x2d2757[_0x26c1('0x32')]);_0x478f51[_0x26c1('0x36')]=_['intersection'](_0x2d2757[_0x26c1('0x31')],qs[_0x26c1('0x37')](_0x2c40fa[_0x26c1('0x32')][_0x26c1('0x37')]));_0x478f51['attributes']=_0x478f51[_0x26c1('0x36')]['length']?_0x478f51[_0x26c1('0x36')]:_0x2d2757[_0x26c1('0x31')];if(!_0x2c40fa[_0x26c1('0x32')][_0x26c1('0x38')]('nolimit')){_0x478f51['limit']=qs[_0x26c1('0x1f')](_0x2c40fa[_0x26c1('0x32')][_0x26c1('0x1f')]);_0x478f51[_0x26c1('0x1d')]=qs['offset'](_0x2c40fa['query'][_0x26c1('0x1d')]);}_0x478f51[_0x26c1('0x39')]=qs[_0x26c1('0x3a')](_0x2c40fa[_0x26c1('0x32')][_0x26c1('0x3a')]);_0x478f51[_0x26c1('0x3b')]=qs[_0x26c1('0x34')](_[_0x26c1('0x3c')](_0x2c40fa['query'],_0x2d2757['filters']),_0x3d4c0d);if(_0x2c40fa[_0x26c1('0x32')][_0x26c1('0x3d')]){_0x478f51['where']=_[_0x26c1('0x3e')](_0x478f51[_0x26c1('0x3b')],{'$or':_[_0x26c1('0x3f')](_0x3d4c0d,function(_0xc4d693){if(_0xc4d693[_0x26c1('0x40')]!==_0x26c1('0x41')){var _0x53629c={};_0x53629c[_0xc4d693[_0x26c1('0x2c')]]={'$like':'%'+_0x2c40fa[_0x26c1('0x32')]['filter']+'%'};return _0x53629c;}})});}_0x478f51=_['merge']({},_0x478f51,_0x2c40fa[_0x26c1('0x42')]);var _0x2d24f8={'where':_0x478f51['where']};return db[_0x26c1('0x2e')][_0x26c1('0x20')](_0x2d24f8)[_0x26c1('0x27')](function(_0x8af3da){_0x5f0c05['count']=_0x8af3da;if(_0x2c40fa[_0x26c1('0x32')]['includeAll']){_0x478f51[_0x26c1('0x43')]=[{'all':!![]}];}return db[_0x26c1('0x2e')][_0x26c1('0x44')](_0x478f51);})[_0x26c1('0x27')](function(_0x35aade){_0x5f0c05[_0x26c1('0x45')]=_0x35aade;return _0x5f0c05;})[_0x26c1('0x27')](respondWithFilteredResult(_0x16dc39,_0x478f51))['catch'](handleError(_0x16dc39,null));};exports[_0x26c1('0x46')]=function(_0x3e47df,_0x2bd0f5){var _0x6f36d2={'raw':![],'where':{'id':_0x3e47df[_0x26c1('0x47')]['id']}},_0x14f0bf={};_0x14f0bf[_0x26c1('0x31')]=_[_0x26c1('0x33')](db[_0x26c1('0x2e')][_0x26c1('0x2f')]);_0x14f0bf[_0x26c1('0x32')]=_[_0x26c1('0x33')](_0x3e47df['query']);_0x14f0bf[_0x26c1('0x34')]=_['intersection'](_0x14f0bf[_0x26c1('0x31')],_0x14f0bf[_0x26c1('0x32')]);_0x6f36d2[_0x26c1('0x36')]=_[_0x26c1('0x35')](_0x14f0bf[_0x26c1('0x31')],qs['fields'](_0x3e47df[_0x26c1('0x32')][_0x26c1('0x37')]));_0x6f36d2['attributes']=_0x6f36d2[_0x26c1('0x36')]['length']?_0x6f36d2[_0x26c1('0x36')]:_0x14f0bf['model'];if(_0x3e47df['query']['includeAll']){_0x6f36d2['include']=[{'all':!![]}];}_0x6f36d2=_['merge']({},_0x6f36d2,_0x3e47df['options']);return db['VtigerAccount'][_0x26c1('0x48')](_0x6f36d2)['then'](handleEntityNotFound(_0x2bd0f5,null))[_0x26c1('0x27')](respondWithResult(_0x2bd0f5,null))[_0x26c1('0x49')](handleError(_0x2bd0f5,null));};exports['create']=function(_0x479d25,_0x3bbae1){return db['VtigerAccount']['create'](_0x479d25[_0x26c1('0x4a')],{})[_0x26c1('0x27')](respondWithResult(_0x3bbae1,0xc9))[_0x26c1('0x49')](handleError(_0x3bbae1,null));};exports[_0x26c1('0x4b')]=function(_0x23a14b,_0x2ad634){if(_0x23a14b['body']['id']){delete _0x23a14b[_0x26c1('0x4a')]['id'];}return db[_0x26c1('0x2e')][_0x26c1('0x48')]({'where':{'id':_0x23a14b[_0x26c1('0x47')]['id']}})[_0x26c1('0x27')](handleEntityNotFound(_0x2ad634,null))['then'](saveUpdates(_0x23a14b[_0x26c1('0x4a')],null))[_0x26c1('0x27')](respondWithResult(_0x2ad634,null))[_0x26c1('0x49')](handleError(_0x2ad634,null));};exports[_0x26c1('0x28')]=function(_0x1c23e4,_0x5c126b){return db[_0x26c1('0x2e')][_0x26c1('0x48')]({'where':{'id':_0x1c23e4[_0x26c1('0x47')]['id']}})['then'](handleEntityNotFound(_0x5c126b,null))[_0x26c1('0x27')](removeEntity(_0x5c126b,null))[_0x26c1('0x49')](handleError(_0x5c126b,null));};exports[_0x26c1('0x4c')]=function(_0x29211f,_0x478a14,_0x483e95){var _0x2e32a6={};var _0x15317d={};var _0x34b423;var _0x500ff9;return db[_0x26c1('0x2e')][_0x26c1('0x4d')]({'where':{'id':_0x29211f[_0x26c1('0x47')]['id']}})['then'](handleEntityNotFound(_0x478a14,null))['then'](function(_0x51eeef){if(_0x51eeef){_0x34b423=_0x51eeef;_0x15317d['model']=_['keys'](db['VtigerConfiguration'][_0x26c1('0x2f')]);_0x15317d[_0x26c1('0x32')]=_[_0x26c1('0x33')](_0x29211f[_0x26c1('0x32')]);_0x15317d[_0x26c1('0x34')]=_[_0x26c1('0x35')](_0x15317d['model'],_0x15317d[_0x26c1('0x32')]);_0x2e32a6[_0x26c1('0x36')]=_['intersection'](_0x15317d[_0x26c1('0x31')],qs[_0x26c1('0x37')](_0x29211f['query']['fields']));_0x2e32a6[_0x26c1('0x36')]=_0x2e32a6[_0x26c1('0x36')][_0x26c1('0x4e')]?_0x2e32a6[_0x26c1('0x36')]:_0x15317d[_0x26c1('0x31')];_0x2e32a6[_0x26c1('0x39')]=qs['sort'](_0x29211f[_0x26c1('0x32')][_0x26c1('0x3a')]);_0x2e32a6['where']=qs[_0x26c1('0x34')](_['pick'](_0x29211f['query'],_0x15317d['filters']));if(_0x29211f[_0x26c1('0x32')][_0x26c1('0x3d')]){_0x2e32a6['where']=_[_0x26c1('0x3e')](_0x2e32a6['where'],{'$or':_[_0x26c1('0x3f')](_0x2e32a6[_0x26c1('0x36')],function(_0x4c321c){var _0x2e731c={};_0x2e731c[_0x4c321c]={'$like':'%'+_0x29211f[_0x26c1('0x32')][_0x26c1('0x3d')]+'%'};return _0x2e731c;})});}_0x2e32a6=_[_0x26c1('0x3e')]({},_0x2e32a6,_0x29211f[_0x26c1('0x42')]);return _0x34b423[_0x26c1('0x4c')](_0x2e32a6);}})[_0x26c1('0x27')](function(_0x115b88){if(_0x115b88){_0x500ff9=_0x115b88[_0x26c1('0x4e')];if(!_0x29211f[_0x26c1('0x32')][_0x26c1('0x38')](_0x26c1('0x4f'))){_0x2e32a6[_0x26c1('0x1f')]=qs[_0x26c1('0x1f')](_0x29211f[_0x26c1('0x32')][_0x26c1('0x1f')]);_0x2e32a6['offset']=qs[_0x26c1('0x1d')](_0x29211f[_0x26c1('0x32')][_0x26c1('0x1d')]);}return _0x34b423['getConfigurations'](_0x2e32a6);}})[_0x26c1('0x27')](function(_0x25f324){if(_0x25f324){return _0x25f324?{'count':_0x500ff9,'rows':_0x25f324}:null;}})['then'](respondWithResult(_0x478a14,null))[_0x26c1('0x49')](handleError(_0x478a14,null));};exports[_0x26c1('0x50')]=function(_0x229620,_0x401a10,_0x4a602e){if(_0x229620['body']['id']){delete _0x229620['body']['id'];}return db[_0x26c1('0x2e')][_0x26c1('0x4d')]({'where':{'id':_0x229620['params']['id']}})[_0x26c1('0x27')](handleEntityNotFound(_0x401a10,null))[_0x26c1('0x27')](function(_0x41c1d3){if(_0x41c1d3){_0x229620[_0x26c1('0x4a')][_0x26c1('0x51')]=_0x41c1d3['id'];_0x229620[_0x26c1('0x4a')]['Subjects']=integrations['getSubjects'](_0x229620[_0x26c1('0x4a')][_0x26c1('0x52')],_0x229620[_0x26c1('0x4a')][_0x26c1('0x40')]);_0x229620[_0x26c1('0x4a')][_0x26c1('0x53')]=integrations['getDescriptions'](_0x229620[_0x26c1('0x4a')]['channel'],_0x229620[_0x26c1('0x4a')]['type']);return db[_0x26c1('0x54')]['create'](_0x229620[_0x26c1('0x4a')],{'include':[{'model':db[_0x26c1('0x55')],'as':_0x26c1('0x56')},{'model':db['VtigerField'],'as':_0x26c1('0x53')}]});}return null;})[_0x26c1('0x27')](respondWithResult(_0x401a10,null))[_0x26c1('0x49')](handleError(_0x401a10,null));};var md5=require(_0x26c1('0x57'));exports['getFields']=function(_0x7327ba,_0x2d5f68,_0x5ccc65){var _0x2e493b=null;var _0x502090=null;var _0x3f518d=null;var _0x22451d=null;var _0x2d1fbf='';return db[_0x26c1('0x2e')][_0x26c1('0x4d')]({'where':{'id':_0x7327ba['params']['id']},'attributes':['id',_0x26c1('0x2c'),_0x26c1('0x58'),'description',_0x26c1('0x59'),_0x26c1('0x5a'),_0x26c1('0x5b'),_0x26c1('0x5c')]})['then'](handleEntityNotFound(_0x2d5f68,null))['then'](function(_0x43b8bf){if(_0x43b8bf){_0x2e493b=_0x43b8bf[_0x26c1('0x58')];_0x502090=_0x43b8bf['accessKey'];_0x3f518d=_0x43b8bf['moduleName'];_0x2d1fbf=_0x43b8bf['remoteUri'];var _0x4cd000=_0x2d1fbf[_0x26c1('0x5d')](-0x1);if(_0x4cd000==='/'){_0x2d1fbf=_0x2d1fbf['substring'](0x0,_0x2d1fbf[_0x26c1('0x5e')](_0x4cd000));}_0x22451d=util[_0x26c1('0x5f')](_0x26c1('0x60'),_0x2d1fbf);var _0x34d88f={'method':_0x26c1('0x61'),'uri':_0x22451d,'qs':{'operation':_0x26c1('0x62'),'username':_0x43b8bf['username']},'json':!![]};return rp(_0x34d88f);}})['then'](function(_0x203525){if(_0x203525[_0x26c1('0x63')]){var _0x453570={'method':_0x26c1('0x64'),'uri':_0x22451d,'form':{'operation':_0x26c1('0x65'),'username':_0x2e493b,'accessKey':md5(_0x203525[_0x26c1('0x66')][_0x26c1('0x67')]+_0x502090)},'json':!![]};return rp(_0x453570);}})[_0x26c1('0x27')](function(_0x46370a){if(_0x46370a[_0x26c1('0x63')]){var _0x3e944f={'method':_0x26c1('0x61'),'uri':_0x22451d,'qs':{'operation':_0x26c1('0x68'),'username':_0x2e493b,'sessionName':_0x46370a[_0x26c1('0x66')]['sessionName'],'elementType':_0x3f518d},'json':!![]};return rp(_0x3e944f);}})['then'](function(_0x118ff7){if(_0x118ff7['success']){var _0x54deea=['autogenerated','reference',_0x26c1('0x69')];_[_0x26c1('0x6a')](_0x118ff7['result'][_0x26c1('0x37')],function(_0x131872){return _0x54deea[_0x26c1('0x6b')](_0x131872['type']['name']);});_[_0x26c1('0x6a')](_0x118ff7['result'][_0x26c1('0x37')],function(_0x38a215){return _0x38a215['editable']===_0x26c1('0x6c');});return{'count':_0x118ff7[_0x26c1('0x66')][_0x26c1('0x37')]['length'],'rows':_[_0x26c1('0x3f')](_0x118ff7[_0x26c1('0x66')][_0x26c1('0x37')],function(_0x18e1cd){return{'id':_0x18e1cd[_0x26c1('0x2c')],'name':_0x18e1cd['label'],'custom':_[_0x26c1('0x6d')](_0x18e1cd[_0x26c1('0x2c')],_0x26c1('0x6e'))?!![]:![],'options':_0x18e1cd[_0x26c1('0x40')][_0x26c1('0x2c')]===_0x26c1('0x6f')&&_0x18e1cd[_0x26c1('0x40')][_0x26c1('0x70')][_0x26c1('0x4e')]>0x0?_[_0x26c1('0x3f')](_0x18e1cd[_0x26c1('0x40')][_0x26c1('0x70')],function(_0x5810db){return{'name':_0x5810db[_0x26c1('0x71')],'value':_0x5810db[_0x26c1('0x72')]};}):[]};})};}})[_0x26c1('0x27')](respondWithResult(_0x2d5f68,null))[_0x26c1('0x49')](function(_0x35f5ab){console['log'](_0x26c1('0x73')+_0x35f5ab);var _0x56c397=_0x7327ba[_0x26c1('0x32')][_0x26c1('0x74')]?0x1f4:_0x35f5ab['statusCode']||0x1f4;logger['error'](_0x26c1('0x75'),_0x26c1('0x76'),_0x56c397,JSON['stringify'](_0x35f5ab));delete _0x35f5ab['name'];if(_0x56c397===0x191){_0x56c397=0x190;}_0x2d5f68[_0x26c1('0x1b')](_0x56c397)['send'](_0x7327ba['query'][_0x26c1('0x74')]?{'message':_0x26c1('0x77'),'statusCode':_0x35f5ab[_0x26c1('0x78')]}:_0x35f5ab);});};
\ No newline at end of file