Built motion from commit ffdca78c.|2.6.24
[motion2.git] / server / api / intDeskAccount / intDeskAccount.controller.js
index 97158ed..130f10a 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0x4c2a=['filters','filter','name','merge','options','count','includeAll','include','findAll','rows','catch','params','find','create','body','getConfigurations','findOne','DeskConfiguration','length','AccountId','Subjects','getSubjects','channel','Descriptions','getDescriptions','DeskField','getFields','priority','authType','username','password','consumerKey','consumerSecret','token','tokenSecret','remoteUri','slice','substring','GET','format','%s/custom_fields','application/json','headers','Authorization','Basic\x20%s','%s:%s','toString','base64','concat','_embedded','active','label','test','statusCode','error','getFields,\x20%s,\x20%s,\x20%s','Wrong\x20credentials','eml-format','zip-dir','fast-json-patch','request-promise','moment','mustache','util','path','to-csv','ejs','squel','crypto','jsforce','desk.js','querystring','papaparse','../../components/auth/service','../../components/parsers/qs','../../config/license/hardware','../../config/logger','api','../../config/utils','../../config/environment','../../config/license/util','../../mysqldb','../../components/integrations/configuration','status','json','offset','limit','undefined','Content-Range','apply','save','update','then','destroy','end','stack','send','map','DeskAccount','rawAttributes','fieldName','type','model','query','keys','intersection','fields','attributes','hasOwnProperty','nolimit','order','sort','where','pick'];(function(_0x121df1,_0x3a06c0){var _0x59b6f8=function(_0x31aabb){while(--_0x31aabb){_0x121df1['push'](_0x121df1['shift']());}};_0x59b6f8(++_0x3a06c0);}(_0x4c2a,0x11d));var _0xa4c2=function(_0x9e2285,_0x4691cf){_0x9e2285=_0x9e2285-0x0;var _0x496966=_0x4c2a[_0x9e2285];return _0x496966;};'use strict';var emlformat=require(_0xa4c2('0x0'));var rimraf=require('rimraf');var zipdir=require(_0xa4c2('0x1'));var jsonpatch=require(_0xa4c2('0x2'));var rp=require(_0xa4c2('0x3'));var moment=require(_0xa4c2('0x4'));var BPromise=require('bluebird');var Mustache=require(_0xa4c2('0x5'));var util=require(_0xa4c2('0x6'));var path=require(_0xa4c2('0x7'));var sox=require('sox');var csv=require(_0xa4c2('0x8'));var ejs=require(_0xa4c2('0x9'));var fs=require('fs');var fs_extra=require('fs-extra');var _=require('lodash');var squel=require(_0xa4c2('0xa'));var crypto=require(_0xa4c2('0xb'));var jsforce=require(_0xa4c2('0xc'));var deskjs=require(_0xa4c2('0xd'));var toCsv=require(_0xa4c2('0x8'));var querystring=require(_0xa4c2('0xe'));var Papa=require(_0xa4c2('0xf'));var Redis=require('ioredis');var authService=require(_0xa4c2('0x10'));var qs=require(_0xa4c2('0x11'));var as=require('../../components/parsers/advancedSearch');var hardwareService=require(_0xa4c2('0x12'));var logger=require(_0xa4c2('0x13'))(_0xa4c2('0x14'));var utils=require(_0xa4c2('0x15'));var config=require(_0xa4c2('0x16'));var licenseUtil=require(_0xa4c2('0x17'));var db=require(_0xa4c2('0x18'))['db'];var integrations=require(_0xa4c2('0x19'));function respondWithStatusCode(_0x3c947f,_0x14a1b2){_0x14a1b2=_0x14a1b2||0xcc;return function(_0x5dd395){if(_0x5dd395){return _0x3c947f['sendStatus'](_0x14a1b2);}return _0x3c947f['status'](_0x14a1b2)['end']();};}function respondWithResult(_0x38683b,_0x3d9a0e){_0x3d9a0e=_0x3d9a0e||0xc8;return function(_0x2ad824){if(_0x2ad824){return _0x38683b[_0xa4c2('0x1a')](_0x3d9a0e)[_0xa4c2('0x1b')](_0x2ad824);}};}function respondWithFilteredResult(_0x3e08cd,_0x210d65){return function(_0xf959f9){if(_0xf959f9){var _0x4ae908=typeof _0x210d65[_0xa4c2('0x1c')]==='undefined'&&typeof _0x210d65[_0xa4c2('0x1d')]===_0xa4c2('0x1e');var _0x385b5f=_0xf959f9['count'];var _0x437799=_0x4ae908?0x0:_0x210d65[_0xa4c2('0x1c')];var _0x3e31ee=_0x4ae908?_0xf959f9['count']:_0x210d65[_0xa4c2('0x1c')]+_0x210d65['limit'];var _0x228f05;if(_0x3e31ee>=_0x385b5f){_0x3e31ee=_0x385b5f;_0x228f05=0xc8;}else{_0x228f05=0xce;}_0x3e08cd['status'](_0x228f05);return _0x3e08cd['set'](_0xa4c2('0x1f'),_0x437799+'-'+_0x3e31ee+'/'+_0x385b5f)[_0xa4c2('0x1b')](_0xf959f9);}return null;};}function patchUpdates(_0x2b5e70){return function(_0x318921){try{jsonpatch[_0xa4c2('0x20')](_0x318921,_0x2b5e70,!![]);}catch(_0x4ff43c){return BPromise['reject'](_0x4ff43c);}return _0x318921[_0xa4c2('0x21')]();};}function saveUpdates(_0x189f85,_0xb6ed38){return function(_0x17c5fd){if(_0x17c5fd){return _0x17c5fd[_0xa4c2('0x22')](_0x189f85)[_0xa4c2('0x23')](function(_0x10ae15){return _0x10ae15;});}return null;};}function removeEntity(_0x275646,_0x405ce4){return function(_0x15bbc6){if(_0x15bbc6){return _0x15bbc6[_0xa4c2('0x24')]()[_0xa4c2('0x23')](function(){_0x275646[_0xa4c2('0x1a')](0xcc)[_0xa4c2('0x25')]();});}};}function handleEntityNotFound(_0x1f5fff,_0x372ff0){return function(_0x103c7b){if(!_0x103c7b){_0x1f5fff['sendStatus'](0x194);}return _0x103c7b;};}function handleError(_0x2f7409,_0x2ca653){_0x2ca653=_0x2ca653||0x1f4;return function(_0x10957c){logger['error'](_0x10957c[_0xa4c2('0x26')]);if(_0x10957c['name']){delete _0x10957c['name'];}_0x2f7409[_0xa4c2('0x1a')](_0x2ca653)[_0xa4c2('0x27')](_0x10957c);};}exports['index']=function(_0x4b50cd,_0x2f7151){var _0x4c8a63={},_0x2a5e90={},_0x44a965={'count':0x0,'rows':[]};var _0x68df44=_[_0xa4c2('0x28')](db[_0xa4c2('0x29')][_0xa4c2('0x2a')],function(_0x4c2f53){return{'name':_0x4c2f53[_0xa4c2('0x2b')],'type':_0x4c2f53[_0xa4c2('0x2c')]['key']};});_0x2a5e90[_0xa4c2('0x2d')]=_[_0xa4c2('0x28')](_0x68df44,'name');_0x2a5e90[_0xa4c2('0x2e')]=_[_0xa4c2('0x2f')](_0x4b50cd[_0xa4c2('0x2e')]);_0x2a5e90['filters']=_[_0xa4c2('0x30')](_0x2a5e90['model'],_0x2a5e90[_0xa4c2('0x2e')]);_0x4c8a63['attributes']=_[_0xa4c2('0x30')](_0x2a5e90[_0xa4c2('0x2d')],qs[_0xa4c2('0x31')](_0x4b50cd[_0xa4c2('0x2e')][_0xa4c2('0x31')]));_0x4c8a63[_0xa4c2('0x32')]=_0x4c8a63[_0xa4c2('0x32')]['length']?_0x4c8a63[_0xa4c2('0x32')]:_0x2a5e90[_0xa4c2('0x2d')];if(!_0x4b50cd[_0xa4c2('0x2e')][_0xa4c2('0x33')](_0xa4c2('0x34'))){_0x4c8a63[_0xa4c2('0x1d')]=qs[_0xa4c2('0x1d')](_0x4b50cd['query'][_0xa4c2('0x1d')]);_0x4c8a63['offset']=qs[_0xa4c2('0x1c')](_0x4b50cd[_0xa4c2('0x2e')][_0xa4c2('0x1c')]);}_0x4c8a63[_0xa4c2('0x35')]=qs['sort'](_0x4b50cd[_0xa4c2('0x2e')][_0xa4c2('0x36')]);_0x4c8a63[_0xa4c2('0x37')]=qs['filters'](_[_0xa4c2('0x38')](_0x4b50cd[_0xa4c2('0x2e')],_0x2a5e90[_0xa4c2('0x39')]),_0x68df44);if(_0x4b50cd[_0xa4c2('0x2e')][_0xa4c2('0x3a')]){_0x4c8a63[_0xa4c2('0x37')]=_['merge'](_0x4c8a63['where'],{'$or':_[_0xa4c2('0x28')](_0x68df44,function(_0x5cd6a3){if(_0x5cd6a3['type']!=='VIRTUAL'){var _0x6817f6={};_0x6817f6[_0x5cd6a3[_0xa4c2('0x3b')]]={'$like':'%'+_0x4b50cd['query'][_0xa4c2('0x3a')]+'%'};return _0x6817f6;}})});}_0x4c8a63=_[_0xa4c2('0x3c')]({},_0x4c8a63,_0x4b50cd[_0xa4c2('0x3d')]);var _0x295c1a={'where':_0x4c8a63[_0xa4c2('0x37')]};return db[_0xa4c2('0x29')][_0xa4c2('0x3e')](_0x295c1a)['then'](function(_0x300fb6){_0x44a965['count']=_0x300fb6;if(_0x4b50cd[_0xa4c2('0x2e')][_0xa4c2('0x3f')]){_0x4c8a63[_0xa4c2('0x40')]=[{'all':!![]}];}return db[_0xa4c2('0x29')][_0xa4c2('0x41')](_0x4c8a63);})[_0xa4c2('0x23')](function(_0x2c901a){_0x44a965[_0xa4c2('0x42')]=_0x2c901a;return _0x44a965;})['then'](respondWithFilteredResult(_0x2f7151,_0x4c8a63))[_0xa4c2('0x43')](handleError(_0x2f7151,null));};exports['show']=function(_0x13e569,_0x5c373b){var _0x2d2ac7={'raw':![],'where':{'id':_0x13e569[_0xa4c2('0x44')]['id']}},_0x283c05={};_0x283c05[_0xa4c2('0x2d')]=_[_0xa4c2('0x2f')](db[_0xa4c2('0x29')][_0xa4c2('0x2a')]);_0x283c05[_0xa4c2('0x2e')]=_['keys'](_0x13e569['query']);_0x283c05[_0xa4c2('0x39')]=_[_0xa4c2('0x30')](_0x283c05['model'],_0x283c05[_0xa4c2('0x2e')]);_0x2d2ac7[_0xa4c2('0x32')]=_['intersection'](_0x283c05[_0xa4c2('0x2d')],qs[_0xa4c2('0x31')](_0x13e569[_0xa4c2('0x2e')][_0xa4c2('0x31')]));_0x2d2ac7['attributes']=_0x2d2ac7[_0xa4c2('0x32')]['length']?_0x2d2ac7[_0xa4c2('0x32')]:_0x283c05[_0xa4c2('0x2d')];if(_0x13e569[_0xa4c2('0x2e')][_0xa4c2('0x3f')]){_0x2d2ac7[_0xa4c2('0x40')]=[{'all':!![]}];}_0x2d2ac7=_[_0xa4c2('0x3c')]({},_0x2d2ac7,_0x13e569[_0xa4c2('0x3d')]);return db['DeskAccount'][_0xa4c2('0x45')](_0x2d2ac7)[_0xa4c2('0x23')](handleEntityNotFound(_0x5c373b,null))[_0xa4c2('0x23')](respondWithResult(_0x5c373b,null))['catch'](handleError(_0x5c373b,null));};exports['create']=function(_0x44a06d,_0x389053){return db['DeskAccount'][_0xa4c2('0x46')](_0x44a06d[_0xa4c2('0x47')],{})['then'](respondWithResult(_0x389053,0xc9))[_0xa4c2('0x43')](handleError(_0x389053,null));};exports['update']=function(_0x1fedcd,_0x5d876c){if(_0x1fedcd[_0xa4c2('0x47')]['id']){delete _0x1fedcd[_0xa4c2('0x47')]['id'];}return db[_0xa4c2('0x29')][_0xa4c2('0x45')]({'where':{'id':_0x1fedcd[_0xa4c2('0x44')]['id']}})[_0xa4c2('0x23')](handleEntityNotFound(_0x5d876c,null))[_0xa4c2('0x23')](saveUpdates(_0x1fedcd[_0xa4c2('0x47')],null))[_0xa4c2('0x23')](respondWithResult(_0x5d876c,null))[_0xa4c2('0x43')](handleError(_0x5d876c,null));};exports[_0xa4c2('0x24')]=function(_0x67c52f,_0x39870d){return db[_0xa4c2('0x29')][_0xa4c2('0x45')]({'where':{'id':_0x67c52f[_0xa4c2('0x44')]['id']}})[_0xa4c2('0x23')](handleEntityNotFound(_0x39870d,null))[_0xa4c2('0x23')](removeEntity(_0x39870d,null))['catch'](handleError(_0x39870d,null));};exports[_0xa4c2('0x48')]=function(_0xb68716,_0x30873a,_0x3b4da7){var _0x3bacb4={};var _0x541dc3={};var _0x1e11bc;var _0x54687d;return db[_0xa4c2('0x29')][_0xa4c2('0x49')]({'where':{'id':_0xb68716[_0xa4c2('0x44')]['id']}})[_0xa4c2('0x23')](handleEntityNotFound(_0x30873a,null))[_0xa4c2('0x23')](function(_0x5367b5){if(_0x5367b5){_0x1e11bc=_0x5367b5;_0x541dc3['model']=_[_0xa4c2('0x2f')](db[_0xa4c2('0x4a')][_0xa4c2('0x2a')]);_0x541dc3[_0xa4c2('0x2e')]=_[_0xa4c2('0x2f')](_0xb68716[_0xa4c2('0x2e')]);_0x541dc3['filters']=_[_0xa4c2('0x30')](_0x541dc3['model'],_0x541dc3['query']);_0x3bacb4[_0xa4c2('0x32')]=_[_0xa4c2('0x30')](_0x541dc3['model'],qs['fields'](_0xb68716[_0xa4c2('0x2e')][_0xa4c2('0x31')]));_0x3bacb4[_0xa4c2('0x32')]=_0x3bacb4[_0xa4c2('0x32')][_0xa4c2('0x4b')]?_0x3bacb4[_0xa4c2('0x32')]:_0x541dc3[_0xa4c2('0x2d')];_0x3bacb4[_0xa4c2('0x35')]=qs[_0xa4c2('0x36')](_0xb68716[_0xa4c2('0x2e')][_0xa4c2('0x36')]);_0x3bacb4['where']=qs['filters'](_[_0xa4c2('0x38')](_0xb68716[_0xa4c2('0x2e')],_0x541dc3['filters']));if(_0xb68716[_0xa4c2('0x2e')]['filter']){_0x3bacb4[_0xa4c2('0x37')]=_['merge'](_0x3bacb4[_0xa4c2('0x37')],{'$or':_[_0xa4c2('0x28')](_0x3bacb4[_0xa4c2('0x32')],function(_0x260fb7){var _0x142cdf={};_0x142cdf[_0x260fb7]={'$like':'%'+_0xb68716[_0xa4c2('0x2e')][_0xa4c2('0x3a')]+'%'};return _0x142cdf;})});}_0x3bacb4=_[_0xa4c2('0x3c')]({},_0x3bacb4,_0xb68716[_0xa4c2('0x3d')]);return _0x1e11bc[_0xa4c2('0x48')](_0x3bacb4);}})['then'](function(_0xef48b5){if(_0xef48b5){_0x54687d=_0xef48b5[_0xa4c2('0x4b')];if(!_0xb68716[_0xa4c2('0x2e')]['hasOwnProperty'](_0xa4c2('0x34'))){_0x3bacb4[_0xa4c2('0x1d')]=qs[_0xa4c2('0x1d')](_0xb68716[_0xa4c2('0x2e')][_0xa4c2('0x1d')]);_0x3bacb4[_0xa4c2('0x1c')]=qs[_0xa4c2('0x1c')](_0xb68716[_0xa4c2('0x2e')][_0xa4c2('0x1c')]);}return _0x1e11bc[_0xa4c2('0x48')](_0x3bacb4);}})[_0xa4c2('0x23')](function(_0x481c81){if(_0x481c81){return _0x481c81?{'count':_0x54687d,'rows':_0x481c81}:null;}})[_0xa4c2('0x23')](respondWithResult(_0x30873a,null))[_0xa4c2('0x43')](handleError(_0x30873a,null));};exports['addConfiguration']=function(_0x47b650,_0x39ca40,_0x48dff0){if(_0x47b650[_0xa4c2('0x47')]['id']){delete _0x47b650[_0xa4c2('0x47')]['id'];}return db[_0xa4c2('0x29')][_0xa4c2('0x49')]({'where':{'id':_0x47b650[_0xa4c2('0x44')]['id']}})[_0xa4c2('0x23')](handleEntityNotFound(_0x39ca40,null))[_0xa4c2('0x23')](function(_0x31cf28){if(_0x31cf28){_0x47b650[_0xa4c2('0x47')][_0xa4c2('0x4c')]=_0x31cf28['id'];_0x47b650['body'][_0xa4c2('0x4d')]=integrations[_0xa4c2('0x4e')](_0x47b650['body'][_0xa4c2('0x4f')],_0x47b650[_0xa4c2('0x47')][_0xa4c2('0x2c')]);_0x47b650['body'][_0xa4c2('0x50')]=integrations[_0xa4c2('0x51')](_0x47b650[_0xa4c2('0x47')]['channel'],_0x47b650[_0xa4c2('0x47')]['type']);return db[_0xa4c2('0x4a')][_0xa4c2('0x46')](_0x47b650[_0xa4c2('0x47')],{'include':[{'model':db[_0xa4c2('0x52')],'as':_0xa4c2('0x4d')},{'model':db[_0xa4c2('0x52')],'as':_0xa4c2('0x50')}]});}return null;})[_0xa4c2('0x23')](respondWithResult(_0x39ca40,null))[_0xa4c2('0x43')](handleError(_0x39ca40,null));};exports[_0xa4c2('0x53')]=function(_0x387fca,_0x3b19c0,_0x10163d){var _0x5cb37f=[{'name':_0xa4c2('0x54'),'label':'priority','custom':![],'options':[{'name':0x1,'value':0x1},{'name':0x2,'value':0x2},{'name':0x3,'value':0x3},{'name':0x4,'value':0x4},{'name':0x5,'value':0x5},{'name':0x6,'value':0x6},{'name':0x7,'value':0x7},{'name':0x8,'value':0x8},{'name':0x9,'value':0x9},{'name':0xa,'value':0xa}]}];var _0x17c47e='';return db['DeskAccount'][_0xa4c2('0x49')]({'where':{'id':_0x387fca[_0xa4c2('0x44')]['id']},'attributes':['id','remoteUri',_0xa4c2('0x55'),_0xa4c2('0x56'),_0xa4c2('0x57'),_0xa4c2('0x58'),_0xa4c2('0x59'),_0xa4c2('0x5a'),_0xa4c2('0x5b')]})[_0xa4c2('0x23')](handleEntityNotFound(_0x3b19c0,null))[_0xa4c2('0x23')](function(_0xc0667c){if(_0xc0667c){_0x17c47e=_0xc0667c[_0xa4c2('0x5c')];var _0x2ebb64=_0x17c47e[_0xa4c2('0x5d')](-0x1);if(_0x2ebb64==='/'){_0x17c47e=_0x17c47e[_0xa4c2('0x5e')](0x0,_0x17c47e['lastIndexOf'](_0x2ebb64));}var _0x4516a6={'method':_0xa4c2('0x5f'),'uri':util[_0xa4c2('0x60')](_0xa4c2('0x61'),_0x17c47e),'headers':{'Content-Type':'application/json','Accept':_0xa4c2('0x62')},'json':!![]};if(_0xc0667c[_0xa4c2('0x55')]==='basic'){_0x4516a6[_0xa4c2('0x63')][_0xa4c2('0x64')]=util[_0xa4c2('0x60')](_0xa4c2('0x65'),new Buffer(util[_0xa4c2('0x60')](_0xa4c2('0x66'),_0xc0667c['username'],_0xc0667c[_0xa4c2('0x57')]))[_0xa4c2('0x67')](_0xa4c2('0x68')));}return rp(_0x4516a6)[_0xa4c2('0x23')](function(_0x22c57c){return _0x5cb37f[_0xa4c2('0x69')](_[_0xa4c2('0x28')](_0x22c57c[_0xa4c2('0x6a')]['entries'],function(_0x44da0d){return{'id':_0x44da0d[_0xa4c2('0x3b')],'name':_0x44da0d[_0xa4c2('0x3b')],'type':_0x44da0d['type'],'active':_0x44da0d[_0xa4c2('0x6b')],'label':_0x44da0d[_0xa4c2('0x6c')],'custom':!![]};}));});}})[_0xa4c2('0x23')](function(_0x432222){return{'count':_0x432222['length'],'rows':_0x432222};})[_0xa4c2('0x23')](respondWithResult(_0x3b19c0,null))['catch'](function(_0xe4ee6d){var _0xf9023d=_0x387fca[_0xa4c2('0x2e')][_0xa4c2('0x6d')]?0x1f4:_0xe4ee6d[_0xa4c2('0x6e')]||0x1f4;logger[_0xa4c2('0x6f')](_0xa4c2('0x70'),'getFields',_0xf9023d,JSON['stringify'](_0xe4ee6d));delete _0xe4ee6d['name'];if(_0xf9023d===0x191){_0xf9023d=0x190;}_0x3b19c0['status'](_0xf9023d)[_0xa4c2('0x27')](_0x387fca[_0xa4c2('0x2e')][_0xa4c2('0x6d')]?{'message':_0xa4c2('0x71'),'statusCode':_0xe4ee6d['statusCode']}:_0xe4ee6d);});};
\ No newline at end of file
+var _0x3162=['hasOwnProperty','sort','where','pick','filters','filter','VIRTUAL','merge','DeskAccount','include','findAll','rows','catch','intersection','includeAll','options','find','create','body','params','getConfigurations','DeskConfiguration','length','order','nolimit','addConfiguration','AccountId','Subjects','getSubjects','Descriptions','channel','DeskField','getFields','priority','findOne','remoteUri','authType','username','password','consumerKey','consumerSecret','token','tokenSecret','slice','lastIndexOf','%s/custom_fields','application/json','basic','headers','Authorization','format','%s:%s','base64','concat','_embedded','entries','active','test','stringify','send','Wrong\x20credentials','statusCode','eml-format','fast-json-patch','request-promise','moment','mustache','util','path','sox','squel','jsforce','desk.js','to-csv','querystring','papaparse','ioredis','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','api','../../config/utils','../../config/license/util','../../mysqldb','sendStatus','status','end','json','offset','undefined','count','limit','set','Content-Range','apply','reject','save','update','destroy','then','error','name','map','rawAttributes','fieldName','type','key','keys','query','model','attributes','fields'];(function(_0x62c958,_0x2bfdbc){var _0x57ec61=function(_0x5c0094){while(--_0x5c0094){_0x62c958['push'](_0x62c958['shift']());}};_0x57ec61(++_0x2bfdbc);}(_0x3162,0x120));var _0x2316=function(_0x5eb294,_0x5b52ba){_0x5eb294=_0x5eb294-0x0;var _0xd139fd=_0x3162[_0x5eb294];return _0xd139fd;};'use strict';var emlformat=require(_0x2316('0x0'));var rimraf=require('rimraf');var zipdir=require('zip-dir');var jsonpatch=require(_0x2316('0x1'));var rp=require(_0x2316('0x2'));var moment=require(_0x2316('0x3'));var BPromise=require('bluebird');var Mustache=require(_0x2316('0x4'));var util=require(_0x2316('0x5'));var path=require(_0x2316('0x6'));var sox=require(_0x2316('0x7'));var csv=require('to-csv');var ejs=require('ejs');var fs=require('fs');var fs_extra=require('fs-extra');var _=require('lodash');var squel=require(_0x2316('0x8'));var crypto=require('crypto');var jsforce=require(_0x2316('0x9'));var deskjs=require(_0x2316('0xa'));var toCsv=require(_0x2316('0xb'));var querystring=require(_0x2316('0xc'));var Papa=require(_0x2316('0xd'));var Redis=require(_0x2316('0xe'));var authService=require('../../components/auth/service');var qs=require(_0x2316('0xf'));var as=require(_0x2316('0x10'));var hardwareService=require(_0x2316('0x11'));var logger=require(_0x2316('0x12'))(_0x2316('0x13'));var utils=require(_0x2316('0x14'));var config=require('../../config/environment');var licenseUtil=require(_0x2316('0x15'));var db=require(_0x2316('0x16'))['db'];var integrations=require('../../components/integrations/configuration');function respondWithStatusCode(_0x538eda,_0x32609b){_0x32609b=_0x32609b||0xcc;return function(_0x390b64){if(_0x390b64){return _0x538eda[_0x2316('0x17')](_0x32609b);}return _0x538eda[_0x2316('0x18')](_0x32609b)[_0x2316('0x19')]();};}function respondWithResult(_0x3e430f,_0x418030){_0x418030=_0x418030||0xc8;return function(_0x31fa19){if(_0x31fa19){return _0x3e430f[_0x2316('0x18')](_0x418030)[_0x2316('0x1a')](_0x31fa19);}};}function respondWithFilteredResult(_0x484f40,_0x318a56){return function(_0x52ea1d){if(_0x52ea1d){var _0x55c7b8=typeof _0x318a56[_0x2316('0x1b')]==='undefined'&&typeof _0x318a56['limit']===_0x2316('0x1c');var _0x20067f=_0x52ea1d['count'];var _0x12bbca=_0x55c7b8?0x0:_0x318a56[_0x2316('0x1b')];var _0x4712bb=_0x55c7b8?_0x52ea1d[_0x2316('0x1d')]:_0x318a56[_0x2316('0x1b')]+_0x318a56[_0x2316('0x1e')];var _0x56df89;if(_0x4712bb>=_0x20067f){_0x4712bb=_0x20067f;_0x56df89=0xc8;}else{_0x56df89=0xce;}_0x484f40[_0x2316('0x18')](_0x56df89);return _0x484f40[_0x2316('0x1f')](_0x2316('0x20'),_0x12bbca+'-'+_0x4712bb+'/'+_0x20067f)['json'](_0x52ea1d);}return null;};}function patchUpdates(_0x1dad72){return function(_0x4734d8){try{jsonpatch[_0x2316('0x21')](_0x4734d8,_0x1dad72,!![]);}catch(_0x38f8bb){return BPromise[_0x2316('0x22')](_0x38f8bb);}return _0x4734d8[_0x2316('0x23')]();};}function saveUpdates(_0x128819,_0x45e329){return function(_0x5766c8){if(_0x5766c8){return _0x5766c8[_0x2316('0x24')](_0x128819)['then'](function(_0x334f10){return _0x334f10;});}return null;};}function removeEntity(_0x29fd55,_0x5bb526){return function(_0x8697ea){if(_0x8697ea){return _0x8697ea[_0x2316('0x25')]()[_0x2316('0x26')](function(){_0x29fd55[_0x2316('0x18')](0xcc)['end']();});}};}function handleEntityNotFound(_0x3ca591,_0x167553){return function(_0x3dae7d){if(!_0x3dae7d){_0x3ca591[_0x2316('0x17')](0x194);}return _0x3dae7d;};}function handleError(_0x1c553d,_0x286a45){_0x286a45=_0x286a45||0x1f4;return function(_0x1ffc2e){logger[_0x2316('0x27')](_0x1ffc2e['stack']);if(_0x1ffc2e[_0x2316('0x28')]){delete _0x1ffc2e[_0x2316('0x28')];}_0x1c553d[_0x2316('0x18')](_0x286a45)['send'](_0x1ffc2e);};}exports['index']=function(_0x5eaf15,_0x267269){var _0x4bf453={},_0x282dd0={},_0x1363f3={'count':0x0,'rows':[]};var _0x1978ab=_[_0x2316('0x29')](db['DeskAccount'][_0x2316('0x2a')],function(_0x61e828){return{'name':_0x61e828[_0x2316('0x2b')],'type':_0x61e828[_0x2316('0x2c')][_0x2316('0x2d')]};});_0x282dd0['model']=_[_0x2316('0x29')](_0x1978ab,_0x2316('0x28'));_0x282dd0['query']=_[_0x2316('0x2e')](_0x5eaf15[_0x2316('0x2f')]);_0x282dd0['filters']=_['intersection'](_0x282dd0[_0x2316('0x30')],_0x282dd0['query']);_0x4bf453[_0x2316('0x31')]=_['intersection'](_0x282dd0['model'],qs[_0x2316('0x32')](_0x5eaf15['query'][_0x2316('0x32')]));_0x4bf453[_0x2316('0x31')]=_0x4bf453[_0x2316('0x31')]['length']?_0x4bf453[_0x2316('0x31')]:_0x282dd0[_0x2316('0x30')];if(!_0x5eaf15['query'][_0x2316('0x33')]('nolimit')){_0x4bf453['limit']=qs['limit'](_0x5eaf15[_0x2316('0x2f')][_0x2316('0x1e')]);_0x4bf453[_0x2316('0x1b')]=qs['offset'](_0x5eaf15['query'][_0x2316('0x1b')]);}_0x4bf453['order']=qs['sort'](_0x5eaf15[_0x2316('0x2f')][_0x2316('0x34')]);_0x4bf453[_0x2316('0x35')]=qs['filters'](_[_0x2316('0x36')](_0x5eaf15['query'],_0x282dd0[_0x2316('0x37')]),_0x1978ab);if(_0x5eaf15[_0x2316('0x2f')][_0x2316('0x38')]){_0x4bf453[_0x2316('0x35')]=_['merge'](_0x4bf453[_0x2316('0x35')],{'$or':_['map'](_0x1978ab,function(_0x391279){if(_0x391279[_0x2316('0x2c')]!==_0x2316('0x39')){var _0x3fb458={};_0x3fb458[_0x391279[_0x2316('0x28')]]={'$like':'%'+_0x5eaf15[_0x2316('0x2f')]['filter']+'%'};return _0x3fb458;}})});}_0x4bf453=_[_0x2316('0x3a')]({},_0x4bf453,_0x5eaf15['options']);var _0x26dc75={'where':_0x4bf453[_0x2316('0x35')]};return db[_0x2316('0x3b')][_0x2316('0x1d')](_0x26dc75)['then'](function(_0x2e52c2){_0x1363f3[_0x2316('0x1d')]=_0x2e52c2;if(_0x5eaf15[_0x2316('0x2f')]['includeAll']){_0x4bf453[_0x2316('0x3c')]=[{'all':!![]}];}return db['DeskAccount'][_0x2316('0x3d')](_0x4bf453);})[_0x2316('0x26')](function(_0x35f191){_0x1363f3[_0x2316('0x3e')]=_0x35f191;return _0x1363f3;})[_0x2316('0x26')](respondWithFilteredResult(_0x267269,_0x4bf453))[_0x2316('0x3f')](handleError(_0x267269,null));};exports['show']=function(_0x59f476,_0x9e651d){var _0xe70905={'raw':![],'where':{'id':_0x59f476['params']['id']}},_0x468a26={};_0x468a26[_0x2316('0x30')]=_[_0x2316('0x2e')](db[_0x2316('0x3b')][_0x2316('0x2a')]);_0x468a26[_0x2316('0x2f')]=_[_0x2316('0x2e')](_0x59f476[_0x2316('0x2f')]);_0x468a26[_0x2316('0x37')]=_[_0x2316('0x40')](_0x468a26[_0x2316('0x30')],_0x468a26['query']);_0xe70905[_0x2316('0x31')]=_[_0x2316('0x40')](_0x468a26['model'],qs[_0x2316('0x32')](_0x59f476[_0x2316('0x2f')][_0x2316('0x32')]));_0xe70905['attributes']=_0xe70905[_0x2316('0x31')]['length']?_0xe70905['attributes']:_0x468a26[_0x2316('0x30')];if(_0x59f476[_0x2316('0x2f')][_0x2316('0x41')]){_0xe70905[_0x2316('0x3c')]=[{'all':!![]}];}_0xe70905=_[_0x2316('0x3a')]({},_0xe70905,_0x59f476[_0x2316('0x42')]);return db[_0x2316('0x3b')][_0x2316('0x43')](_0xe70905)[_0x2316('0x26')](handleEntityNotFound(_0x9e651d,null))['then'](respondWithResult(_0x9e651d,null))[_0x2316('0x3f')](handleError(_0x9e651d,null));};exports[_0x2316('0x44')]=function(_0x50028b,_0x3ea289){return db[_0x2316('0x3b')][_0x2316('0x44')](_0x50028b[_0x2316('0x45')],{})[_0x2316('0x26')](respondWithResult(_0x3ea289,0xc9))[_0x2316('0x3f')](handleError(_0x3ea289,null));};exports[_0x2316('0x24')]=function(_0x1e77ff,_0x291790){if(_0x1e77ff['body']['id']){delete _0x1e77ff[_0x2316('0x45')]['id'];}return db['DeskAccount'][_0x2316('0x43')]({'where':{'id':_0x1e77ff[_0x2316('0x46')]['id']}})['then'](handleEntityNotFound(_0x291790,null))['then'](saveUpdates(_0x1e77ff[_0x2316('0x45')],null))[_0x2316('0x26')](respondWithResult(_0x291790,null))['catch'](handleError(_0x291790,null));};exports[_0x2316('0x25')]=function(_0x497d7b,_0x2481c5){return db[_0x2316('0x3b')][_0x2316('0x43')]({'where':{'id':_0x497d7b[_0x2316('0x46')]['id']}})[_0x2316('0x26')](handleEntityNotFound(_0x2481c5,null))[_0x2316('0x26')](removeEntity(_0x2481c5,null))[_0x2316('0x3f')](handleError(_0x2481c5,null));};exports[_0x2316('0x47')]=function(_0x4fd588,_0x1f6a84,_0x4e80e2){var _0x5d74fd={};var _0x30ff80={};var _0x3d8817;var _0xdfdb1c;return db[_0x2316('0x3b')]['findOne']({'where':{'id':_0x4fd588[_0x2316('0x46')]['id']}})[_0x2316('0x26')](handleEntityNotFound(_0x1f6a84,null))[_0x2316('0x26')](function(_0x33e20d){if(_0x33e20d){_0x3d8817=_0x33e20d;_0x30ff80[_0x2316('0x30')]=_[_0x2316('0x2e')](db[_0x2316('0x48')][_0x2316('0x2a')]);_0x30ff80['query']=_[_0x2316('0x2e')](_0x4fd588[_0x2316('0x2f')]);_0x30ff80['filters']=_[_0x2316('0x40')](_0x30ff80[_0x2316('0x30')],_0x30ff80['query']);_0x5d74fd[_0x2316('0x31')]=_[_0x2316('0x40')](_0x30ff80[_0x2316('0x30')],qs[_0x2316('0x32')](_0x4fd588[_0x2316('0x2f')]['fields']));_0x5d74fd['attributes']=_0x5d74fd[_0x2316('0x31')][_0x2316('0x49')]?_0x5d74fd[_0x2316('0x31')]:_0x30ff80[_0x2316('0x30')];_0x5d74fd[_0x2316('0x4a')]=qs[_0x2316('0x34')](_0x4fd588['query'][_0x2316('0x34')]);_0x5d74fd[_0x2316('0x35')]=qs[_0x2316('0x37')](_[_0x2316('0x36')](_0x4fd588[_0x2316('0x2f')],_0x30ff80[_0x2316('0x37')]));if(_0x4fd588[_0x2316('0x2f')][_0x2316('0x38')]){_0x5d74fd[_0x2316('0x35')]=_['merge'](_0x5d74fd[_0x2316('0x35')],{'$or':_['map'](_0x5d74fd[_0x2316('0x31')],function(_0x5c431b){var _0x185912={};_0x185912[_0x5c431b]={'$like':'%'+_0x4fd588[_0x2316('0x2f')][_0x2316('0x38')]+'%'};return _0x185912;})});}_0x5d74fd=_[_0x2316('0x3a')]({},_0x5d74fd,_0x4fd588[_0x2316('0x42')]);return _0x3d8817[_0x2316('0x47')](_0x5d74fd);}})[_0x2316('0x26')](function(_0x4d58b8){if(_0x4d58b8){_0xdfdb1c=_0x4d58b8['length'];if(!_0x4fd588[_0x2316('0x2f')][_0x2316('0x33')](_0x2316('0x4b'))){_0x5d74fd[_0x2316('0x1e')]=qs[_0x2316('0x1e')](_0x4fd588[_0x2316('0x2f')][_0x2316('0x1e')]);_0x5d74fd['offset']=qs[_0x2316('0x1b')](_0x4fd588[_0x2316('0x2f')]['offset']);}return _0x3d8817[_0x2316('0x47')](_0x5d74fd);}})[_0x2316('0x26')](function(_0x3c3044){if(_0x3c3044){return _0x3c3044?{'count':_0xdfdb1c,'rows':_0x3c3044}:null;}})[_0x2316('0x26')](respondWithResult(_0x1f6a84,null))[_0x2316('0x3f')](handleError(_0x1f6a84,null));};exports[_0x2316('0x4c')]=function(_0x505a35,_0x24b8ea,_0x3318f3){if(_0x505a35['body']['id']){delete _0x505a35[_0x2316('0x45')]['id'];}return db['DeskAccount']['findOne']({'where':{'id':_0x505a35[_0x2316('0x46')]['id']}})[_0x2316('0x26')](handleEntityNotFound(_0x24b8ea,null))[_0x2316('0x26')](function(_0x467f9e){if(_0x467f9e){_0x505a35[_0x2316('0x45')][_0x2316('0x4d')]=_0x467f9e['id'];_0x505a35[_0x2316('0x45')][_0x2316('0x4e')]=integrations[_0x2316('0x4f')](_0x505a35[_0x2316('0x45')]['channel'],_0x505a35[_0x2316('0x45')]['type']);_0x505a35[_0x2316('0x45')][_0x2316('0x50')]=integrations['getDescriptions'](_0x505a35[_0x2316('0x45')][_0x2316('0x51')],_0x505a35[_0x2316('0x45')]['type']);return db['DeskConfiguration'][_0x2316('0x44')](_0x505a35['body'],{'include':[{'model':db[_0x2316('0x52')],'as':'Subjects'},{'model':db[_0x2316('0x52')],'as':_0x2316('0x50')}]});}return null;})[_0x2316('0x26')](respondWithResult(_0x24b8ea,null))[_0x2316('0x3f')](handleError(_0x24b8ea,null));};exports[_0x2316('0x53')]=function(_0x488033,_0x232f23,_0x3f056a){var _0x25c0e6=[{'name':_0x2316('0x54'),'label':_0x2316('0x54'),'custom':![],'options':[{'name':0x1,'value':0x1},{'name':0x2,'value':0x2},{'name':0x3,'value':0x3},{'name':0x4,'value':0x4},{'name':0x5,'value':0x5},{'name':0x6,'value':0x6},{'name':0x7,'value':0x7},{'name':0x8,'value':0x8},{'name':0x9,'value':0x9},{'name':0xa,'value':0xa}]}];var _0x41d7a3='';return db[_0x2316('0x3b')][_0x2316('0x55')]({'where':{'id':_0x488033[_0x2316('0x46')]['id']},'attributes':['id',_0x2316('0x56'),_0x2316('0x57'),_0x2316('0x58'),_0x2316('0x59'),_0x2316('0x5a'),_0x2316('0x5b'),_0x2316('0x5c'),_0x2316('0x5d')]})['then'](handleEntityNotFound(_0x232f23,null))['then'](function(_0x2506b0){if(_0x2506b0){_0x41d7a3=_0x2506b0[_0x2316('0x56')];var _0x18ab24=_0x41d7a3[_0x2316('0x5e')](-0x1);if(_0x18ab24==='/'){_0x41d7a3=_0x41d7a3['substring'](0x0,_0x41d7a3[_0x2316('0x5f')](_0x18ab24));}var _0x4c3e9f={'method':'GET','uri':util['format'](_0x2316('0x60'),_0x41d7a3),'headers':{'Content-Type':_0x2316('0x61'),'Accept':_0x2316('0x61')},'json':!![]};if(_0x2506b0[_0x2316('0x57')]===_0x2316('0x62')){_0x4c3e9f[_0x2316('0x63')][_0x2316('0x64')]=util[_0x2316('0x65')]('Basic\x20%s',new Buffer(util[_0x2316('0x65')](_0x2316('0x66'),_0x2506b0[_0x2316('0x58')],_0x2506b0['password']))['toString'](_0x2316('0x67')));}return rp(_0x4c3e9f)[_0x2316('0x26')](function(_0x39814e){return _0x25c0e6[_0x2316('0x68')](_['map'](_0x39814e[_0x2316('0x69')][_0x2316('0x6a')],function(_0x3900d1){return{'id':_0x3900d1[_0x2316('0x28')],'name':_0x3900d1[_0x2316('0x28')],'type':_0x3900d1[_0x2316('0x2c')],'active':_0x3900d1[_0x2316('0x6b')],'label':_0x3900d1['label'],'custom':!![]};}));});}})[_0x2316('0x26')](function(_0x4fc064){return{'count':_0x4fc064[_0x2316('0x49')],'rows':_0x4fc064};})[_0x2316('0x26')](respondWithResult(_0x232f23,null))[_0x2316('0x3f')](function(_0xc4ccc2){var _0x15d75b=_0x488033[_0x2316('0x2f')][_0x2316('0x6c')]?0x1f4:_0xc4ccc2['statusCode']||0x1f4;logger[_0x2316('0x27')]('getFields,\x20%s,\x20%s,\x20%s',_0x2316('0x53'),_0x15d75b,JSON[_0x2316('0x6d')](_0xc4ccc2));delete _0xc4ccc2['name'];if(_0x15d75b===0x191){_0x15d75b=0x190;}_0x232f23[_0x2316('0x18')](_0x15d75b)[_0x2316('0x6e')](_0x488033[_0x2316('0x2f')][_0x2316('0x6c')]?{'message':_0x2316('0x6f'),'statusCode':_0xc4ccc2[_0x2316('0x70')]}:_0xc4ccc2);});};
\ No newline at end of file