ac5ee483baf570ccaedb4fe1f2b040ec74c3ecbb
[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 _0x50ca=['intersection','attributes','length','nolimit','sort','where','merge','map','VIRTUAL','filter','options','CmHopperHistory','includeAll','include','findAll','rows','catch','show','params','fields','find','create','body','describe','uniqueid','rimraf','request-promise','moment','mustache','util','to-csv','ejs','fs-extra','squel','crypto','jsforce','desk.js','querystring','papaparse','ioredis','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','api','../../config/utils','../../config/license/util','sendStatus','end','status','json','offset','limit','undefined','count','Content-Range','reject','save','update','then','destroy','name','index','rawAttributes','model','query','keys','filters'];(function(_0x1aa277,_0x1edd4f){var _0x2f21e5=function(_0x439cbc){while(--_0x439cbc){_0x1aa277['push'](_0x1aa277['shift']());}};_0x2f21e5(++_0x1edd4f);}(_0x50ca,0x16d));var _0xa50c=function(_0x167cc1,_0x56ef5a){_0x167cc1=_0x167cc1-0x0;var _0x10bc4b=_0x50ca[_0x167cc1];return _0x10bc4b;};'use strict';var emlformat=require('eml-format');var rimraf=require(_0xa50c('0x0'));var zipdir=require('zip-dir');var jsonpatch=require('fast-json-patch');var rp=require(_0xa50c('0x1'));var moment=require(_0xa50c('0x2'));var BPromise=require('bluebird');var Mustache=require(_0xa50c('0x3'));var util=require(_0xa50c('0x4'));var path=require('path');var sox=require('sox');var csv=require(_0xa50c('0x5'));var ejs=require(_0xa50c('0x6'));var fs=require('fs');var fs_extra=require(_0xa50c('0x7'));var _=require('lodash');var squel=require(_0xa50c('0x8'));var crypto=require(_0xa50c('0x9'));var jsforce=require(_0xa50c('0xa'));var deskjs=require(_0xa50c('0xb'));var toCsv=require(_0xa50c('0x5'));var querystring=require(_0xa50c('0xc'));var Papa=require(_0xa50c('0xd'));var Redis=require(_0xa50c('0xe'));var authService=require('../../components/auth/service');var qs=require(_0xa50c('0xf'));var as=require(_0xa50c('0x10'));var hardwareService=require(_0xa50c('0x11'));var logger=require(_0xa50c('0x12'))(_0xa50c('0x13'));var utils=require(_0xa50c('0x14'));var config=require('../../config/environment');var licenseUtil=require(_0xa50c('0x15'));var db=require('../../mysqldb')['db'];function respondWithStatusCode(_0x51702e,_0x214149){_0x214149=_0x214149||0xcc;return function(_0x285847){if(_0x285847){return _0x51702e[_0xa50c('0x16')](_0x214149);}return _0x51702e['status'](_0x214149)[_0xa50c('0x17')]();};}function respondWithResult(_0x50fc37,_0x38dc49){_0x38dc49=_0x38dc49||0xc8;return function(_0x221388){if(_0x221388){return _0x50fc37[_0xa50c('0x18')](_0x38dc49)[_0xa50c('0x19')](_0x221388);}};}function respondWithFilteredResult(_0x58a1e3,_0x2f42a8){return function(_0xec3050){if(_0xec3050){var _0x339ce9=typeof _0x2f42a8[_0xa50c('0x1a')]==='undefined'&&typeof _0x2f42a8[_0xa50c('0x1b')]===_0xa50c('0x1c');var _0x514473=_0xec3050[_0xa50c('0x1d')];var _0x2a594e=_0x339ce9?0x0:_0x2f42a8[_0xa50c('0x1a')];var _0x1fa033=_0x339ce9?_0xec3050[_0xa50c('0x1d')]:_0x2f42a8['offset']+_0x2f42a8[_0xa50c('0x1b')];var _0x4560cb;if(_0x1fa033>=_0x514473){_0x1fa033=_0x514473;_0x4560cb=0xc8;}else{_0x4560cb=0xce;}_0x58a1e3[_0xa50c('0x18')](_0x4560cb);return _0x58a1e3['set'](_0xa50c('0x1e'),_0x2a594e+'-'+_0x1fa033+'/'+_0x514473)[_0xa50c('0x19')](_0xec3050);}return null;};}function patchUpdates(_0x373148){return function(_0x568191){try{jsonpatch['apply'](_0x568191,_0x373148,!![]);}catch(_0x2302be){return BPromise[_0xa50c('0x1f')](_0x2302be);}return _0x568191[_0xa50c('0x20')]();};}function saveUpdates(_0xa35c84,_0x3932be){return function(_0x334781){if(_0x334781){return _0x334781[_0xa50c('0x21')](_0xa35c84)[_0xa50c('0x22')](function(_0x320e22){return _0x320e22;});}return null;};}function removeEntity(_0x2ef926,_0x3f5028){return function(_0x582baf){if(_0x582baf){return _0x582baf[_0xa50c('0x23')]()[_0xa50c('0x22')](function(){_0x2ef926[_0xa50c('0x18')](0xcc)[_0xa50c('0x17')]();});}};}function handleEntityNotFound(_0x56f403,_0x2f1219){return function(_0x261132){if(!_0x261132){_0x56f403['sendStatus'](0x194);}return _0x261132;};}function handleError(_0xfbebb3,_0x44d062){_0x44d062=_0x44d062||0x1f4;return function(_0x484f6c){logger['error'](_0x484f6c['stack']);if(_0x484f6c[_0xa50c('0x24')]){delete _0x484f6c[_0xa50c('0x24')];}_0xfbebb3[_0xa50c('0x18')](_0x44d062)['send'](_0x484f6c);};}exports[_0xa50c('0x25')]=function(_0x317630,_0x13d483){var _0x34ee48={},_0x412a53={},_0x573313={'count':0x0,'rows':[]};var _0x28a0ca=_['map'](db['CmHopperHistory'][_0xa50c('0x26')],function(_0x1727a5){return{'name':_0x1727a5['fieldName'],'type':_0x1727a5['type']['key']};});_0x412a53[_0xa50c('0x27')]=_['map'](_0x28a0ca,'name');_0x412a53[_0xa50c('0x28')]=_[_0xa50c('0x29')](_0x317630[_0xa50c('0x28')]);_0x412a53[_0xa50c('0x2a')]=_[_0xa50c('0x2b')](_0x412a53['model'],_0x412a53[_0xa50c('0x28')]);_0x34ee48[_0xa50c('0x2c')]=_[_0xa50c('0x2b')](_0x412a53[_0xa50c('0x27')],qs['fields'](_0x317630['query']['fields']));_0x34ee48[_0xa50c('0x2c')]=_0x34ee48[_0xa50c('0x2c')][_0xa50c('0x2d')]?_0x34ee48['attributes']:_0x412a53[_0xa50c('0x27')];if(!_0x317630[_0xa50c('0x28')]['hasOwnProperty'](_0xa50c('0x2e'))){_0x34ee48[_0xa50c('0x1b')]=qs['limit'](_0x317630[_0xa50c('0x28')]['limit']);_0x34ee48[_0xa50c('0x1a')]=qs[_0xa50c('0x1a')](_0x317630[_0xa50c('0x28')][_0xa50c('0x1a')]);}_0x34ee48['order']=qs[_0xa50c('0x2f')](_0x317630[_0xa50c('0x28')][_0xa50c('0x2f')]);_0x34ee48['where']=qs[_0xa50c('0x2a')](_['pick'](_0x317630['query'],_0x412a53[_0xa50c('0x2a')]),_0x28a0ca);if(_0x317630['query']['filter']){_0x34ee48[_0xa50c('0x30')]=_[_0xa50c('0x31')](_0x34ee48['where'],{'$or':_[_0xa50c('0x32')](_0x28a0ca,function(_0x4afcd0){if(_0x4afcd0['type']!==_0xa50c('0x33')){var _0x5f0ce3={};_0x5f0ce3[_0x4afcd0[_0xa50c('0x24')]]={'$like':'%'+_0x317630[_0xa50c('0x28')][_0xa50c('0x34')]+'%'};return _0x5f0ce3;}})});}_0x34ee48=_['merge']({},_0x34ee48,_0x317630[_0xa50c('0x35')]);var _0x519bf4={'where':_0x34ee48[_0xa50c('0x30')]};return db[_0xa50c('0x36')][_0xa50c('0x1d')](_0x519bf4)['then'](function(_0x10b585){_0x573313['count']=_0x10b585;if(_0x317630['query'][_0xa50c('0x37')]){_0x34ee48[_0xa50c('0x38')]=[{'all':!![]}];}return db['CmHopperHistory'][_0xa50c('0x39')](_0x34ee48);})[_0xa50c('0x22')](function(_0x5a79de){_0x573313[_0xa50c('0x3a')]=_0x5a79de;return _0x573313;})[_0xa50c('0x22')](respondWithFilteredResult(_0x13d483,_0x34ee48))[_0xa50c('0x3b')](handleError(_0x13d483,null));};exports[_0xa50c('0x3c')]=function(_0x3d784d,_0x812bda){var _0x173c13={'raw':!![],'where':{'id':_0x3d784d[_0xa50c('0x3d')]['id']}},_0x34133d={};_0x34133d[_0xa50c('0x27')]=_[_0xa50c('0x29')](db[_0xa50c('0x36')][_0xa50c('0x26')]);_0x34133d[_0xa50c('0x28')]=_[_0xa50c('0x29')](_0x3d784d['query']);_0x34133d[_0xa50c('0x2a')]=_['intersection'](_0x34133d[_0xa50c('0x27')],_0x34133d[_0xa50c('0x28')]);_0x173c13['attributes']=_[_0xa50c('0x2b')](_0x34133d[_0xa50c('0x27')],qs[_0xa50c('0x3e')](_0x3d784d[_0xa50c('0x28')][_0xa50c('0x3e')]));_0x173c13[_0xa50c('0x2c')]=_0x173c13[_0xa50c('0x2c')]['length']?_0x173c13[_0xa50c('0x2c')]:_0x34133d[_0xa50c('0x27')];if(_0x3d784d[_0xa50c('0x28')][_0xa50c('0x37')]){_0x173c13[_0xa50c('0x38')]=[{'all':!![]}];}_0x173c13=_[_0xa50c('0x31')]({},_0x173c13,_0x3d784d[_0xa50c('0x35')]);return db[_0xa50c('0x36')][_0xa50c('0x3f')](_0x173c13)[_0xa50c('0x22')](handleEntityNotFound(_0x812bda,null))[_0xa50c('0x22')](respondWithResult(_0x812bda,null))[_0xa50c('0x3b')](handleError(_0x812bda,null));};exports[_0xa50c('0x40')]=function(_0x2ae88e,_0x3bb408){return db[_0xa50c('0x36')][_0xa50c('0x40')](_0x2ae88e[_0xa50c('0x41')],{})[_0xa50c('0x22')](respondWithResult(_0x3bb408,0xc9))['catch'](handleError(_0x3bb408,null));};exports[_0xa50c('0x42')]=function(_0x87e3f1,_0x2fbf91){return db['CmHopperHistory'][_0xa50c('0x42')]()['then'](respondWithResult(_0x2fbf91,null))['catch'](handleError(_0x2fbf91,null));};exports[_0xa50c('0x21')]=function(_0x3a12a4,_0xefd317){if(_0x3a12a4[_0xa50c('0x41')]['uniqueid']){delete _0x3a12a4[_0xa50c('0x41')][_0xa50c('0x43')];}return db[_0xa50c('0x36')][_0xa50c('0x3f')]({'where':{'uniqueid':_0x3a12a4[_0xa50c('0x3d')]['id']}})[_0xa50c('0x22')](handleEntityNotFound(_0xefd317,null))[_0xa50c('0x22')](saveUpdates(_0x3a12a4[_0xa50c('0x41')],null))[_0xa50c('0x22')](respondWithResult(_0xefd317,null))[_0xa50c('0x3b')](handleError(_0xefd317,null));};