Built motion from commit da617fac.|2.6.6
[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 _0x4d84=['filters','intersection','fields','attributes','hasOwnProperty','nolimit','order','sort','where','merge','filter','options','include','findAll','rows','show','length','includeAll','find','create','body','catch','describe','params','eml-format','rimraf','fast-json-patch','request-promise','mustache','util','path','sox','to-csv','ejs','fs-extra','lodash','crypto','desk.js','querystring','ioredis','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','api','../../config/utils','../../config/environment','../../config/license/util','../../mysqldb','status','json','offset','undefined','limit','count','Content-Range','reject','save','update','then','destroy','end','error','stack','name','index','map','CmHopperHistory','rawAttributes','fieldName','type','key','model','query','keys'];(function(_0x387a18,_0x4d00c6){var _0x219016=function(_0x5c343b){while(--_0x5c343b){_0x387a18['push'](_0x387a18['shift']());}};_0x219016(++_0x4d00c6);}(_0x4d84,0xf9));var _0x44d8=function(_0x2edf70,_0x3b24e1){_0x2edf70=_0x2edf70-0x0;var _0x193515=_0x4d84[_0x2edf70];return _0x193515;};'use strict';var emlformat=require(_0x44d8('0x0'));var rimraf=require(_0x44d8('0x1'));var zipdir=require('zip-dir');var jsonpatch=require(_0x44d8('0x2'));var rp=require(_0x44d8('0x3'));var moment=require('moment');var BPromise=require('bluebird');var Mustache=require(_0x44d8('0x4'));var util=require(_0x44d8('0x5'));var path=require(_0x44d8('0x6'));var sox=require(_0x44d8('0x7'));var csv=require(_0x44d8('0x8'));var ejs=require(_0x44d8('0x9'));var fs=require('fs');var fs_extra=require(_0x44d8('0xa'));var _=require(_0x44d8('0xb'));var squel=require('squel');var crypto=require(_0x44d8('0xc'));var jsforce=require('jsforce');var deskjs=require(_0x44d8('0xd'));var toCsv=require(_0x44d8('0x8'));var querystring=require(_0x44d8('0xe'));var Papa=require('papaparse');var Redis=require(_0x44d8('0xf'));var authService=require('../../components/auth/service');var qs=require(_0x44d8('0x10'));var as=require(_0x44d8('0x11'));var hardwareService=require(_0x44d8('0x12'));var logger=require(_0x44d8('0x13'))(_0x44d8('0x14'));var utils=require(_0x44d8('0x15'));var config=require(_0x44d8('0x16'));var licenseUtil=require(_0x44d8('0x17'));var db=require(_0x44d8('0x18'))['db'];function respondWithStatusCode(_0x51f32e,_0x26bc7e){_0x26bc7e=_0x26bc7e||0xcc;return function(_0x26b3b0){if(_0x26b3b0){return _0x51f32e['sendStatus'](_0x26bc7e);}return _0x51f32e[_0x44d8('0x19')](_0x26bc7e)['end']();};}function respondWithResult(_0x4e80a9,_0x1d82a8){_0x1d82a8=_0x1d82a8||0xc8;return function(_0x2fb39e){if(_0x2fb39e){return _0x4e80a9[_0x44d8('0x19')](_0x1d82a8)[_0x44d8('0x1a')](_0x2fb39e);}};}function respondWithFilteredResult(_0x46e0e5,_0x3a6514){return function(_0x20dfd9){if(_0x20dfd9){var _0x56d95f=typeof _0x3a6514[_0x44d8('0x1b')]===_0x44d8('0x1c')&&typeof _0x3a6514[_0x44d8('0x1d')]===_0x44d8('0x1c');var _0x3996c8=_0x20dfd9[_0x44d8('0x1e')];var _0x3258a3=_0x56d95f?0x0:_0x3a6514[_0x44d8('0x1b')];var _0x1e2e3a=_0x56d95f?_0x20dfd9[_0x44d8('0x1e')]:_0x3a6514[_0x44d8('0x1b')]+_0x3a6514[_0x44d8('0x1d')];var _0x1b6602;if(_0x1e2e3a>=_0x3996c8){_0x1e2e3a=_0x3996c8;_0x1b6602=0xc8;}else{_0x1b6602=0xce;}_0x46e0e5[_0x44d8('0x19')](_0x1b6602);return _0x46e0e5['set'](_0x44d8('0x1f'),_0x3258a3+'-'+_0x1e2e3a+'/'+_0x3996c8)['json'](_0x20dfd9);}return null;};}function patchUpdates(_0x422ebc){return function(_0x24f74d){try{jsonpatch['apply'](_0x24f74d,_0x422ebc,!![]);}catch(_0x33db4c){return BPromise[_0x44d8('0x20')](_0x33db4c);}return _0x24f74d[_0x44d8('0x21')]();};}function saveUpdates(_0x13839b,_0x4d5998){return function(_0x1573a3){if(_0x1573a3){return _0x1573a3[_0x44d8('0x22')](_0x13839b)[_0x44d8('0x23')](function(_0x313d18){return _0x313d18;});}return null;};}function removeEntity(_0x587568,_0x91a5f4){return function(_0x57bf04){if(_0x57bf04){return _0x57bf04[_0x44d8('0x24')]()[_0x44d8('0x23')](function(){_0x587568[_0x44d8('0x19')](0xcc)[_0x44d8('0x25')]();});}};}function handleEntityNotFound(_0x46645a,_0x3e42f5){return function(_0x598705){if(!_0x598705){_0x46645a['sendStatus'](0x194);}return _0x598705;};}function handleError(_0x444fa3,_0x17d6d4){_0x17d6d4=_0x17d6d4||0x1f4;return function(_0xafee8f){logger[_0x44d8('0x26')](_0xafee8f[_0x44d8('0x27')]);if(_0xafee8f[_0x44d8('0x28')]){delete _0xafee8f[_0x44d8('0x28')];}_0x444fa3[_0x44d8('0x19')](_0x17d6d4)['send'](_0xafee8f);};}exports[_0x44d8('0x29')]=function(_0x35e157,_0x5595af){var _0x350569={},_0x5898a0={},_0x43e3d8={'count':0x0,'rows':[]};var _0x42c017=_[_0x44d8('0x2a')](db[_0x44d8('0x2b')][_0x44d8('0x2c')],function(_0x21070e){return{'name':_0x21070e[_0x44d8('0x2d')],'type':_0x21070e[_0x44d8('0x2e')][_0x44d8('0x2f')]};});_0x5898a0[_0x44d8('0x30')]=_['map'](_0x42c017,_0x44d8('0x28'));_0x5898a0[_0x44d8('0x31')]=_[_0x44d8('0x32')](_0x35e157['query']);_0x5898a0[_0x44d8('0x33')]=_[_0x44d8('0x34')](_0x5898a0[_0x44d8('0x30')],_0x5898a0['query']);_0x350569['attributes']=_[_0x44d8('0x34')](_0x5898a0[_0x44d8('0x30')],qs['fields'](_0x35e157[_0x44d8('0x31')][_0x44d8('0x35')]));_0x350569[_0x44d8('0x36')]=_0x350569[_0x44d8('0x36')]['length']?_0x350569[_0x44d8('0x36')]:_0x5898a0[_0x44d8('0x30')];if(!_0x35e157[_0x44d8('0x31')][_0x44d8('0x37')](_0x44d8('0x38'))){_0x350569['limit']=qs[_0x44d8('0x1d')](_0x35e157[_0x44d8('0x31')][_0x44d8('0x1d')]);_0x350569[_0x44d8('0x1b')]=qs['offset'](_0x35e157[_0x44d8('0x31')][_0x44d8('0x1b')]);}_0x350569[_0x44d8('0x39')]=qs['sort'](_0x35e157[_0x44d8('0x31')][_0x44d8('0x3a')]);_0x350569[_0x44d8('0x3b')]=qs[_0x44d8('0x33')](_['pick'](_0x35e157[_0x44d8('0x31')],_0x5898a0[_0x44d8('0x33')]),_0x42c017);if(_0x35e157[_0x44d8('0x31')]['filter']){_0x350569['where']=_[_0x44d8('0x3c')](_0x350569[_0x44d8('0x3b')],{'$or':_['map'](_0x42c017,function(_0x469318){if(_0x469318[_0x44d8('0x2e')]!=='VIRTUAL'){var _0x59ec2c={};_0x59ec2c[_0x469318[_0x44d8('0x28')]]={'$like':'%'+_0x35e157[_0x44d8('0x31')][_0x44d8('0x3d')]+'%'};return _0x59ec2c;}})});}_0x350569=_[_0x44d8('0x3c')]({},_0x350569,_0x35e157[_0x44d8('0x3e')]);var _0x565db9={'where':_0x350569['where']};return db[_0x44d8('0x2b')][_0x44d8('0x1e')](_0x565db9)['then'](function(_0x8ceb6e){_0x43e3d8[_0x44d8('0x1e')]=_0x8ceb6e;if(_0x35e157[_0x44d8('0x31')]['includeAll']){_0x350569[_0x44d8('0x3f')]=[{'all':!![]}];}return db['CmHopperHistory'][_0x44d8('0x40')](_0x350569);})[_0x44d8('0x23')](function(_0x1b1c19){_0x43e3d8[_0x44d8('0x41')]=_0x1b1c19;return _0x43e3d8;})['then'](respondWithFilteredResult(_0x5595af,_0x350569))['catch'](handleError(_0x5595af,null));};exports[_0x44d8('0x42')]=function(_0xa8c8fe,_0x5111ed){var _0x107645={'raw':!![],'where':{'id':_0xa8c8fe['params']['id']}},_0x2c6943={};_0x2c6943[_0x44d8('0x30')]=_[_0x44d8('0x32')](db[_0x44d8('0x2b')][_0x44d8('0x2c')]);_0x2c6943[_0x44d8('0x31')]=_[_0x44d8('0x32')](_0xa8c8fe[_0x44d8('0x31')]);_0x2c6943[_0x44d8('0x33')]=_['intersection'](_0x2c6943[_0x44d8('0x30')],_0x2c6943['query']);_0x107645['attributes']=_['intersection'](_0x2c6943[_0x44d8('0x30')],qs[_0x44d8('0x35')](_0xa8c8fe[_0x44d8('0x31')][_0x44d8('0x35')]));_0x107645[_0x44d8('0x36')]=_0x107645[_0x44d8('0x36')][_0x44d8('0x43')]?_0x107645[_0x44d8('0x36')]:_0x2c6943[_0x44d8('0x30')];if(_0xa8c8fe[_0x44d8('0x31')][_0x44d8('0x44')]){_0x107645[_0x44d8('0x3f')]=[{'all':!![]}];}_0x107645=_[_0x44d8('0x3c')]({},_0x107645,_0xa8c8fe['options']);return db[_0x44d8('0x2b')][_0x44d8('0x45')](_0x107645)[_0x44d8('0x23')](handleEntityNotFound(_0x5111ed,null))[_0x44d8('0x23')](respondWithResult(_0x5111ed,null))['catch'](handleError(_0x5111ed,null));};exports[_0x44d8('0x46')]=function(_0x2b4f32,_0x162b46){return db[_0x44d8('0x2b')]['create'](_0x2b4f32[_0x44d8('0x47')],{})[_0x44d8('0x23')](respondWithResult(_0x162b46,0xc9))[_0x44d8('0x48')](handleError(_0x162b46,null));};exports[_0x44d8('0x49')]=function(_0x51abb1,_0x5f33df){return db['CmHopperHistory'][_0x44d8('0x49')]()['then'](respondWithResult(_0x5f33df,null))['catch'](handleError(_0x5f33df,null));};exports[_0x44d8('0x22')]=function(_0x2a3cd0,_0x53e74a){if(_0x2a3cd0['body']['uniqueid']){delete _0x2a3cd0[_0x44d8('0x47')]['uniqueid'];}return db['CmHopperHistory']['find']({'where':{'uniqueid':_0x2a3cd0[_0x44d8('0x4a')]['id']}})[_0x44d8('0x23')](handleEntityNotFound(_0x53e74a,null))['then'](saveUpdates(_0x2a3cd0[_0x44d8('0x47')],null))[_0x44d8('0x23')](respondWithResult(_0x53e74a,null))['catch'](handleError(_0x53e74a,null));};