ccda60380df87fee6b3edbe7e7e9ed24aaa861e7
[motion-next.git] / server / api / intFreshsalesAccount / intFreshsalesAccount.controller.js
1 const a268_0x1261=['getConfigurations','Descriptions','query','body','../../mysqldb','Token\x20token=','rows','../../components/parsers/qs','update','filters','util','keys','status','AccountId','VIRTUAL','../../config/logger','getFields,\x20%s,\x20%s,\x20%s','params','limit','remoteUri','like','then','channel','fieldName','%s%s','count','addConfiguration','lastIndexOf','show','findOne','includeAll','pick','Content-Range','users','offset','substring','Subjects','model','sendStatus','catch','fields','attributes','email','FreshsalesAccount','filter','map','Wrong\x20credentials','undefined','create','Requested\x20Resource\x20not\x20Found','error','stack','order','type','format','apiKey','getDescriptions','test','json','include','length','request-promise-native','key','rawAttributes','getFields','options','nolimit','sequelize','intersection','FreshsalesField','statusCode','where','FreshsalesConfiguration','name','username','merge','slice','stringify','sort'];(function(_0xdb2730,_0x1261dc){const _0x108d9d=function(_0x31d707){while(--_0x31d707){_0xdb2730['push'](_0xdb2730['shift']());}};_0x108d9d(++_0x1261dc);}(a268_0x1261,0x159));const a268_0x108d=function(_0xdb2730,_0x1261dc){_0xdb2730=_0xdb2730-0x0;let _0x108d9d=a268_0x1261[_0xdb2730];return _0x108d9d;};const _0x94871a=a268_0x108d;'use strict';const rp=require(_0x94871a('0x20')),util=require(_0x94871a('0x3c')),_=require('lodash'),qs=require(_0x94871a('0x39')),logger=require(_0x94871a('0x41'))('api'),db=require(_0x94871a('0x36'))['db'],{Op}=require(_0x94871a('0x26')),integrations=require('../../components/integrations/configuration');function respondWithResult(_0x31d707,_0x314ed0){return _0x314ed0=_0x314ed0||0xc8,function(_0x16dedd){const _0x184ed6=a268_0x108d;if(_0x16dedd)return _0x31d707[_0x184ed6('0x3e')](_0x314ed0)['json'](_0x16dedd);};}function respondWithFilteredResult(_0x304469,_0x3e74f8){return function(_0x31dce0){const _0x52246b=a268_0x108d;if(_0x31dce0){const _0x465a2d=_0x31dce0[_0x52246b('0x4b')],_0x193f4e=_0x3e74f8['offset'];let _0x3fe62c=_0x3e74f8[_0x52246b('0x5')]+_0x3e74f8[_0x52246b('0x44')],_0x36b791;return _0x3fe62c>=_0x465a2d?(_0x3fe62c=_0x465a2d,_0x36b791=0xc8):_0x36b791=0xce,_0x304469['status'](_0x36b791),_0x304469['set'](_0x52246b('0x3'),_0x193f4e+'-'+_0x3fe62c+'/'+_0x465a2d)[_0x52246b('0x1d')](_0x31dce0);}return null;};}function saveUpdates(_0x1e8764){return function(_0x222afc){const _0x45cae3=a268_0x108d;if(_0x222afc)return _0x222afc[_0x45cae3('0x3a')](_0x1e8764)[_0x45cae3('0x47')](function(_0x1819e5){return _0x1819e5;});return null;};}function removeEntity(_0x269952){return function(_0x2b2184){if(_0x2b2184)return _0x2b2184['destroy']()['then'](function(){const _0x2512aa=a268_0x108d;_0x269952[_0x2512aa('0x3e')](0xcc)['end']();});};}function handleEntityNotFound(_0x289c53){return function(_0xb71358){const _0x3dec5f=a268_0x108d;return!_0xb71358&&_0x289c53[_0x3dec5f('0x9')](0x194),_0xb71358;};}function handleError(_0x1e9248,_0x5865a4){return _0x5865a4=_0x5865a4||0x1f4,function(_0x66b2bf){const _0x3df140=a268_0x108d;logger[_0x3df140('0x15')](_0x66b2bf[_0x3df140('0x16')]),_0x66b2bf[_0x3df140('0x2c')]&&delete _0x66b2bf[_0x3df140('0x2c')],_0x1e9248[_0x3df140('0x3e')](_0x5865a4)['send'](_0x66b2bf);};}exports['index']=function(_0x3a26bc,_0xb25e41){const _0x1bf952=_0x94871a;let _0x478fc1={};const _0x1a0c64={},_0xd4d47f={'count':0x0,'rows':[]},_0x46bc8b=_[_0x1bf952('0x10')](db[_0x1bf952('0xe')][_0x1bf952('0x22')],function(_0x30d2a8){const _0x57665a=_0x1bf952;return{'name':_0x30d2a8[_0x57665a('0x49')],'type':_0x30d2a8['type'][_0x57665a('0x21')]};});_0x1a0c64[_0x1bf952('0x8')]=_[_0x1bf952('0x10')](_0x46bc8b,'name'),_0x1a0c64[_0x1bf952('0x34')]=_[_0x1bf952('0x3d')](_0x3a26bc['query']),_0x1a0c64[_0x1bf952('0x3b')]=_['intersection'](_0x1a0c64[_0x1bf952('0x8')],_0x1a0c64['query']),_0x478fc1[_0x1bf952('0xc')]=_[_0x1bf952('0x27')](_0x1a0c64[_0x1bf952('0x8')],qs[_0x1bf952('0xb')](_0x3a26bc[_0x1bf952('0x34')]['fields'])),_0x478fc1['attributes']=_0x478fc1['attributes'][_0x1bf952('0x1f')]?_0x478fc1['attributes']:_0x1a0c64[_0x1bf952('0x8')];typeof _0x3a26bc['query'][_0x1bf952('0x25')]===_0x1bf952('0x12')&&(_0x478fc1[_0x1bf952('0x44')]=qs[_0x1bf952('0x44')](_0x3a26bc[_0x1bf952('0x34')][_0x1bf952('0x44')]),_0x478fc1[_0x1bf952('0x5')]=qs[_0x1bf952('0x5')](_0x3a26bc[_0x1bf952('0x34')][_0x1bf952('0x5')]));_0x478fc1['order']=qs['sort'](_0x3a26bc['query'][_0x1bf952('0x31')]),_0x478fc1[_0x1bf952('0x2a')]=qs[_0x1bf952('0x3b')](_[_0x1bf952('0x2')](_0x3a26bc[_0x1bf952('0x34')],_0x1a0c64[_0x1bf952('0x3b')]),_0x46bc8b);_0x3a26bc['query'][_0x1bf952('0xf')]&&(_0x478fc1[_0x1bf952('0x2a')]=_[_0x1bf952('0x2e')](_0x478fc1[_0x1bf952('0x2a')],{[Op['or']]:_[_0x1bf952('0x10')](_0x46bc8b,function(_0x5c76e9){const _0x281d7c=_0x1bf952;if(_0x5c76e9['type']!==_0x281d7c('0x40')){const _0x42436f={};return _0x42436f[_0x5c76e9['name']]={[Op['like']]:'%'+_0x3a26bc[_0x281d7c('0x34')][_0x281d7c('0xf')]+'%'},_0x42436f;}})}));_0x478fc1=_['merge']({},_0x478fc1,_0x3a26bc[_0x1bf952('0x24')]);const _0x9cb7be={'where':_0x478fc1['where']};return db[_0x1bf952('0xe')][_0x1bf952('0x4b')](_0x9cb7be)['then'](function(_0x2fed3b){const _0x53e4a1=_0x1bf952;return _0xd4d47f[_0x53e4a1('0x4b')]=_0x2fed3b,_0x3a26bc[_0x53e4a1('0x34')][_0x53e4a1('0x1')]&&(_0x478fc1[_0x53e4a1('0x1e')]=[{'all':!![]}]),db[_0x53e4a1('0xe')]['findAll'](_0x478fc1);})[_0x1bf952('0x47')](function(_0x32ad79){const _0x2a711b=_0x1bf952;return _0xd4d47f[_0x2a711b('0x38')]=_0x32ad79,_0xd4d47f;})['then'](respondWithFilteredResult(_0xb25e41,_0x478fc1))[_0x1bf952('0xa')](handleError(_0xb25e41,null));},exports[_0x94871a('0x4e')]=function(_0x4013f4,_0x46a88a){const _0x2c0f8a=_0x94871a;let _0x120978={'raw':![],'where':{'id':_0x4013f4[_0x2c0f8a('0x43')]['id']}};const _0x4c2fc8={};return _0x4c2fc8[_0x2c0f8a('0x8')]=_[_0x2c0f8a('0x3d')](db[_0x2c0f8a('0xe')]['rawAttributes']),_0x4c2fc8['query']=_['keys'](_0x4013f4[_0x2c0f8a('0x34')]),_0x4c2fc8[_0x2c0f8a('0x3b')]=_[_0x2c0f8a('0x27')](_0x4c2fc8['model'],_0x4c2fc8[_0x2c0f8a('0x34')]),_0x120978[_0x2c0f8a('0xc')]=_[_0x2c0f8a('0x27')](_0x4c2fc8[_0x2c0f8a('0x8')],qs['fields'](_0x4013f4[_0x2c0f8a('0x34')][_0x2c0f8a('0xb')])),_0x120978[_0x2c0f8a('0xc')]=_0x120978['attributes']['length']?_0x120978[_0x2c0f8a('0xc')]:_0x4c2fc8['model'],_0x4013f4[_0x2c0f8a('0x34')][_0x2c0f8a('0x1')]&&(_0x120978['include']=[{'all':!![]}]),_0x120978=_[_0x2c0f8a('0x2e')]({},_0x120978,_0x4013f4[_0x2c0f8a('0x24')]),db[_0x2c0f8a('0xe')][_0x2c0f8a('0x0')](_0x120978)[_0x2c0f8a('0x47')](handleEntityNotFound(_0x46a88a,null))[_0x2c0f8a('0x47')](respondWithResult(_0x46a88a,null))[_0x2c0f8a('0xa')](handleError(_0x46a88a,null));},exports[_0x94871a('0x13')]=function(_0x39e49c,_0x59e56b){const _0x5e876a=_0x94871a;return db[_0x5e876a('0xe')]['create'](_0x39e49c[_0x5e876a('0x35')],{})['then'](respondWithResult(_0x59e56b,0xc9))[_0x5e876a('0xa')](handleError(_0x59e56b,null));},exports['update']=function(_0x343df3,_0x119f7f){const _0x3c793d=_0x94871a;return _0x343df3[_0x3c793d('0x35')]['id']&&delete _0x343df3[_0x3c793d('0x35')]['id'],db[_0x3c793d('0xe')][_0x3c793d('0x0')]({'where':{'id':_0x343df3[_0x3c793d('0x43')]['id']}})[_0x3c793d('0x47')](handleEntityNotFound(_0x119f7f,null))[_0x3c793d('0x47')](saveUpdates(_0x343df3[_0x3c793d('0x35')],null))[_0x3c793d('0x47')](respondWithResult(_0x119f7f,null))[_0x3c793d('0xa')](handleError(_0x119f7f,null));},exports['destroy']=function(_0xe024,_0x18d4b7){const _0x620bd1=_0x94871a;return db[_0x620bd1('0xe')][_0x620bd1('0x0')]({'where':{'id':_0xe024[_0x620bd1('0x43')]['id']}})[_0x620bd1('0x47')](handleEntityNotFound(_0x18d4b7,null))[_0x620bd1('0x47')](removeEntity(_0x18d4b7,null))['catch'](handleError(_0x18d4b7,null));},exports[_0x94871a('0x32')]=function(_0xc37c07,_0x18c818){const _0x4c7a9d=_0x94871a;let _0x5370c7={};const _0x28233c={};let _0x7f0e1c,_0x6e01f7;return db[_0x4c7a9d('0xe')][_0x4c7a9d('0x0')]({'where':{'id':_0xc37c07[_0x4c7a9d('0x43')]['id']}})[_0x4c7a9d('0x47')](handleEntityNotFound(_0x18c818,null))[_0x4c7a9d('0x47')](function(_0x2c15b0){const _0x7b9dea=_0x4c7a9d;if(_0x2c15b0)return _0x7f0e1c=_0x2c15b0,_0x28233c[_0x7b9dea('0x8')]=_[_0x7b9dea('0x3d')](db[_0x7b9dea('0x2b')][_0x7b9dea('0x22')]),_0x28233c[_0x7b9dea('0x34')]=_[_0x7b9dea('0x3d')](_0xc37c07[_0x7b9dea('0x34')]),_0x28233c[_0x7b9dea('0x3b')]=_[_0x7b9dea('0x27')](_0x28233c[_0x7b9dea('0x8')],_0x28233c[_0x7b9dea('0x34')]),_0x5370c7[_0x7b9dea('0xc')]=_[_0x7b9dea('0x27')](_0x28233c['model'],qs[_0x7b9dea('0xb')](_0xc37c07[_0x7b9dea('0x34')][_0x7b9dea('0xb')])),_0x5370c7[_0x7b9dea('0xc')]=_0x5370c7[_0x7b9dea('0xc')][_0x7b9dea('0x1f')]?_0x5370c7[_0x7b9dea('0xc')]:_0x28233c['model'],_0x5370c7[_0x7b9dea('0x17')]=qs[_0x7b9dea('0x31')](_0xc37c07[_0x7b9dea('0x34')][_0x7b9dea('0x31')]),_0x5370c7['where']=qs[_0x7b9dea('0x3b')](_[_0x7b9dea('0x2')](_0xc37c07[_0x7b9dea('0x34')],_0x28233c[_0x7b9dea('0x3b')])),_0xc37c07['query']['filter']&&(_0x5370c7[_0x7b9dea('0x2a')]=_[_0x7b9dea('0x2e')](_0x5370c7['where'],{[Op['or']]:_[_0x7b9dea('0x10')](_0x5370c7[_0x7b9dea('0xc')],function(_0x47cfee){const _0x2be757=_0x7b9dea,_0x43e4f3={};return _0x43e4f3[_0x47cfee]={[Op[_0x2be757('0x46')]]:'%'+_0xc37c07[_0x2be757('0x34')][_0x2be757('0xf')]+'%'},_0x43e4f3;})})),_0x5370c7=_[_0x7b9dea('0x2e')]({},_0x5370c7,_0xc37c07[_0x7b9dea('0x24')]),_0x7f0e1c[_0x7b9dea('0x32')](_0x5370c7);})[_0x4c7a9d('0x47')](function(_0xb7e5df){const _0x15dc6a=_0x4c7a9d;if(_0xb7e5df)return _0x6e01f7=_0xb7e5df[_0x15dc6a('0x1f')],typeof _0xc37c07[_0x15dc6a('0x34')]['nolimit']==='undefined'&&(_0x5370c7[_0x15dc6a('0x44')]=qs[_0x15dc6a('0x44')](_0xc37c07['query']['limit']),_0x5370c7[_0x15dc6a('0x5')]=qs['offset'](_0xc37c07[_0x15dc6a('0x34')][_0x15dc6a('0x5')])),_0x7f0e1c[_0x15dc6a('0x32')](_0x5370c7);})['then'](function(_0x2b1636){if(_0x2b1636)return _0x2b1636?{'count':_0x6e01f7,'rows':_0x2b1636}:null;})[_0x4c7a9d('0x47')](respondWithResult(_0x18c818,null))['catch'](handleError(_0x18c818,null));},exports[_0x94871a('0x4c')]=function(_0x1d1733,_0x5e39ae){const _0x555522=_0x94871a;return _0x1d1733[_0x555522('0x35')]['id']&&delete _0x1d1733['body']['id'],db[_0x555522('0xe')][_0x555522('0x0')]({'where':{'id':_0x1d1733[_0x555522('0x43')]['id']}})[_0x555522('0x47')](handleEntityNotFound(_0x5e39ae,null))[_0x555522('0x47')](function(_0x495e73){const _0xec51fe=_0x555522;if(_0x495e73)return _0x1d1733[_0xec51fe('0x35')][_0xec51fe('0x3f')]=_0x495e73['id'],_0x1d1733[_0xec51fe('0x35')][_0xec51fe('0x7')]=integrations['getSubjects'](_0x1d1733[_0xec51fe('0x35')][_0xec51fe('0x48')],_0x1d1733['body'][_0xec51fe('0x18')]),_0x1d1733[_0xec51fe('0x35')][_0xec51fe('0x33')]=integrations[_0xec51fe('0x1b')](_0x1d1733[_0xec51fe('0x35')][_0xec51fe('0x48')],_0x1d1733[_0xec51fe('0x35')][_0xec51fe('0x18')]),db[_0xec51fe('0x2b')]['create'](_0x1d1733[_0xec51fe('0x35')],{'include':[{'model':db[_0xec51fe('0x28')],'as':_0xec51fe('0x7')},{'model':db[_0xec51fe('0x28')],'as':_0xec51fe('0x33')}]});return null;})['then'](respondWithResult(_0x5e39ae,null))['catch'](handleError(_0x5e39ae,null));},exports[_0x94871a('0x23')]=function(_0xf0b353,_0x31ab5e){const _0x1f8621=_0x94871a;let _0x1ea4dd='',_0x2a3cd5='';return db[_0x1f8621('0xe')][_0x1f8621('0x0')]({'where':{'id':_0xf0b353['params']['id']},'attributes':['id',_0x1f8621('0x2d'),_0x1f8621('0x45'),_0x1f8621('0x1a')]})[_0x1f8621('0x47')](handleEntityNotFound(_0x31ab5e,null))[_0x1f8621('0x47')](function(_0x27b262){const _0x420cb5=_0x1f8621;if(_0x27b262){_0x2a3cd5=_0x27b262['username'],_0x1ea4dd=_0x27b262[_0x420cb5('0x45')];const _0x30a1b7=_0x27b262[_0x420cb5('0x45')][_0x420cb5('0x2f')](-0x1);return _0x30a1b7==='/'&&(_0x1ea4dd=_0x1ea4dd[_0x420cb5('0x6')](0x0,_0x1ea4dd[_0x420cb5('0x4d')](_0x30a1b7))),rp({'method':'GET','uri':util[_0x420cb5('0x19')](_0x420cb5('0x4a'),_0x1ea4dd,'/api/selector/owners'),'headers':{'Authorization':_0x420cb5('0x37')+_0x27b262[_0x420cb5('0x1a')]},'json':!![]});}})['then'](function(_0x362dc4){const _0x188dd2=_0x1f8621;if(_0x362dc4){const _0x53cdc5=_0x362dc4[_0x188dd2('0x4')];let _0x453c24=![],_0x39beea=null;for(_0x39beea=0x0;_0x39beea<_0x53cdc5['length'];_0x39beea++){_0x53cdc5[_0x39beea][_0x188dd2('0xd')]===_0x2a3cd5&&(_0x453c24=!![]);}if(_0x453c24)return!![];else throw new Error({'statusCode':0x194,'message':_0x188dd2('0x14')});}})['then'](respondWithResult(_0x31ab5e,null))[_0x1f8621('0xa')](function(_0x185367){const _0x1c7887=_0x1f8621;let _0x56b7cd=_0xf0b353[_0x1c7887('0x34')][_0x1c7887('0x1c')]?0x1f4:_0x185367[_0x1c7887('0x29')]||0x1f4;logger[_0x1c7887('0x15')](_0x1c7887('0x42'),'getFields',_0x56b7cd,JSON[_0x1c7887('0x30')](_0x185367)),delete _0x185367[_0x1c7887('0x2c')],_0x56b7cd===0x191&&(_0x56b7cd=0x190),_0x31ab5e[_0x1c7887('0x3e')](_0x56b7cd)['send'](_0xf0b353['query'][_0x1c7887('0x1c')]?{'message':_0x1c7887('0x11'),'statusCode':_0x185367[_0x1c7887('0x29')]}:_0x185367);});};