Built motion from commit ddca4d0d.|2.5.47
[motion2.git] / server / api / cmHopperHistory / cmHopperHistory.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 _0xe61f=['create','body','describe','uniqueid','params','eml-format','rimraf','request-promise','moment','mustache','util','path','sox','lodash','crypto','jsforce','desk.js','querystring','papaparse','ioredis','../../components/auth/service','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','../../config/utils','../../config/environment','../../mysqldb','status','end','json','offset','undefined','limit','count','set','Content-Range','reject','save','update','then','destroy','name','index','map','rawAttributes','fieldName','type','key','model','query','keys','intersection','attributes','fields','hasOwnProperty','nolimit','sort','where','pick','merge','VIRTUAL','CmHopperHistory','includeAll','findAll','rows','catch','show','filters','include','options'];(function(_0x368bba,_0x1f625b){var _0x409f8f=function(_0x463373){while(--_0x463373){_0x368bba['push'](_0x368bba['shift']());}};_0x409f8f(++_0x1f625b);}(_0xe61f,0x11d));var _0xfe61=function(_0xfae23b,_0x2be4ba){_0xfae23b=_0xfae23b-0x0;var _0x200640=_0xe61f[_0xfae23b];return _0x200640;};'use strict';var emlformat=require(_0xfe61('0x0'));var rimraf=require(_0xfe61('0x1'));var zipdir=require('zip-dir');var jsonpatch=require('fast-json-patch');var rp=require(_0xfe61('0x2'));var moment=require(_0xfe61('0x3'));var BPromise=require('bluebird');var Mustache=require(_0xfe61('0x4'));var util=require(_0xfe61('0x5'));var path=require(_0xfe61('0x6'));var sox=require(_0xfe61('0x7'));var csv=require('to-csv');var ejs=require('ejs');var fs=require('fs');var fs_extra=require('fs-extra');var _=require(_0xfe61('0x8'));var squel=require('squel');var crypto=require(_0xfe61('0x9'));var jsforce=require(_0xfe61('0xa'));var deskjs=require(_0xfe61('0xb'));var toCsv=require('to-csv');var querystring=require(_0xfe61('0xc'));var Papa=require(_0xfe61('0xd'));var Redis=require(_0xfe61('0xe'));var authService=require(_0xfe61('0xf'));var qs=require('../../components/parsers/qs');var as=require(_0xfe61('0x10'));var hardwareService=require(_0xfe61('0x11'));var logger=require(_0xfe61('0x12'))('api');var utils=require(_0xfe61('0x13'));var config=require(_0xfe61('0x14'));var licenseUtil=require('../../config/license/util');var db=require(_0xfe61('0x15'))['db'];function respondWithStatusCode(_0x1dbe4c,_0x3dde46){_0x3dde46=_0x3dde46||0xcc;return function(_0x483b09){if(_0x483b09){return _0x1dbe4c['sendStatus'](_0x3dde46);}return _0x1dbe4c[_0xfe61('0x16')](_0x3dde46)[_0xfe61('0x17')]();};}function respondWithResult(_0x1402bc,_0x47ec05){_0x47ec05=_0x47ec05||0xc8;return function(_0x146141){if(_0x146141){return _0x1402bc[_0xfe61('0x16')](_0x47ec05)[_0xfe61('0x18')](_0x146141);}};}function respondWithFilteredResult(_0x51ab93,_0x518447){return function(_0x3e3c9e){if(_0x3e3c9e){var _0xee21b0=typeof _0x518447[_0xfe61('0x19')]===_0xfe61('0x1a')&&typeof _0x518447[_0xfe61('0x1b')]===_0xfe61('0x1a');var _0x41db19=_0x3e3c9e['count'];var _0x40fe81=_0xee21b0?0x0:_0x518447[_0xfe61('0x19')];var _0x28d9b4=_0xee21b0?_0x3e3c9e[_0xfe61('0x1c')]:_0x518447[_0xfe61('0x19')]+_0x518447[_0xfe61('0x1b')];var _0x4921ea;if(_0x28d9b4>=_0x41db19){_0x28d9b4=_0x41db19;_0x4921ea=0xc8;}else{_0x4921ea=0xce;}_0x51ab93[_0xfe61('0x16')](_0x4921ea);return _0x51ab93[_0xfe61('0x1d')](_0xfe61('0x1e'),_0x40fe81+'-'+_0x28d9b4+'/'+_0x41db19)[_0xfe61('0x18')](_0x3e3c9e);}return null;};}function patchUpdates(_0x420a12){return function(_0xbd219d){try{jsonpatch['apply'](_0xbd219d,_0x420a12,!![]);}catch(_0xa097ad){return BPromise[_0xfe61('0x1f')](_0xa097ad);}return _0xbd219d[_0xfe61('0x20')]();};}function saveUpdates(_0x28ac76,_0x1f8e7e){return function(_0x1f659d){if(_0x1f659d){return _0x1f659d[_0xfe61('0x21')](_0x28ac76)[_0xfe61('0x22')](function(_0x46673b){return _0x46673b;});}return null;};}function removeEntity(_0x5641c3,_0x209f64){return function(_0x2ef09a){if(_0x2ef09a){return _0x2ef09a[_0xfe61('0x23')]()[_0xfe61('0x22')](function(){_0x5641c3[_0xfe61('0x16')](0xcc)['end']();});}};}function handleEntityNotFound(_0x2adf7b,_0x3405af){return function(_0x1c07c6){if(!_0x1c07c6){_0x2adf7b['sendStatus'](0x194);}return _0x1c07c6;};}function handleError(_0x4d0b98,_0x38fd57){_0x38fd57=_0x38fd57||0x1f4;return function(_0x2ae46c){logger['error'](_0x2ae46c['stack']);if(_0x2ae46c[_0xfe61('0x24')]){delete _0x2ae46c[_0xfe61('0x24')];}_0x4d0b98[_0xfe61('0x16')](_0x38fd57)['send'](_0x2ae46c);};}exports[_0xfe61('0x25')]=function(_0x22f0a2,_0x47edde){var _0xee2c11={},_0x1ad822={},_0x3298b9={'count':0x0,'rows':[]};var _0x3f067f=_[_0xfe61('0x26')](db['CmHopperHistory'][_0xfe61('0x27')],function(_0x231f43){return{'name':_0x231f43[_0xfe61('0x28')],'type':_0x231f43[_0xfe61('0x29')][_0xfe61('0x2a')]};});_0x1ad822[_0xfe61('0x2b')]=_[_0xfe61('0x26')](_0x3f067f,_0xfe61('0x24'));_0x1ad822[_0xfe61('0x2c')]=_[_0xfe61('0x2d')](_0x22f0a2[_0xfe61('0x2c')]);_0x1ad822['filters']=_[_0xfe61('0x2e')](_0x1ad822['model'],_0x1ad822[_0xfe61('0x2c')]);_0xee2c11[_0xfe61('0x2f')]=_[_0xfe61('0x2e')](_0x1ad822[_0xfe61('0x2b')],qs[_0xfe61('0x30')](_0x22f0a2[_0xfe61('0x2c')][_0xfe61('0x30')]));_0xee2c11[_0xfe61('0x2f')]=_0xee2c11[_0xfe61('0x2f')]['length']?_0xee2c11['attributes']:_0x1ad822[_0xfe61('0x2b')];if(!_0x22f0a2[_0xfe61('0x2c')][_0xfe61('0x31')](_0xfe61('0x32'))){_0xee2c11[_0xfe61('0x1b')]=qs[_0xfe61('0x1b')](_0x22f0a2['query'][_0xfe61('0x1b')]);_0xee2c11[_0xfe61('0x19')]=qs[_0xfe61('0x19')](_0x22f0a2[_0xfe61('0x2c')][_0xfe61('0x19')]);}_0xee2c11['order']=qs['sort'](_0x22f0a2[_0xfe61('0x2c')][_0xfe61('0x33')]);_0xee2c11[_0xfe61('0x34')]=qs['filters'](_[_0xfe61('0x35')](_0x22f0a2['query'],_0x1ad822['filters']),_0x3f067f);if(_0x22f0a2['query']['filter']){_0xee2c11['where']=_[_0xfe61('0x36')](_0xee2c11['where'],{'$or':_[_0xfe61('0x26')](_0x3f067f,function(_0x12b21a){if(_0x12b21a[_0xfe61('0x29')]!==_0xfe61('0x37')){var _0x102055={};_0x102055[_0x12b21a[_0xfe61('0x24')]]={'$like':'%'+_0x22f0a2[_0xfe61('0x2c')]['filter']+'%'};return _0x102055;}})});}_0xee2c11=_[_0xfe61('0x36')]({},_0xee2c11,_0x22f0a2['options']);var _0x560910={'where':_0xee2c11[_0xfe61('0x34')]};return db[_0xfe61('0x38')][_0xfe61('0x1c')](_0x560910)[_0xfe61('0x22')](function(_0x5cf322){_0x3298b9['count']=_0x5cf322;if(_0x22f0a2[_0xfe61('0x2c')][_0xfe61('0x39')]){_0xee2c11['include']=[{'all':!![]}];}return db['CmHopperHistory'][_0xfe61('0x3a')](_0xee2c11);})['then'](function(_0x296e95){_0x3298b9[_0xfe61('0x3b')]=_0x296e95;return _0x3298b9;})[_0xfe61('0x22')](respondWithFilteredResult(_0x47edde,_0xee2c11))[_0xfe61('0x3c')](handleError(_0x47edde,null));};exports[_0xfe61('0x3d')]=function(_0x5463b6,_0x248b86){var _0x4c19c3={'raw':!![],'where':{'id':_0x5463b6['params']['id']}},_0x406182={};_0x406182[_0xfe61('0x2b')]=_[_0xfe61('0x2d')](db[_0xfe61('0x38')][_0xfe61('0x27')]);_0x406182[_0xfe61('0x2c')]=_[_0xfe61('0x2d')](_0x5463b6[_0xfe61('0x2c')]);_0x406182[_0xfe61('0x3e')]=_[_0xfe61('0x2e')](_0x406182[_0xfe61('0x2b')],_0x406182[_0xfe61('0x2c')]);_0x4c19c3['attributes']=_[_0xfe61('0x2e')](_0x406182[_0xfe61('0x2b')],qs[_0xfe61('0x30')](_0x5463b6[_0xfe61('0x2c')][_0xfe61('0x30')]));_0x4c19c3['attributes']=_0x4c19c3[_0xfe61('0x2f')]['length']?_0x4c19c3[_0xfe61('0x2f')]:_0x406182['model'];if(_0x5463b6[_0xfe61('0x2c')]['includeAll']){_0x4c19c3[_0xfe61('0x3f')]=[{'all':!![]}];}_0x4c19c3=_['merge']({},_0x4c19c3,_0x5463b6[_0xfe61('0x40')]);return db[_0xfe61('0x38')]['find'](_0x4c19c3)[_0xfe61('0x22')](handleEntityNotFound(_0x248b86,null))['then'](respondWithResult(_0x248b86,null))[_0xfe61('0x3c')](handleError(_0x248b86,null));};exports[_0xfe61('0x41')]=function(_0x19588c,_0x31cdd7){return db['CmHopperHistory']['create'](_0x19588c[_0xfe61('0x42')],{})[_0xfe61('0x22')](respondWithResult(_0x31cdd7,0xc9))['catch'](handleError(_0x31cdd7,null));};exports[_0xfe61('0x43')]=function(_0xb37238,_0x4ae0e7){return db[_0xfe61('0x38')]['describe']()[_0xfe61('0x22')](respondWithResult(_0x4ae0e7,null))[_0xfe61('0x3c')](handleError(_0x4ae0e7,null));};exports[_0xfe61('0x21')]=function(_0x36dc58,_0x5a2eaa){if(_0x36dc58[_0xfe61('0x42')][_0xfe61('0x44')]){delete _0x36dc58[_0xfe61('0x42')][_0xfe61('0x44')];}return db[_0xfe61('0x38')]['find']({'where':{'uniqueid':_0x36dc58[_0xfe61('0x45')]['id']}})['then'](handleEntityNotFound(_0x5a2eaa,null))[_0xfe61('0x22')](saveUpdates(_0x36dc58[_0xfe61('0x42')],null))['then'](respondWithResult(_0x5a2eaa,null))[_0xfe61('0x3c')](handleError(_0x5a2eaa,null));};