Built motion from commit c116dc8b.|2.6.30
[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 _0xe725=['undefined','count','set','Content-Range','apply','update','destroy','then','error','name','send','index','fieldName','type','key','model','map','query','keys','filters','intersection','fields','attributes','length','hasOwnProperty','order','sort','pick','merge','where','VIRTUAL','filter','CmHopperHistory','includeAll','include','findAll','rows','catch','show','options','find','create','describe','body','uniqueid','params','eml-format','rimraf','zip-dir','request-promise','moment','bluebird','mustache','util','path','sox','to-csv','fs-extra','squel','jsforce','desk.js','querystring','papaparse','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','../../config/environment','../../config/license/util','status','end','json','offset','limit'];(function(_0x23b776,_0x498230){var _0x27e693=function(_0x5ae8da){while(--_0x5ae8da){_0x23b776['push'](_0x23b776['shift']());}};_0x27e693(++_0x498230);}(_0xe725,0x15a));var _0x5e72=function(_0x3dd15e,_0x1f0015){_0x3dd15e=_0x3dd15e-0x0;var _0x231fd0=_0xe725[_0x3dd15e];return _0x231fd0;};'use strict';var emlformat=require(_0x5e72('0x0'));var rimraf=require(_0x5e72('0x1'));var zipdir=require(_0x5e72('0x2'));var jsonpatch=require('fast-json-patch');var rp=require(_0x5e72('0x3'));var moment=require(_0x5e72('0x4'));var BPromise=require(_0x5e72('0x5'));var Mustache=require(_0x5e72('0x6'));var util=require(_0x5e72('0x7'));var path=require(_0x5e72('0x8'));var sox=require(_0x5e72('0x9'));var csv=require(_0x5e72('0xa'));var ejs=require('ejs');var fs=require('fs');var fs_extra=require(_0x5e72('0xb'));var _=require('lodash');var squel=require(_0x5e72('0xc'));var crypto=require('crypto');var jsforce=require(_0x5e72('0xd'));var deskjs=require(_0x5e72('0xe'));var toCsv=require(_0x5e72('0xa'));var querystring=require(_0x5e72('0xf'));var Papa=require(_0x5e72('0x10'));var Redis=require('ioredis');var authService=require(_0x5e72('0x11'));var qs=require(_0x5e72('0x12'));var as=require(_0x5e72('0x13'));var hardwareService=require(_0x5e72('0x14'));var logger=require(_0x5e72('0x15'))('api');var utils=require('../../config/utils');var config=require(_0x5e72('0x16'));var licenseUtil=require(_0x5e72('0x17'));var db=require('../../mysqldb')['db'];function respondWithStatusCode(_0x1a45bc,_0x3ca86d){_0x3ca86d=_0x3ca86d||0xcc;return function(_0x4ce670){if(_0x4ce670){return _0x1a45bc['sendStatus'](_0x3ca86d);}return _0x1a45bc[_0x5e72('0x18')](_0x3ca86d)[_0x5e72('0x19')]();};}function respondWithResult(_0x30370a,_0x40ff0c){_0x40ff0c=_0x40ff0c||0xc8;return function(_0x3cf63e){if(_0x3cf63e){return _0x30370a[_0x5e72('0x18')](_0x40ff0c)[_0x5e72('0x1a')](_0x3cf63e);}};}function respondWithFilteredResult(_0x48b104,_0x6d7861){return function(_0x59e751){if(_0x59e751){var _0x72a9a3=typeof _0x6d7861[_0x5e72('0x1b')]==='undefined'&&typeof _0x6d7861[_0x5e72('0x1c')]===_0x5e72('0x1d');var _0x19aaf9=_0x59e751[_0x5e72('0x1e')];var _0x422f32=_0x72a9a3?0x0:_0x6d7861[_0x5e72('0x1b')];var _0x4df550=_0x72a9a3?_0x59e751['count']:_0x6d7861[_0x5e72('0x1b')]+_0x6d7861[_0x5e72('0x1c')];var _0x27da22;if(_0x4df550>=_0x19aaf9){_0x4df550=_0x19aaf9;_0x27da22=0xc8;}else{_0x27da22=0xce;}_0x48b104['status'](_0x27da22);return _0x48b104[_0x5e72('0x1f')](_0x5e72('0x20'),_0x422f32+'-'+_0x4df550+'/'+_0x19aaf9)[_0x5e72('0x1a')](_0x59e751);}return null;};}function patchUpdates(_0x360675){return function(_0x46bf5c){try{jsonpatch[_0x5e72('0x21')](_0x46bf5c,_0x360675,!![]);}catch(_0x3e0f07){return BPromise['reject'](_0x3e0f07);}return _0x46bf5c['save']();};}function saveUpdates(_0x25c130,_0x1ad198){return function(_0x2403e1){if(_0x2403e1){return _0x2403e1[_0x5e72('0x22')](_0x25c130)['then'](function(_0x172dee){return _0x172dee;});}return null;};}function removeEntity(_0x1d766e,_0x41ea7b){return function(_0x44a445){if(_0x44a445){return _0x44a445[_0x5e72('0x23')]()[_0x5e72('0x24')](function(){_0x1d766e['status'](0xcc)[_0x5e72('0x19')]();});}};}function handleEntityNotFound(_0x2be15e,_0x5a4dd1){return function(_0x234b2e){if(!_0x234b2e){_0x2be15e['sendStatus'](0x194);}return _0x234b2e;};}function handleError(_0x3c9da5,_0x1bf97c){_0x1bf97c=_0x1bf97c||0x1f4;return function(_0x10e6d4){logger[_0x5e72('0x25')](_0x10e6d4['stack']);if(_0x10e6d4[_0x5e72('0x26')]){delete _0x10e6d4['name'];}_0x3c9da5['status'](_0x1bf97c)[_0x5e72('0x27')](_0x10e6d4);};}exports[_0x5e72('0x28')]=function(_0x37f2bd,_0xef2cd0){var _0x137218={},_0x447893={},_0x44ca47={'count':0x0,'rows':[]};var _0x31aa1f=_['map'](db['CmHopperHistory']['rawAttributes'],function(_0xa25423){return{'name':_0xa25423[_0x5e72('0x29')],'type':_0xa25423[_0x5e72('0x2a')][_0x5e72('0x2b')]};});_0x447893[_0x5e72('0x2c')]=_[_0x5e72('0x2d')](_0x31aa1f,_0x5e72('0x26'));_0x447893[_0x5e72('0x2e')]=_[_0x5e72('0x2f')](_0x37f2bd[_0x5e72('0x2e')]);_0x447893[_0x5e72('0x30')]=_[_0x5e72('0x31')](_0x447893[_0x5e72('0x2c')],_0x447893[_0x5e72('0x2e')]);_0x137218['attributes']=_[_0x5e72('0x31')](_0x447893[_0x5e72('0x2c')],qs[_0x5e72('0x32')](_0x37f2bd[_0x5e72('0x2e')][_0x5e72('0x32')]));_0x137218[_0x5e72('0x33')]=_0x137218[_0x5e72('0x33')][_0x5e72('0x34')]?_0x137218[_0x5e72('0x33')]:_0x447893[_0x5e72('0x2c')];if(!_0x37f2bd[_0x5e72('0x2e')][_0x5e72('0x35')]('nolimit')){_0x137218[_0x5e72('0x1c')]=qs[_0x5e72('0x1c')](_0x37f2bd[_0x5e72('0x2e')]['limit']);_0x137218[_0x5e72('0x1b')]=qs[_0x5e72('0x1b')](_0x37f2bd[_0x5e72('0x2e')][_0x5e72('0x1b')]);}_0x137218[_0x5e72('0x36')]=qs[_0x5e72('0x37')](_0x37f2bd['query']['sort']);_0x137218['where']=qs[_0x5e72('0x30')](_[_0x5e72('0x38')](_0x37f2bd[_0x5e72('0x2e')],_0x447893[_0x5e72('0x30')]),_0x31aa1f);if(_0x37f2bd['query']['filter']){_0x137218['where']=_[_0x5e72('0x39')](_0x137218[_0x5e72('0x3a')],{'$or':_[_0x5e72('0x2d')](_0x31aa1f,function(_0x99c318){if(_0x99c318[_0x5e72('0x2a')]!==_0x5e72('0x3b')){var _0x1ae09d={};_0x1ae09d[_0x99c318[_0x5e72('0x26')]]={'$like':'%'+_0x37f2bd['query'][_0x5e72('0x3c')]+'%'};return _0x1ae09d;}})});}_0x137218=_[_0x5e72('0x39')]({},_0x137218,_0x37f2bd['options']);var _0x4a89e8={'where':_0x137218[_0x5e72('0x3a')]};return db[_0x5e72('0x3d')][_0x5e72('0x1e')](_0x4a89e8)['then'](function(_0x39959d){_0x44ca47[_0x5e72('0x1e')]=_0x39959d;if(_0x37f2bd[_0x5e72('0x2e')][_0x5e72('0x3e')]){_0x137218[_0x5e72('0x3f')]=[{'all':!![]}];}return db['CmHopperHistory'][_0x5e72('0x40')](_0x137218);})[_0x5e72('0x24')](function(_0x413537){_0x44ca47[_0x5e72('0x41')]=_0x413537;return _0x44ca47;})['then'](respondWithFilteredResult(_0xef2cd0,_0x137218))[_0x5e72('0x42')](handleError(_0xef2cd0,null));};exports[_0x5e72('0x43')]=function(_0x167415,_0xeebd6){var _0x5ac767={'raw':!![],'where':{'id':_0x167415['params']['id']}},_0x1ff102={};_0x1ff102[_0x5e72('0x2c')]=_[_0x5e72('0x2f')](db[_0x5e72('0x3d')]['rawAttributes']);_0x1ff102['query']=_['keys'](_0x167415[_0x5e72('0x2e')]);_0x1ff102[_0x5e72('0x30')]=_['intersection'](_0x1ff102['model'],_0x1ff102['query']);_0x5ac767['attributes']=_[_0x5e72('0x31')](_0x1ff102[_0x5e72('0x2c')],qs[_0x5e72('0x32')](_0x167415['query'][_0x5e72('0x32')]));_0x5ac767[_0x5e72('0x33')]=_0x5ac767[_0x5e72('0x33')][_0x5e72('0x34')]?_0x5ac767[_0x5e72('0x33')]:_0x1ff102[_0x5e72('0x2c')];if(_0x167415[_0x5e72('0x2e')]['includeAll']){_0x5ac767[_0x5e72('0x3f')]=[{'all':!![]}];}_0x5ac767=_[_0x5e72('0x39')]({},_0x5ac767,_0x167415[_0x5e72('0x44')]);return db[_0x5e72('0x3d')][_0x5e72('0x45')](_0x5ac767)[_0x5e72('0x24')](handleEntityNotFound(_0xeebd6,null))['then'](respondWithResult(_0xeebd6,null))[_0x5e72('0x42')](handleError(_0xeebd6,null));};exports[_0x5e72('0x46')]=function(_0x48164e,_0x7ad03){return db['CmHopperHistory'][_0x5e72('0x46')](_0x48164e['body'],{})['then'](respondWithResult(_0x7ad03,0xc9))['catch'](handleError(_0x7ad03,null));};exports[_0x5e72('0x47')]=function(_0x1e5545,_0x164393){return db[_0x5e72('0x3d')]['describe']()['then'](respondWithResult(_0x164393,null))[_0x5e72('0x42')](handleError(_0x164393,null));};exports[_0x5e72('0x22')]=function(_0x27a68c,_0x3c721c){if(_0x27a68c[_0x5e72('0x48')][_0x5e72('0x49')]){delete _0x27a68c[_0x5e72('0x48')][_0x5e72('0x49')];}return db['CmHopperHistory'][_0x5e72('0x45')]({'where':{'uniqueid':_0x27a68c[_0x5e72('0x4a')]['id']}})[_0x5e72('0x24')](handleEntityNotFound(_0x3c721c,null))['then'](saveUpdates(_0x27a68c[_0x5e72('0x48')],null))[_0x5e72('0x24')](respondWithResult(_0x3c721c,null))[_0x5e72('0x42')](handleError(_0x3c721c,null));};