54f0659ef2a5f7a1b926b0ab7d9f9bde3b782838
[motion-next.git] / server / api / intSugarcrmAccount / intSugarcrmAccount.controller.js
1 const a307_0x5e39=['pick','../../components/integrations/configuration','PLAIN','map','stringify','parent_type','show','getSubjects','type','name','nolimit','error','VIRTUAL','description','values','channel','findOne','getFields,\x20%s,\x20%s,\x20%s','json','fieldName','password','params','POST','create','send','order','direction','update','findAll','include','test','limit','filter','status','parent_name','request-promise-native','index','query','SugarcrmField','lodash','get_module_fields','where','SugarcrmAccount','Calls','statusCode','options','endsWith','Subjects','getFields','../../components/parsers/qs','merge','set','then','body','rawAttributes','remoteUri','model','created_by','duration_hours','getConfigurations','lastIndexOf','destroy','intersection','filters','util','undefined','offset','substring','/service/v4_1/rest.php','stack','sequelize','format','includeAll','AccountId','username','count','SugarcrmConfiguration','includes','length','catch','attributes','remove','Descriptions','slice','%s%s','rows','Password\x20Expired','like','getDescriptions','fields','login','../../mysqldb','sort','keys','JSON'];(function(_0x42aacb,_0x5e3900){const _0x3f6b41=function(_0x1fd22b){while(--_0x1fd22b){_0x42aacb['push'](_0x42aacb['shift']());}};_0x3f6b41(++_0x5e3900);}(a307_0x5e39,0x19e));const a307_0x3f6b=function(_0x42aacb,_0x5e3900){_0x42aacb=_0x42aacb-0x0;let _0x3f6b41=a307_0x5e39[_0x42aacb];return _0x3f6b41;};const _0x54e02a=a307_0x3f6b;'use strict';const rp=require(_0x54e02a('0x1')),util=require(_0x54e02a('0x1e')),_=require(_0x54e02a('0x5')),qs=require(_0x54e02a('0xf')),logger=require('../../config/logger')('api'),db=require(_0x54e02a('0x39'))['db'],{Op}=require(_0x54e02a('0x24')),integrations=require(_0x54e02a('0x3e'));function respondWithResult(_0x1fd22b,_0x555441){return _0x555441=_0x555441||0xc8,function(_0x1c95ba){const _0x4aecae=a307_0x3f6b;if(_0x1c95ba)return _0x1fd22b[_0x4aecae('0x5e')](_0x555441)['json'](_0x1c95ba);};}function respondWithFilteredResult(_0x5e1475,_0x3d8cad){return function(_0x5dd5b9){const _0xdaefaf=a307_0x3f6b;if(_0x5dd5b9){const _0x3e9d9b=_0x5dd5b9[_0xdaefaf('0x29')],_0x6acb0e=_0x3d8cad[_0xdaefaf('0x20')];let _0x1ecb9c=_0x3d8cad[_0xdaefaf('0x20')]+_0x3d8cad[_0xdaefaf('0x5c')],_0x17ef32;return _0x1ecb9c>=_0x3e9d9b?(_0x1ecb9c=_0x3e9d9b,_0x17ef32=0xc8):_0x17ef32=0xce,_0x5e1475[_0xdaefaf('0x5e')](_0x17ef32),_0x5e1475[_0xdaefaf('0x11')]('Content-Range',_0x6acb0e+'-'+_0x1ecb9c+'/'+_0x3e9d9b)[_0xdaefaf('0x4f')](_0x5dd5b9);}return null;};}function saveUpdates(_0x105c19){return function(_0x390944){const _0x4a3894=a307_0x3f6b;if(_0x390944)return _0x390944[_0x4a3894('0x58')](_0x105c19)[_0x4a3894('0x12')](function(_0x2ccd8d){return _0x2ccd8d;});return null;};}function removeEntity(_0xa63fa8){return function(_0x505452){const _0x4965fc=a307_0x3f6b;if(_0x505452)return _0x505452[_0x4965fc('0x1b')]()[_0x4965fc('0x12')](function(){const _0x24b3a1=_0x4965fc;_0xa63fa8[_0x24b3a1('0x5e')](0xcc)['end']();});};}function handleEntityNotFound(_0x505db0){return function(_0x3c12cd){return!_0x3c12cd&&_0x505db0['sendStatus'](0x194),_0x3c12cd;};}function handleError(_0x3c69dd,_0x2c6202){return _0x2c6202=_0x2c6202||0x1f4,function(_0x44a067){const _0x3be1c6=a307_0x3f6b;logger[_0x3be1c6('0x48')](_0x44a067[_0x3be1c6('0x23')]),_0x44a067[_0x3be1c6('0x46')]&&delete _0x44a067['name'],_0x3c69dd['status'](_0x2c6202)[_0x3be1c6('0x55')](_0x44a067);};}exports[_0x54e02a('0x2')]=function(_0x56b7ff,_0x213b09){const _0x54e920=_0x54e02a;let _0x3a879c={};const _0x3d1622={},_0x1b1908={'count':0x0,'rows':[]},_0x2e7350=_[_0x54e920('0x40')](db[_0x54e920('0x8')]['rawAttributes'],function(_0x1ef5a0){const _0x5dada5=_0x54e920;return{'name':_0x1ef5a0[_0x5dada5('0x50')],'type':_0x1ef5a0['type']['key']};});_0x3d1622[_0x54e920('0x16')]=_[_0x54e920('0x40')](_0x2e7350,_0x54e920('0x46')),_0x3d1622[_0x54e920('0x3')]=_[_0x54e920('0x3b')](_0x56b7ff['query']),_0x3d1622['filters']=_[_0x54e920('0x1c')](_0x3d1622[_0x54e920('0x16')],_0x3d1622['query']),_0x3a879c[_0x54e920('0x2e')]=_[_0x54e920('0x1c')](_0x3d1622[_0x54e920('0x16')],qs[_0x54e920('0x37')](_0x56b7ff['query'][_0x54e920('0x37')])),_0x3a879c[_0x54e920('0x2e')]=_0x3a879c[_0x54e920('0x2e')]['length']?_0x3a879c[_0x54e920('0x2e')]:_0x3d1622['model'];typeof _0x56b7ff['query'][_0x54e920('0x47')]===_0x54e920('0x1f')&&(_0x3a879c[_0x54e920('0x5c')]=qs[_0x54e920('0x5c')](_0x56b7ff[_0x54e920('0x3')][_0x54e920('0x5c')]),_0x3a879c['offset']=qs[_0x54e920('0x20')](_0x56b7ff[_0x54e920('0x3')][_0x54e920('0x20')]));_0x3a879c[_0x54e920('0x56')]=qs[_0x54e920('0x3a')](_0x56b7ff['query']['sort']),_0x3a879c[_0x54e920('0x7')]=qs[_0x54e920('0x1d')](_['pick'](_0x56b7ff['query'],_0x3d1622['filters']),_0x2e7350);_0x56b7ff[_0x54e920('0x3')][_0x54e920('0x5d')]&&(_0x3a879c[_0x54e920('0x7')]=_['merge'](_0x3a879c[_0x54e920('0x7')],{[Op['or']]:_[_0x54e920('0x40')](_0x2e7350,function(_0x153602){const _0xcba449=_0x54e920;if(_0x153602[_0xcba449('0x45')]!==_0xcba449('0x49')){const _0x40172d={};return _0x40172d[_0x153602[_0xcba449('0x46')]]={[Op[_0xcba449('0x35')]]:'%'+_0x56b7ff[_0xcba449('0x3')]['filter']+'%'},_0x40172d;}})}));_0x3a879c=_[_0x54e920('0x10')]({},_0x3a879c,_0x56b7ff[_0x54e920('0xb')]);const _0x29916={'where':_0x3a879c['where']};return db[_0x54e920('0x8')][_0x54e920('0x29')](_0x29916)[_0x54e920('0x12')](function(_0x49ba1d){const _0x14f777=_0x54e920;return _0x1b1908[_0x14f777('0x29')]=_0x49ba1d,_0x56b7ff[_0x14f777('0x3')][_0x14f777('0x26')]&&(_0x3a879c[_0x14f777('0x5a')]=[{'all':!![]}]),db[_0x14f777('0x8')][_0x14f777('0x59')](_0x3a879c);})[_0x54e920('0x12')](function(_0x9039c6){const _0x5a872f=_0x54e920;return _0x1b1908[_0x5a872f('0x33')]=_0x9039c6,_0x1b1908;})[_0x54e920('0x12')](respondWithFilteredResult(_0x213b09,_0x3a879c))[_0x54e920('0x2d')](handleError(_0x213b09,null));},exports[_0x54e02a('0x43')]=function(_0x9b4228,_0x3211bf){const _0x18667=_0x54e02a;let _0x2b6fb={'raw':![],'where':{'id':_0x9b4228[_0x18667('0x52')]['id']}};const _0x4c7298={};return _0x4c7298[_0x18667('0x16')]=_[_0x18667('0x3b')](db[_0x18667('0x8')][_0x18667('0x14')]),_0x4c7298['query']=_[_0x18667('0x3b')](_0x9b4228[_0x18667('0x3')]),_0x4c7298['filters']=_[_0x18667('0x1c')](_0x4c7298['model'],_0x4c7298['query']),_0x2b6fb[_0x18667('0x2e')]=_['intersection'](_0x4c7298[_0x18667('0x16')],qs[_0x18667('0x37')](_0x9b4228[_0x18667('0x3')][_0x18667('0x37')])),_0x2b6fb[_0x18667('0x2e')]=_0x2b6fb[_0x18667('0x2e')][_0x18667('0x2c')]?_0x2b6fb[_0x18667('0x2e')]:_0x4c7298['model'],_0x9b4228[_0x18667('0x3')][_0x18667('0x26')]&&(_0x2b6fb[_0x18667('0x5a')]=[{'all':!![]}]),_0x2b6fb=_[_0x18667('0x10')]({},_0x2b6fb,_0x9b4228[_0x18667('0xb')]),db[_0x18667('0x8')]['findOne'](_0x2b6fb)[_0x18667('0x12')](handleEntityNotFound(_0x3211bf,null))['then'](respondWithResult(_0x3211bf,null))[_0x18667('0x2d')](handleError(_0x3211bf,null));},exports[_0x54e02a('0x54')]=function(_0x58c0f0,_0x17f9e8){const _0x2ba134=_0x54e02a;return db[_0x2ba134('0x8')]['create'](_0x58c0f0['body'],{})[_0x2ba134('0x12')](respondWithResult(_0x17f9e8,0xc9))[_0x2ba134('0x2d')](handleError(_0x17f9e8,null));},exports['update']=function(_0x28d213,_0x210bcb){const _0x57e1b6=_0x54e02a;return _0x28d213[_0x57e1b6('0x13')]['id']&&delete _0x28d213['body']['id'],db[_0x57e1b6('0x8')][_0x57e1b6('0x4d')]({'where':{'id':_0x28d213[_0x57e1b6('0x52')]['id']}})['then'](handleEntityNotFound(_0x210bcb,null))[_0x57e1b6('0x12')](saveUpdates(_0x28d213[_0x57e1b6('0x13')],null))['then'](respondWithResult(_0x210bcb,null))[_0x57e1b6('0x2d')](handleError(_0x210bcb,null));},exports[_0x54e02a('0x1b')]=function(_0x5ec793,_0x8c5082){const _0x1bcb1f=_0x54e02a;return db[_0x1bcb1f('0x8')]['findOne']({'where':{'id':_0x5ec793[_0x1bcb1f('0x52')]['id']}})[_0x1bcb1f('0x12')](handleEntityNotFound(_0x8c5082,null))[_0x1bcb1f('0x12')](removeEntity(_0x8c5082,null))[_0x1bcb1f('0x2d')](handleError(_0x8c5082,null));},exports['getConfigurations']=function(_0x3133d1,_0x51a4f8){const _0x340a38=_0x54e02a;let _0x452cd2={};const _0x4da3a2={};let _0x2ff777,_0x4f67e1;return db[_0x340a38('0x8')][_0x340a38('0x4d')]({'where':{'id':_0x3133d1[_0x340a38('0x52')]['id']}})['then'](handleEntityNotFound(_0x51a4f8,null))[_0x340a38('0x12')](function(_0x2be072){const _0x54e2e9=_0x340a38;if(_0x2be072)return _0x2ff777=_0x2be072,_0x4da3a2[_0x54e2e9('0x16')]=_['keys'](db[_0x54e2e9('0x2a')][_0x54e2e9('0x14')]),_0x4da3a2['query']=_['keys'](_0x3133d1[_0x54e2e9('0x3')]),_0x4da3a2[_0x54e2e9('0x1d')]=_['intersection'](_0x4da3a2[_0x54e2e9('0x16')],_0x4da3a2[_0x54e2e9('0x3')]),_0x452cd2[_0x54e2e9('0x2e')]=_['intersection'](_0x4da3a2[_0x54e2e9('0x16')],qs['fields'](_0x3133d1[_0x54e2e9('0x3')]['fields'])),_0x452cd2[_0x54e2e9('0x2e')]=_0x452cd2[_0x54e2e9('0x2e')][_0x54e2e9('0x2c')]?_0x452cd2['attributes']:_0x4da3a2[_0x54e2e9('0x16')],_0x452cd2[_0x54e2e9('0x56')]=qs[_0x54e2e9('0x3a')](_0x3133d1['query']['sort']),_0x452cd2[_0x54e2e9('0x7')]=qs[_0x54e2e9('0x1d')](_[_0x54e2e9('0x3d')](_0x3133d1[_0x54e2e9('0x3')],_0x4da3a2[_0x54e2e9('0x1d')])),_0x3133d1['query'][_0x54e2e9('0x5d')]&&(_0x452cd2[_0x54e2e9('0x7')]=_[_0x54e2e9('0x10')](_0x452cd2[_0x54e2e9('0x7')],{[Op['or']]:_[_0x54e2e9('0x40')](_0x452cd2[_0x54e2e9('0x2e')],function(_0x480f57){const _0x11826b=_0x54e2e9,_0x195a8a={};return _0x195a8a[_0x480f57]={[Op[_0x11826b('0x35')]]:'%'+_0x3133d1[_0x11826b('0x3')][_0x11826b('0x5d')]+'%'},_0x195a8a;})})),_0x452cd2=_[_0x54e2e9('0x10')]({},_0x452cd2,_0x3133d1[_0x54e2e9('0xb')]),_0x2ff777[_0x54e2e9('0x19')](_0x452cd2);})[_0x340a38('0x12')](function(_0x3b1998){const _0x3f7852=_0x340a38;if(_0x3b1998)return _0x4f67e1=_0x3b1998[_0x3f7852('0x2c')],typeof _0x3133d1[_0x3f7852('0x3')]['nolimit']==='undefined'&&(_0x452cd2[_0x3f7852('0x5c')]=qs[_0x3f7852('0x5c')](_0x3133d1['query'][_0x3f7852('0x5c')]),_0x452cd2[_0x3f7852('0x20')]=qs[_0x3f7852('0x20')](_0x3133d1['query'][_0x3f7852('0x20')])),_0x2ff777['getConfigurations'](_0x452cd2);})[_0x340a38('0x12')](function(_0x5a96bf){if(_0x5a96bf)return _0x5a96bf?{'count':_0x4f67e1,'rows':_0x5a96bf}:null;})[_0x340a38('0x12')](respondWithResult(_0x51a4f8,null))['catch'](handleError(_0x51a4f8,null));},exports['addConfiguration']=function(_0x11c132,_0x24ade1){const _0x49e691=_0x54e02a;return _0x11c132['body']['id']&&delete _0x11c132['body']['id'],db['SugarcrmAccount'][_0x49e691('0x4d')]({'where':{'id':_0x11c132[_0x49e691('0x52')]['id']}})['then'](handleEntityNotFound(_0x24ade1,null))['then'](function(_0x1b898a){const _0x526774=_0x49e691;if(_0x1b898a)return _0x11c132[_0x526774('0x13')][_0x526774('0x27')]=_0x1b898a['id'],_0x11c132[_0x526774('0x13')][_0x526774('0xd')]=integrations[_0x526774('0x44')](_0x11c132['body'][_0x526774('0x4c')],_0x11c132[_0x526774('0x13')][_0x526774('0x45')]),_0x11c132[_0x526774('0x13')][_0x526774('0x30')]=integrations[_0x526774('0x36')](_0x11c132[_0x526774('0x13')][_0x526774('0x4c')],_0x11c132[_0x526774('0x13')][_0x526774('0x45')]),db[_0x526774('0x2a')]['create'](_0x11c132['body'],{'include':[{'model':db['SugarcrmField'],'as':_0x526774('0xd')},{'model':db[_0x526774('0x4')],'as':_0x526774('0x30')}]});return null;})[_0x49e691('0x12')](respondWithResult(_0x24ade1,null))[_0x49e691('0x2d')](handleError(_0x24ade1,null));},exports[_0x54e02a('0xe')]=function(_0x5b0d1e,_0x4071bb){const _0x1871ec=_0x54e02a;let _0xe8e5fa='';const _0x1e1e7c=['id',_0x1871ec('0x46'),'assigned_user_id',_0x1871ec('0x17'),_0x1871ec('0x4a'),'date_start',_0x1871ec('0x18'),'duration_minutes','parent_id',_0x1871ec('0x42'),_0x1871ec('0x0'),_0x1871ec('0x57')];return db[_0x1871ec('0x8')][_0x1871ec('0x4d')]({'where':{'id':_0x5b0d1e[_0x1871ec('0x52')]['id']},'attributes':['id',_0x1871ec('0x28'),_0x1871ec('0x51'),'remoteUri']})['then'](handleEntityNotFound(_0x4071bb,null))[_0x1871ec('0x12')](function(_0x4a5c24){const _0xcca72e=_0x1871ec;if(_0x4a5c24){_0xe8e5fa=_0x4a5c24[_0xcca72e('0x15')];const _0x202ee5=_0xe8e5fa[_0xcca72e('0x31')](-0x1);return _0x202ee5==='/'&&(_0xe8e5fa=_0xe8e5fa[_0xcca72e('0x21')](0x0,_0xe8e5fa[_0xcca72e('0x1a')](_0x202ee5))),rp({'method':'POST','uri':util[_0xcca72e('0x25')](_0xcca72e('0x32'),_0xe8e5fa,_0xcca72e('0x22')),'json':!![],'form':{'method':_0xcca72e('0x38'),'input_type':_0xcca72e('0x3c'),'response_type':_0xcca72e('0x3c'),'rest_data':JSON[_0xcca72e('0x41')]({'user_auth':{'user_name':_0x4a5c24[_0xcca72e('0x28')],'password':_0x4a5c24['password'],'encryption':_0xcca72e('0x3f')},'application':'xCALLY\x20Motion\x20Integration'})}});}})[_0x1871ec('0x12')](function(_0x3dc4f0){const _0x4f7031=_0x1871ec;if(_0x3dc4f0&&_0x3dc4f0[_0x4f7031('0x46')]!=='Invalid\x20Login'&&_0x3dc4f0[_0x4f7031('0x46')]!==_0x4f7031('0x34'))return rp({'method':_0x4f7031('0x53'),'uri':util[_0x4f7031('0x25')](_0x4f7031('0x32'),_0xe8e5fa,_0x4f7031('0x22')),'json':!![],'form':{'method':_0x4f7031('0x6'),'input_type':_0x4f7031('0x3c'),'response_type':_0x4f7031('0x3c'),'rest_data':JSON[_0x4f7031('0x41')]({'session':_0x3dc4f0['id'],'module_name':_0x4f7031('0x9')})}})[_0x4f7031('0x12')](function(_0x589c1f){const _0x456d61=_0x4f7031;if(_0x589c1f){const _0x2dafcd=_[_0x456d61('0x4b')](_0x589c1f['module_fields']);return _[_0x456d61('0x2f')](_0x2dafcd,function(_0x80c061){const _0x21272b=_0x456d61;return _0x1e1e7c[_0x21272b('0x2b')](_0x80c061[_0x21272b('0x46')]);}),{'count':_0x2dafcd['length'],'rows':_[_0x456d61('0x40')](_0x2dafcd,function(_0x236749){const _0x34c944=_0x456d61;return{'id':_0x236749[_0x34c944('0x46')],'name':_0x236749['label'],'custom':_[_0x34c944('0xc')](_0x236749[_0x34c944('0x46')],'_c')?!![]:![],'options':_0x236749['options']?_[_0x34c944('0x40')](_['values'](_0x236749[_0x34c944('0xb')]),function(_0x44cdf0){const _0x58f892=_0x34c944;return{'name':_0x44cdf0['value'],'value':_0x44cdf0[_0x58f892('0x46')]};}):[]};})};}})[_0x4f7031('0x12')](respondWithResult(_0x4071bb,null))[_0x4f7031('0x2d')](function(_0x122a60){const _0x26fb0f=_0x4f7031;let _0x517088=_0x5b0d1e[_0x26fb0f('0x3')][_0x26fb0f('0x5b')]?0x1f4:_0x122a60[_0x26fb0f('0xa')]||0x1f4;logger['error'](_0x26fb0f('0x4e'),_0x26fb0f('0xe'),_0x517088,JSON[_0x26fb0f('0x41')](_0x122a60)),delete _0x122a60[_0x26fb0f('0x46')],_0x517088===0x191&&(_0x517088=0x190),_0x4071bb['status'](_0x517088)[_0x26fb0f('0x55')](_0x5b0d1e['query'][_0x26fb0f('0x5b')]?{'message':'Wrong\x20credentials','statusCode':_0x122a60[_0x26fb0f('0xa')]}:_0x122a60);});else{const _0x17b14f=0x1f4;_0x4071bb[_0x4f7031('0x5e')](_0x17b14f)[_0x4f7031('0x55')]({'message':'Wrong\x20credentials','statusCode':0x190});}});};