Built motion from commit b5996064.|2.6.21
[motion2.git] / server / api / intZendeskAccount / intZendeskAccount.controller.js
index e6bd8cf..244958d 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0x5eb8=['sort','where','filter','merge','type','options','includeAll','findAll','catch','show','params','keys','length','include','find','create','body','update','getConfigurations','findOne','ZendeskConfiguration','pick','addConfiguration','AccountId','Subjects','getSubjects','channel','getDescriptions','ZendeskField','getFields','username','password','token','authType','remoteUri','slice','substring','lastIndexOf','format','ticket_fields','headers','Basic\x20%s','%s:%s','toString','base64','Sequelize','ValidationError','Unknown\x20authentication\x20type','subject','description','group','remove','includes','title','position','system_field_options','custom_field_options','send','Wrong\x20credentials','statusCode','zip-dir','fast-json-patch','request-promise','moment','bluebird','mustache','util','path','sox','to-csv','ejs','fs-extra','squel','crypto','jsforce','papaparse','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','../../config/utils','../../config/environment','../../mysqldb','../../components/integrations/configuration','status','json','offset','undefined','limit','count','set','Content-Range','reject','save','destroy','then','sendStatus','error','stack','name','map','ZendeskAccount','rawAttributes','fieldName','key','model','query','filters','intersection','attributes','fields','hasOwnProperty','nolimit','order'];(function(_0x21de89,_0x367053){var _0x290b7e=function(_0x540704){while(--_0x540704){_0x21de89['push'](_0x21de89['shift']());}};_0x290b7e(++_0x367053);}(_0x5eb8,0xb0));var _0x85eb=function(_0x533e4e,_0x4eba54){_0x533e4e=_0x533e4e-0x0;var _0x1f14bb=_0x5eb8[_0x533e4e];return _0x1f14bb;};'use strict';var emlformat=require('eml-format');var rimraf=require('rimraf');var zipdir=require(_0x85eb('0x0'));var jsonpatch=require(_0x85eb('0x1'));var rp=require(_0x85eb('0x2'));var moment=require(_0x85eb('0x3'));var BPromise=require(_0x85eb('0x4'));var Mustache=require(_0x85eb('0x5'));var util=require(_0x85eb('0x6'));var path=require(_0x85eb('0x7'));var sox=require(_0x85eb('0x8'));var csv=require(_0x85eb('0x9'));var ejs=require(_0x85eb('0xa'));var fs=require('fs');var fs_extra=require(_0x85eb('0xb'));var _=require('lodash');var squel=require(_0x85eb('0xc'));var crypto=require(_0x85eb('0xd'));var jsforce=require(_0x85eb('0xe'));var deskjs=require('desk.js');var toCsv=require(_0x85eb('0x9'));var querystring=require('querystring');var Papa=require(_0x85eb('0xf'));var Redis=require(_0x85eb('0x10'));var authService=require(_0x85eb('0x11'));var qs=require(_0x85eb('0x12'));var as=require(_0x85eb('0x13'));var hardwareService=require(_0x85eb('0x14'));var logger=require(_0x85eb('0x15'))('api');var utils=require(_0x85eb('0x16'));var config=require(_0x85eb('0x17'));var licenseUtil=require('../../config/license/util');var db=require(_0x85eb('0x18'))['db'];var integrations=require(_0x85eb('0x19'));function respondWithStatusCode(_0x2f42ba,_0x259f72){_0x259f72=_0x259f72||0xcc;return function(_0x4db167){if(_0x4db167){return _0x2f42ba['sendStatus'](_0x259f72);}return _0x2f42ba[_0x85eb('0x1a')](_0x259f72)['end']();};}function respondWithResult(_0x18ca53,_0x23a82a){_0x23a82a=_0x23a82a||0xc8;return function(_0x600a7f){if(_0x600a7f){return _0x18ca53[_0x85eb('0x1a')](_0x23a82a)[_0x85eb('0x1b')](_0x600a7f);}};}function respondWithFilteredResult(_0x49efdf,_0x2e5c0a){return function(_0x59237b){if(_0x59237b){var _0x17140b=typeof _0x2e5c0a[_0x85eb('0x1c')]===_0x85eb('0x1d')&&typeof _0x2e5c0a[_0x85eb('0x1e')]==='undefined';var _0x5c5cbb=_0x59237b['count'];var _0xe198ca=_0x17140b?0x0:_0x2e5c0a[_0x85eb('0x1c')];var _0x10cf2f=_0x17140b?_0x59237b[_0x85eb('0x1f')]:_0x2e5c0a[_0x85eb('0x1c')]+_0x2e5c0a[_0x85eb('0x1e')];var _0x5acd3d;if(_0x10cf2f>=_0x5c5cbb){_0x10cf2f=_0x5c5cbb;_0x5acd3d=0xc8;}else{_0x5acd3d=0xce;}_0x49efdf[_0x85eb('0x1a')](_0x5acd3d);return _0x49efdf[_0x85eb('0x20')](_0x85eb('0x21'),_0xe198ca+'-'+_0x10cf2f+'/'+_0x5c5cbb)['json'](_0x59237b);}return null;};}function patchUpdates(_0x4b4b38){return function(_0x48bd86){try{jsonpatch['apply'](_0x48bd86,_0x4b4b38,!![]);}catch(_0x244667){return BPromise[_0x85eb('0x22')](_0x244667);}return _0x48bd86[_0x85eb('0x23')]();};}function saveUpdates(_0x255ca7,_0x465c74){return function(_0x3fc6da){if(_0x3fc6da){return _0x3fc6da['update'](_0x255ca7)['then'](function(_0x5b48d9){return _0x5b48d9;});}return null;};}function removeEntity(_0x298e84,_0x1426c8){return function(_0x3f7a4d){if(_0x3f7a4d){return _0x3f7a4d[_0x85eb('0x24')]()[_0x85eb('0x25')](function(){_0x298e84[_0x85eb('0x1a')](0xcc)['end']();});}};}function handleEntityNotFound(_0x39d3fe,_0x3453cd){return function(_0x4709ad){if(!_0x4709ad){_0x39d3fe[_0x85eb('0x26')](0x194);}return _0x4709ad;};}function handleError(_0x3e2326,_0x57a03c){_0x57a03c=_0x57a03c||0x1f4;return function(_0x2e5aa3){logger[_0x85eb('0x27')](_0x2e5aa3[_0x85eb('0x28')]);if(_0x2e5aa3[_0x85eb('0x29')]){delete _0x2e5aa3[_0x85eb('0x29')];}_0x3e2326[_0x85eb('0x1a')](_0x57a03c)['send'](_0x2e5aa3);};}exports['index']=function(_0x37515c,_0x585f2a){var _0xa9b14f={},_0x5255eb={},_0x4229e9={'count':0x0,'rows':[]};var _0x3570f7=_[_0x85eb('0x2a')](db[_0x85eb('0x2b')][_0x85eb('0x2c')],function(_0xf4ac13){return{'name':_0xf4ac13[_0x85eb('0x2d')],'type':_0xf4ac13['type'][_0x85eb('0x2e')]};});_0x5255eb[_0x85eb('0x2f')]=_['map'](_0x3570f7,_0x85eb('0x29'));_0x5255eb['query']=_['keys'](_0x37515c[_0x85eb('0x30')]);_0x5255eb[_0x85eb('0x31')]=_[_0x85eb('0x32')](_0x5255eb[_0x85eb('0x2f')],_0x5255eb[_0x85eb('0x30')]);_0xa9b14f[_0x85eb('0x33')]=_[_0x85eb('0x32')](_0x5255eb[_0x85eb('0x2f')],qs[_0x85eb('0x34')](_0x37515c[_0x85eb('0x30')]['fields']));_0xa9b14f[_0x85eb('0x33')]=_0xa9b14f[_0x85eb('0x33')]['length']?_0xa9b14f['attributes']:_0x5255eb[_0x85eb('0x2f')];if(!_0x37515c[_0x85eb('0x30')][_0x85eb('0x35')](_0x85eb('0x36'))){_0xa9b14f[_0x85eb('0x1e')]=qs[_0x85eb('0x1e')](_0x37515c[_0x85eb('0x30')][_0x85eb('0x1e')]);_0xa9b14f[_0x85eb('0x1c')]=qs[_0x85eb('0x1c')](_0x37515c[_0x85eb('0x30')][_0x85eb('0x1c')]);}_0xa9b14f[_0x85eb('0x37')]=qs[_0x85eb('0x38')](_0x37515c['query'][_0x85eb('0x38')]);_0xa9b14f[_0x85eb('0x39')]=qs['filters'](_['pick'](_0x37515c[_0x85eb('0x30')],_0x5255eb[_0x85eb('0x31')]),_0x3570f7);if(_0x37515c['query'][_0x85eb('0x3a')]){_0xa9b14f['where']=_[_0x85eb('0x3b')](_0xa9b14f['where'],{'$or':_[_0x85eb('0x2a')](_0x3570f7,function(_0x5ce7e4){if(_0x5ce7e4[_0x85eb('0x3c')]!=='VIRTUAL'){var _0x38ab0f={};_0x38ab0f[_0x5ce7e4[_0x85eb('0x29')]]={'$like':'%'+_0x37515c['query'][_0x85eb('0x3a')]+'%'};return _0x38ab0f;}})});}_0xa9b14f=_['merge']({},_0xa9b14f,_0x37515c[_0x85eb('0x3d')]);var _0x331260={'where':_0xa9b14f['where']};return db[_0x85eb('0x2b')]['count'](_0x331260)['then'](function(_0x1b8a71){_0x4229e9['count']=_0x1b8a71;if(_0x37515c[_0x85eb('0x30')][_0x85eb('0x3e')]){_0xa9b14f['include']=[{'all':!![]}];}return db['ZendeskAccount'][_0x85eb('0x3f')](_0xa9b14f);})[_0x85eb('0x25')](function(_0x48160e){_0x4229e9['rows']=_0x48160e;return _0x4229e9;})[_0x85eb('0x25')](respondWithFilteredResult(_0x585f2a,_0xa9b14f))[_0x85eb('0x40')](handleError(_0x585f2a,null));};exports[_0x85eb('0x41')]=function(_0x202681,_0x3be961){var _0x5b7411={'raw':![],'where':{'id':_0x202681[_0x85eb('0x42')]['id']}},_0x5ccf8a={};_0x5ccf8a[_0x85eb('0x2f')]=_[_0x85eb('0x43')](db[_0x85eb('0x2b')][_0x85eb('0x2c')]);_0x5ccf8a[_0x85eb('0x30')]=_[_0x85eb('0x43')](_0x202681[_0x85eb('0x30')]);_0x5ccf8a['filters']=_[_0x85eb('0x32')](_0x5ccf8a[_0x85eb('0x2f')],_0x5ccf8a['query']);_0x5b7411[_0x85eb('0x33')]=_[_0x85eb('0x32')](_0x5ccf8a[_0x85eb('0x2f')],qs[_0x85eb('0x34')](_0x202681[_0x85eb('0x30')][_0x85eb('0x34')]));_0x5b7411['attributes']=_0x5b7411[_0x85eb('0x33')][_0x85eb('0x44')]?_0x5b7411[_0x85eb('0x33')]:_0x5ccf8a[_0x85eb('0x2f')];if(_0x202681[_0x85eb('0x30')][_0x85eb('0x3e')]){_0x5b7411[_0x85eb('0x45')]=[{'all':!![]}];}_0x5b7411=_[_0x85eb('0x3b')]({},_0x5b7411,_0x202681['options']);return db[_0x85eb('0x2b')][_0x85eb('0x46')](_0x5b7411)[_0x85eb('0x25')](handleEntityNotFound(_0x3be961,null))[_0x85eb('0x25')](respondWithResult(_0x3be961,null))[_0x85eb('0x40')](handleError(_0x3be961,null));};exports[_0x85eb('0x47')]=function(_0x3c387a,_0x77fdc4){return db[_0x85eb('0x2b')][_0x85eb('0x47')](_0x3c387a[_0x85eb('0x48')],{})[_0x85eb('0x25')](respondWithResult(_0x77fdc4,0xc9))['catch'](handleError(_0x77fdc4,null));};exports[_0x85eb('0x49')]=function(_0x2c951b,_0x22d9d6){if(_0x2c951b['body']['id']){delete _0x2c951b[_0x85eb('0x48')]['id'];}return db[_0x85eb('0x2b')][_0x85eb('0x46')]({'where':{'id':_0x2c951b[_0x85eb('0x42')]['id']}})[_0x85eb('0x25')](handleEntityNotFound(_0x22d9d6,null))['then'](saveUpdates(_0x2c951b[_0x85eb('0x48')],null))[_0x85eb('0x25')](respondWithResult(_0x22d9d6,null))[_0x85eb('0x40')](handleError(_0x22d9d6,null));};exports['destroy']=function(_0xc5cb43,_0x4550fd){return db[_0x85eb('0x2b')]['find']({'where':{'id':_0xc5cb43['params']['id']}})[_0x85eb('0x25')](handleEntityNotFound(_0x4550fd,null))['then'](removeEntity(_0x4550fd,null))['catch'](handleError(_0x4550fd,null));};exports[_0x85eb('0x4a')]=function(_0x593723,_0x39316d,_0xfb0ac){var _0x4e3d96={};var _0x4abe5e={};var _0x27ce2a;var _0x249511;return db[_0x85eb('0x2b')][_0x85eb('0x4b')]({'where':{'id':_0x593723[_0x85eb('0x42')]['id']}})['then'](handleEntityNotFound(_0x39316d,null))[_0x85eb('0x25')](function(_0x30062e){if(_0x30062e){_0x27ce2a=_0x30062e;_0x4abe5e[_0x85eb('0x2f')]=_[_0x85eb('0x43')](db[_0x85eb('0x4c')]['rawAttributes']);_0x4abe5e[_0x85eb('0x30')]=_['keys'](_0x593723[_0x85eb('0x30')]);_0x4abe5e[_0x85eb('0x31')]=_['intersection'](_0x4abe5e[_0x85eb('0x2f')],_0x4abe5e[_0x85eb('0x30')]);_0x4e3d96[_0x85eb('0x33')]=_[_0x85eb('0x32')](_0x4abe5e[_0x85eb('0x2f')],qs[_0x85eb('0x34')](_0x593723['query'][_0x85eb('0x34')]));_0x4e3d96['attributes']=_0x4e3d96[_0x85eb('0x33')][_0x85eb('0x44')]?_0x4e3d96['attributes']:_0x4abe5e[_0x85eb('0x2f')];_0x4e3d96[_0x85eb('0x37')]=qs['sort'](_0x593723[_0x85eb('0x30')]['sort']);_0x4e3d96[_0x85eb('0x39')]=qs[_0x85eb('0x31')](_[_0x85eb('0x4d')](_0x593723[_0x85eb('0x30')],_0x4abe5e[_0x85eb('0x31')]));if(_0x593723[_0x85eb('0x30')]['filter']){_0x4e3d96[_0x85eb('0x39')]=_[_0x85eb('0x3b')](_0x4e3d96[_0x85eb('0x39')],{'$or':_[_0x85eb('0x2a')](_0x4e3d96[_0x85eb('0x33')],function(_0x1529dd){var _0x2024df={};_0x2024df[_0x1529dd]={'$like':'%'+_0x593723[_0x85eb('0x30')][_0x85eb('0x3a')]+'%'};return _0x2024df;})});}_0x4e3d96=_[_0x85eb('0x3b')]({},_0x4e3d96,_0x593723[_0x85eb('0x3d')]);return _0x27ce2a['getConfigurations'](_0x4e3d96);}})[_0x85eb('0x25')](function(_0x21b873){if(_0x21b873){_0x249511=_0x21b873[_0x85eb('0x44')];if(!_0x593723[_0x85eb('0x30')][_0x85eb('0x35')](_0x85eb('0x36'))){_0x4e3d96['limit']=qs[_0x85eb('0x1e')](_0x593723['query'][_0x85eb('0x1e')]);_0x4e3d96[_0x85eb('0x1c')]=qs[_0x85eb('0x1c')](_0x593723[_0x85eb('0x30')][_0x85eb('0x1c')]);}return _0x27ce2a['getConfigurations'](_0x4e3d96);}})[_0x85eb('0x25')](function(_0x143d65){if(_0x143d65){return _0x143d65?{'count':_0x249511,'rows':_0x143d65}:null;}})[_0x85eb('0x25')](respondWithResult(_0x39316d,null))[_0x85eb('0x40')](handleError(_0x39316d,null));};exports[_0x85eb('0x4e')]=function(_0x14cab8,_0x23fcf9,_0x5de716){if(_0x14cab8['body']['id']){delete _0x14cab8[_0x85eb('0x48')]['id'];}return db['ZendeskAccount'][_0x85eb('0x4b')]({'where':{'id':_0x14cab8[_0x85eb('0x42')]['id']}})[_0x85eb('0x25')](handleEntityNotFound(_0x23fcf9,null))[_0x85eb('0x25')](function(_0x259ee3){if(_0x259ee3){_0x14cab8['body'][_0x85eb('0x4f')]=_0x259ee3['id'];_0x14cab8[_0x85eb('0x48')][_0x85eb('0x50')]=integrations[_0x85eb('0x51')](_0x14cab8[_0x85eb('0x48')][_0x85eb('0x52')],_0x14cab8['body']['type']);_0x14cab8[_0x85eb('0x48')]['Descriptions']=integrations[_0x85eb('0x53')](_0x14cab8[_0x85eb('0x48')][_0x85eb('0x52')],_0x14cab8[_0x85eb('0x48')][_0x85eb('0x3c')]);return db[_0x85eb('0x4c')]['create'](_0x14cab8[_0x85eb('0x48')],{'include':[{'model':db[_0x85eb('0x54')],'as':_0x85eb('0x50')},{'model':db[_0x85eb('0x54')],'as':'Descriptions'}]});}return null;})[_0x85eb('0x25')](respondWithResult(_0x23fcf9,null))[_0x85eb('0x40')](handleError(_0x23fcf9,null));};exports[_0x85eb('0x55')]=function(_0x14bf0e,_0x5037c7,_0x459317){var _0x2e6734='';return db[_0x85eb('0x2b')][_0x85eb('0x4b')]({'where':{'id':_0x14bf0e[_0x85eb('0x42')]['id']},'attributes':['id',_0x85eb('0x56'),_0x85eb('0x57'),_0x85eb('0x58'),_0x85eb('0x59'),_0x85eb('0x5a')]})[_0x85eb('0x25')](handleEntityNotFound(_0x5037c7,null))[_0x85eb('0x25')](function(_0x1d9d3a){if(_0x1d9d3a){_0x2e6734=_0x1d9d3a[_0x85eb('0x5a')];var _0x2f2464=_0x2e6734[_0x85eb('0x5b')](-0x1);if(_0x2f2464==='/'){_0x2e6734=_0x2e6734[_0x85eb('0x5c')](0x0,_0x2e6734[_0x85eb('0x5d')](_0x2f2464));}var _0x106caa={'method':'GET','uri':util[_0x85eb('0x5e')]('%s/%s',_0x2e6734,_0x85eb('0x5f')),'json':!![]};switch(_0x1d9d3a[_0x85eb('0x59')]){case _0x85eb('0x57'):_0x106caa[_0x85eb('0x60')]={'Authorization':util[_0x85eb('0x5e')](_0x85eb('0x61'),new Buffer(util[_0x85eb('0x5e')](_0x85eb('0x62'),_0x1d9d3a[_0x85eb('0x56')],_0x1d9d3a['password']))[_0x85eb('0x63')](_0x85eb('0x64')))};break;case _0x85eb('0x58'):_0x106caa[_0x85eb('0x60')]={'Authorization':util[_0x85eb('0x5e')]('Basic\x20%s',new Buffer(util[_0x85eb('0x5e')]('%s/token:%s',_0x1d9d3a[_0x85eb('0x56')],_0x1d9d3a[_0x85eb('0x58')]))[_0x85eb('0x63')]('base64'))};break;default:throw new db[(_0x85eb('0x65'))][(_0x85eb('0x66'))](_0x85eb('0x67'));}return rp(_0x106caa);}})['then'](function(_0x588c72){if(_0x588c72){var _0x45a1ef=[_0x85eb('0x68'),_0x85eb('0x69'),_0x85eb('0x6a'),'assignee'];_[_0x85eb('0x6b')](_0x588c72['ticket_fields'],function(_0x11a3bd){return _0x45a1ef[_0x85eb('0x6c')](_0x11a3bd[_0x85eb('0x3c')]);});return{'count':_0x588c72[_0x85eb('0x5f')][_0x85eb('0x44')],'rows':_[_0x85eb('0x2a')](_0x588c72['ticket_fields'],function(_0x9a80a1){return{'id':_0x9a80a1['id'],'name':_0x9a80a1['position']>0x7?_0x9a80a1[_0x85eb('0x6d')]:_0x9a80a1[_0x85eb('0x3c')],'custom':_0x9a80a1[_0x85eb('0x6e')]>0x7?!![]:![],'options':_0x9a80a1[_0x85eb('0x6f')]?_0x9a80a1[_0x85eb('0x6f')]:_0x9a80a1[_0x85eb('0x70')]?_0x9a80a1[_0x85eb('0x70')]:[]};})};}})[_0x85eb('0x25')](respondWithResult(_0x5037c7,null))[_0x85eb('0x40')](function(_0x543146){var _0x3358c8=_0x14bf0e[_0x85eb('0x30')]['test']?0x1f4:_0x543146['statusCode']||0x1f4;logger[_0x85eb('0x27')]('getFields,\x20%s,\x20%s,\x20%s',_0x85eb('0x55'),_0x3358c8,JSON['stringify'](_0x543146));delete _0x543146[_0x85eb('0x29')];if(_0x3358c8===0x191){_0x3358c8=0x190;}_0x5037c7['status'](_0x3358c8)[_0x85eb('0x71')](_0x14bf0e[_0x85eb('0x30')]['test']?{'message':_0x85eb('0x72'),'statusCode':_0x543146[_0x85eb('0x73')]}:_0x543146);});};
\ No newline at end of file
+var _0x84a0=['../../config/license/hardware','../../config/logger','api','../../config/utils','../../mysqldb','../../components/integrations/configuration','sendStatus','status','end','json','offset','limit','undefined','count','set','Content-Range','apply','reject','save','then','destroy','name','index','map','rawAttributes','type','key','model','query','keys','filters','intersection','attributes','fields','nolimit','sort','where','pick','filter','merge','VIRTUAL','options','includeAll','ZendeskAccount','findAll','rows','show','length','include','find','catch','create','body','update','params','findOne','ZendeskConfiguration','order','getConfigurations','hasOwnProperty','AccountId','Subjects','getSubjects','channel','getDescriptions','ZendeskField','Descriptions','username','authType','remoteUri','slice','substring','lastIndexOf','GET','format','%s/%s','password','headers','Basic\x20%s','%s:%s','toString','%s/token:%s','token','ValidationError','Unknown\x20authentication\x20type','subject','description','assignee','remove','ticket_fields','includes','position','title','system_field_options','custom_field_options','error','getFields,\x20%s,\x20%s,\x20%s','stringify','send','test','Wrong\x20credentials','statusCode','eml-format','rimraf','zip-dir','fast-json-patch','moment','bluebird','path','sox','ejs','fs-extra','lodash','squel','crypto','desk.js','to-csv','querystring','papaparse','ioredis','../../components/parsers/advancedSearch'];(function(_0xaade75,_0x5c6662){var _0x510584=function(_0x1b7219){while(--_0x1b7219){_0xaade75['push'](_0xaade75['shift']());}};_0x510584(++_0x5c6662);}(_0x84a0,0x66));var _0x084a=function(_0x137272,_0x354f5f){_0x137272=_0x137272-0x0;var _0x34c22d=_0x84a0[_0x137272];return _0x34c22d;};'use strict';var emlformat=require(_0x084a('0x0'));var rimraf=require(_0x084a('0x1'));var zipdir=require(_0x084a('0x2'));var jsonpatch=require(_0x084a('0x3'));var rp=require('request-promise');var moment=require(_0x084a('0x4'));var BPromise=require(_0x084a('0x5'));var Mustache=require('mustache');var util=require('util');var path=require(_0x084a('0x6'));var sox=require(_0x084a('0x7'));var csv=require('to-csv');var ejs=require(_0x084a('0x8'));var fs=require('fs');var fs_extra=require(_0x084a('0x9'));var _=require(_0x084a('0xa'));var squel=require(_0x084a('0xb'));var crypto=require(_0x084a('0xc'));var jsforce=require('jsforce');var deskjs=require(_0x084a('0xd'));var toCsv=require(_0x084a('0xe'));var querystring=require(_0x084a('0xf'));var Papa=require(_0x084a('0x10'));var Redis=require(_0x084a('0x11'));var authService=require('../../components/auth/service');var qs=require('../../components/parsers/qs');var as=require(_0x084a('0x12'));var hardwareService=require(_0x084a('0x13'));var logger=require(_0x084a('0x14'))(_0x084a('0x15'));var utils=require(_0x084a('0x16'));var config=require('../../config/environment');var licenseUtil=require('../../config/license/util');var db=require(_0x084a('0x17'))['db'];var integrations=require(_0x084a('0x18'));function respondWithStatusCode(_0xec90a5,_0x9245b1){_0x9245b1=_0x9245b1||0xcc;return function(_0x1bdfb8){if(_0x1bdfb8){return _0xec90a5[_0x084a('0x19')](_0x9245b1);}return _0xec90a5[_0x084a('0x1a')](_0x9245b1)[_0x084a('0x1b')]();};}function respondWithResult(_0x5aef40,_0x4277c9){_0x4277c9=_0x4277c9||0xc8;return function(_0x4b9cc5){if(_0x4b9cc5){return _0x5aef40[_0x084a('0x1a')](_0x4277c9)[_0x084a('0x1c')](_0x4b9cc5);}};}function respondWithFilteredResult(_0x366624,_0x2d35b8){return function(_0xd20527){if(_0xd20527){var _0x4cbd16=typeof _0x2d35b8[_0x084a('0x1d')]==='undefined'&&typeof _0x2d35b8[_0x084a('0x1e')]===_0x084a('0x1f');var _0x4af43e=_0xd20527[_0x084a('0x20')];var _0x32c729=_0x4cbd16?0x0:_0x2d35b8[_0x084a('0x1d')];var _0x14bb19=_0x4cbd16?_0xd20527[_0x084a('0x20')]:_0x2d35b8[_0x084a('0x1d')]+_0x2d35b8[_0x084a('0x1e')];var _0x34e86e;if(_0x14bb19>=_0x4af43e){_0x14bb19=_0x4af43e;_0x34e86e=0xc8;}else{_0x34e86e=0xce;}_0x366624[_0x084a('0x1a')](_0x34e86e);return _0x366624[_0x084a('0x21')](_0x084a('0x22'),_0x32c729+'-'+_0x14bb19+'/'+_0x4af43e)[_0x084a('0x1c')](_0xd20527);}return null;};}function patchUpdates(_0x116328){return function(_0x126efb){try{jsonpatch[_0x084a('0x23')](_0x126efb,_0x116328,!![]);}catch(_0x506f71){return BPromise[_0x084a('0x24')](_0x506f71);}return _0x126efb[_0x084a('0x25')]();};}function saveUpdates(_0x41a90f,_0x2d62bf){return function(_0x1c3f6c){if(_0x1c3f6c){return _0x1c3f6c['update'](_0x41a90f)[_0x084a('0x26')](function(_0x288e9e){return _0x288e9e;});}return null;};}function removeEntity(_0x6346a5,_0x1f2c9f){return function(_0x18b43d){if(_0x18b43d){return _0x18b43d[_0x084a('0x27')]()['then'](function(){_0x6346a5[_0x084a('0x1a')](0xcc)[_0x084a('0x1b')]();});}};}function handleEntityNotFound(_0x54233b,_0x5b1474){return function(_0x8806d5){if(!_0x8806d5){_0x54233b[_0x084a('0x19')](0x194);}return _0x8806d5;};}function handleError(_0xfc9b8c,_0x4c5658){_0x4c5658=_0x4c5658||0x1f4;return function(_0x5596ac){logger['error'](_0x5596ac['stack']);if(_0x5596ac[_0x084a('0x28')]){delete _0x5596ac['name'];}_0xfc9b8c['status'](_0x4c5658)['send'](_0x5596ac);};}exports[_0x084a('0x29')]=function(_0x4651e6,_0x388062){var _0x2c4149={},_0x3be7a6={},_0x25a2a1={'count':0x0,'rows':[]};var _0x378de6=_[_0x084a('0x2a')](db['ZendeskAccount'][_0x084a('0x2b')],function(_0x3b2b38){return{'name':_0x3b2b38['fieldName'],'type':_0x3b2b38[_0x084a('0x2c')][_0x084a('0x2d')]};});_0x3be7a6[_0x084a('0x2e')]=_[_0x084a('0x2a')](_0x378de6,_0x084a('0x28'));_0x3be7a6[_0x084a('0x2f')]=_[_0x084a('0x30')](_0x4651e6[_0x084a('0x2f')]);_0x3be7a6[_0x084a('0x31')]=_[_0x084a('0x32')](_0x3be7a6[_0x084a('0x2e')],_0x3be7a6[_0x084a('0x2f')]);_0x2c4149[_0x084a('0x33')]=_['intersection'](_0x3be7a6['model'],qs[_0x084a('0x34')](_0x4651e6[_0x084a('0x2f')][_0x084a('0x34')]));_0x2c4149[_0x084a('0x33')]=_0x2c4149[_0x084a('0x33')]['length']?_0x2c4149[_0x084a('0x33')]:_0x3be7a6[_0x084a('0x2e')];if(!_0x4651e6[_0x084a('0x2f')]['hasOwnProperty'](_0x084a('0x35'))){_0x2c4149[_0x084a('0x1e')]=qs[_0x084a('0x1e')](_0x4651e6['query']['limit']);_0x2c4149['offset']=qs[_0x084a('0x1d')](_0x4651e6[_0x084a('0x2f')][_0x084a('0x1d')]);}_0x2c4149['order']=qs[_0x084a('0x36')](_0x4651e6[_0x084a('0x2f')][_0x084a('0x36')]);_0x2c4149[_0x084a('0x37')]=qs[_0x084a('0x31')](_[_0x084a('0x38')](_0x4651e6[_0x084a('0x2f')],_0x3be7a6[_0x084a('0x31')]),_0x378de6);if(_0x4651e6[_0x084a('0x2f')][_0x084a('0x39')]){_0x2c4149[_0x084a('0x37')]=_[_0x084a('0x3a')](_0x2c4149[_0x084a('0x37')],{'$or':_[_0x084a('0x2a')](_0x378de6,function(_0x10983f){if(_0x10983f['type']!==_0x084a('0x3b')){var _0x1dada8={};_0x1dada8[_0x10983f[_0x084a('0x28')]]={'$like':'%'+_0x4651e6[_0x084a('0x2f')][_0x084a('0x39')]+'%'};return _0x1dada8;}})});}_0x2c4149=_[_0x084a('0x3a')]({},_0x2c4149,_0x4651e6[_0x084a('0x3c')]);var _0x183e10={'where':_0x2c4149[_0x084a('0x37')]};return db['ZendeskAccount'][_0x084a('0x20')](_0x183e10)[_0x084a('0x26')](function(_0x25a081){_0x25a2a1[_0x084a('0x20')]=_0x25a081;if(_0x4651e6[_0x084a('0x2f')][_0x084a('0x3d')]){_0x2c4149['include']=[{'all':!![]}];}return db[_0x084a('0x3e')][_0x084a('0x3f')](_0x2c4149);})['then'](function(_0x410fdb){_0x25a2a1[_0x084a('0x40')]=_0x410fdb;return _0x25a2a1;})[_0x084a('0x26')](respondWithFilteredResult(_0x388062,_0x2c4149))['catch'](handleError(_0x388062,null));};exports[_0x084a('0x41')]=function(_0xba1081,_0x4fe9c2){var _0x3e2b92={'raw':![],'where':{'id':_0xba1081['params']['id']}},_0xfb565c={};_0xfb565c['model']=_[_0x084a('0x30')](db[_0x084a('0x3e')][_0x084a('0x2b')]);_0xfb565c[_0x084a('0x2f')]=_[_0x084a('0x30')](_0xba1081[_0x084a('0x2f')]);_0xfb565c[_0x084a('0x31')]=_[_0x084a('0x32')](_0xfb565c[_0x084a('0x2e')],_0xfb565c[_0x084a('0x2f')]);_0x3e2b92[_0x084a('0x33')]=_['intersection'](_0xfb565c['model'],qs[_0x084a('0x34')](_0xba1081[_0x084a('0x2f')][_0x084a('0x34')]));_0x3e2b92['attributes']=_0x3e2b92[_0x084a('0x33')][_0x084a('0x42')]?_0x3e2b92[_0x084a('0x33')]:_0xfb565c[_0x084a('0x2e')];if(_0xba1081[_0x084a('0x2f')]['includeAll']){_0x3e2b92[_0x084a('0x43')]=[{'all':!![]}];}_0x3e2b92=_['merge']({},_0x3e2b92,_0xba1081[_0x084a('0x3c')]);return db[_0x084a('0x3e')][_0x084a('0x44')](_0x3e2b92)['then'](handleEntityNotFound(_0x4fe9c2,null))['then'](respondWithResult(_0x4fe9c2,null))[_0x084a('0x45')](handleError(_0x4fe9c2,null));};exports[_0x084a('0x46')]=function(_0x505965,_0x29d8c2){return db[_0x084a('0x3e')][_0x084a('0x46')](_0x505965[_0x084a('0x47')],{})['then'](respondWithResult(_0x29d8c2,0xc9))[_0x084a('0x45')](handleError(_0x29d8c2,null));};exports[_0x084a('0x48')]=function(_0x31677b,_0x10856d){if(_0x31677b['body']['id']){delete _0x31677b[_0x084a('0x47')]['id'];}return db[_0x084a('0x3e')][_0x084a('0x44')]({'where':{'id':_0x31677b[_0x084a('0x49')]['id']}})['then'](handleEntityNotFound(_0x10856d,null))['then'](saveUpdates(_0x31677b[_0x084a('0x47')],null))[_0x084a('0x26')](respondWithResult(_0x10856d,null))[_0x084a('0x45')](handleError(_0x10856d,null));};exports[_0x084a('0x27')]=function(_0xf936e,_0x3b2df4){return db[_0x084a('0x3e')][_0x084a('0x44')]({'where':{'id':_0xf936e[_0x084a('0x49')]['id']}})[_0x084a('0x26')](handleEntityNotFound(_0x3b2df4,null))[_0x084a('0x26')](removeEntity(_0x3b2df4,null))[_0x084a('0x45')](handleError(_0x3b2df4,null));};exports['getConfigurations']=function(_0xcdd5b,_0x37fce4,_0x29fa4b){var _0x39edc1={};var _0x2091b1={};var _0x1c972c;var _0xa5362;return db['ZendeskAccount'][_0x084a('0x4a')]({'where':{'id':_0xcdd5b[_0x084a('0x49')]['id']}})[_0x084a('0x26')](handleEntityNotFound(_0x37fce4,null))['then'](function(_0x54ca1f){if(_0x54ca1f){_0x1c972c=_0x54ca1f;_0x2091b1[_0x084a('0x2e')]=_['keys'](db[_0x084a('0x4b')][_0x084a('0x2b')]);_0x2091b1['query']=_[_0x084a('0x30')](_0xcdd5b['query']);_0x2091b1['filters']=_[_0x084a('0x32')](_0x2091b1[_0x084a('0x2e')],_0x2091b1[_0x084a('0x2f')]);_0x39edc1[_0x084a('0x33')]=_[_0x084a('0x32')](_0x2091b1[_0x084a('0x2e')],qs[_0x084a('0x34')](_0xcdd5b['query'][_0x084a('0x34')]));_0x39edc1[_0x084a('0x33')]=_0x39edc1[_0x084a('0x33')]['length']?_0x39edc1[_0x084a('0x33')]:_0x2091b1[_0x084a('0x2e')];_0x39edc1[_0x084a('0x4c')]=qs[_0x084a('0x36')](_0xcdd5b['query'][_0x084a('0x36')]);_0x39edc1['where']=qs[_0x084a('0x31')](_[_0x084a('0x38')](_0xcdd5b[_0x084a('0x2f')],_0x2091b1['filters']));if(_0xcdd5b['query'][_0x084a('0x39')]){_0x39edc1[_0x084a('0x37')]=_['merge'](_0x39edc1[_0x084a('0x37')],{'$or':_['map'](_0x39edc1['attributes'],function(_0x195ae2){var _0x3f3fd7={};_0x3f3fd7[_0x195ae2]={'$like':'%'+_0xcdd5b[_0x084a('0x2f')][_0x084a('0x39')]+'%'};return _0x3f3fd7;})});}_0x39edc1=_[_0x084a('0x3a')]({},_0x39edc1,_0xcdd5b[_0x084a('0x3c')]);return _0x1c972c[_0x084a('0x4d')](_0x39edc1);}})[_0x084a('0x26')](function(_0x114aa5){if(_0x114aa5){_0xa5362=_0x114aa5['length'];if(!_0xcdd5b[_0x084a('0x2f')][_0x084a('0x4e')](_0x084a('0x35'))){_0x39edc1['limit']=qs[_0x084a('0x1e')](_0xcdd5b[_0x084a('0x2f')]['limit']);_0x39edc1[_0x084a('0x1d')]=qs['offset'](_0xcdd5b['query'][_0x084a('0x1d')]);}return _0x1c972c['getConfigurations'](_0x39edc1);}})['then'](function(_0x2368f5){if(_0x2368f5){return _0x2368f5?{'count':_0xa5362,'rows':_0x2368f5}:null;}})[_0x084a('0x26')](respondWithResult(_0x37fce4,null))[_0x084a('0x45')](handleError(_0x37fce4,null));};exports['addConfiguration']=function(_0xff6c9e,_0xbd063c,_0x2311f5){if(_0xff6c9e[_0x084a('0x47')]['id']){delete _0xff6c9e[_0x084a('0x47')]['id'];}return db[_0x084a('0x3e')][_0x084a('0x4a')]({'where':{'id':_0xff6c9e['params']['id']}})['then'](handleEntityNotFound(_0xbd063c,null))[_0x084a('0x26')](function(_0x36ba24){if(_0x36ba24){_0xff6c9e['body'][_0x084a('0x4f')]=_0x36ba24['id'];_0xff6c9e[_0x084a('0x47')][_0x084a('0x50')]=integrations[_0x084a('0x51')](_0xff6c9e['body'][_0x084a('0x52')],_0xff6c9e[_0x084a('0x47')][_0x084a('0x2c')]);_0xff6c9e['body']['Descriptions']=integrations[_0x084a('0x53')](_0xff6c9e[_0x084a('0x47')][_0x084a('0x52')],_0xff6c9e[_0x084a('0x47')][_0x084a('0x2c')]);return db[_0x084a('0x4b')][_0x084a('0x46')](_0xff6c9e['body'],{'include':[{'model':db[_0x084a('0x54')],'as':'Subjects'},{'model':db['ZendeskField'],'as':_0x084a('0x55')}]});}return null;})[_0x084a('0x26')](respondWithResult(_0xbd063c,null))[_0x084a('0x45')](handleError(_0xbd063c,null));};exports['getFields']=function(_0x163a5d,_0x57729c,_0x1eb7be){var _0x1054ea='';return db[_0x084a('0x3e')][_0x084a('0x4a')]({'where':{'id':_0x163a5d[_0x084a('0x49')]['id']},'attributes':['id',_0x084a('0x56'),'password','token',_0x084a('0x57'),_0x084a('0x58')]})[_0x084a('0x26')](handleEntityNotFound(_0x57729c,null))[_0x084a('0x26')](function(_0x22abf5){if(_0x22abf5){_0x1054ea=_0x22abf5[_0x084a('0x58')];var _0x5c655f=_0x1054ea[_0x084a('0x59')](-0x1);if(_0x5c655f==='/'){_0x1054ea=_0x1054ea[_0x084a('0x5a')](0x0,_0x1054ea[_0x084a('0x5b')](_0x5c655f));}var _0x33c040={'method':_0x084a('0x5c'),'uri':util[_0x084a('0x5d')](_0x084a('0x5e'),_0x1054ea,'ticket_fields'),'json':!![]};switch(_0x22abf5[_0x084a('0x57')]){case _0x084a('0x5f'):_0x33c040[_0x084a('0x60')]={'Authorization':util[_0x084a('0x5d')](_0x084a('0x61'),new Buffer(util[_0x084a('0x5d')](_0x084a('0x62'),_0x22abf5[_0x084a('0x56')],_0x22abf5[_0x084a('0x5f')]))[_0x084a('0x63')]('base64'))};break;case'token':_0x33c040['headers']={'Authorization':util[_0x084a('0x5d')](_0x084a('0x61'),new Buffer(util['format'](_0x084a('0x64'),_0x22abf5[_0x084a('0x56')],_0x22abf5[_0x084a('0x65')]))[_0x084a('0x63')]('base64'))};break;default:throw new db['Sequelize'][(_0x084a('0x66'))](_0x084a('0x67'));}return rp(_0x33c040);}})[_0x084a('0x26')](function(_0x37d05a){if(_0x37d05a){var _0x155450=[_0x084a('0x68'),_0x084a('0x69'),'group',_0x084a('0x6a')];_[_0x084a('0x6b')](_0x37d05a[_0x084a('0x6c')],function(_0x137bba){return _0x155450[_0x084a('0x6d')](_0x137bba[_0x084a('0x2c')]);});return{'count':_0x37d05a[_0x084a('0x6c')]['length'],'rows':_[_0x084a('0x2a')](_0x37d05a[_0x084a('0x6c')],function(_0x26a88c){return{'id':_0x26a88c['id'],'name':_0x26a88c[_0x084a('0x6e')]>0x7?_0x26a88c[_0x084a('0x6f')]:_0x26a88c[_0x084a('0x2c')],'custom':_0x26a88c[_0x084a('0x6e')]>0x7?!![]:![],'options':_0x26a88c[_0x084a('0x70')]?_0x26a88c[_0x084a('0x70')]:_0x26a88c[_0x084a('0x71')]?_0x26a88c[_0x084a('0x71')]:[]};})};}})['then'](respondWithResult(_0x57729c,null))[_0x084a('0x45')](function(_0x29916a){var _0x4b8f1f=_0x163a5d[_0x084a('0x2f')]['test']?0x1f4:_0x29916a['statusCode']||0x1f4;logger[_0x084a('0x72')](_0x084a('0x73'),'getFields',_0x4b8f1f,JSON[_0x084a('0x74')](_0x29916a));delete _0x29916a[_0x084a('0x28')];if(_0x4b8f1f===0x191){_0x4b8f1f=0x190;}_0x57729c[_0x084a('0x1a')](_0x4b8f1f)[_0x084a('0x75')](_0x163a5d[_0x084a('0x2f')][_0x084a('0x76')]?{'message':_0x084a('0x77'),'statusCode':_0x29916a[_0x084a('0x78')]}:_0x29916a);});};
\ No newline at end of file