Built motion from commit 4c281f94.|2.6.31
[motion2.git] / server / api / intVtigerAccount / intVtigerAccount.controller.js
index 2f8054f..e3729fe 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0x468b=['intersection','model','attributes','fields','length','hasOwnProperty','nolimit','order','sort','pick','filter','where','VIRTUAL','merge','options','findAll','show','params','includeAll','catch','create','body','getConfigurations','findOne','VtigerConfiguration','addConfiguration','AccountId','Subjects','Descriptions','getDescriptions','channel','VtigerField','md5','getFields','username','description','moduleName','remoteUri','serverUrl','accessKey','slice','substring','lastIndexOf','%s/webservice.php','getchallenge','success','login','result','token','describe','sessionName','autogenerated','reference','owner','remove','editable','false','label','startsWith','cf_','picklist','picklistValues','getFields,\x20%s,\x20%s,\x20%s','stringify','test','Wrong\x20credentials','statusCode','eml-format','rimraf','zip-dir','bluebird','sox','to-csv','ejs','fs-extra','lodash','crypto','jsforce','querystring','papaparse','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','api','../../config/license/util','../../mysqldb','../../components/integrations/configuration','sendStatus','status','json','undefined','limit','offset','count','Content-Range','reject','update','then','destroy','error','stack','name','map','VtigerAccount','rawAttributes','fieldName','type','key','keys','query','filters'];(function(_0x1accf7,_0x15d116){var _0x47e097=function(_0x5e6e0a){while(--_0x5e6e0a){_0x1accf7['push'](_0x1accf7['shift']());}};_0x47e097(++_0x15d116);}(_0x468b,0x121));var _0xb468=function(_0x21a9d9,_0x4d5ac8){_0x21a9d9=_0x21a9d9-0x0;var _0x46adce=_0x468b[_0x21a9d9];return _0x46adce;};'use strict';var emlformat=require(_0xb468('0x0'));var rimraf=require(_0xb468('0x1'));var zipdir=require(_0xb468('0x2'));var jsonpatch=require('fast-json-patch');var rp=require('request-promise');var moment=require('moment');var BPromise=require(_0xb468('0x3'));var Mustache=require('mustache');var util=require('util');var path=require('path');var sox=require(_0xb468('0x4'));var csv=require(_0xb468('0x5'));var ejs=require(_0xb468('0x6'));var fs=require('fs');var fs_extra=require(_0xb468('0x7'));var _=require(_0xb468('0x8'));var squel=require('squel');var crypto=require(_0xb468('0x9'));var jsforce=require(_0xb468('0xa'));var deskjs=require('desk.js');var toCsv=require(_0xb468('0x5'));var querystring=require(_0xb468('0xb'));var Papa=require(_0xb468('0xc'));var Redis=require('ioredis');var authService=require('../../components/auth/service');var qs=require(_0xb468('0xd'));var as=require(_0xb468('0xe'));var hardwareService=require(_0xb468('0xf'));var logger=require('../../config/logger')(_0xb468('0x10'));var utils=require('../../config/utils');var config=require('../../config/environment');var licenseUtil=require(_0xb468('0x11'));var db=require(_0xb468('0x12'))['db'];var integrations=require(_0xb468('0x13'));function respondWithStatusCode(_0x128728,_0x265a5e){_0x265a5e=_0x265a5e||0xcc;return function(_0x3ea557){if(_0x3ea557){return _0x128728[_0xb468('0x14')](_0x265a5e);}return _0x128728[_0xb468('0x15')](_0x265a5e)['end']();};}function respondWithResult(_0x5b2805,_0x57b878){_0x57b878=_0x57b878||0xc8;return function(_0x390d99){if(_0x390d99){return _0x5b2805[_0xb468('0x15')](_0x57b878)[_0xb468('0x16')](_0x390d99);}};}function respondWithFilteredResult(_0x47ebf8,_0x2f78c3){return function(_0x33582c){if(_0x33582c){var _0x59991f=typeof _0x2f78c3['offset']===_0xb468('0x17')&&typeof _0x2f78c3[_0xb468('0x18')]==='undefined';var _0x3d2697=_0x33582c['count'];var _0x11a63c=_0x59991f?0x0:_0x2f78c3[_0xb468('0x19')];var _0x3a62cd=_0x59991f?_0x33582c[_0xb468('0x1a')]:_0x2f78c3[_0xb468('0x19')]+_0x2f78c3[_0xb468('0x18')];var _0x51fb2f;if(_0x3a62cd>=_0x3d2697){_0x3a62cd=_0x3d2697;_0x51fb2f=0xc8;}else{_0x51fb2f=0xce;}_0x47ebf8[_0xb468('0x15')](_0x51fb2f);return _0x47ebf8['set'](_0xb468('0x1b'),_0x11a63c+'-'+_0x3a62cd+'/'+_0x3d2697)['json'](_0x33582c);}return null;};}function patchUpdates(_0x1ecafb){return function(_0x2b1c49){try{jsonpatch['apply'](_0x2b1c49,_0x1ecafb,!![]);}catch(_0x4f9661){return BPromise[_0xb468('0x1c')](_0x4f9661);}return _0x2b1c49['save']();};}function saveUpdates(_0x190c55,_0x4eb46e){return function(_0x1a6abe){if(_0x1a6abe){return _0x1a6abe[_0xb468('0x1d')](_0x190c55)[_0xb468('0x1e')](function(_0x43df32){return _0x43df32;});}return null;};}function removeEntity(_0x2d7242,_0x3757e6){return function(_0x505903){if(_0x505903){return _0x505903[_0xb468('0x1f')]()[_0xb468('0x1e')](function(){_0x2d7242[_0xb468('0x15')](0xcc)['end']();});}};}function handleEntityNotFound(_0x4f9bd2,_0x4fd98e){return function(_0x1892a6){if(!_0x1892a6){_0x4f9bd2[_0xb468('0x14')](0x194);}return _0x1892a6;};}function handleError(_0x5e4183,_0x3bc6ea){_0x3bc6ea=_0x3bc6ea||0x1f4;return function(_0x1d3fef){logger[_0xb468('0x20')](_0x1d3fef[_0xb468('0x21')]);if(_0x1d3fef[_0xb468('0x22')]){delete _0x1d3fef[_0xb468('0x22')];}_0x5e4183[_0xb468('0x15')](_0x3bc6ea)['send'](_0x1d3fef);};}exports['index']=function(_0x15f494,_0x34d3d7){var _0x224622={},_0x494366={},_0x8e019d={'count':0x0,'rows':[]};var _0x1e2572=_[_0xb468('0x23')](db[_0xb468('0x24')][_0xb468('0x25')],function(_0x1e6155){return{'name':_0x1e6155[_0xb468('0x26')],'type':_0x1e6155[_0xb468('0x27')][_0xb468('0x28')]};});_0x494366['model']=_[_0xb468('0x23')](_0x1e2572,'name');_0x494366['query']=_[_0xb468('0x29')](_0x15f494[_0xb468('0x2a')]);_0x494366[_0xb468('0x2b')]=_[_0xb468('0x2c')](_0x494366[_0xb468('0x2d')],_0x494366[_0xb468('0x2a')]);_0x224622[_0xb468('0x2e')]=_['intersection'](_0x494366['model'],qs[_0xb468('0x2f')](_0x15f494[_0xb468('0x2a')][_0xb468('0x2f')]));_0x224622[_0xb468('0x2e')]=_0x224622['attributes'][_0xb468('0x30')]?_0x224622['attributes']:_0x494366[_0xb468('0x2d')];if(!_0x15f494[_0xb468('0x2a')][_0xb468('0x31')](_0xb468('0x32'))){_0x224622[_0xb468('0x18')]=qs['limit'](_0x15f494['query'][_0xb468('0x18')]);_0x224622[_0xb468('0x19')]=qs[_0xb468('0x19')](_0x15f494[_0xb468('0x2a')]['offset']);}_0x224622[_0xb468('0x33')]=qs['sort'](_0x15f494['query'][_0xb468('0x34')]);_0x224622['where']=qs[_0xb468('0x2b')](_[_0xb468('0x35')](_0x15f494[_0xb468('0x2a')],_0x494366[_0xb468('0x2b')]),_0x1e2572);if(_0x15f494[_0xb468('0x2a')][_0xb468('0x36')]){_0x224622[_0xb468('0x37')]=_['merge'](_0x224622[_0xb468('0x37')],{'$or':_['map'](_0x1e2572,function(_0x483b28){if(_0x483b28['type']!==_0xb468('0x38')){var _0x41b8b9={};_0x41b8b9[_0x483b28['name']]={'$like':'%'+_0x15f494[_0xb468('0x2a')][_0xb468('0x36')]+'%'};return _0x41b8b9;}})});}_0x224622=_[_0xb468('0x39')]({},_0x224622,_0x15f494[_0xb468('0x3a')]);var _0x1c22f5={'where':_0x224622['where']};return db['VtigerAccount']['count'](_0x1c22f5)[_0xb468('0x1e')](function(_0x3caef1){_0x8e019d[_0xb468('0x1a')]=_0x3caef1;if(_0x15f494['query']['includeAll']){_0x224622['include']=[{'all':!![]}];}return db[_0xb468('0x24')][_0xb468('0x3b')](_0x224622);})['then'](function(_0x4bc71c){_0x8e019d['rows']=_0x4bc71c;return _0x8e019d;})[_0xb468('0x1e')](respondWithFilteredResult(_0x34d3d7,_0x224622))['catch'](handleError(_0x34d3d7,null));};exports[_0xb468('0x3c')]=function(_0x5f585d,_0x4d6a11){var _0xaa4fca={'raw':![],'where':{'id':_0x5f585d[_0xb468('0x3d')]['id']}},_0x12c1bc={};_0x12c1bc['model']=_['keys'](db[_0xb468('0x24')][_0xb468('0x25')]);_0x12c1bc[_0xb468('0x2a')]=_[_0xb468('0x29')](_0x5f585d['query']);_0x12c1bc[_0xb468('0x2b')]=_[_0xb468('0x2c')](_0x12c1bc[_0xb468('0x2d')],_0x12c1bc[_0xb468('0x2a')]);_0xaa4fca['attributes']=_[_0xb468('0x2c')](_0x12c1bc[_0xb468('0x2d')],qs[_0xb468('0x2f')](_0x5f585d[_0xb468('0x2a')]['fields']));_0xaa4fca['attributes']=_0xaa4fca[_0xb468('0x2e')][_0xb468('0x30')]?_0xaa4fca[_0xb468('0x2e')]:_0x12c1bc[_0xb468('0x2d')];if(_0x5f585d[_0xb468('0x2a')][_0xb468('0x3e')]){_0xaa4fca['include']=[{'all':!![]}];}_0xaa4fca=_['merge']({},_0xaa4fca,_0x5f585d[_0xb468('0x3a')]);return db[_0xb468('0x24')]['find'](_0xaa4fca)[_0xb468('0x1e')](handleEntityNotFound(_0x4d6a11,null))[_0xb468('0x1e')](respondWithResult(_0x4d6a11,null))[_0xb468('0x3f')](handleError(_0x4d6a11,null));};exports[_0xb468('0x40')]=function(_0x58aa2f,_0x9ea3ce){return db[_0xb468('0x24')][_0xb468('0x40')](_0x58aa2f[_0xb468('0x41')],{})[_0xb468('0x1e')](respondWithResult(_0x9ea3ce,0xc9))[_0xb468('0x3f')](handleError(_0x9ea3ce,null));};exports[_0xb468('0x1d')]=function(_0x477b18,_0x39ce0e){if(_0x477b18[_0xb468('0x41')]['id']){delete _0x477b18[_0xb468('0x41')]['id'];}return db[_0xb468('0x24')]['find']({'where':{'id':_0x477b18[_0xb468('0x3d')]['id']}})[_0xb468('0x1e')](handleEntityNotFound(_0x39ce0e,null))[_0xb468('0x1e')](saveUpdates(_0x477b18[_0xb468('0x41')],null))['then'](respondWithResult(_0x39ce0e,null))[_0xb468('0x3f')](handleError(_0x39ce0e,null));};exports[_0xb468('0x1f')]=function(_0x38d8ec,_0x5f14e0){return db[_0xb468('0x24')]['find']({'where':{'id':_0x38d8ec[_0xb468('0x3d')]['id']}})['then'](handleEntityNotFound(_0x5f14e0,null))['then'](removeEntity(_0x5f14e0,null))[_0xb468('0x3f')](handleError(_0x5f14e0,null));};exports[_0xb468('0x42')]=function(_0x57b18e,_0x237339,_0xb66f4f){var _0x3a7f6e={};var _0x2c1e07={};var _0x271065;var _0x13cd22;return db[_0xb468('0x24')][_0xb468('0x43')]({'where':{'id':_0x57b18e[_0xb468('0x3d')]['id']}})[_0xb468('0x1e')](handleEntityNotFound(_0x237339,null))[_0xb468('0x1e')](function(_0x3d8991){if(_0x3d8991){_0x271065=_0x3d8991;_0x2c1e07[_0xb468('0x2d')]=_[_0xb468('0x29')](db[_0xb468('0x44')][_0xb468('0x25')]);_0x2c1e07[_0xb468('0x2a')]=_[_0xb468('0x29')](_0x57b18e[_0xb468('0x2a')]);_0x2c1e07[_0xb468('0x2b')]=_[_0xb468('0x2c')](_0x2c1e07[_0xb468('0x2d')],_0x2c1e07[_0xb468('0x2a')]);_0x3a7f6e[_0xb468('0x2e')]=_['intersection'](_0x2c1e07[_0xb468('0x2d')],qs['fields'](_0x57b18e[_0xb468('0x2a')]['fields']));_0x3a7f6e[_0xb468('0x2e')]=_0x3a7f6e[_0xb468('0x2e')][_0xb468('0x30')]?_0x3a7f6e[_0xb468('0x2e')]:_0x2c1e07[_0xb468('0x2d')];_0x3a7f6e[_0xb468('0x33')]=qs[_0xb468('0x34')](_0x57b18e[_0xb468('0x2a')][_0xb468('0x34')]);_0x3a7f6e[_0xb468('0x37')]=qs['filters'](_[_0xb468('0x35')](_0x57b18e[_0xb468('0x2a')],_0x2c1e07[_0xb468('0x2b')]));if(_0x57b18e[_0xb468('0x2a')]['filter']){_0x3a7f6e['where']=_[_0xb468('0x39')](_0x3a7f6e['where'],{'$or':_[_0xb468('0x23')](_0x3a7f6e[_0xb468('0x2e')],function(_0x1a7b95){var _0x2a1787={};_0x2a1787[_0x1a7b95]={'$like':'%'+_0x57b18e[_0xb468('0x2a')][_0xb468('0x36')]+'%'};return _0x2a1787;})});}_0x3a7f6e=_[_0xb468('0x39')]({},_0x3a7f6e,_0x57b18e[_0xb468('0x3a')]);return _0x271065['getConfigurations'](_0x3a7f6e);}})[_0xb468('0x1e')](function(_0x4af92a){if(_0x4af92a){_0x13cd22=_0x4af92a[_0xb468('0x30')];if(!_0x57b18e['query'][_0xb468('0x31')](_0xb468('0x32'))){_0x3a7f6e['limit']=qs[_0xb468('0x18')](_0x57b18e[_0xb468('0x2a')][_0xb468('0x18')]);_0x3a7f6e[_0xb468('0x19')]=qs[_0xb468('0x19')](_0x57b18e[_0xb468('0x2a')][_0xb468('0x19')]);}return _0x271065[_0xb468('0x42')](_0x3a7f6e);}})[_0xb468('0x1e')](function(_0x48c8ee){if(_0x48c8ee){return _0x48c8ee?{'count':_0x13cd22,'rows':_0x48c8ee}:null;}})[_0xb468('0x1e')](respondWithResult(_0x237339,null))[_0xb468('0x3f')](handleError(_0x237339,null));};exports[_0xb468('0x45')]=function(_0x450875,_0xb667aa,_0x2d5b55){if(_0x450875[_0xb468('0x41')]['id']){delete _0x450875[_0xb468('0x41')]['id'];}return db[_0xb468('0x24')]['findOne']({'where':{'id':_0x450875['params']['id']}})[_0xb468('0x1e')](handleEntityNotFound(_0xb667aa,null))[_0xb468('0x1e')](function(_0x3b0964){if(_0x3b0964){_0x450875[_0xb468('0x41')][_0xb468('0x46')]=_0x3b0964['id'];_0x450875[_0xb468('0x41')][_0xb468('0x47')]=integrations['getSubjects'](_0x450875[_0xb468('0x41')]['channel'],_0x450875['body'][_0xb468('0x27')]);_0x450875['body'][_0xb468('0x48')]=integrations[_0xb468('0x49')](_0x450875['body'][_0xb468('0x4a')],_0x450875['body'][_0xb468('0x27')]);return db[_0xb468('0x44')][_0xb468('0x40')](_0x450875[_0xb468('0x41')],{'include':[{'model':db['VtigerField'],'as':_0xb468('0x47')},{'model':db[_0xb468('0x4b')],'as':_0xb468('0x48')}]});}return null;})[_0xb468('0x1e')](respondWithResult(_0xb667aa,null))['catch'](handleError(_0xb667aa,null));};var md5=require(_0xb468('0x4c'));exports[_0xb468('0x4d')]=function(_0x34febd,_0x31df39,_0x2cdec7){var _0x523e31=null;var _0x56f566=null;var _0x510cae=null;var _0x1934c4=null;var _0x14cbb8='';return db[_0xb468('0x24')][_0xb468('0x43')]({'where':{'id':_0x34febd[_0xb468('0x3d')]['id']},'attributes':['id','name',_0xb468('0x4e'),_0xb468('0x4f'),_0xb468('0x50'),_0xb468('0x51'),_0xb468('0x52'),_0xb468('0x53')]})[_0xb468('0x1e')](handleEntityNotFound(_0x31df39,null))['then'](function(_0x44958b){if(_0x44958b){_0x523e31=_0x44958b[_0xb468('0x4e')];_0x56f566=_0x44958b['accessKey'];_0x510cae=_0x44958b[_0xb468('0x50')];_0x14cbb8=_0x44958b[_0xb468('0x51')];var _0x52cf59=_0x14cbb8[_0xb468('0x54')](-0x1);if(_0x52cf59==='/'){_0x14cbb8=_0x14cbb8[_0xb468('0x55')](0x0,_0x14cbb8[_0xb468('0x56')](_0x52cf59));}_0x1934c4=util['format'](_0xb468('0x57'),_0x14cbb8);var _0x4e9739={'method':'GET','uri':_0x1934c4,'qs':{'operation':_0xb468('0x58'),'username':_0x44958b[_0xb468('0x4e')]},'json':!![]};return rp(_0x4e9739);}})[_0xb468('0x1e')](function(_0x1469bf){if(_0x1469bf[_0xb468('0x59')]){var _0x254c9c={'method':'POST','uri':_0x1934c4,'form':{'operation':_0xb468('0x5a'),'username':_0x523e31,'accessKey':md5(_0x1469bf[_0xb468('0x5b')][_0xb468('0x5c')]+_0x56f566)},'json':!![]};return rp(_0x254c9c);}})[_0xb468('0x1e')](function(_0x4d9cfc){if(_0x4d9cfc[_0xb468('0x59')]){var _0x326f2b={'method':'GET','uri':_0x1934c4,'qs':{'operation':_0xb468('0x5d'),'username':_0x523e31,'sessionName':_0x4d9cfc[_0xb468('0x5b')][_0xb468('0x5e')],'elementType':_0x510cae},'json':!![]};return rp(_0x326f2b);}})[_0xb468('0x1e')](function(_0xa207b0){if(_0xa207b0[_0xb468('0x59')]){var _0x38bc07=[_0xb468('0x5f'),_0xb468('0x60'),_0xb468('0x61')];_[_0xb468('0x62')](_0xa207b0[_0xb468('0x5b')][_0xb468('0x2f')],function(_0x1a08a8){return _0x38bc07['includes'](_0x1a08a8[_0xb468('0x27')]['name']);});_[_0xb468('0x62')](_0xa207b0[_0xb468('0x5b')][_0xb468('0x2f')],function(_0x3fc921){return _0x3fc921[_0xb468('0x63')]===_0xb468('0x64');});return{'count':_0xa207b0['result']['fields'][_0xb468('0x30')],'rows':_['map'](_0xa207b0[_0xb468('0x5b')][_0xb468('0x2f')],function(_0x2f783f){return{'id':_0x2f783f[_0xb468('0x22')],'name':_0x2f783f[_0xb468('0x65')],'custom':_[_0xb468('0x66')](_0x2f783f[_0xb468('0x22')],_0xb468('0x67'))?!![]:![],'options':_0x2f783f[_0xb468('0x27')][_0xb468('0x22')]===_0xb468('0x68')&&_0x2f783f[_0xb468('0x27')][_0xb468('0x69')][_0xb468('0x30')]>0x0?_[_0xb468('0x23')](_0x2f783f[_0xb468('0x27')][_0xb468('0x69')],function(_0xdbf489){return{'name':_0xdbf489['label'],'value':_0xdbf489['value']};}):[]};})};}})[_0xb468('0x1e')](respondWithResult(_0x31df39,null))[_0xb468('0x3f')](function(_0x42d21e){console['log']('vTiger\x20error:\x20'+_0x42d21e);var _0x4a25df=_0x34febd[_0xb468('0x2a')]['test']?0x1f4:_0x42d21e['statusCode']||0x1f4;logger[_0xb468('0x20')](_0xb468('0x6a'),'getFields',_0x4a25df,JSON[_0xb468('0x6b')](_0x42d21e));delete _0x42d21e[_0xb468('0x22')];if(_0x4a25df===0x191){_0x4a25df=0x190;}_0x31df39[_0xb468('0x15')](_0x4a25df)['send'](_0x34febd[_0xb468('0x2a')][_0xb468('0x6c')]?{'message':_0xb468('0x6d'),'statusCode':_0x42d21e[_0xb468('0x6e')]}:_0x42d21e);});};
\ No newline at end of file
+var _0xcb2f=['description','moduleName','remoteUri','serverUrl','accessKey','slice','substring','lastIndexOf','format','%s/webservice.php','GET','getchallenge','success','POST','login','token','describe','result','sessionName','autogenerated','reference','owner','remove','includes','editable','label','startsWith','cf_','picklist','picklistValues','value','log','vTiger\x20error:\x20','test','statusCode','error','getFields,\x20%s,\x20%s,\x20%s','stringify','send','Wrong\x20credentials','rimraf','fast-json-patch','request-promise','moment','bluebird','path','to-csv','ejs','fs-extra','lodash','squel','crypto','jsforce','desk.js','querystring','papaparse','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','api','../../config/utils','../../config/license/util','../../mysqldb','../../components/integrations/configuration','sendStatus','status','end','json','offset','undefined','limit','count','set','Content-Range','reject','save','update','then','destroy','stack','name','map','VtigerAccount','rawAttributes','fieldName','model','keys','query','filters','intersection','attributes','fields','length','hasOwnProperty','nolimit','order','sort','where','pick','merge','type','filter','options','includeAll','include','findAll','rows','catch','show','params','find','create','body','getConfigurations','addConfiguration','findOne','AccountId','Subjects','getSubjects','Descriptions','getDescriptions','channel','VtigerConfiguration','VtigerField','md5','getFields','username'];(function(_0x40a045,_0x516f0e){var _0x1a687c=function(_0x48c9fe){while(--_0x48c9fe){_0x40a045['push'](_0x40a045['shift']());}};_0x1a687c(++_0x516f0e);}(_0xcb2f,0x12a));var _0xfcb2=function(_0x241bdd,_0x2d0fd2){_0x241bdd=_0x241bdd-0x0;var _0x45ccfd=_0xcb2f[_0x241bdd];return _0x45ccfd;};'use strict';var emlformat=require('eml-format');var rimraf=require(_0xfcb2('0x0'));var zipdir=require('zip-dir');var jsonpatch=require(_0xfcb2('0x1'));var rp=require(_0xfcb2('0x2'));var moment=require(_0xfcb2('0x3'));var BPromise=require(_0xfcb2('0x4'));var Mustache=require('mustache');var util=require('util');var path=require(_0xfcb2('0x5'));var sox=require('sox');var csv=require(_0xfcb2('0x6'));var ejs=require(_0xfcb2('0x7'));var fs=require('fs');var fs_extra=require(_0xfcb2('0x8'));var _=require(_0xfcb2('0x9'));var squel=require(_0xfcb2('0xa'));var crypto=require(_0xfcb2('0xb'));var jsforce=require(_0xfcb2('0xc'));var deskjs=require(_0xfcb2('0xd'));var toCsv=require(_0xfcb2('0x6'));var querystring=require(_0xfcb2('0xe'));var Papa=require(_0xfcb2('0xf'));var Redis=require(_0xfcb2('0x10'));var authService=require(_0xfcb2('0x11'));var qs=require(_0xfcb2('0x12'));var as=require(_0xfcb2('0x13'));var hardwareService=require(_0xfcb2('0x14'));var logger=require('../../config/logger')(_0xfcb2('0x15'));var utils=require(_0xfcb2('0x16'));var config=require('../../config/environment');var licenseUtil=require(_0xfcb2('0x17'));var db=require(_0xfcb2('0x18'))['db'];var integrations=require(_0xfcb2('0x19'));function respondWithStatusCode(_0x142641,_0x3707e1){_0x3707e1=_0x3707e1||0xcc;return function(_0x5a50f2){if(_0x5a50f2){return _0x142641[_0xfcb2('0x1a')](_0x3707e1);}return _0x142641[_0xfcb2('0x1b')](_0x3707e1)[_0xfcb2('0x1c')]();};}function respondWithResult(_0x4a5149,_0x2d260b){_0x2d260b=_0x2d260b||0xc8;return function(_0x5bef67){if(_0x5bef67){return _0x4a5149[_0xfcb2('0x1b')](_0x2d260b)[_0xfcb2('0x1d')](_0x5bef67);}};}function respondWithFilteredResult(_0x182db5,_0x454eb1){return function(_0x33160d){if(_0x33160d){var _0x388e89=typeof _0x454eb1[_0xfcb2('0x1e')]===_0xfcb2('0x1f')&&typeof _0x454eb1[_0xfcb2('0x20')]===_0xfcb2('0x1f');var _0x23925d=_0x33160d['count'];var _0x36b23f=_0x388e89?0x0:_0x454eb1[_0xfcb2('0x1e')];var _0x338a44=_0x388e89?_0x33160d[_0xfcb2('0x21')]:_0x454eb1[_0xfcb2('0x1e')]+_0x454eb1[_0xfcb2('0x20')];var _0x50bc2e;if(_0x338a44>=_0x23925d){_0x338a44=_0x23925d;_0x50bc2e=0xc8;}else{_0x50bc2e=0xce;}_0x182db5[_0xfcb2('0x1b')](_0x50bc2e);return _0x182db5[_0xfcb2('0x22')](_0xfcb2('0x23'),_0x36b23f+'-'+_0x338a44+'/'+_0x23925d)[_0xfcb2('0x1d')](_0x33160d);}return null;};}function patchUpdates(_0x22674d){return function(_0x4753d3){try{jsonpatch['apply'](_0x4753d3,_0x22674d,!![]);}catch(_0xd82dc1){return BPromise[_0xfcb2('0x24')](_0xd82dc1);}return _0x4753d3[_0xfcb2('0x25')]();};}function saveUpdates(_0x7ec579,_0x157cc0){return function(_0x437392){if(_0x437392){return _0x437392[_0xfcb2('0x26')](_0x7ec579)[_0xfcb2('0x27')](function(_0x348819){return _0x348819;});}return null;};}function removeEntity(_0x521c3f,_0x28da73){return function(_0x25634b){if(_0x25634b){return _0x25634b[_0xfcb2('0x28')]()[_0xfcb2('0x27')](function(){_0x521c3f[_0xfcb2('0x1b')](0xcc)['end']();});}};}function handleEntityNotFound(_0x5a360c,_0x2602c1){return function(_0x1c432f){if(!_0x1c432f){_0x5a360c[_0xfcb2('0x1a')](0x194);}return _0x1c432f;};}function handleError(_0x13dd25,_0x563abd){_0x563abd=_0x563abd||0x1f4;return function(_0x46aece){logger['error'](_0x46aece[_0xfcb2('0x29')]);if(_0x46aece[_0xfcb2('0x2a')]){delete _0x46aece[_0xfcb2('0x2a')];}_0x13dd25[_0xfcb2('0x1b')](_0x563abd)['send'](_0x46aece);};}exports['index']=function(_0x3aa038,_0x4c8c9b){var _0xcb846f={},_0x3ea517={},_0x267764={'count':0x0,'rows':[]};var _0x3112ca=_[_0xfcb2('0x2b')](db[_0xfcb2('0x2c')][_0xfcb2('0x2d')],function(_0x14a126){return{'name':_0x14a126[_0xfcb2('0x2e')],'type':_0x14a126['type']['key']};});_0x3ea517[_0xfcb2('0x2f')]=_[_0xfcb2('0x2b')](_0x3112ca,_0xfcb2('0x2a'));_0x3ea517['query']=_[_0xfcb2('0x30')](_0x3aa038[_0xfcb2('0x31')]);_0x3ea517[_0xfcb2('0x32')]=_[_0xfcb2('0x33')](_0x3ea517['model'],_0x3ea517[_0xfcb2('0x31')]);_0xcb846f[_0xfcb2('0x34')]=_[_0xfcb2('0x33')](_0x3ea517[_0xfcb2('0x2f')],qs[_0xfcb2('0x35')](_0x3aa038[_0xfcb2('0x31')][_0xfcb2('0x35')]));_0xcb846f[_0xfcb2('0x34')]=_0xcb846f[_0xfcb2('0x34')][_0xfcb2('0x36')]?_0xcb846f['attributes']:_0x3ea517[_0xfcb2('0x2f')];if(!_0x3aa038['query'][_0xfcb2('0x37')](_0xfcb2('0x38'))){_0xcb846f[_0xfcb2('0x20')]=qs[_0xfcb2('0x20')](_0x3aa038['query'][_0xfcb2('0x20')]);_0xcb846f[_0xfcb2('0x1e')]=qs[_0xfcb2('0x1e')](_0x3aa038[_0xfcb2('0x31')]['offset']);}_0xcb846f[_0xfcb2('0x39')]=qs[_0xfcb2('0x3a')](_0x3aa038[_0xfcb2('0x31')][_0xfcb2('0x3a')]);_0xcb846f[_0xfcb2('0x3b')]=qs[_0xfcb2('0x32')](_[_0xfcb2('0x3c')](_0x3aa038['query'],_0x3ea517['filters']),_0x3112ca);if(_0x3aa038[_0xfcb2('0x31')]['filter']){_0xcb846f[_0xfcb2('0x3b')]=_[_0xfcb2('0x3d')](_0xcb846f[_0xfcb2('0x3b')],{'$or':_[_0xfcb2('0x2b')](_0x3112ca,function(_0x5cb9b2){if(_0x5cb9b2[_0xfcb2('0x3e')]!=='VIRTUAL'){var _0x46b6c8={};_0x46b6c8[_0x5cb9b2['name']]={'$like':'%'+_0x3aa038[_0xfcb2('0x31')][_0xfcb2('0x3f')]+'%'};return _0x46b6c8;}})});}_0xcb846f=_[_0xfcb2('0x3d')]({},_0xcb846f,_0x3aa038[_0xfcb2('0x40')]);var _0x41395a={'where':_0xcb846f[_0xfcb2('0x3b')]};return db[_0xfcb2('0x2c')][_0xfcb2('0x21')](_0x41395a)['then'](function(_0x4315c9){_0x267764[_0xfcb2('0x21')]=_0x4315c9;if(_0x3aa038[_0xfcb2('0x31')][_0xfcb2('0x41')]){_0xcb846f[_0xfcb2('0x42')]=[{'all':!![]}];}return db[_0xfcb2('0x2c')][_0xfcb2('0x43')](_0xcb846f);})[_0xfcb2('0x27')](function(_0x3fa753){_0x267764[_0xfcb2('0x44')]=_0x3fa753;return _0x267764;})['then'](respondWithFilteredResult(_0x4c8c9b,_0xcb846f))[_0xfcb2('0x45')](handleError(_0x4c8c9b,null));};exports[_0xfcb2('0x46')]=function(_0x48499b,_0x33eaa0){var _0x3d1683={'raw':![],'where':{'id':_0x48499b[_0xfcb2('0x47')]['id']}},_0xad7a32={};_0xad7a32[_0xfcb2('0x2f')]=_[_0xfcb2('0x30')](db[_0xfcb2('0x2c')][_0xfcb2('0x2d')]);_0xad7a32[_0xfcb2('0x31')]=_[_0xfcb2('0x30')](_0x48499b[_0xfcb2('0x31')]);_0xad7a32[_0xfcb2('0x32')]=_[_0xfcb2('0x33')](_0xad7a32['model'],_0xad7a32['query']);_0x3d1683['attributes']=_[_0xfcb2('0x33')](_0xad7a32[_0xfcb2('0x2f')],qs[_0xfcb2('0x35')](_0x48499b[_0xfcb2('0x31')]['fields']));_0x3d1683['attributes']=_0x3d1683[_0xfcb2('0x34')]['length']?_0x3d1683[_0xfcb2('0x34')]:_0xad7a32[_0xfcb2('0x2f')];if(_0x48499b[_0xfcb2('0x31')][_0xfcb2('0x41')]){_0x3d1683[_0xfcb2('0x42')]=[{'all':!![]}];}_0x3d1683=_['merge']({},_0x3d1683,_0x48499b['options']);return db['VtigerAccount'][_0xfcb2('0x48')](_0x3d1683)['then'](handleEntityNotFound(_0x33eaa0,null))['then'](respondWithResult(_0x33eaa0,null))[_0xfcb2('0x45')](handleError(_0x33eaa0,null));};exports[_0xfcb2('0x49')]=function(_0x233c2a,_0x20a038){return db[_0xfcb2('0x2c')]['create'](_0x233c2a[_0xfcb2('0x4a')],{})[_0xfcb2('0x27')](respondWithResult(_0x20a038,0xc9))['catch'](handleError(_0x20a038,null));};exports[_0xfcb2('0x26')]=function(_0xceea66,_0x25871d){if(_0xceea66['body']['id']){delete _0xceea66[_0xfcb2('0x4a')]['id'];}return db[_0xfcb2('0x2c')]['find']({'where':{'id':_0xceea66[_0xfcb2('0x47')]['id']}})['then'](handleEntityNotFound(_0x25871d,null))[_0xfcb2('0x27')](saveUpdates(_0xceea66[_0xfcb2('0x4a')],null))['then'](respondWithResult(_0x25871d,null))['catch'](handleError(_0x25871d,null));};exports[_0xfcb2('0x28')]=function(_0x9baca9,_0x12e040){return db[_0xfcb2('0x2c')]['find']({'where':{'id':_0x9baca9[_0xfcb2('0x47')]['id']}})[_0xfcb2('0x27')](handleEntityNotFound(_0x12e040,null))[_0xfcb2('0x27')](removeEntity(_0x12e040,null))[_0xfcb2('0x45')](handleError(_0x12e040,null));};exports[_0xfcb2('0x4b')]=function(_0x542094,_0xbf5154,_0x367199){var _0x54df2c={};var _0x45a5fe={};var _0x3087cd;var _0x272172;return db[_0xfcb2('0x2c')]['findOne']({'where':{'id':_0x542094['params']['id']}})[_0xfcb2('0x27')](handleEntityNotFound(_0xbf5154,null))[_0xfcb2('0x27')](function(_0x2310fa){if(_0x2310fa){_0x3087cd=_0x2310fa;_0x45a5fe[_0xfcb2('0x2f')]=_['keys'](db['VtigerConfiguration']['rawAttributes']);_0x45a5fe[_0xfcb2('0x31')]=_['keys'](_0x542094[_0xfcb2('0x31')]);_0x45a5fe[_0xfcb2('0x32')]=_[_0xfcb2('0x33')](_0x45a5fe[_0xfcb2('0x2f')],_0x45a5fe[_0xfcb2('0x31')]);_0x54df2c['attributes']=_[_0xfcb2('0x33')](_0x45a5fe[_0xfcb2('0x2f')],qs[_0xfcb2('0x35')](_0x542094[_0xfcb2('0x31')][_0xfcb2('0x35')]));_0x54df2c[_0xfcb2('0x34')]=_0x54df2c[_0xfcb2('0x34')][_0xfcb2('0x36')]?_0x54df2c[_0xfcb2('0x34')]:_0x45a5fe[_0xfcb2('0x2f')];_0x54df2c['order']=qs[_0xfcb2('0x3a')](_0x542094[_0xfcb2('0x31')][_0xfcb2('0x3a')]);_0x54df2c[_0xfcb2('0x3b')]=qs[_0xfcb2('0x32')](_[_0xfcb2('0x3c')](_0x542094[_0xfcb2('0x31')],_0x45a5fe['filters']));if(_0x542094[_0xfcb2('0x31')]['filter']){_0x54df2c['where']=_[_0xfcb2('0x3d')](_0x54df2c[_0xfcb2('0x3b')],{'$or':_[_0xfcb2('0x2b')](_0x54df2c[_0xfcb2('0x34')],function(_0x3f626c){var _0x158a68={};_0x158a68[_0x3f626c]={'$like':'%'+_0x542094[_0xfcb2('0x31')][_0xfcb2('0x3f')]+'%'};return _0x158a68;})});}_0x54df2c=_[_0xfcb2('0x3d')]({},_0x54df2c,_0x542094[_0xfcb2('0x40')]);return _0x3087cd[_0xfcb2('0x4b')](_0x54df2c);}})[_0xfcb2('0x27')](function(_0x1e76d1){if(_0x1e76d1){_0x272172=_0x1e76d1[_0xfcb2('0x36')];if(!_0x542094[_0xfcb2('0x31')][_0xfcb2('0x37')](_0xfcb2('0x38'))){_0x54df2c[_0xfcb2('0x20')]=qs[_0xfcb2('0x20')](_0x542094[_0xfcb2('0x31')][_0xfcb2('0x20')]);_0x54df2c[_0xfcb2('0x1e')]=qs[_0xfcb2('0x1e')](_0x542094['query'][_0xfcb2('0x1e')]);}return _0x3087cd[_0xfcb2('0x4b')](_0x54df2c);}})[_0xfcb2('0x27')](function(_0x19e96e){if(_0x19e96e){return _0x19e96e?{'count':_0x272172,'rows':_0x19e96e}:null;}})[_0xfcb2('0x27')](respondWithResult(_0xbf5154,null))['catch'](handleError(_0xbf5154,null));};exports[_0xfcb2('0x4c')]=function(_0x58323d,_0x21c2f8,_0x3875c9){if(_0x58323d[_0xfcb2('0x4a')]['id']){delete _0x58323d[_0xfcb2('0x4a')]['id'];}return db[_0xfcb2('0x2c')][_0xfcb2('0x4d')]({'where':{'id':_0x58323d[_0xfcb2('0x47')]['id']}})[_0xfcb2('0x27')](handleEntityNotFound(_0x21c2f8,null))['then'](function(_0x4325cc){if(_0x4325cc){_0x58323d[_0xfcb2('0x4a')][_0xfcb2('0x4e')]=_0x4325cc['id'];_0x58323d[_0xfcb2('0x4a')][_0xfcb2('0x4f')]=integrations[_0xfcb2('0x50')](_0x58323d[_0xfcb2('0x4a')]['channel'],_0x58323d[_0xfcb2('0x4a')][_0xfcb2('0x3e')]);_0x58323d[_0xfcb2('0x4a')][_0xfcb2('0x51')]=integrations[_0xfcb2('0x52')](_0x58323d[_0xfcb2('0x4a')][_0xfcb2('0x53')],_0x58323d[_0xfcb2('0x4a')][_0xfcb2('0x3e')]);return db[_0xfcb2('0x54')][_0xfcb2('0x49')](_0x58323d[_0xfcb2('0x4a')],{'include':[{'model':db[_0xfcb2('0x55')],'as':_0xfcb2('0x4f')},{'model':db[_0xfcb2('0x55')],'as':_0xfcb2('0x51')}]});}return null;})[_0xfcb2('0x27')](respondWithResult(_0x21c2f8,null))[_0xfcb2('0x45')](handleError(_0x21c2f8,null));};var md5=require(_0xfcb2('0x56'));exports[_0xfcb2('0x57')]=function(_0xa8b142,_0x5cc5e4,_0x446ba1){var _0x592f4e=null;var _0x188ee1=null;var _0x5acb3d=null;var _0x55487b=null;var _0x2853f3='';return db[_0xfcb2('0x2c')][_0xfcb2('0x4d')]({'where':{'id':_0xa8b142[_0xfcb2('0x47')]['id']},'attributes':['id',_0xfcb2('0x2a'),_0xfcb2('0x58'),_0xfcb2('0x59'),_0xfcb2('0x5a'),_0xfcb2('0x5b'),_0xfcb2('0x5c'),_0xfcb2('0x5d')]})[_0xfcb2('0x27')](handleEntityNotFound(_0x5cc5e4,null))[_0xfcb2('0x27')](function(_0x29a21b){if(_0x29a21b){_0x592f4e=_0x29a21b[_0xfcb2('0x58')];_0x188ee1=_0x29a21b[_0xfcb2('0x5d')];_0x5acb3d=_0x29a21b[_0xfcb2('0x5a')];_0x2853f3=_0x29a21b[_0xfcb2('0x5b')];var _0x2b5216=_0x2853f3[_0xfcb2('0x5e')](-0x1);if(_0x2b5216==='/'){_0x2853f3=_0x2853f3[_0xfcb2('0x5f')](0x0,_0x2853f3[_0xfcb2('0x60')](_0x2b5216));}_0x55487b=util[_0xfcb2('0x61')](_0xfcb2('0x62'),_0x2853f3);var _0xf109d3={'method':_0xfcb2('0x63'),'uri':_0x55487b,'qs':{'operation':_0xfcb2('0x64'),'username':_0x29a21b[_0xfcb2('0x58')]},'json':!![]};return rp(_0xf109d3);}})['then'](function(_0x54f359){if(_0x54f359[_0xfcb2('0x65')]){var _0x35a94d={'method':_0xfcb2('0x66'),'uri':_0x55487b,'form':{'operation':_0xfcb2('0x67'),'username':_0x592f4e,'accessKey':md5(_0x54f359['result'][_0xfcb2('0x68')]+_0x188ee1)},'json':!![]};return rp(_0x35a94d);}})['then'](function(_0x2b488a){if(_0x2b488a[_0xfcb2('0x65')]){var _0x12a9e9={'method':_0xfcb2('0x63'),'uri':_0x55487b,'qs':{'operation':_0xfcb2('0x69'),'username':_0x592f4e,'sessionName':_0x2b488a[_0xfcb2('0x6a')][_0xfcb2('0x6b')],'elementType':_0x5acb3d},'json':!![]};return rp(_0x12a9e9);}})['then'](function(_0x579a04){if(_0x579a04['success']){var _0x3e7d3d=[_0xfcb2('0x6c'),_0xfcb2('0x6d'),_0xfcb2('0x6e')];_[_0xfcb2('0x6f')](_0x579a04[_0xfcb2('0x6a')][_0xfcb2('0x35')],function(_0xa356c7){return _0x3e7d3d[_0xfcb2('0x70')](_0xa356c7[_0xfcb2('0x3e')][_0xfcb2('0x2a')]);});_[_0xfcb2('0x6f')](_0x579a04['result'][_0xfcb2('0x35')],function(_0x5c8c0f){return _0x5c8c0f[_0xfcb2('0x71')]==='false';});return{'count':_0x579a04['result'][_0xfcb2('0x35')][_0xfcb2('0x36')],'rows':_[_0xfcb2('0x2b')](_0x579a04[_0xfcb2('0x6a')][_0xfcb2('0x35')],function(_0x27ee68){return{'id':_0x27ee68[_0xfcb2('0x2a')],'name':_0x27ee68[_0xfcb2('0x72')],'custom':_[_0xfcb2('0x73')](_0x27ee68['name'],_0xfcb2('0x74'))?!![]:![],'options':_0x27ee68['type'][_0xfcb2('0x2a')]===_0xfcb2('0x75')&&_0x27ee68['type'][_0xfcb2('0x76')][_0xfcb2('0x36')]>0x0?_[_0xfcb2('0x2b')](_0x27ee68[_0xfcb2('0x3e')][_0xfcb2('0x76')],function(_0x803bcb){return{'name':_0x803bcb[_0xfcb2('0x72')],'value':_0x803bcb[_0xfcb2('0x77')]};}):[]};})};}})[_0xfcb2('0x27')](respondWithResult(_0x5cc5e4,null))[_0xfcb2('0x45')](function(_0x109353){console[_0xfcb2('0x78')](_0xfcb2('0x79')+_0x109353);var _0x3461bd=_0xa8b142[_0xfcb2('0x31')][_0xfcb2('0x7a')]?0x1f4:_0x109353[_0xfcb2('0x7b')]||0x1f4;logger[_0xfcb2('0x7c')](_0xfcb2('0x7d'),_0xfcb2('0x57'),_0x3461bd,JSON[_0xfcb2('0x7e')](_0x109353));delete _0x109353['name'];if(_0x3461bd===0x191){_0x3461bd=0x190;}_0x5cc5e4[_0xfcb2('0x1b')](_0x3461bd)[_0xfcb2('0x7f')](_0xa8b142[_0xfcb2('0x31')]['test']?{'message':_0xfcb2('0x80'),'statusCode':_0x109353[_0xfcb2('0x7b')]}:_0x109353);});};
\ No newline at end of file