Built motion from commit b5413ace.|2.6.9
[motion2.git] / server / api / intDeskAccount / intDeskAccount.controller.js
1 // *************************************************************************
2 // *                                                                       *
3 // * xCALLY Motion -  The Omnichannel Contact Center                       *
4 // * Copyright (c) Xenialab s.r.l. All Rights Reserved                     *
5 // *                                                                       *
6 // *************************************************************************
7 // *                                                                       *
8 // * Email: info@xcally.com                                                *
9 // * Website: https://www.xcally.com                                       *
10 // *                                                                       *
11 // *************************************************************************
12 // *                                                                       *
13 // * The SOFTWARE PRODUCT is protected by copyright laws and international *
14 // * copyright treaties, as well as other intellectual property laws and   *
15 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                         *
16 // *                                                                       *
17 // *************************************************************************
18 var _0xf1c8=['DeskField','getFields','priority','remoteUri','password','consumerKey','consumerSecret','token','slice','substring','lastIndexOf','%s/custom_fields','application/json','authType','Authorization','format','%s:%s','username','toString','concat','_embedded','entries','active','label','test','getFields,\x20%s,\x20%s,\x20%s','Wrong\x20credentials','statusCode','eml-format','rimraf','zip-dir','fast-json-patch','request-promise','mustache','util','path','to-csv','lodash','squel','crypto','querystring','ioredis','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','api','../../config/utils','../../components/integrations/configuration','sendStatus','status','end','offset','limit','count','set','Content-Range','save','update','then','error','name','send','index','map','DeskAccount','rawAttributes','fieldName','key','query','keys','intersection','model','attributes','hasOwnProperty','nolimit','order','sort','where','pick','filters','filter','merge','type','VIRTUAL','options','includeAll','findAll','rows','catch','show','params','fields','length','include','find','body','findOne','DeskConfiguration','getConfigurations','addConfiguration','AccountId','Subjects','getSubjects','channel','Descriptions','getDescriptions','create'];(function(_0x3e12fd,_0x3cb5fc){var _0x6c8a9c=function(_0x5139ab){while(--_0x5139ab){_0x3e12fd['push'](_0x3e12fd['shift']());}};_0x6c8a9c(++_0x3cb5fc);}(_0xf1c8,0x15d));var _0x8f1c=function(_0x5392e8,_0x1ca8b9){_0x5392e8=_0x5392e8-0x0;var _0x43fce6=_0xf1c8[_0x5392e8];return _0x43fce6;};'use strict';var emlformat=require(_0x8f1c('0x0'));var rimraf=require(_0x8f1c('0x1'));var zipdir=require(_0x8f1c('0x2'));var jsonpatch=require(_0x8f1c('0x3'));var rp=require(_0x8f1c('0x4'));var moment=require('moment');var BPromise=require('bluebird');var Mustache=require(_0x8f1c('0x5'));var util=require(_0x8f1c('0x6'));var path=require(_0x8f1c('0x7'));var sox=require('sox');var csv=require(_0x8f1c('0x8'));var ejs=require('ejs');var fs=require('fs');var fs_extra=require('fs-extra');var _=require(_0x8f1c('0x9'));var squel=require(_0x8f1c('0xa'));var crypto=require(_0x8f1c('0xb'));var jsforce=require('jsforce');var deskjs=require('desk.js');var toCsv=require(_0x8f1c('0x8'));var querystring=require(_0x8f1c('0xc'));var Papa=require('papaparse');var Redis=require(_0x8f1c('0xd'));var authService=require('../../components/auth/service');var qs=require(_0x8f1c('0xe'));var as=require(_0x8f1c('0xf'));var hardwareService=require(_0x8f1c('0x10'));var logger=require('../../config/logger')(_0x8f1c('0x11'));var utils=require(_0x8f1c('0x12'));var config=require('../../config/environment');var licenseUtil=require('../../config/license/util');var db=require('../../mysqldb')['db'];var integrations=require(_0x8f1c('0x13'));function respondWithStatusCode(_0x30bb13,_0x49885a){_0x49885a=_0x49885a||0xcc;return function(_0x506153){if(_0x506153){return _0x30bb13[_0x8f1c('0x14')](_0x49885a);}return _0x30bb13[_0x8f1c('0x15')](_0x49885a)[_0x8f1c('0x16')]();};}function respondWithResult(_0x2973c2,_0x5cf16d){_0x5cf16d=_0x5cf16d||0xc8;return function(_0xe8313e){if(_0xe8313e){return _0x2973c2['status'](_0x5cf16d)['json'](_0xe8313e);}};}function respondWithFilteredResult(_0x10fe4a,_0x2d24f7){return function(_0x97c312){if(_0x97c312){var _0x469e96=typeof _0x2d24f7[_0x8f1c('0x17')]==='undefined'&&typeof _0x2d24f7[_0x8f1c('0x18')]==='undefined';var _0x5d04f0=_0x97c312[_0x8f1c('0x19')];var _0x30cea2=_0x469e96?0x0:_0x2d24f7['offset'];var _0x4fae42=_0x469e96?_0x97c312[_0x8f1c('0x19')]:_0x2d24f7[_0x8f1c('0x17')]+_0x2d24f7[_0x8f1c('0x18')];var _0x1be8d6;if(_0x4fae42>=_0x5d04f0){_0x4fae42=_0x5d04f0;_0x1be8d6=0xc8;}else{_0x1be8d6=0xce;}_0x10fe4a['status'](_0x1be8d6);return _0x10fe4a[_0x8f1c('0x1a')](_0x8f1c('0x1b'),_0x30cea2+'-'+_0x4fae42+'/'+_0x5d04f0)['json'](_0x97c312);}return null;};}function patchUpdates(_0x119736){return function(_0x46e757){try{jsonpatch['apply'](_0x46e757,_0x119736,!![]);}catch(_0x111140){return BPromise['reject'](_0x111140);}return _0x46e757[_0x8f1c('0x1c')]();};}function saveUpdates(_0x1be26b,_0x24d42e){return function(_0x2c7695){if(_0x2c7695){return _0x2c7695[_0x8f1c('0x1d')](_0x1be26b)[_0x8f1c('0x1e')](function(_0x255f9a){return _0x255f9a;});}return null;};}function removeEntity(_0x4a7ec5,_0x509e1f){return function(_0x9cffd5){if(_0x9cffd5){return _0x9cffd5['destroy']()[_0x8f1c('0x1e')](function(){_0x4a7ec5[_0x8f1c('0x15')](0xcc)['end']();});}};}function handleEntityNotFound(_0x87aabe,_0x9e684d){return function(_0xc3deb4){if(!_0xc3deb4){_0x87aabe[_0x8f1c('0x14')](0x194);}return _0xc3deb4;};}function handleError(_0x3501bf,_0x19c037){_0x19c037=_0x19c037||0x1f4;return function(_0x455f66){logger[_0x8f1c('0x1f')](_0x455f66['stack']);if(_0x455f66[_0x8f1c('0x20')]){delete _0x455f66[_0x8f1c('0x20')];}_0x3501bf['status'](_0x19c037)[_0x8f1c('0x21')](_0x455f66);};}exports[_0x8f1c('0x22')]=function(_0x47530b,_0x4eed99){var _0x2b54b2={},_0x5a1a8f={},_0x1b9bb2={'count':0x0,'rows':[]};var _0x7ff259=_[_0x8f1c('0x23')](db[_0x8f1c('0x24')][_0x8f1c('0x25')],function(_0xfec2da){return{'name':_0xfec2da[_0x8f1c('0x26')],'type':_0xfec2da['type'][_0x8f1c('0x27')]};});_0x5a1a8f['model']=_[_0x8f1c('0x23')](_0x7ff259,_0x8f1c('0x20'));_0x5a1a8f[_0x8f1c('0x28')]=_[_0x8f1c('0x29')](_0x47530b[_0x8f1c('0x28')]);_0x5a1a8f['filters']=_[_0x8f1c('0x2a')](_0x5a1a8f[_0x8f1c('0x2b')],_0x5a1a8f[_0x8f1c('0x28')]);_0x2b54b2[_0x8f1c('0x2c')]=_[_0x8f1c('0x2a')](_0x5a1a8f[_0x8f1c('0x2b')],qs['fields'](_0x47530b['query']['fields']));_0x2b54b2[_0x8f1c('0x2c')]=_0x2b54b2[_0x8f1c('0x2c')]['length']?_0x2b54b2[_0x8f1c('0x2c')]:_0x5a1a8f[_0x8f1c('0x2b')];if(!_0x47530b['query'][_0x8f1c('0x2d')](_0x8f1c('0x2e'))){_0x2b54b2[_0x8f1c('0x18')]=qs[_0x8f1c('0x18')](_0x47530b[_0x8f1c('0x28')][_0x8f1c('0x18')]);_0x2b54b2[_0x8f1c('0x17')]=qs['offset'](_0x47530b[_0x8f1c('0x28')][_0x8f1c('0x17')]);}_0x2b54b2[_0x8f1c('0x2f')]=qs[_0x8f1c('0x30')](_0x47530b[_0x8f1c('0x28')][_0x8f1c('0x30')]);_0x2b54b2[_0x8f1c('0x31')]=qs['filters'](_[_0x8f1c('0x32')](_0x47530b['query'],_0x5a1a8f[_0x8f1c('0x33')]),_0x7ff259);if(_0x47530b[_0x8f1c('0x28')][_0x8f1c('0x34')]){_0x2b54b2[_0x8f1c('0x31')]=_[_0x8f1c('0x35')](_0x2b54b2[_0x8f1c('0x31')],{'$or':_['map'](_0x7ff259,function(_0x2a5f4e){if(_0x2a5f4e[_0x8f1c('0x36')]!==_0x8f1c('0x37')){var _0x39742a={};_0x39742a[_0x2a5f4e[_0x8f1c('0x20')]]={'$like':'%'+_0x47530b[_0x8f1c('0x28')]['filter']+'%'};return _0x39742a;}})});}_0x2b54b2=_['merge']({},_0x2b54b2,_0x47530b[_0x8f1c('0x38')]);var _0x36c823={'where':_0x2b54b2[_0x8f1c('0x31')]};return db['DeskAccount'][_0x8f1c('0x19')](_0x36c823)[_0x8f1c('0x1e')](function(_0x3d433b){_0x1b9bb2[_0x8f1c('0x19')]=_0x3d433b;if(_0x47530b['query'][_0x8f1c('0x39')]){_0x2b54b2['include']=[{'all':!![]}];}return db[_0x8f1c('0x24')][_0x8f1c('0x3a')](_0x2b54b2);})[_0x8f1c('0x1e')](function(_0x5b1713){_0x1b9bb2[_0x8f1c('0x3b')]=_0x5b1713;return _0x1b9bb2;})[_0x8f1c('0x1e')](respondWithFilteredResult(_0x4eed99,_0x2b54b2))[_0x8f1c('0x3c')](handleError(_0x4eed99,null));};exports[_0x8f1c('0x3d')]=function(_0x116536,_0x2f03c5){var _0x3e551a={'raw':![],'where':{'id':_0x116536[_0x8f1c('0x3e')]['id']}},_0x13f833={};_0x13f833['model']=_[_0x8f1c('0x29')](db[_0x8f1c('0x24')][_0x8f1c('0x25')]);_0x13f833[_0x8f1c('0x28')]=_[_0x8f1c('0x29')](_0x116536[_0x8f1c('0x28')]);_0x13f833[_0x8f1c('0x33')]=_[_0x8f1c('0x2a')](_0x13f833[_0x8f1c('0x2b')],_0x13f833[_0x8f1c('0x28')]);_0x3e551a[_0x8f1c('0x2c')]=_[_0x8f1c('0x2a')](_0x13f833[_0x8f1c('0x2b')],qs[_0x8f1c('0x3f')](_0x116536[_0x8f1c('0x28')][_0x8f1c('0x3f')]));_0x3e551a[_0x8f1c('0x2c')]=_0x3e551a['attributes'][_0x8f1c('0x40')]?_0x3e551a[_0x8f1c('0x2c')]:_0x13f833[_0x8f1c('0x2b')];if(_0x116536[_0x8f1c('0x28')][_0x8f1c('0x39')]){_0x3e551a[_0x8f1c('0x41')]=[{'all':!![]}];}_0x3e551a=_[_0x8f1c('0x35')]({},_0x3e551a,_0x116536[_0x8f1c('0x38')]);return db[_0x8f1c('0x24')][_0x8f1c('0x42')](_0x3e551a)[_0x8f1c('0x1e')](handleEntityNotFound(_0x2f03c5,null))[_0x8f1c('0x1e')](respondWithResult(_0x2f03c5,null))[_0x8f1c('0x3c')](handleError(_0x2f03c5,null));};exports['create']=function(_0x25a929,_0x263aaa){return db['DeskAccount']['create'](_0x25a929['body'],{})[_0x8f1c('0x1e')](respondWithResult(_0x263aaa,0xc9))[_0x8f1c('0x3c')](handleError(_0x263aaa,null));};exports[_0x8f1c('0x1d')]=function(_0x5c19b8,_0x46d4c3){if(_0x5c19b8['body']['id']){delete _0x5c19b8[_0x8f1c('0x43')]['id'];}return db[_0x8f1c('0x24')][_0x8f1c('0x42')]({'where':{'id':_0x5c19b8[_0x8f1c('0x3e')]['id']}})['then'](handleEntityNotFound(_0x46d4c3,null))[_0x8f1c('0x1e')](saveUpdates(_0x5c19b8[_0x8f1c('0x43')],null))[_0x8f1c('0x1e')](respondWithResult(_0x46d4c3,null))[_0x8f1c('0x3c')](handleError(_0x46d4c3,null));};exports['destroy']=function(_0x33ed5a,_0x29832c){return db[_0x8f1c('0x24')]['find']({'where':{'id':_0x33ed5a[_0x8f1c('0x3e')]['id']}})['then'](handleEntityNotFound(_0x29832c,null))[_0x8f1c('0x1e')](removeEntity(_0x29832c,null))[_0x8f1c('0x3c')](handleError(_0x29832c,null));};exports['getConfigurations']=function(_0x2eb9d3,_0x2593a1,_0x57b36a){var _0x442dad={};var _0x448f14={};var _0x552171;var _0x315cff;return db[_0x8f1c('0x24')][_0x8f1c('0x44')]({'where':{'id':_0x2eb9d3['params']['id']}})[_0x8f1c('0x1e')](handleEntityNotFound(_0x2593a1,null))['then'](function(_0xe793ee){if(_0xe793ee){_0x552171=_0xe793ee;_0x448f14['model']=_[_0x8f1c('0x29')](db[_0x8f1c('0x45')][_0x8f1c('0x25')]);_0x448f14[_0x8f1c('0x28')]=_[_0x8f1c('0x29')](_0x2eb9d3['query']);_0x448f14[_0x8f1c('0x33')]=_[_0x8f1c('0x2a')](_0x448f14[_0x8f1c('0x2b')],_0x448f14[_0x8f1c('0x28')]);_0x442dad[_0x8f1c('0x2c')]=_['intersection'](_0x448f14[_0x8f1c('0x2b')],qs[_0x8f1c('0x3f')](_0x2eb9d3[_0x8f1c('0x28')][_0x8f1c('0x3f')]));_0x442dad[_0x8f1c('0x2c')]=_0x442dad[_0x8f1c('0x2c')][_0x8f1c('0x40')]?_0x442dad[_0x8f1c('0x2c')]:_0x448f14[_0x8f1c('0x2b')];_0x442dad[_0x8f1c('0x2f')]=qs[_0x8f1c('0x30')](_0x2eb9d3[_0x8f1c('0x28')]['sort']);_0x442dad[_0x8f1c('0x31')]=qs[_0x8f1c('0x33')](_[_0x8f1c('0x32')](_0x2eb9d3['query'],_0x448f14['filters']));if(_0x2eb9d3[_0x8f1c('0x28')][_0x8f1c('0x34')]){_0x442dad[_0x8f1c('0x31')]=_[_0x8f1c('0x35')](_0x442dad['where'],{'$or':_[_0x8f1c('0x23')](_0x442dad['attributes'],function(_0x3be888){var _0x90aab6={};_0x90aab6[_0x3be888]={'$like':'%'+_0x2eb9d3[_0x8f1c('0x28')][_0x8f1c('0x34')]+'%'};return _0x90aab6;})});}_0x442dad=_[_0x8f1c('0x35')]({},_0x442dad,_0x2eb9d3['options']);return _0x552171[_0x8f1c('0x46')](_0x442dad);}})[_0x8f1c('0x1e')](function(_0x1b4b8d){if(_0x1b4b8d){_0x315cff=_0x1b4b8d[_0x8f1c('0x40')];if(!_0x2eb9d3[_0x8f1c('0x28')][_0x8f1c('0x2d')]('nolimit')){_0x442dad[_0x8f1c('0x18')]=qs[_0x8f1c('0x18')](_0x2eb9d3['query']['limit']);_0x442dad[_0x8f1c('0x17')]=qs[_0x8f1c('0x17')](_0x2eb9d3[_0x8f1c('0x28')][_0x8f1c('0x17')]);}return _0x552171['getConfigurations'](_0x442dad);}})['then'](function(_0xd7af9a){if(_0xd7af9a){return _0xd7af9a?{'count':_0x315cff,'rows':_0xd7af9a}:null;}})[_0x8f1c('0x1e')](respondWithResult(_0x2593a1,null))[_0x8f1c('0x3c')](handleError(_0x2593a1,null));};exports[_0x8f1c('0x47')]=function(_0x1e0db0,_0x3db501,_0x4c24b7){if(_0x1e0db0[_0x8f1c('0x43')]['id']){delete _0x1e0db0[_0x8f1c('0x43')]['id'];}return db[_0x8f1c('0x24')][_0x8f1c('0x44')]({'where':{'id':_0x1e0db0[_0x8f1c('0x3e')]['id']}})[_0x8f1c('0x1e')](handleEntityNotFound(_0x3db501,null))[_0x8f1c('0x1e')](function(_0x4a9b5b){if(_0x4a9b5b){_0x1e0db0[_0x8f1c('0x43')][_0x8f1c('0x48')]=_0x4a9b5b['id'];_0x1e0db0[_0x8f1c('0x43')][_0x8f1c('0x49')]=integrations[_0x8f1c('0x4a')](_0x1e0db0[_0x8f1c('0x43')][_0x8f1c('0x4b')],_0x1e0db0[_0x8f1c('0x43')]['type']);_0x1e0db0[_0x8f1c('0x43')][_0x8f1c('0x4c')]=integrations[_0x8f1c('0x4d')](_0x1e0db0[_0x8f1c('0x43')]['channel'],_0x1e0db0[_0x8f1c('0x43')]['type']);return db[_0x8f1c('0x45')][_0x8f1c('0x4e')](_0x1e0db0[_0x8f1c('0x43')],{'include':[{'model':db[_0x8f1c('0x4f')],'as':_0x8f1c('0x49')},{'model':db[_0x8f1c('0x4f')],'as':_0x8f1c('0x4c')}]});}return null;})[_0x8f1c('0x1e')](respondWithResult(_0x3db501,null))[_0x8f1c('0x3c')](handleError(_0x3db501,null));};exports[_0x8f1c('0x50')]=function(_0x8f7dd9,_0x147ebb,_0x4a4488){var _0x2e44a2=[{'name':'priority','label':_0x8f1c('0x51'),'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 _0x52530b='';return db[_0x8f1c('0x24')][_0x8f1c('0x44')]({'where':{'id':_0x8f7dd9[_0x8f1c('0x3e')]['id']},'attributes':['id',_0x8f1c('0x52'),'authType','username',_0x8f1c('0x53'),_0x8f1c('0x54'),_0x8f1c('0x55'),_0x8f1c('0x56'),'tokenSecret']})['then'](handleEntityNotFound(_0x147ebb,null))[_0x8f1c('0x1e')](function(_0x1ea03b){if(_0x1ea03b){_0x52530b=_0x1ea03b[_0x8f1c('0x52')];var _0x3aecc6=_0x52530b[_0x8f1c('0x57')](-0x1);if(_0x3aecc6==='/'){_0x52530b=_0x52530b[_0x8f1c('0x58')](0x0,_0x52530b[_0x8f1c('0x59')](_0x3aecc6));}var _0x575d9e={'method':'GET','uri':util['format'](_0x8f1c('0x5a'),_0x52530b),'headers':{'Content-Type':_0x8f1c('0x5b'),'Accept':_0x8f1c('0x5b')},'json':!![]};if(_0x1ea03b[_0x8f1c('0x5c')]==='basic'){_0x575d9e['headers'][_0x8f1c('0x5d')]=util[_0x8f1c('0x5e')]('Basic\x20%s',new Buffer(util['format'](_0x8f1c('0x5f'),_0x1ea03b[_0x8f1c('0x60')],_0x1ea03b['password']))[_0x8f1c('0x61')]('base64'));}return rp(_0x575d9e)[_0x8f1c('0x1e')](function(_0x32a937){return _0x2e44a2[_0x8f1c('0x62')](_['map'](_0x32a937[_0x8f1c('0x63')][_0x8f1c('0x64')],function(_0x1efdaa){return{'id':_0x1efdaa[_0x8f1c('0x20')],'name':_0x1efdaa[_0x8f1c('0x20')],'type':_0x1efdaa[_0x8f1c('0x36')],'active':_0x1efdaa[_0x8f1c('0x65')],'label':_0x1efdaa[_0x8f1c('0x66')],'custom':!![]};}));});}})['then'](function(_0x4768d9){return{'count':_0x4768d9['length'],'rows':_0x4768d9};})[_0x8f1c('0x1e')](respondWithResult(_0x147ebb,null))[_0x8f1c('0x3c')](function(_0x332ecc){var _0xb7b418=_0x8f7dd9[_0x8f1c('0x28')][_0x8f1c('0x67')]?0x1f4:_0x332ecc['statusCode']||0x1f4;logger[_0x8f1c('0x1f')](_0x8f1c('0x68'),_0x8f1c('0x50'),_0xb7b418,JSON['stringify'](_0x332ecc));delete _0x332ecc[_0x8f1c('0x20')];if(_0xb7b418===0x191){_0xb7b418=0x190;}_0x147ebb[_0x8f1c('0x15')](_0xb7b418)[_0x8f1c('0x21')](_0x8f7dd9[_0x8f1c('0x28')][_0x8f1c('0x67')]?{'message':_0x8f1c('0x69'),'statusCode':_0x332ecc[_0x8f1c('0x6a')]}:_0x332ecc);});};