9ecb8b4e9023e5f812b2d74a3eaaa17de8d6dd8b
[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 _0x15cf=['error','name','send','map','CmHopperHistory','rawAttributes','type','key','model','query','keys','filters','intersection','attributes','fields','length','hasOwnProperty','nolimit','sort','where','merge','VIRTUAL','filter','options','includeAll','catch','show','params','include','create','body','describe','uniqueid','find','eml-format','zip-dir','fast-json-patch','moment','bluebird','mustache','util','to-csv','ejs','squel','jsforce','desk.js','querystring','papaparse','ioredis','../../components/auth/service','../../config/license/hardware','api','../../config/utils','../../config/license/util','../../mysqldb','sendStatus','status','end','offset','undefined','limit','count','set','Content-Range','json','apply','reject','update','then'];(function(_0x28fca4,_0x11e78b){var _0x42fd01=function(_0x33a97e){while(--_0x33a97e){_0x28fca4['push'](_0x28fca4['shift']());}};_0x42fd01(++_0x11e78b);}(_0x15cf,0x17b));var _0xf15c=function(_0x4c98b9,_0x1ad11b){_0x4c98b9=_0x4c98b9-0x0;var _0x3a257a=_0x15cf[_0x4c98b9];return _0x3a257a;};'use strict';var emlformat=require(_0xf15c('0x0'));var rimraf=require('rimraf');var zipdir=require(_0xf15c('0x1'));var jsonpatch=require(_0xf15c('0x2'));var rp=require('request-promise');var moment=require(_0xf15c('0x3'));var BPromise=require(_0xf15c('0x4'));var Mustache=require(_0xf15c('0x5'));var util=require(_0xf15c('0x6'));var path=require('path');var sox=require('sox');var csv=require(_0xf15c('0x7'));var ejs=require(_0xf15c('0x8'));var fs=require('fs');var fs_extra=require('fs-extra');var _=require('lodash');var squel=require(_0xf15c('0x9'));var crypto=require('crypto');var jsforce=require(_0xf15c('0xa'));var deskjs=require(_0xf15c('0xb'));var toCsv=require(_0xf15c('0x7'));var querystring=require(_0xf15c('0xc'));var Papa=require(_0xf15c('0xd'));var Redis=require(_0xf15c('0xe'));var authService=require(_0xf15c('0xf'));var qs=require('../../components/parsers/qs');var as=require('../../components/parsers/advancedSearch');var hardwareService=require(_0xf15c('0x10'));var logger=require('../../config/logger')(_0xf15c('0x11'));var utils=require(_0xf15c('0x12'));var config=require('../../config/environment');var licenseUtil=require(_0xf15c('0x13'));var db=require(_0xf15c('0x14'))['db'];function respondWithStatusCode(_0x1fcf30,_0x1057fe){_0x1057fe=_0x1057fe||0xcc;return function(_0xc37bf2){if(_0xc37bf2){return _0x1fcf30[_0xf15c('0x15')](_0x1057fe);}return _0x1fcf30[_0xf15c('0x16')](_0x1057fe)[_0xf15c('0x17')]();};}function respondWithResult(_0xfc222,_0x50b2cd){_0x50b2cd=_0x50b2cd||0xc8;return function(_0x2af518){if(_0x2af518){return _0xfc222[_0xf15c('0x16')](_0x50b2cd)['json'](_0x2af518);}};}function respondWithFilteredResult(_0x3d9df8,_0x4eb20f){return function(_0x5dff2e){if(_0x5dff2e){var _0xc7cacd=typeof _0x4eb20f[_0xf15c('0x18')]===_0xf15c('0x19')&&typeof _0x4eb20f[_0xf15c('0x1a')]===_0xf15c('0x19');var _0x2603e1=_0x5dff2e[_0xf15c('0x1b')];var _0x2eec7e=_0xc7cacd?0x0:_0x4eb20f[_0xf15c('0x18')];var _0x5f09f5=_0xc7cacd?_0x5dff2e[_0xf15c('0x1b')]:_0x4eb20f['offset']+_0x4eb20f['limit'];var _0x52aa33;if(_0x5f09f5>=_0x2603e1){_0x5f09f5=_0x2603e1;_0x52aa33=0xc8;}else{_0x52aa33=0xce;}_0x3d9df8[_0xf15c('0x16')](_0x52aa33);return _0x3d9df8[_0xf15c('0x1c')](_0xf15c('0x1d'),_0x2eec7e+'-'+_0x5f09f5+'/'+_0x2603e1)[_0xf15c('0x1e')](_0x5dff2e);}return null;};}function patchUpdates(_0xce497){return function(_0x13a4b9){try{jsonpatch[_0xf15c('0x1f')](_0x13a4b9,_0xce497,!![]);}catch(_0x24e3ed){return BPromise[_0xf15c('0x20')](_0x24e3ed);}return _0x13a4b9['save']();};}function saveUpdates(_0x16f15c,_0x19a48d){return function(_0x1dff67){if(_0x1dff67){return _0x1dff67[_0xf15c('0x21')](_0x16f15c)[_0xf15c('0x22')](function(_0x2f4498){return _0x2f4498;});}return null;};}function removeEntity(_0x56ca75,_0x22b07e){return function(_0x571ad6){if(_0x571ad6){return _0x571ad6['destroy']()[_0xf15c('0x22')](function(){_0x56ca75[_0xf15c('0x16')](0xcc)['end']();});}};}function handleEntityNotFound(_0x176a5e,_0x37aa75){return function(_0x1596ae){if(!_0x1596ae){_0x176a5e['sendStatus'](0x194);}return _0x1596ae;};}function handleError(_0x1722bf,_0x4db9eb){_0x4db9eb=_0x4db9eb||0x1f4;return function(_0x356872){logger[_0xf15c('0x23')](_0x356872['stack']);if(_0x356872['name']){delete _0x356872[_0xf15c('0x24')];}_0x1722bf[_0xf15c('0x16')](_0x4db9eb)[_0xf15c('0x25')](_0x356872);};}exports['index']=function(_0x173275,_0x11edbf){var _0x2a753d={},_0x1f5364={},_0xe0c49a={'count':0x0,'rows':[]};var _0x1d3cc8=_[_0xf15c('0x26')](db[_0xf15c('0x27')][_0xf15c('0x28')],function(_0x4e595e){return{'name':_0x4e595e['fieldName'],'type':_0x4e595e[_0xf15c('0x29')][_0xf15c('0x2a')]};});_0x1f5364[_0xf15c('0x2b')]=_[_0xf15c('0x26')](_0x1d3cc8,'name');_0x1f5364[_0xf15c('0x2c')]=_[_0xf15c('0x2d')](_0x173275['query']);_0x1f5364[_0xf15c('0x2e')]=_[_0xf15c('0x2f')](_0x1f5364[_0xf15c('0x2b')],_0x1f5364[_0xf15c('0x2c')]);_0x2a753d[_0xf15c('0x30')]=_['intersection'](_0x1f5364[_0xf15c('0x2b')],qs['fields'](_0x173275[_0xf15c('0x2c')][_0xf15c('0x31')]));_0x2a753d[_0xf15c('0x30')]=_0x2a753d[_0xf15c('0x30')][_0xf15c('0x32')]?_0x2a753d[_0xf15c('0x30')]:_0x1f5364[_0xf15c('0x2b')];if(!_0x173275[_0xf15c('0x2c')][_0xf15c('0x33')](_0xf15c('0x34'))){_0x2a753d[_0xf15c('0x1a')]=qs[_0xf15c('0x1a')](_0x173275[_0xf15c('0x2c')][_0xf15c('0x1a')]);_0x2a753d[_0xf15c('0x18')]=qs[_0xf15c('0x18')](_0x173275[_0xf15c('0x2c')][_0xf15c('0x18')]);}_0x2a753d['order']=qs[_0xf15c('0x35')](_0x173275[_0xf15c('0x2c')][_0xf15c('0x35')]);_0x2a753d[_0xf15c('0x36')]=qs[_0xf15c('0x2e')](_['pick'](_0x173275[_0xf15c('0x2c')],_0x1f5364[_0xf15c('0x2e')]),_0x1d3cc8);if(_0x173275['query']['filter']){_0x2a753d[_0xf15c('0x36')]=_[_0xf15c('0x37')](_0x2a753d[_0xf15c('0x36')],{'$or':_[_0xf15c('0x26')](_0x1d3cc8,function(_0x153042){if(_0x153042[_0xf15c('0x29')]!==_0xf15c('0x38')){var _0x96cfef={};_0x96cfef[_0x153042[_0xf15c('0x24')]]={'$like':'%'+_0x173275[_0xf15c('0x2c')][_0xf15c('0x39')]+'%'};return _0x96cfef;}})});}_0x2a753d=_[_0xf15c('0x37')]({},_0x2a753d,_0x173275[_0xf15c('0x3a')]);var _0xaee811={'where':_0x2a753d[_0xf15c('0x36')]};return db[_0xf15c('0x27')]['count'](_0xaee811)['then'](function(_0x3cf69c){_0xe0c49a[_0xf15c('0x1b')]=_0x3cf69c;if(_0x173275[_0xf15c('0x2c')][_0xf15c('0x3b')]){_0x2a753d['include']=[{'all':!![]}];}return db['CmHopperHistory']['findAll'](_0x2a753d);})[_0xf15c('0x22')](function(_0x10ede0){_0xe0c49a['rows']=_0x10ede0;return _0xe0c49a;})[_0xf15c('0x22')](respondWithFilteredResult(_0x11edbf,_0x2a753d))[_0xf15c('0x3c')](handleError(_0x11edbf,null));};exports[_0xf15c('0x3d')]=function(_0x1e930d,_0x385390){var _0x26f349={'raw':!![],'where':{'id':_0x1e930d[_0xf15c('0x3e')]['id']}},_0x31fe3e={};_0x31fe3e[_0xf15c('0x2b')]=_[_0xf15c('0x2d')](db[_0xf15c('0x27')][_0xf15c('0x28')]);_0x31fe3e['query']=_[_0xf15c('0x2d')](_0x1e930d[_0xf15c('0x2c')]);_0x31fe3e[_0xf15c('0x2e')]=_[_0xf15c('0x2f')](_0x31fe3e['model'],_0x31fe3e[_0xf15c('0x2c')]);_0x26f349[_0xf15c('0x30')]=_[_0xf15c('0x2f')](_0x31fe3e[_0xf15c('0x2b')],qs[_0xf15c('0x31')](_0x1e930d[_0xf15c('0x2c')][_0xf15c('0x31')]));_0x26f349[_0xf15c('0x30')]=_0x26f349[_0xf15c('0x30')][_0xf15c('0x32')]?_0x26f349['attributes']:_0x31fe3e[_0xf15c('0x2b')];if(_0x1e930d['query'][_0xf15c('0x3b')]){_0x26f349[_0xf15c('0x3f')]=[{'all':!![]}];}_0x26f349=_[_0xf15c('0x37')]({},_0x26f349,_0x1e930d[_0xf15c('0x3a')]);return db[_0xf15c('0x27')]['find'](_0x26f349)[_0xf15c('0x22')](handleEntityNotFound(_0x385390,null))[_0xf15c('0x22')](respondWithResult(_0x385390,null))[_0xf15c('0x3c')](handleError(_0x385390,null));};exports[_0xf15c('0x40')]=function(_0x5ad4a7,_0xb9a319){return db[_0xf15c('0x27')]['create'](_0x5ad4a7[_0xf15c('0x41')],{})[_0xf15c('0x22')](respondWithResult(_0xb9a319,0xc9))[_0xf15c('0x3c')](handleError(_0xb9a319,null));};exports[_0xf15c('0x42')]=function(_0x48fa46,_0x3c414f){return db[_0xf15c('0x27')]['describe']()[_0xf15c('0x22')](respondWithResult(_0x3c414f,null))[_0xf15c('0x3c')](handleError(_0x3c414f,null));};exports[_0xf15c('0x21')]=function(_0x246470,_0xc59beb){if(_0x246470['body'][_0xf15c('0x43')]){delete _0x246470[_0xf15c('0x41')][_0xf15c('0x43')];}return db[_0xf15c('0x27')][_0xf15c('0x44')]({'where':{'uniqueid':_0x246470['params']['id']}})[_0xf15c('0x22')](handleEntityNotFound(_0xc59beb,null))[_0xf15c('0x22')](saveUpdates(_0x246470[_0xf15c('0x41')],null))['then'](respondWithResult(_0xc59beb,null))[_0xf15c('0x3c')](handleError(_0xc59beb,null));};