Built motion from commit ffdca78c.|2.6.24
[motion2.git] / server / api / intVtigerAccount / intVtigerAccount.controller.js
index 476be0e..f01feac 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0x606f=['jsforce','desk.js','papaparse','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/logger','../../config/utils','../../config/environment','../../config/license/util','../../components/integrations/configuration','sendStatus','status','json','count','offset','limit','Content-Range','apply','reject','save','then','destroy','end','name','send','map','VtigerAccount','type','key','model','query','keys','filters','intersection','attributes','fields','length','hasOwnProperty','nolimit','order','sort','where','filter','merge','VIRTUAL','includeAll','findAll','rows','catch','params','rawAttributes','include','options','find','create','update','body','findOne','pick','getConfigurations','addConfiguration','Subjects','getSubjects','channel','Descriptions','getDescriptions','VtigerField','md5','getFields','username','description','moduleName','remoteUri','serverUrl','accessKey','slice','substring','lastIndexOf','format','%s/webservice.php','getchallenge','success','POST','result','token','describe','autogenerated','includes','remove','false','label','cf_','picklist','picklistValues','value','log','vTiger\x20error:\x20','test','statusCode','error','getFields,\x20%s,\x20%s,\x20%s','stringify','Wrong\x20credentials','eml-format','rimraf','zip-dir','fast-json-patch','request-promise','moment','bluebird','mustache','util','path','sox','to-csv','ejs','fs-extra','lodash','squel','crypto'];(function(_0x5c9fad,_0x8eeb1c){var _0x41fc1c=function(_0x49265d){while(--_0x49265d){_0x5c9fad['push'](_0x5c9fad['shift']());}};_0x41fc1c(++_0x8eeb1c);}(_0x606f,0xe1));var _0xf606=function(_0x3dd15e,_0x1f0015){_0x3dd15e=_0x3dd15e-0x0;var _0x231fd0=_0x606f[_0x3dd15e];return _0x231fd0;};'use strict';var emlformat=require(_0xf606('0x0'));var rimraf=require(_0xf606('0x1'));var zipdir=require(_0xf606('0x2'));var jsonpatch=require(_0xf606('0x3'));var rp=require(_0xf606('0x4'));var moment=require(_0xf606('0x5'));var BPromise=require(_0xf606('0x6'));var Mustache=require(_0xf606('0x7'));var util=require(_0xf606('0x8'));var path=require(_0xf606('0x9'));var sox=require(_0xf606('0xa'));var csv=require(_0xf606('0xb'));var ejs=require(_0xf606('0xc'));var fs=require('fs');var fs_extra=require(_0xf606('0xd'));var _=require(_0xf606('0xe'));var squel=require(_0xf606('0xf'));var crypto=require(_0xf606('0x10'));var jsforce=require(_0xf606('0x11'));var deskjs=require(_0xf606('0x12'));var toCsv=require(_0xf606('0xb'));var querystring=require('querystring');var Papa=require(_0xf606('0x13'));var Redis=require('ioredis');var authService=require(_0xf606('0x14'));var qs=require(_0xf606('0x15'));var as=require(_0xf606('0x16'));var hardwareService=require('../../config/license/hardware');var logger=require(_0xf606('0x17'))('api');var utils=require(_0xf606('0x18'));var config=require(_0xf606('0x19'));var licenseUtil=require(_0xf606('0x1a'));var db=require('../../mysqldb')['db'];var integrations=require(_0xf606('0x1b'));function respondWithStatusCode(_0x11ff8a,_0x5da645){_0x5da645=_0x5da645||0xcc;return function(_0x2c58f4){if(_0x2c58f4){return _0x11ff8a[_0xf606('0x1c')](_0x5da645);}return _0x11ff8a[_0xf606('0x1d')](_0x5da645)['end']();};}function respondWithResult(_0x3f3f29,_0x85a33a){_0x85a33a=_0x85a33a||0xc8;return function(_0x23ac51){if(_0x23ac51){return _0x3f3f29['status'](_0x85a33a)[_0xf606('0x1e')](_0x23ac51);}};}function respondWithFilteredResult(_0x12c17d,_0x2a1e13){return function(_0x115db5){if(_0x115db5){var _0x48149a=typeof _0x2a1e13['offset']==='undefined'&&typeof _0x2a1e13['limit']==='undefined';var _0x3b7f03=_0x115db5[_0xf606('0x1f')];var _0x189174=_0x48149a?0x0:_0x2a1e13[_0xf606('0x20')];var _0xf1586=_0x48149a?_0x115db5[_0xf606('0x1f')]:_0x2a1e13[_0xf606('0x20')]+_0x2a1e13[_0xf606('0x21')];var _0x14240f;if(_0xf1586>=_0x3b7f03){_0xf1586=_0x3b7f03;_0x14240f=0xc8;}else{_0x14240f=0xce;}_0x12c17d[_0xf606('0x1d')](_0x14240f);return _0x12c17d['set'](_0xf606('0x22'),_0x189174+'-'+_0xf1586+'/'+_0x3b7f03)['json'](_0x115db5);}return null;};}function patchUpdates(_0x1c9bf2){return function(_0x4f4079){try{jsonpatch[_0xf606('0x23')](_0x4f4079,_0x1c9bf2,!![]);}catch(_0x2567ef){return BPromise[_0xf606('0x24')](_0x2567ef);}return _0x4f4079[_0xf606('0x25')]();};}function saveUpdates(_0x5df21b,_0x219546){return function(_0x5bb21d){if(_0x5bb21d){return _0x5bb21d['update'](_0x5df21b)[_0xf606('0x26')](function(_0x4be587){return _0x4be587;});}return null;};}function removeEntity(_0x5bbc2e,_0x1f285b){return function(_0x743833){if(_0x743833){return _0x743833[_0xf606('0x27')]()[_0xf606('0x26')](function(){_0x5bbc2e['status'](0xcc)[_0xf606('0x28')]();});}};}function handleEntityNotFound(_0x326f9a,_0x321e58){return function(_0x4e4438){if(!_0x4e4438){_0x326f9a[_0xf606('0x1c')](0x194);}return _0x4e4438;};}function handleError(_0x47c319,_0x53a42b){_0x53a42b=_0x53a42b||0x1f4;return function(_0x457e1d){logger['error'](_0x457e1d['stack']);if(_0x457e1d[_0xf606('0x29')]){delete _0x457e1d[_0xf606('0x29')];}_0x47c319['status'](_0x53a42b)[_0xf606('0x2a')](_0x457e1d);};}exports['index']=function(_0x58798f,_0x372297){var _0x316f79={},_0x30a935={},_0x58d6b1={'count':0x0,'rows':[]};var _0x4af3ef=_[_0xf606('0x2b')](db[_0xf606('0x2c')]['rawAttributes'],function(_0x5ace18){return{'name':_0x5ace18['fieldName'],'type':_0x5ace18[_0xf606('0x2d')][_0xf606('0x2e')]};});_0x30a935[_0xf606('0x2f')]=_[_0xf606('0x2b')](_0x4af3ef,'name');_0x30a935[_0xf606('0x30')]=_[_0xf606('0x31')](_0x58798f[_0xf606('0x30')]);_0x30a935[_0xf606('0x32')]=_[_0xf606('0x33')](_0x30a935['model'],_0x30a935[_0xf606('0x30')]);_0x316f79[_0xf606('0x34')]=_[_0xf606('0x33')](_0x30a935[_0xf606('0x2f')],qs['fields'](_0x58798f['query'][_0xf606('0x35')]));_0x316f79[_0xf606('0x34')]=_0x316f79[_0xf606('0x34')][_0xf606('0x36')]?_0x316f79['attributes']:_0x30a935['model'];if(!_0x58798f[_0xf606('0x30')][_0xf606('0x37')](_0xf606('0x38'))){_0x316f79['limit']=qs[_0xf606('0x21')](_0x58798f[_0xf606('0x30')][_0xf606('0x21')]);_0x316f79[_0xf606('0x20')]=qs['offset'](_0x58798f[_0xf606('0x30')][_0xf606('0x20')]);}_0x316f79[_0xf606('0x39')]=qs[_0xf606('0x3a')](_0x58798f['query'][_0xf606('0x3a')]);_0x316f79[_0xf606('0x3b')]=qs['filters'](_['pick'](_0x58798f[_0xf606('0x30')],_0x30a935[_0xf606('0x32')]),_0x4af3ef);if(_0x58798f['query'][_0xf606('0x3c')]){_0x316f79[_0xf606('0x3b')]=_[_0xf606('0x3d')](_0x316f79[_0xf606('0x3b')],{'$or':_['map'](_0x4af3ef,function(_0x330a27){if(_0x330a27[_0xf606('0x2d')]!==_0xf606('0x3e')){var _0x5592ee={};_0x5592ee[_0x330a27[_0xf606('0x29')]]={'$like':'%'+_0x58798f['query'][_0xf606('0x3c')]+'%'};return _0x5592ee;}})});}_0x316f79=_[_0xf606('0x3d')]({},_0x316f79,_0x58798f['options']);var _0x5e7db6={'where':_0x316f79[_0xf606('0x3b')]};return db['VtigerAccount'][_0xf606('0x1f')](_0x5e7db6)['then'](function(_0x2c6abe){_0x58d6b1[_0xf606('0x1f')]=_0x2c6abe;if(_0x58798f['query'][_0xf606('0x3f')]){_0x316f79['include']=[{'all':!![]}];}return db[_0xf606('0x2c')][_0xf606('0x40')](_0x316f79);})[_0xf606('0x26')](function(_0x4370ca){_0x58d6b1[_0xf606('0x41')]=_0x4370ca;return _0x58d6b1;})[_0xf606('0x26')](respondWithFilteredResult(_0x372297,_0x316f79))[_0xf606('0x42')](handleError(_0x372297,null));};exports['show']=function(_0x1b4049,_0x47bf3d){var _0x44fad7={'raw':![],'where':{'id':_0x1b4049[_0xf606('0x43')]['id']}},_0xa43818={};_0xa43818[_0xf606('0x2f')]=_['keys'](db[_0xf606('0x2c')][_0xf606('0x44')]);_0xa43818[_0xf606('0x30')]=_['keys'](_0x1b4049['query']);_0xa43818['filters']=_[_0xf606('0x33')](_0xa43818[_0xf606('0x2f')],_0xa43818[_0xf606('0x30')]);_0x44fad7[_0xf606('0x34')]=_[_0xf606('0x33')](_0xa43818[_0xf606('0x2f')],qs['fields'](_0x1b4049[_0xf606('0x30')][_0xf606('0x35')]));_0x44fad7['attributes']=_0x44fad7['attributes'][_0xf606('0x36')]?_0x44fad7[_0xf606('0x34')]:_0xa43818[_0xf606('0x2f')];if(_0x1b4049[_0xf606('0x30')]['includeAll']){_0x44fad7[_0xf606('0x45')]=[{'all':!![]}];}_0x44fad7=_['merge']({},_0x44fad7,_0x1b4049[_0xf606('0x46')]);return db[_0xf606('0x2c')][_0xf606('0x47')](_0x44fad7)[_0xf606('0x26')](handleEntityNotFound(_0x47bf3d,null))[_0xf606('0x26')](respondWithResult(_0x47bf3d,null))[_0xf606('0x42')](handleError(_0x47bf3d,null));};exports[_0xf606('0x48')]=function(_0x1c5906,_0x3bf9f1){return db['VtigerAccount'][_0xf606('0x48')](_0x1c5906['body'],{})[_0xf606('0x26')](respondWithResult(_0x3bf9f1,0xc9))[_0xf606('0x42')](handleError(_0x3bf9f1,null));};exports[_0xf606('0x49')]=function(_0x20ae21,_0x185f21){if(_0x20ae21['body']['id']){delete _0x20ae21[_0xf606('0x4a')]['id'];}return db['VtigerAccount'][_0xf606('0x47')]({'where':{'id':_0x20ae21[_0xf606('0x43')]['id']}})[_0xf606('0x26')](handleEntityNotFound(_0x185f21,null))[_0xf606('0x26')](saveUpdates(_0x20ae21[_0xf606('0x4a')],null))[_0xf606('0x26')](respondWithResult(_0x185f21,null))['catch'](handleError(_0x185f21,null));};exports[_0xf606('0x27')]=function(_0x1aff7c,_0x2cfe17){return db['VtigerAccount'][_0xf606('0x47')]({'where':{'id':_0x1aff7c['params']['id']}})[_0xf606('0x26')](handleEntityNotFound(_0x2cfe17,null))[_0xf606('0x26')](removeEntity(_0x2cfe17,null))['catch'](handleError(_0x2cfe17,null));};exports['getConfigurations']=function(_0x283d09,_0x229c24,_0x3f86e6){var _0x1aeac9={};var _0x1b0839={};var _0x4f29f6;var _0x1b7045;return db[_0xf606('0x2c')][_0xf606('0x4b')]({'where':{'id':_0x283d09['params']['id']}})[_0xf606('0x26')](handleEntityNotFound(_0x229c24,null))['then'](function(_0x5167c1){if(_0x5167c1){_0x4f29f6=_0x5167c1;_0x1b0839[_0xf606('0x2f')]=_[_0xf606('0x31')](db['VtigerConfiguration'][_0xf606('0x44')]);_0x1b0839['query']=_[_0xf606('0x31')](_0x283d09[_0xf606('0x30')]);_0x1b0839[_0xf606('0x32')]=_[_0xf606('0x33')](_0x1b0839[_0xf606('0x2f')],_0x1b0839['query']);_0x1aeac9[_0xf606('0x34')]=_[_0xf606('0x33')](_0x1b0839['model'],qs[_0xf606('0x35')](_0x283d09[_0xf606('0x30')]['fields']));_0x1aeac9['attributes']=_0x1aeac9['attributes'][_0xf606('0x36')]?_0x1aeac9['attributes']:_0x1b0839['model'];_0x1aeac9[_0xf606('0x39')]=qs[_0xf606('0x3a')](_0x283d09[_0xf606('0x30')]['sort']);_0x1aeac9[_0xf606('0x3b')]=qs[_0xf606('0x32')](_[_0xf606('0x4c')](_0x283d09[_0xf606('0x30')],_0x1b0839['filters']));if(_0x283d09['query'][_0xf606('0x3c')]){_0x1aeac9['where']=_[_0xf606('0x3d')](_0x1aeac9[_0xf606('0x3b')],{'$or':_[_0xf606('0x2b')](_0x1aeac9[_0xf606('0x34')],function(_0x33fcdf){var _0xc37527={};_0xc37527[_0x33fcdf]={'$like':'%'+_0x283d09[_0xf606('0x30')][_0xf606('0x3c')]+'%'};return _0xc37527;})});}_0x1aeac9=_[_0xf606('0x3d')]({},_0x1aeac9,_0x283d09['options']);return _0x4f29f6['getConfigurations'](_0x1aeac9);}})['then'](function(_0x155754){if(_0x155754){_0x1b7045=_0x155754[_0xf606('0x36')];if(!_0x283d09['query'][_0xf606('0x37')](_0xf606('0x38'))){_0x1aeac9[_0xf606('0x21')]=qs[_0xf606('0x21')](_0x283d09[_0xf606('0x30')][_0xf606('0x21')]);_0x1aeac9['offset']=qs[_0xf606('0x20')](_0x283d09[_0xf606('0x30')]['offset']);}return _0x4f29f6[_0xf606('0x4d')](_0x1aeac9);}})['then'](function(_0x20baf6){if(_0x20baf6){return _0x20baf6?{'count':_0x1b7045,'rows':_0x20baf6}:null;}})['then'](respondWithResult(_0x229c24,null))['catch'](handleError(_0x229c24,null));};exports[_0xf606('0x4e')]=function(_0x441f6a,_0x1c658b,_0x1f9bc9){if(_0x441f6a['body']['id']){delete _0x441f6a[_0xf606('0x4a')]['id'];}return db[_0xf606('0x2c')][_0xf606('0x4b')]({'where':{'id':_0x441f6a[_0xf606('0x43')]['id']}})[_0xf606('0x26')](handleEntityNotFound(_0x1c658b,null))[_0xf606('0x26')](function(_0xdc207){if(_0xdc207){_0x441f6a[_0xf606('0x4a')]['AccountId']=_0xdc207['id'];_0x441f6a['body'][_0xf606('0x4f')]=integrations[_0xf606('0x50')](_0x441f6a[_0xf606('0x4a')][_0xf606('0x51')],_0x441f6a['body']['type']);_0x441f6a[_0xf606('0x4a')][_0xf606('0x52')]=integrations[_0xf606('0x53')](_0x441f6a['body'][_0xf606('0x51')],_0x441f6a[_0xf606('0x4a')]['type']);return db['VtigerConfiguration'][_0xf606('0x48')](_0x441f6a['body'],{'include':[{'model':db[_0xf606('0x54')],'as':'Subjects'},{'model':db[_0xf606('0x54')],'as':_0xf606('0x52')}]});}return null;})[_0xf606('0x26')](respondWithResult(_0x1c658b,null))[_0xf606('0x42')](handleError(_0x1c658b,null));};var md5=require(_0xf606('0x55'));exports[_0xf606('0x56')]=function(_0x39b504,_0x110347,_0x4f8441){var _0x7b0ba=null;var _0x370cc3=null;var _0x1db626=null;var _0x5909c0=null;var _0x1c7f77='';return db[_0xf606('0x2c')]['findOne']({'where':{'id':_0x39b504[_0xf606('0x43')]['id']},'attributes':['id',_0xf606('0x29'),_0xf606('0x57'),_0xf606('0x58'),_0xf606('0x59'),_0xf606('0x5a'),_0xf606('0x5b'),'accessKey']})[_0xf606('0x26')](handleEntityNotFound(_0x110347,null))['then'](function(_0x4e2663){if(_0x4e2663){_0x7b0ba=_0x4e2663[_0xf606('0x57')];_0x370cc3=_0x4e2663[_0xf606('0x5c')];_0x1db626=_0x4e2663[_0xf606('0x59')];_0x1c7f77=_0x4e2663[_0xf606('0x5a')];var _0x3877d7=_0x1c7f77[_0xf606('0x5d')](-0x1);if(_0x3877d7==='/'){_0x1c7f77=_0x1c7f77[_0xf606('0x5e')](0x0,_0x1c7f77[_0xf606('0x5f')](_0x3877d7));}_0x5909c0=util[_0xf606('0x60')](_0xf606('0x61'),_0x1c7f77);var _0x2c1a23={'method':'GET','uri':_0x5909c0,'qs':{'operation':_0xf606('0x62'),'username':_0x4e2663['username']},'json':!![]};return rp(_0x2c1a23);}})['then'](function(_0x66031f){if(_0x66031f[_0xf606('0x63')]){var _0x137efa={'method':_0xf606('0x64'),'uri':_0x5909c0,'form':{'operation':'login','username':_0x7b0ba,'accessKey':md5(_0x66031f[_0xf606('0x65')][_0xf606('0x66')]+_0x370cc3)},'json':!![]};return rp(_0x137efa);}})[_0xf606('0x26')](function(_0x590622){if(_0x590622[_0xf606('0x63')]){var _0xb24b3e={'method':'GET','uri':_0x5909c0,'qs':{'operation':_0xf606('0x67'),'username':_0x7b0ba,'sessionName':_0x590622[_0xf606('0x65')]['sessionName'],'elementType':_0x1db626},'json':!![]};return rp(_0xb24b3e);}})[_0xf606('0x26')](function(_0x3414ec){if(_0x3414ec['success']){var _0x5a1f36=[_0xf606('0x68'),'reference','owner'];_['remove'](_0x3414ec['result']['fields'],function(_0x6d690d){return _0x5a1f36[_0xf606('0x69')](_0x6d690d[_0xf606('0x2d')]['name']);});_[_0xf606('0x6a')](_0x3414ec['result']['fields'],function(_0x18b172){return _0x18b172['editable']===_0xf606('0x6b');});return{'count':_0x3414ec[_0xf606('0x65')][_0xf606('0x35')]['length'],'rows':_[_0xf606('0x2b')](_0x3414ec['result'][_0xf606('0x35')],function(_0x4f6508){return{'id':_0x4f6508[_0xf606('0x29')],'name':_0x4f6508[_0xf606('0x6c')],'custom':_['startsWith'](_0x4f6508['name'],_0xf606('0x6d'))?!![]:![],'options':_0x4f6508[_0xf606('0x2d')]['name']===_0xf606('0x6e')&&_0x4f6508[_0xf606('0x2d')][_0xf606('0x6f')][_0xf606('0x36')]>0x0?_[_0xf606('0x2b')](_0x4f6508['type'][_0xf606('0x6f')],function(_0x3ef99e){return{'name':_0x3ef99e[_0xf606('0x6c')],'value':_0x3ef99e[_0xf606('0x70')]};}):[]};})};}})['then'](respondWithResult(_0x110347,null))[_0xf606('0x42')](function(_0x22b04e){console[_0xf606('0x71')](_0xf606('0x72')+_0x22b04e);var _0x417ba2=_0x39b504[_0xf606('0x30')][_0xf606('0x73')]?0x1f4:_0x22b04e[_0xf606('0x74')]||0x1f4;logger[_0xf606('0x75')](_0xf606('0x76'),_0xf606('0x56'),_0x417ba2,JSON[_0xf606('0x77')](_0x22b04e));delete _0x22b04e[_0xf606('0x29')];if(_0x417ba2===0x191){_0x417ba2=0x190;}_0x110347[_0xf606('0x1d')](_0x417ba2)['send'](_0x39b504[_0xf606('0x30')]['test']?{'message':_0xf606('0x78'),'statusCode':_0x22b04e['statusCode']}:_0x22b04e);});};
\ 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