51b064159da22d550bb2ca4b46c30bcc02f1eb48
[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 _0xc415=['limit','count','set','apply','save','update','then','destroy','error','stack','name','send','index','map','rawAttributes','fieldName','key','query','filters','model','fields','attributes','length','hasOwnProperty','nolimit','order','sort','pick','filter','where','merge','type','VIRTUAL','options','includeAll','findAll','rows','catch','show','params','keys','CmHopperHistory','intersection','find','create','body','describe','uniqueid','eml-format','fast-json-patch','request-promise','moment','bluebird','mustache','util','path','sox','ejs','lodash','squel','crypto','querystring','papaparse','ioredis','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','api','../../config/utils','../../config/environment','../../mysqldb','sendStatus','status','end','json','offset'];(function(_0x352d26,_0x4018e1){var _0x510584=function(_0x59d79b){while(--_0x59d79b){_0x352d26['push'](_0x352d26['shift']());}};_0x510584(++_0x4018e1);}(_0xc415,0x114));var _0x5c41=function(_0x57e574,_0x1f3866){_0x57e574=_0x57e574-0x0;var _0x40fe9e=_0xc415[_0x57e574];return _0x40fe9e;};'use strict';var emlformat=require(_0x5c41('0x0'));var rimraf=require('rimraf');var zipdir=require('zip-dir');var jsonpatch=require(_0x5c41('0x1'));var rp=require(_0x5c41('0x2'));var moment=require(_0x5c41('0x3'));var BPromise=require(_0x5c41('0x4'));var Mustache=require(_0x5c41('0x5'));var util=require(_0x5c41('0x6'));var path=require(_0x5c41('0x7'));var sox=require(_0x5c41('0x8'));var csv=require('to-csv');var ejs=require(_0x5c41('0x9'));var fs=require('fs');var fs_extra=require('fs-extra');var _=require(_0x5c41('0xa'));var squel=require(_0x5c41('0xb'));var crypto=require(_0x5c41('0xc'));var jsforce=require('jsforce');var deskjs=require('desk.js');var toCsv=require('to-csv');var querystring=require(_0x5c41('0xd'));var Papa=require(_0x5c41('0xe'));var Redis=require(_0x5c41('0xf'));var authService=require('../../components/auth/service');var qs=require(_0x5c41('0x10'));var as=require(_0x5c41('0x11'));var hardwareService=require(_0x5c41('0x12'));var logger=require('../../config/logger')(_0x5c41('0x13'));var utils=require(_0x5c41('0x14'));var config=require(_0x5c41('0x15'));var licenseUtil=require('../../config/license/util');var db=require(_0x5c41('0x16'))['db'];function respondWithStatusCode(_0x4bc118,_0x5f24bb){_0x5f24bb=_0x5f24bb||0xcc;return function(_0x5b30fb){if(_0x5b30fb){return _0x4bc118[_0x5c41('0x17')](_0x5f24bb);}return _0x4bc118[_0x5c41('0x18')](_0x5f24bb)[_0x5c41('0x19')]();};}function respondWithResult(_0xfa4941,_0x27a0dd){_0x27a0dd=_0x27a0dd||0xc8;return function(_0x51ecb6){if(_0x51ecb6){return _0xfa4941[_0x5c41('0x18')](_0x27a0dd)[_0x5c41('0x1a')](_0x51ecb6);}};}function respondWithFilteredResult(_0x46de8a,_0x22de94){return function(_0x166639){if(_0x166639){var _0x257ab7=typeof _0x22de94[_0x5c41('0x1b')]==='undefined'&&typeof _0x22de94[_0x5c41('0x1c')]==='undefined';var _0x200e97=_0x166639['count'];var _0x490404=_0x257ab7?0x0:_0x22de94[_0x5c41('0x1b')];var _0xce8fe8=_0x257ab7?_0x166639[_0x5c41('0x1d')]:_0x22de94['offset']+_0x22de94[_0x5c41('0x1c')];var _0x3d94d7;if(_0xce8fe8>=_0x200e97){_0xce8fe8=_0x200e97;_0x3d94d7=0xc8;}else{_0x3d94d7=0xce;}_0x46de8a['status'](_0x3d94d7);return _0x46de8a[_0x5c41('0x1e')]('Content-Range',_0x490404+'-'+_0xce8fe8+'/'+_0x200e97)[_0x5c41('0x1a')](_0x166639);}return null;};}function patchUpdates(_0x1278d3){return function(_0xf09286){try{jsonpatch[_0x5c41('0x1f')](_0xf09286,_0x1278d3,!![]);}catch(_0x43d8d5){return BPromise['reject'](_0x43d8d5);}return _0xf09286[_0x5c41('0x20')]();};}function saveUpdates(_0x31f29,_0xd0f593){return function(_0x1f1b25){if(_0x1f1b25){return _0x1f1b25[_0x5c41('0x21')](_0x31f29)[_0x5c41('0x22')](function(_0x2af57e){return _0x2af57e;});}return null;};}function removeEntity(_0x451925,_0x35e188){return function(_0x2b990c){if(_0x2b990c){return _0x2b990c[_0x5c41('0x23')]()[_0x5c41('0x22')](function(){_0x451925['status'](0xcc)[_0x5c41('0x19')]();});}};}function handleEntityNotFound(_0xb915d1,_0x18f623){return function(_0x2e4608){if(!_0x2e4608){_0xb915d1[_0x5c41('0x17')](0x194);}return _0x2e4608;};}function handleError(_0xc0136b,_0x454853){_0x454853=_0x454853||0x1f4;return function(_0x3a4e6f){logger[_0x5c41('0x24')](_0x3a4e6f[_0x5c41('0x25')]);if(_0x3a4e6f['name']){delete _0x3a4e6f[_0x5c41('0x26')];}_0xc0136b['status'](_0x454853)[_0x5c41('0x27')](_0x3a4e6f);};}exports[_0x5c41('0x28')]=function(_0x148659,_0x43c4a1){var _0x5bd53c={},_0x82d45f={},_0x453a8e={'count':0x0,'rows':[]};var _0x52f99a=_[_0x5c41('0x29')](db['CmHopperHistory'][_0x5c41('0x2a')],function(_0x475ea8){return{'name':_0x475ea8[_0x5c41('0x2b')],'type':_0x475ea8['type'][_0x5c41('0x2c')]};});_0x82d45f['model']=_[_0x5c41('0x29')](_0x52f99a,_0x5c41('0x26'));_0x82d45f[_0x5c41('0x2d')]=_['keys'](_0x148659[_0x5c41('0x2d')]);_0x82d45f[_0x5c41('0x2e')]=_['intersection'](_0x82d45f[_0x5c41('0x2f')],_0x82d45f[_0x5c41('0x2d')]);_0x5bd53c['attributes']=_['intersection'](_0x82d45f[_0x5c41('0x2f')],qs[_0x5c41('0x30')](_0x148659['query'][_0x5c41('0x30')]));_0x5bd53c[_0x5c41('0x31')]=_0x5bd53c[_0x5c41('0x31')][_0x5c41('0x32')]?_0x5bd53c[_0x5c41('0x31')]:_0x82d45f[_0x5c41('0x2f')];if(!_0x148659[_0x5c41('0x2d')][_0x5c41('0x33')](_0x5c41('0x34'))){_0x5bd53c[_0x5c41('0x1c')]=qs[_0x5c41('0x1c')](_0x148659[_0x5c41('0x2d')][_0x5c41('0x1c')]);_0x5bd53c[_0x5c41('0x1b')]=qs['offset'](_0x148659[_0x5c41('0x2d')][_0x5c41('0x1b')]);}_0x5bd53c[_0x5c41('0x35')]=qs[_0x5c41('0x36')](_0x148659[_0x5c41('0x2d')][_0x5c41('0x36')]);_0x5bd53c['where']=qs[_0x5c41('0x2e')](_[_0x5c41('0x37')](_0x148659['query'],_0x82d45f[_0x5c41('0x2e')]),_0x52f99a);if(_0x148659[_0x5c41('0x2d')][_0x5c41('0x38')]){_0x5bd53c[_0x5c41('0x39')]=_[_0x5c41('0x3a')](_0x5bd53c[_0x5c41('0x39')],{'$or':_[_0x5c41('0x29')](_0x52f99a,function(_0x52d833){if(_0x52d833[_0x5c41('0x3b')]!==_0x5c41('0x3c')){var _0x48defa={};_0x48defa[_0x52d833[_0x5c41('0x26')]]={'$like':'%'+_0x148659[_0x5c41('0x2d')][_0x5c41('0x38')]+'%'};return _0x48defa;}})});}_0x5bd53c=_[_0x5c41('0x3a')]({},_0x5bd53c,_0x148659[_0x5c41('0x3d')]);var _0x1c2906={'where':_0x5bd53c[_0x5c41('0x39')]};return db['CmHopperHistory'][_0x5c41('0x1d')](_0x1c2906)[_0x5c41('0x22')](function(_0x271646){_0x453a8e[_0x5c41('0x1d')]=_0x271646;if(_0x148659[_0x5c41('0x2d')][_0x5c41('0x3e')]){_0x5bd53c['include']=[{'all':!![]}];}return db['CmHopperHistory'][_0x5c41('0x3f')](_0x5bd53c);})[_0x5c41('0x22')](function(_0x3c0a9c){_0x453a8e[_0x5c41('0x40')]=_0x3c0a9c;return _0x453a8e;})[_0x5c41('0x22')](respondWithFilteredResult(_0x43c4a1,_0x5bd53c))[_0x5c41('0x41')](handleError(_0x43c4a1,null));};exports[_0x5c41('0x42')]=function(_0x2751a3,_0x4f1678){var _0xc575e9={'raw':!![],'where':{'id':_0x2751a3[_0x5c41('0x43')]['id']}},_0x3a36ec={};_0x3a36ec[_0x5c41('0x2f')]=_[_0x5c41('0x44')](db[_0x5c41('0x45')][_0x5c41('0x2a')]);_0x3a36ec[_0x5c41('0x2d')]=_[_0x5c41('0x44')](_0x2751a3['query']);_0x3a36ec['filters']=_[_0x5c41('0x46')](_0x3a36ec[_0x5c41('0x2f')],_0x3a36ec[_0x5c41('0x2d')]);_0xc575e9['attributes']=_[_0x5c41('0x46')](_0x3a36ec[_0x5c41('0x2f')],qs['fields'](_0x2751a3[_0x5c41('0x2d')][_0x5c41('0x30')]));_0xc575e9[_0x5c41('0x31')]=_0xc575e9[_0x5c41('0x31')][_0x5c41('0x32')]?_0xc575e9[_0x5c41('0x31')]:_0x3a36ec[_0x5c41('0x2f')];if(_0x2751a3[_0x5c41('0x2d')][_0x5c41('0x3e')]){_0xc575e9['include']=[{'all':!![]}];}_0xc575e9=_[_0x5c41('0x3a')]({},_0xc575e9,_0x2751a3[_0x5c41('0x3d')]);return db[_0x5c41('0x45')][_0x5c41('0x47')](_0xc575e9)[_0x5c41('0x22')](handleEntityNotFound(_0x4f1678,null))['then'](respondWithResult(_0x4f1678,null))[_0x5c41('0x41')](handleError(_0x4f1678,null));};exports[_0x5c41('0x48')]=function(_0x2efdd2,_0x41f199){return db[_0x5c41('0x45')][_0x5c41('0x48')](_0x2efdd2[_0x5c41('0x49')],{})[_0x5c41('0x22')](respondWithResult(_0x41f199,0xc9))[_0x5c41('0x41')](handleError(_0x41f199,null));};exports[_0x5c41('0x4a')]=function(_0x505c6d,_0x19383c){return db[_0x5c41('0x45')][_0x5c41('0x4a')]()['then'](respondWithResult(_0x19383c,null))[_0x5c41('0x41')](handleError(_0x19383c,null));};exports[_0x5c41('0x21')]=function(_0x37d5c8,_0x152d59){if(_0x37d5c8['body'][_0x5c41('0x4b')]){delete _0x37d5c8[_0x5c41('0x49')][_0x5c41('0x4b')];}return db[_0x5c41('0x45')]['find']({'where':{'uniqueid':_0x37d5c8[_0x5c41('0x43')]['id']}})[_0x5c41('0x22')](handleEntityNotFound(_0x152d59,null))[_0x5c41('0x22')](saveUpdates(_0x37d5c8[_0x5c41('0x49')],null))[_0x5c41('0x22')](respondWithResult(_0x152d59,null))[_0x5c41('0x41')](handleError(_0x152d59,null));};