Built motion from commit a9fb64cc6defd8fb3a5cc199221f878e91c0e969. Version 3.0.0...
[motion-next.git] / server / api / intFreshdeskAccount / intFreshdeskAccount.controller.js
1 const a255_0x42d0=['FreshdeskConfiguration','label','query','Basic\x20%s','FreshdeskAccount','keys','filter','count','findAll','format','../../mysqldb','undefined','fieldName','agent','order','Subjects','create','apiKey','catch','params','default','base64','addConfiguration','map','api/v2/ticket_fields','pick','index','where','AccountId','FreshdeskField','slice','description','sequelize','stringify','nolimit','send','merge','test','like','include','getFields','key','end','json','Descriptions','priority','then','from','%s:X','status','attributes','subject','source','filters','options','VIRTUAL','requester','limit','set','fields','choices','GET','channel','lastIndexOf','findOne','getFields,\x20%s,\x20%s,\x20%s','includes','error','api','intersection','offset','model','show','sendStatus','update','name','body','includeAll','sort','destroy','getDescriptions','group','statusCode','rows','type','stack','rawAttributes','getConfigurations','length','remoteUri'];(function(_0x30f94d,_0x42d040){const _0x19ff89=function(_0x5afbc1){while(--_0x5afbc1){_0x30f94d['push'](_0x30f94d['shift']());}};_0x19ff89(++_0x42d040);}(a255_0x42d0,0x140));const a255_0x19ff=function(_0x30f94d,_0x42d040){_0x30f94d=_0x30f94d-0x0;let _0x19ff89=a255_0x42d0[_0x30f94d];return _0x19ff89;};const _0x1c8506=a255_0x19ff;'use strict';const rp=require('request-promise-native'),util=require('util'),_=require('lodash'),qs=require('../../components/parsers/qs'),logger=require('../../config/logger')(_0x1c8506('0x12')),db=require(_0x1c8506('0x32'))['db'],{Op}=require(_0x1c8506('0x48')),integrations=require('../../components/integrations/configuration');function respondWithResult(_0x5afbc1,_0x1e8512){return _0x1e8512=_0x1e8512||0xc8,function(_0x5b0e05){const _0x144146=a255_0x19ff;if(_0x5b0e05)return _0x5afbc1[_0x144146('0x59')](_0x1e8512)[_0x144146('0x53')](_0x5b0e05);};}function respondWithFilteredResult(_0x115cef,_0x345425){return function(_0x2cb088){const _0x585348=a255_0x19ff;if(_0x2cb088){const _0x1299d1=_0x2cb088[_0x585348('0x2f')],_0x2b665b=_0x345425[_0x585348('0x14')];let _0x1a99fe=_0x345425[_0x585348('0x14')]+_0x345425[_0x585348('0x7')],_0x3bc4c5;return _0x1a99fe>=_0x1299d1?(_0x1a99fe=_0x1299d1,_0x3bc4c5=0xc8):_0x3bc4c5=0xce,_0x115cef[_0x585348('0x59')](_0x3bc4c5),_0x115cef[_0x585348('0x8')]('Content-Range',_0x2b665b+'-'+_0x1a99fe+'/'+_0x1299d1)['json'](_0x2cb088);}return null;};}function saveUpdates(_0x18da8b){return function(_0x27bfdc){const _0x42cc14=a255_0x19ff;if(_0x27bfdc)return _0x27bfdc[_0x42cc14('0x18')](_0x18da8b)['then'](function(_0x57f9cc){return _0x57f9cc;});return null;};}function removeEntity(_0x5e417f){return function(_0x17f760){if(_0x17f760)return _0x17f760['destroy']()['then'](function(){const _0x1dc465=a255_0x19ff;_0x5e417f[_0x1dc465('0x59')](0xcc)[_0x1dc465('0x52')]();});};}function handleEntityNotFound(_0x522528){return function(_0x4e8f26){const _0x5f1d6f=a255_0x19ff;return!_0x4e8f26&&_0x522528[_0x5f1d6f('0x17')](0x194),_0x4e8f26;};}function handleError(_0x325b3a,_0x56b331){return _0x56b331=_0x56b331||0x1f4,function(_0x46590e){const _0xd83462=a255_0x19ff;logger[_0xd83462('0x11')](_0x46590e[_0xd83462('0x23')]),_0x46590e[_0xd83462('0x19')]&&delete _0x46590e[_0xd83462('0x19')],_0x325b3a[_0xd83462('0x59')](_0x56b331)[_0xd83462('0x4b')](_0x46590e);};}exports[_0x1c8506('0x42')]=function(_0x47d6ad,_0x13ce16){const _0x521bc4=_0x1c8506;let _0x42f7ed={};const _0x5a0142={},_0x2ea2e9={'count':0x0,'rows':[]},_0x39235e=_[_0x521bc4('0x3f')](db['FreshdeskAccount'][_0x521bc4('0x24')],function(_0x6c4181){const _0x2bf7eb=_0x521bc4;return{'name':_0x6c4181[_0x2bf7eb('0x34')],'type':_0x6c4181[_0x2bf7eb('0x22')][_0x2bf7eb('0x51')]};});_0x5a0142[_0x521bc4('0x15')]=_[_0x521bc4('0x3f')](_0x39235e,_0x521bc4('0x19')),_0x5a0142[_0x521bc4('0x2a')]=_[_0x521bc4('0x2d')](_0x47d6ad['query']),_0x5a0142[_0x521bc4('0x3')]=_[_0x521bc4('0x13')](_0x5a0142[_0x521bc4('0x15')],_0x5a0142[_0x521bc4('0x2a')]),_0x42f7ed[_0x521bc4('0x0')]=_[_0x521bc4('0x13')](_0x5a0142[_0x521bc4('0x15')],qs[_0x521bc4('0x9')](_0x47d6ad[_0x521bc4('0x2a')][_0x521bc4('0x9')])),_0x42f7ed[_0x521bc4('0x0')]=_0x42f7ed[_0x521bc4('0x0')][_0x521bc4('0x26')]?_0x42f7ed[_0x521bc4('0x0')]:_0x5a0142[_0x521bc4('0x15')];typeof _0x47d6ad[_0x521bc4('0x2a')]['nolimit']===_0x521bc4('0x33')&&(_0x42f7ed['limit']=qs['limit'](_0x47d6ad[_0x521bc4('0x2a')][_0x521bc4('0x7')]),_0x42f7ed[_0x521bc4('0x14')]=qs['offset'](_0x47d6ad[_0x521bc4('0x2a')][_0x521bc4('0x14')]));_0x42f7ed[_0x521bc4('0x36')]=qs['sort'](_0x47d6ad[_0x521bc4('0x2a')]['sort']),_0x42f7ed[_0x521bc4('0x43')]=qs[_0x521bc4('0x3')](_['pick'](_0x47d6ad[_0x521bc4('0x2a')],_0x5a0142[_0x521bc4('0x3')]),_0x39235e);_0x47d6ad[_0x521bc4('0x2a')][_0x521bc4('0x2e')]&&(_0x42f7ed[_0x521bc4('0x43')]=_[_0x521bc4('0x4c')](_0x42f7ed[_0x521bc4('0x43')],{[Op['or']]:_[_0x521bc4('0x3f')](_0x39235e,function(_0x56b35d){const _0x4c6fd8=_0x521bc4;if(_0x56b35d[_0x4c6fd8('0x22')]!==_0x4c6fd8('0x5')){const _0x484d14={};return _0x484d14[_0x56b35d[_0x4c6fd8('0x19')]]={[Op[_0x4c6fd8('0x4e')]]:'%'+_0x47d6ad[_0x4c6fd8('0x2a')][_0x4c6fd8('0x2e')]+'%'},_0x484d14;}})}));_0x42f7ed=_['merge']({},_0x42f7ed,_0x47d6ad['options']);const _0x4908be={'where':_0x42f7ed[_0x521bc4('0x43')]};return db[_0x521bc4('0x2c')]['count'](_0x4908be)[_0x521bc4('0x56')](function(_0x149137){const _0x2fff56=_0x521bc4;return _0x2ea2e9['count']=_0x149137,_0x47d6ad[_0x2fff56('0x2a')]['includeAll']&&(_0x42f7ed[_0x2fff56('0x4f')]=[{'all':!![]}]),db[_0x2fff56('0x2c')][_0x2fff56('0x30')](_0x42f7ed);})[_0x521bc4('0x56')](function(_0x55c78d){const _0x191b31=_0x521bc4;return _0x2ea2e9[_0x191b31('0x21')]=_0x55c78d,_0x2ea2e9;})['then'](respondWithFilteredResult(_0x13ce16,_0x42f7ed))[_0x521bc4('0x3a')](handleError(_0x13ce16,null));},exports[_0x1c8506('0x16')]=function(_0x1036d3,_0x2ce9a4){const _0x5ad494=_0x1c8506;let _0xc16309={'raw':![],'where':{'id':_0x1036d3[_0x5ad494('0x3b')]['id']}};const _0x2fa504={};return _0x2fa504[_0x5ad494('0x15')]=_[_0x5ad494('0x2d')](db[_0x5ad494('0x2c')][_0x5ad494('0x24')]),_0x2fa504[_0x5ad494('0x2a')]=_[_0x5ad494('0x2d')](_0x1036d3[_0x5ad494('0x2a')]),_0x2fa504['filters']=_[_0x5ad494('0x13')](_0x2fa504[_0x5ad494('0x15')],_0x2fa504[_0x5ad494('0x2a')]),_0xc16309['attributes']=_[_0x5ad494('0x13')](_0x2fa504[_0x5ad494('0x15')],qs[_0x5ad494('0x9')](_0x1036d3[_0x5ad494('0x2a')][_0x5ad494('0x9')])),_0xc16309[_0x5ad494('0x0')]=_0xc16309[_0x5ad494('0x0')][_0x5ad494('0x26')]?_0xc16309['attributes']:_0x2fa504[_0x5ad494('0x15')],_0x1036d3[_0x5ad494('0x2a')][_0x5ad494('0x1b')]&&(_0xc16309['include']=[{'all':!![]}]),_0xc16309=_[_0x5ad494('0x4c')]({},_0xc16309,_0x1036d3[_0x5ad494('0x4')]),db[_0x5ad494('0x2c')][_0x5ad494('0xe')](_0xc16309)[_0x5ad494('0x56')](handleEntityNotFound(_0x2ce9a4,null))[_0x5ad494('0x56')](respondWithResult(_0x2ce9a4,null))[_0x5ad494('0x3a')](handleError(_0x2ce9a4,null));},exports[_0x1c8506('0x38')]=function(_0x22c7c0,_0x21f151){const _0x41520c=_0x1c8506;return db['FreshdeskAccount'][_0x41520c('0x38')](_0x22c7c0['body'],{})['then'](respondWithResult(_0x21f151,0xc9))['catch'](handleError(_0x21f151,null));},exports[_0x1c8506('0x18')]=function(_0x1195ad,_0x545e88){const _0x54ab16=_0x1c8506;return _0x1195ad[_0x54ab16('0x1a')]['id']&&delete _0x1195ad[_0x54ab16('0x1a')]['id'],db[_0x54ab16('0x2c')][_0x54ab16('0xe')]({'where':{'id':_0x1195ad[_0x54ab16('0x3b')]['id']}})[_0x54ab16('0x56')](handleEntityNotFound(_0x545e88,null))[_0x54ab16('0x56')](saveUpdates(_0x1195ad[_0x54ab16('0x1a')],null))[_0x54ab16('0x56')](respondWithResult(_0x545e88,null))[_0x54ab16('0x3a')](handleError(_0x545e88,null));},exports[_0x1c8506('0x1d')]=function(_0x2622d6,_0x161953){const _0x196424=_0x1c8506;return db['FreshdeskAccount'][_0x196424('0xe')]({'where':{'id':_0x2622d6['params']['id']}})[_0x196424('0x56')](handleEntityNotFound(_0x161953,null))['then'](removeEntity(_0x161953,null))['catch'](handleError(_0x161953,null));},exports[_0x1c8506('0x25')]=function(_0x1b5849,_0x11f216){const _0x2d48b6=_0x1c8506;let _0x1dd602={};const _0x1b8ca2={};let _0x438691,_0x2ed2df;return db[_0x2d48b6('0x2c')][_0x2d48b6('0xe')]({'where':{'id':_0x1b5849[_0x2d48b6('0x3b')]['id']}})['then'](handleEntityNotFound(_0x11f216,null))[_0x2d48b6('0x56')](function(_0xb73230){const _0x4dc68f=_0x2d48b6;if(_0xb73230)return _0x438691=_0xb73230,_0x1b8ca2[_0x4dc68f('0x15')]=_[_0x4dc68f('0x2d')](db[_0x4dc68f('0x28')]['rawAttributes']),_0x1b8ca2['query']=_['keys'](_0x1b5849[_0x4dc68f('0x2a')]),_0x1b8ca2[_0x4dc68f('0x3')]=_[_0x4dc68f('0x13')](_0x1b8ca2['model'],_0x1b8ca2[_0x4dc68f('0x2a')]),_0x1dd602[_0x4dc68f('0x0')]=_[_0x4dc68f('0x13')](_0x1b8ca2[_0x4dc68f('0x15')],qs['fields'](_0x1b5849['query']['fields'])),_0x1dd602[_0x4dc68f('0x0')]=_0x1dd602[_0x4dc68f('0x0')][_0x4dc68f('0x26')]?_0x1dd602[_0x4dc68f('0x0')]:_0x1b8ca2[_0x4dc68f('0x15')],_0x1dd602[_0x4dc68f('0x36')]=qs[_0x4dc68f('0x1c')](_0x1b5849[_0x4dc68f('0x2a')][_0x4dc68f('0x1c')]),_0x1dd602['where']=qs[_0x4dc68f('0x3')](_[_0x4dc68f('0x41')](_0x1b5849[_0x4dc68f('0x2a')],_0x1b8ca2['filters'])),_0x1b5849[_0x4dc68f('0x2a')]['filter']&&(_0x1dd602['where']=_[_0x4dc68f('0x4c')](_0x1dd602[_0x4dc68f('0x43')],{[Op['or']]:_['map'](_0x1dd602[_0x4dc68f('0x0')],function(_0x4ac1e9){const _0x471083=_0x4dc68f,_0x42bf31={};return _0x42bf31[_0x4ac1e9]={[Op['like']]:'%'+_0x1b5849[_0x471083('0x2a')]['filter']+'%'},_0x42bf31;})})),_0x1dd602=_[_0x4dc68f('0x4c')]({},_0x1dd602,_0x1b5849['options']),_0x438691['getConfigurations'](_0x1dd602);})[_0x2d48b6('0x56')](function(_0x599ed1){const _0x263a54=_0x2d48b6;if(_0x599ed1)return _0x2ed2df=_0x599ed1[_0x263a54('0x26')],typeof _0x1b5849['query'][_0x263a54('0x4a')]===_0x263a54('0x33')&&(_0x1dd602[_0x263a54('0x7')]=qs[_0x263a54('0x7')](_0x1b5849[_0x263a54('0x2a')][_0x263a54('0x7')]),_0x1dd602[_0x263a54('0x14')]=qs[_0x263a54('0x14')](_0x1b5849[_0x263a54('0x2a')][_0x263a54('0x14')])),_0x438691['getConfigurations'](_0x1dd602);})[_0x2d48b6('0x56')](function(_0x418356){if(_0x418356)return _0x418356?{'count':_0x2ed2df,'rows':_0x418356}:null;})[_0x2d48b6('0x56')](respondWithResult(_0x11f216,null))[_0x2d48b6('0x3a')](handleError(_0x11f216,null));},exports[_0x1c8506('0x3e')]=function(_0x589509,_0x4fd00f){const _0x131406=_0x1c8506;return _0x589509[_0x131406('0x1a')]['id']&&delete _0x589509['body']['id'],db[_0x131406('0x2c')][_0x131406('0xe')]({'where':{'id':_0x589509['params']['id']}})['then'](handleEntityNotFound(_0x4fd00f,null))[_0x131406('0x56')](function(_0x14c58f){const _0x10994e=_0x131406;if(_0x14c58f)return _0x589509[_0x10994e('0x1a')][_0x10994e('0x44')]=_0x14c58f['id'],_0x589509[_0x10994e('0x1a')]['Subjects']=integrations['getSubjects'](_0x589509[_0x10994e('0x1a')]['channel'],_0x589509[_0x10994e('0x1a')][_0x10994e('0x22')]),_0x589509['body'][_0x10994e('0x54')]=integrations[_0x10994e('0x1e')](_0x589509['body'][_0x10994e('0xc')],_0x589509[_0x10994e('0x1a')][_0x10994e('0x22')]),db[_0x10994e('0x28')]['create'](_0x589509[_0x10994e('0x1a')],{'include':[{'model':db[_0x10994e('0x45')],'as':_0x10994e('0x37')},{'model':db['FreshdeskField'],'as':_0x10994e('0x54')}]});return null;})[_0x131406('0x56')](respondWithResult(_0x4fd00f,null))[_0x131406('0x3a')](handleError(_0x4fd00f,null));},exports['getFields']=function(_0x3c7426,_0x5139de){const _0x455abb=_0x1c8506;let _0x518550='';return db[_0x455abb('0x2c')][_0x455abb('0xe')]({'where':{'id':_0x3c7426[_0x455abb('0x3b')]['id']},'attributes':['id',_0x455abb('0x27'),_0x455abb('0x39')]})['then'](handleEntityNotFound(_0x5139de,null))[_0x455abb('0x56')](function(_0x4550f2){const _0x14455f=_0x455abb;if(_0x4550f2){_0x518550=_0x4550f2['remoteUri'];const _0xb0885e=_0x518550[_0x14455f('0x46')](-0x1);return _0xb0885e==='/'&&(_0x518550=_0x518550['substring'](0x0,_0x518550[_0x14455f('0xd')](_0xb0885e))),rp({'method':_0x14455f('0xb'),'uri':util[_0x14455f('0x31')]('%s/%s',_0x518550,_0x14455f('0x40')),'headers':{'Authorization':util[_0x14455f('0x31')](_0x14455f('0x2b'),Buffer[_0x14455f('0x57')](util[_0x14455f('0x31')](_0x14455f('0x58'),_0x4550f2['apiKey']))['toString'](_0x14455f('0x3d')))},'json':!![]});}})['then'](function(_0x4227ef){const _0x474458=_0x455abb;if(_0x4227ef){const _0x4dd95e=[_0x474458('0x6'),_0x474458('0x1'),_0x474458('0x35'),_0x474458('0x47'),'status',_0x474458('0x55'),_0x474458('0x1f'),_0x474458('0x2'),'ticket_type',_0x474458('0x1f'),'company'];return _['remove'](_0x4227ef,function(_0x5a1f27){const _0x2279b9=_0x474458;return _0x4dd95e[_0x2279b9('0x10')](_0x5a1f27[_0x2279b9('0x19')])||!_0x5a1f27[_0x2279b9('0x3c')]&&_0x5a1f27[_0x2279b9('0x22')]!=='custom_text'&&_0x5a1f27[_0x2279b9('0x22')]!=='custom_dropdown';}),{'count':_0x4227ef[_0x474458('0x26')],'rows':_['map'](_0x4227ef,function(_0x265b6b){const _0x3eb278=_0x474458;return{'id':_0x265b6b['name'],'name':_0x265b6b[_0x3eb278('0x29')],'custom':!_0x265b6b[_0x3eb278('0x3c')],'options':_0x265b6b['choices']?_[_0x3eb278('0x3f')](_0x265b6b[_0x3eb278('0xa')],function(_0x2edc1e){return{'name':_['capitalize'](_0x2edc1e),'value':_0x2edc1e};}):[]};})};}})['then'](respondWithResult(_0x5139de,null))[_0x455abb('0x3a')](function(_0x186b2d){const _0x582cfd=_0x455abb;let _0x575241=_0x3c7426[_0x582cfd('0x2a')][_0x582cfd('0x4d')]?0x1f4:_0x186b2d[_0x582cfd('0x20')]||0x1f4;logger[_0x582cfd('0x11')](_0x582cfd('0xf'),_0x582cfd('0x50'),_0x575241,JSON[_0x582cfd('0x49')](_0x186b2d)),delete _0x186b2d[_0x582cfd('0x19')],_0x575241===0x191&&(_0x575241=0x190),_0x5139de[_0x582cfd('0x59')](_0x575241)[_0x582cfd('0x4b')](_0x3c7426[_0x582cfd('0x2a')][_0x582cfd('0x4d')]?{'message':'Wrong\x20credentials','statusCode':_0x186b2d['statusCode']}:_0x186b2d);});};