0c87e4bda347e11e2e8483b75db000c60e07ec3e
[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 _0xb881=['json','limit','undefined','count','offset','set','Content-Range','apply','reject','save','update','then','error','stack','name','send','index','map','CmHopperHistory','fieldName','type','key','model','query','filters','fields','attributes','length','hasOwnProperty','order','sort','pick','filter','where','merge','options','include','findAll','rows','catch','show','keys','rawAttributes','intersection','create','describe','body','find','rimraf','zip-dir','moment','bluebird','mustache','util','sox','to-csv','ejs','fs-extra','squel','crypto','jsforce','ioredis','../../components/auth/service','../../components/parsers/qs','../../config/license/hardware','../../config/logger','../../config/utils','../../config/environment','../../config/license/util','../../mysqldb','sendStatus','status','end'];(function(_0x293e1a,_0x25ecfc){var _0x5b6a1e=function(_0x776e9b){while(--_0x776e9b){_0x293e1a['push'](_0x293e1a['shift']());}};_0x5b6a1e(++_0x25ecfc);}(_0xb881,0xc2));var _0x1b88=function(_0xb15db6,_0x388d94){_0xb15db6=_0xb15db6-0x0;var _0x1db34d=_0xb881[_0xb15db6];return _0x1db34d;};'use strict';var emlformat=require('eml-format');var rimraf=require(_0x1b88('0x0'));var zipdir=require(_0x1b88('0x1'));var jsonpatch=require('fast-json-patch');var rp=require('request-promise');var moment=require(_0x1b88('0x2'));var BPromise=require(_0x1b88('0x3'));var Mustache=require(_0x1b88('0x4'));var util=require(_0x1b88('0x5'));var path=require('path');var sox=require(_0x1b88('0x6'));var csv=require(_0x1b88('0x7'));var ejs=require(_0x1b88('0x8'));var fs=require('fs');var fs_extra=require(_0x1b88('0x9'));var _=require('lodash');var squel=require(_0x1b88('0xa'));var crypto=require(_0x1b88('0xb'));var jsforce=require(_0x1b88('0xc'));var deskjs=require('desk.js');var toCsv=require(_0x1b88('0x7'));var querystring=require('querystring');var Papa=require('papaparse');var Redis=require(_0x1b88('0xd'));var authService=require(_0x1b88('0xe'));var qs=require(_0x1b88('0xf'));var as=require('../../components/parsers/advancedSearch');var hardwareService=require(_0x1b88('0x10'));var logger=require(_0x1b88('0x11'))('api');var utils=require(_0x1b88('0x12'));var config=require(_0x1b88('0x13'));var licenseUtil=require(_0x1b88('0x14'));var db=require(_0x1b88('0x15'))['db'];function respondWithStatusCode(_0x5b777f,_0x45df85){_0x45df85=_0x45df85||0xcc;return function(_0x3114ff){if(_0x3114ff){return _0x5b777f[_0x1b88('0x16')](_0x45df85);}return _0x5b777f[_0x1b88('0x17')](_0x45df85)[_0x1b88('0x18')]();};}function respondWithResult(_0x21b58c,_0x3f6586){_0x3f6586=_0x3f6586||0xc8;return function(_0x4033bd){if(_0x4033bd){return _0x21b58c[_0x1b88('0x17')](_0x3f6586)[_0x1b88('0x19')](_0x4033bd);}};}function respondWithFilteredResult(_0x29d130,_0x587803){return function(_0x33fca1){if(_0x33fca1){var _0x2d30a5=typeof _0x587803['offset']==='undefined'&&typeof _0x587803[_0x1b88('0x1a')]===_0x1b88('0x1b');var _0x5508e3=_0x33fca1[_0x1b88('0x1c')];var _0x3ae2ae=_0x2d30a5?0x0:_0x587803[_0x1b88('0x1d')];var _0x40b23d=_0x2d30a5?_0x33fca1[_0x1b88('0x1c')]:_0x587803[_0x1b88('0x1d')]+_0x587803['limit'];var _0x3aa28a;if(_0x40b23d>=_0x5508e3){_0x40b23d=_0x5508e3;_0x3aa28a=0xc8;}else{_0x3aa28a=0xce;}_0x29d130[_0x1b88('0x17')](_0x3aa28a);return _0x29d130[_0x1b88('0x1e')](_0x1b88('0x1f'),_0x3ae2ae+'-'+_0x40b23d+'/'+_0x5508e3)[_0x1b88('0x19')](_0x33fca1);}return null;};}function patchUpdates(_0x13c6c7){return function(_0x406eeb){try{jsonpatch[_0x1b88('0x20')](_0x406eeb,_0x13c6c7,!![]);}catch(_0x3940aa){return BPromise[_0x1b88('0x21')](_0x3940aa);}return _0x406eeb[_0x1b88('0x22')]();};}function saveUpdates(_0x8063c1,_0x426d6c){return function(_0x317484){if(_0x317484){return _0x317484[_0x1b88('0x23')](_0x8063c1)['then'](function(_0x84aa5a){return _0x84aa5a;});}return null;};}function removeEntity(_0x5c4e8c,_0x2b7bf6){return function(_0x3fa429){if(_0x3fa429){return _0x3fa429['destroy']()[_0x1b88('0x24')](function(){_0x5c4e8c['status'](0xcc)[_0x1b88('0x18')]();});}};}function handleEntityNotFound(_0x14c110,_0x3b7e6a){return function(_0x365814){if(!_0x365814){_0x14c110['sendStatus'](0x194);}return _0x365814;};}function handleError(_0x6acb69,_0x1e8b74){_0x1e8b74=_0x1e8b74||0x1f4;return function(_0x1f6360){logger[_0x1b88('0x25')](_0x1f6360[_0x1b88('0x26')]);if(_0x1f6360[_0x1b88('0x27')]){delete _0x1f6360[_0x1b88('0x27')];}_0x6acb69[_0x1b88('0x17')](_0x1e8b74)[_0x1b88('0x28')](_0x1f6360);};}exports[_0x1b88('0x29')]=function(_0x437532,_0x5855fe){var _0x70e3fd={},_0x5e2c90={},_0x50ec32={'count':0x0,'rows':[]};var _0x1af869=_[_0x1b88('0x2a')](db[_0x1b88('0x2b')]['rawAttributes'],function(_0x57d615){return{'name':_0x57d615[_0x1b88('0x2c')],'type':_0x57d615[_0x1b88('0x2d')][_0x1b88('0x2e')]};});_0x5e2c90[_0x1b88('0x2f')]=_[_0x1b88('0x2a')](_0x1af869,_0x1b88('0x27'));_0x5e2c90[_0x1b88('0x30')]=_['keys'](_0x437532[_0x1b88('0x30')]);_0x5e2c90[_0x1b88('0x31')]=_['intersection'](_0x5e2c90['model'],_0x5e2c90[_0x1b88('0x30')]);_0x70e3fd['attributes']=_['intersection'](_0x5e2c90[_0x1b88('0x2f')],qs[_0x1b88('0x32')](_0x437532[_0x1b88('0x30')]['fields']));_0x70e3fd['attributes']=_0x70e3fd[_0x1b88('0x33')][_0x1b88('0x34')]?_0x70e3fd[_0x1b88('0x33')]:_0x5e2c90[_0x1b88('0x2f')];if(!_0x437532['query'][_0x1b88('0x35')]('nolimit')){_0x70e3fd[_0x1b88('0x1a')]=qs[_0x1b88('0x1a')](_0x437532[_0x1b88('0x30')][_0x1b88('0x1a')]);_0x70e3fd[_0x1b88('0x1d')]=qs[_0x1b88('0x1d')](_0x437532['query'][_0x1b88('0x1d')]);}_0x70e3fd[_0x1b88('0x36')]=qs[_0x1b88('0x37')](_0x437532[_0x1b88('0x30')][_0x1b88('0x37')]);_0x70e3fd['where']=qs['filters'](_[_0x1b88('0x38')](_0x437532[_0x1b88('0x30')],_0x5e2c90[_0x1b88('0x31')]),_0x1af869);if(_0x437532[_0x1b88('0x30')][_0x1b88('0x39')]){_0x70e3fd[_0x1b88('0x3a')]=_[_0x1b88('0x3b')](_0x70e3fd['where'],{'$or':_['map'](_0x1af869,function(_0x27b982){if(_0x27b982[_0x1b88('0x2d')]!=='VIRTUAL'){var _0x20e59d={};_0x20e59d[_0x27b982[_0x1b88('0x27')]]={'$like':'%'+_0x437532[_0x1b88('0x30')][_0x1b88('0x39')]+'%'};return _0x20e59d;}})});}_0x70e3fd=_[_0x1b88('0x3b')]({},_0x70e3fd,_0x437532[_0x1b88('0x3c')]);var _0x15cc7d={'where':_0x70e3fd[_0x1b88('0x3a')]};return db[_0x1b88('0x2b')][_0x1b88('0x1c')](_0x15cc7d)[_0x1b88('0x24')](function(_0x119a9c){_0x50ec32[_0x1b88('0x1c')]=_0x119a9c;if(_0x437532[_0x1b88('0x30')]['includeAll']){_0x70e3fd[_0x1b88('0x3d')]=[{'all':!![]}];}return db[_0x1b88('0x2b')][_0x1b88('0x3e')](_0x70e3fd);})[_0x1b88('0x24')](function(_0xbf21ca){_0x50ec32[_0x1b88('0x3f')]=_0xbf21ca;return _0x50ec32;})['then'](respondWithFilteredResult(_0x5855fe,_0x70e3fd))[_0x1b88('0x40')](handleError(_0x5855fe,null));};exports[_0x1b88('0x41')]=function(_0x5333f3,_0x4c240d){var _0x1e87ea={'raw':!![],'where':{'id':_0x5333f3['params']['id']}},_0x28e59a={};_0x28e59a[_0x1b88('0x2f')]=_[_0x1b88('0x42')](db['CmHopperHistory'][_0x1b88('0x43')]);_0x28e59a['query']=_[_0x1b88('0x42')](_0x5333f3['query']);_0x28e59a[_0x1b88('0x31')]=_[_0x1b88('0x44')](_0x28e59a[_0x1b88('0x2f')],_0x28e59a[_0x1b88('0x30')]);_0x1e87ea[_0x1b88('0x33')]=_['intersection'](_0x28e59a[_0x1b88('0x2f')],qs[_0x1b88('0x32')](_0x5333f3[_0x1b88('0x30')][_0x1b88('0x32')]));_0x1e87ea[_0x1b88('0x33')]=_0x1e87ea[_0x1b88('0x33')][_0x1b88('0x34')]?_0x1e87ea[_0x1b88('0x33')]:_0x28e59a['model'];if(_0x5333f3[_0x1b88('0x30')]['includeAll']){_0x1e87ea[_0x1b88('0x3d')]=[{'all':!![]}];}_0x1e87ea=_[_0x1b88('0x3b')]({},_0x1e87ea,_0x5333f3[_0x1b88('0x3c')]);return db[_0x1b88('0x2b')]['find'](_0x1e87ea)[_0x1b88('0x24')](handleEntityNotFound(_0x4c240d,null))[_0x1b88('0x24')](respondWithResult(_0x4c240d,null))[_0x1b88('0x40')](handleError(_0x4c240d,null));};exports[_0x1b88('0x45')]=function(_0xff0905,_0x152a6c){return db[_0x1b88('0x2b')][_0x1b88('0x45')](_0xff0905['body'],{})[_0x1b88('0x24')](respondWithResult(_0x152a6c,0xc9))['catch'](handleError(_0x152a6c,null));};exports[_0x1b88('0x46')]=function(_0x5aa473,_0x55ff83){return db[_0x1b88('0x2b')][_0x1b88('0x46')]()[_0x1b88('0x24')](respondWithResult(_0x55ff83,null))[_0x1b88('0x40')](handleError(_0x55ff83,null));};exports['update']=function(_0x4bd63a,_0x21521a){if(_0x4bd63a[_0x1b88('0x47')]['uniqueid']){delete _0x4bd63a[_0x1b88('0x47')]['uniqueid'];}return db[_0x1b88('0x2b')][_0x1b88('0x48')]({'where':{'uniqueid':_0x4bd63a['params']['id']}})[_0x1b88('0x24')](handleEntityNotFound(_0x21521a,null))[_0x1b88('0x24')](saveUpdates(_0x4bd63a[_0x1b88('0x47')],null))['then'](respondWithResult(_0x21521a,null))[_0x1b88('0x40')](handleError(_0x21521a,null));};