Built motion from commit (unavailable).|2.5.4
[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 _0xbd8a=['set','apply','reject','save','then','destroy','error','stack','name','index','map','fieldName','type','key','model','query','keys','attributes','intersection','fields','nolimit','limit','sort','where','filters','pick','merge','options','CmHopperHistory','count','includeAll','include','findAll','rows','catch','show','params','rawAttributes','create','body','describe','uniqueid','find','rimraf','zip-dir','fast-json-patch','moment','bluebird','mustache','util','path','to-csv','ejs','squel','crypto','jsforce','querystring','papaparse','../../components/parsers/qs','../../config/license/hardware','../../config/logger','api','../../config/utils','../../config/environment','sendStatus','end','status','json','offset'];(function(_0x59cb86,_0x493f63){var _0x515d2a=function(_0x4208d3){while(--_0x4208d3){_0x59cb86['push'](_0x59cb86['shift']());}};_0x515d2a(++_0x493f63);}(_0xbd8a,0xb5));var _0xabd8=function(_0x59e7e0,_0x3ec148){_0x59e7e0=_0x59e7e0-0x0;var _0x26b058=_0xbd8a[_0x59e7e0];return _0x26b058;};'use strict';var pdf=require('html-pdf');var emlformat=require('eml-format');var rimraf=require(_0xabd8('0x0'));var zipdir=require(_0xabd8('0x1'));var jsonpatch=require(_0xabd8('0x2'));var rp=require('request-promise');var moment=require(_0xabd8('0x3'));var BPromise=require(_0xabd8('0x4'));var Mustache=require(_0xabd8('0x5'));var util=require(_0xabd8('0x6'));var path=require(_0xabd8('0x7'));var sox=require('sox');var csv=require(_0xabd8('0x8'));var ejs=require(_0xabd8('0x9'));var fs=require('fs');var _=require('lodash');var squel=require(_0xabd8('0xa'));var crypto=require(_0xabd8('0xb'));var jsforce=require(_0xabd8('0xc'));var deskjs=require('desk.js');var toCsv=require(_0xabd8('0x8'));var querystring=require(_0xabd8('0xd'));var Papa=require(_0xabd8('0xe'));var Redis=require('ioredis');var authService=require('../../components/auth/service');var qs=require(_0xabd8('0xf'));var as=require('../../components/parsers/advancedSearch');var hardwareService=require(_0xabd8('0x10'));var logger=require(_0xabd8('0x11'))(_0xabd8('0x12'));var utils=require(_0xabd8('0x13'));var config=require(_0xabd8('0x14'));var db=require('../../mysqldb')['db'];function respondWithStatusCode(_0x40d0b9,_0x50e17c){_0x50e17c=_0x50e17c||0xcc;return function(_0x39adce){if(_0x39adce){return _0x40d0b9[_0xabd8('0x15')](_0x50e17c);}return _0x40d0b9['status'](_0x50e17c)[_0xabd8('0x16')]();};}function respondWithResult(_0x1b3bc6,_0x21b84c){_0x21b84c=_0x21b84c||0xc8;return function(_0x251147){if(_0x251147){return _0x1b3bc6[_0xabd8('0x17')](_0x21b84c)[_0xabd8('0x18')](_0x251147);}};}function respondWithFilteredResult(_0x50c7b5,_0x1830b9){return function(_0x5be710){if(_0x5be710){var _0x2afe22=_0x5be710['count'],_0x332952=_0x1830b9[_0xabd8('0x19')],_0x4f4454=_0x1830b9[_0xabd8('0x19')]+_0x1830b9['limit'],_0x181df2;if(_0x4f4454>=_0x2afe22){_0x4f4454=_0x2afe22;_0x181df2=0xc8;}else{_0x181df2=0xce;}_0x50c7b5[_0xabd8('0x17')](_0x181df2);return _0x50c7b5[_0xabd8('0x1a')]('Content-Range',_0x332952+'-'+_0x4f4454+'/'+_0x2afe22)[_0xabd8('0x18')](_0x5be710);}return null;};}function patchUpdates(_0xc6c779){return function(_0x3f685b){try{jsonpatch[_0xabd8('0x1b')](_0x3f685b,_0xc6c779,!![]);}catch(_0xe8589a){return BPromise[_0xabd8('0x1c')](_0xe8589a);}return _0x3f685b[_0xabd8('0x1d')]();};}function saveUpdates(_0x4aed91,_0x8a6ff6){return function(_0x1c6cc6){if(_0x1c6cc6){return _0x1c6cc6['update'](_0x4aed91)[_0xabd8('0x1e')](function(_0x38c725){return _0x38c725;});}return null;};}function removeEntity(_0x996a70,_0xe5c20a){return function(_0x235599){if(_0x235599){return _0x235599[_0xabd8('0x1f')]()['then'](function(){_0x996a70[_0xabd8('0x17')](0xcc)[_0xabd8('0x16')]();});}};}function handleEntityNotFound(_0x5db64c,_0x17aee7){return function(_0xf8bc1c){if(!_0xf8bc1c){_0x5db64c[_0xabd8('0x15')](0x194);}return _0xf8bc1c;};}function handleError(_0x202050,_0x279005){_0x279005=_0x279005||0x1f4;return function(_0x2636fe){logger[_0xabd8('0x20')](_0x2636fe[_0xabd8('0x21')]);if(_0x2636fe[_0xabd8('0x22')]){delete _0x2636fe[_0xabd8('0x22')];}_0x202050[_0xabd8('0x17')](_0x279005)['send'](_0x2636fe);};}exports[_0xabd8('0x23')]=function(_0x5a513e,_0x1f9a9){var _0x39c88c={},_0x17134b={},_0x51aff3={'count':0x0,'rows':[]};var _0x9c640a=_[_0xabd8('0x24')](db['CmHopperHistory']['rawAttributes'],function(_0x3e0f23){return{'name':_0x3e0f23[_0xabd8('0x25')],'type':_0x3e0f23[_0xabd8('0x26')][_0xabd8('0x27')]};});_0x17134b[_0xabd8('0x28')]=_[_0xabd8('0x24')](_0x9c640a,_0xabd8('0x22'));_0x17134b[_0xabd8('0x29')]=_[_0xabd8('0x2a')](_0x5a513e[_0xabd8('0x29')]);_0x17134b['filters']=_['intersection'](_0x17134b[_0xabd8('0x28')],_0x17134b[_0xabd8('0x29')]);_0x39c88c[_0xabd8('0x2b')]=_[_0xabd8('0x2c')](_0x17134b[_0xabd8('0x28')],qs[_0xabd8('0x2d')](_0x5a513e[_0xabd8('0x29')][_0xabd8('0x2d')]));_0x39c88c[_0xabd8('0x2b')]=_0x39c88c[_0xabd8('0x2b')]['length']?_0x39c88c['attributes']:_0x17134b[_0xabd8('0x28')];if(!_0x5a513e[_0xabd8('0x29')]['hasOwnProperty'](_0xabd8('0x2e'))){_0x39c88c['limit']=qs[_0xabd8('0x2f')](_0x5a513e[_0xabd8('0x29')]['limit']);_0x39c88c[_0xabd8('0x19')]=qs[_0xabd8('0x19')](_0x5a513e[_0xabd8('0x29')][_0xabd8('0x19')]);}_0x39c88c['order']=qs[_0xabd8('0x30')](_0x5a513e[_0xabd8('0x29')]['sort']);_0x39c88c[_0xabd8('0x31')]=qs[_0xabd8('0x32')](_[_0xabd8('0x33')](_0x5a513e[_0xabd8('0x29')],_0x17134b[_0xabd8('0x32')]),_0x9c640a);if(_0x5a513e[_0xabd8('0x29')]['filter']){_0x39c88c[_0xabd8('0x31')]=_[_0xabd8('0x34')](_0x39c88c[_0xabd8('0x31')],{'$or':_[_0xabd8('0x24')](_0x9c640a,function(_0x2ee451){if(_0x2ee451['type']!=='VIRTUAL'){var _0x310931={};_0x310931[_0x2ee451[_0xabd8('0x22')]]={'$like':'%'+_0x5a513e[_0xabd8('0x29')]['filter']+'%'};return _0x310931;}})});}_0x39c88c=_[_0xabd8('0x34')]({},_0x39c88c,_0x5a513e[_0xabd8('0x35')]);var _0x1dab98={'where':_0x39c88c[_0xabd8('0x31')]};return db[_0xabd8('0x36')]['count'](_0x1dab98)['then'](function(_0x25cc8d){_0x51aff3[_0xabd8('0x37')]=_0x25cc8d;if(_0x5a513e[_0xabd8('0x29')][_0xabd8('0x38')]){_0x39c88c[_0xabd8('0x39')]=[{'all':!![]}];}return db['CmHopperHistory'][_0xabd8('0x3a')](_0x39c88c);})[_0xabd8('0x1e')](function(_0x469933){_0x51aff3[_0xabd8('0x3b')]=_0x469933;return _0x51aff3;})[_0xabd8('0x1e')](respondWithFilteredResult(_0x1f9a9,_0x39c88c))[_0xabd8('0x3c')](handleError(_0x1f9a9,null));};exports[_0xabd8('0x3d')]=function(_0x5e1928,_0xc00b30){var _0x4aee34={'raw':!![],'where':{'id':_0x5e1928[_0xabd8('0x3e')]['id']}},_0x352efc={};_0x352efc['model']=_['keys'](db['CmHopperHistory'][_0xabd8('0x3f')]);_0x352efc[_0xabd8('0x29')]=_['keys'](_0x5e1928[_0xabd8('0x29')]);_0x352efc[_0xabd8('0x32')]=_[_0xabd8('0x2c')](_0x352efc['model'],_0x352efc[_0xabd8('0x29')]);_0x4aee34[_0xabd8('0x2b')]=_['intersection'](_0x352efc[_0xabd8('0x28')],qs[_0xabd8('0x2d')](_0x5e1928[_0xabd8('0x29')][_0xabd8('0x2d')]));_0x4aee34[_0xabd8('0x2b')]=_0x4aee34[_0xabd8('0x2b')]['length']?_0x4aee34[_0xabd8('0x2b')]:_0x352efc['model'];if(_0x5e1928['query']['includeAll']){_0x4aee34[_0xabd8('0x39')]=[{'all':!![]}];}_0x4aee34=_[_0xabd8('0x34')]({},_0x4aee34,_0x5e1928[_0xabd8('0x35')]);return db[_0xabd8('0x36')]['find'](_0x4aee34)[_0xabd8('0x1e')](handleEntityNotFound(_0xc00b30,null))['then'](respondWithResult(_0xc00b30,null))[_0xabd8('0x3c')](handleError(_0xc00b30,null));};exports[_0xabd8('0x40')]=function(_0x18a939,_0x230a2d){return db[_0xabd8('0x36')]['create'](_0x18a939[_0xabd8('0x41')],{})[_0xabd8('0x1e')](respondWithResult(_0x230a2d,0xc9))[_0xabd8('0x3c')](handleError(_0x230a2d,null));};exports[_0xabd8('0x42')]=function(_0x80a80b,_0xe4e19e){return db[_0xabd8('0x36')][_0xabd8('0x42')]()[_0xabd8('0x1e')](respondWithResult(_0xe4e19e,null))[_0xabd8('0x3c')](handleError(_0xe4e19e,null));};exports['update']=function(_0x2778da,_0xae95aa){if(_0x2778da[_0xabd8('0x41')][_0xabd8('0x43')]){delete _0x2778da[_0xabd8('0x41')][_0xabd8('0x43')];}return db['CmHopperHistory'][_0xabd8('0x44')]({'where':{'uniqueid':_0x2778da[_0xabd8('0x3e')]['id']}})[_0xabd8('0x1e')](handleEntityNotFound(_0xae95aa,null))['then'](saveUpdates(_0x2778da['body'],null))[_0xabd8('0x1e')](respondWithResult(_0xae95aa,null))[_0xabd8('0x3c')](handleError(_0xae95aa,null));};