d020e595cddf7691b350321ad425bbbff3af489e
[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 _0xf00f=['uniqueid','find','eml-format','zip-dir','fast-json-patch','request-promise','moment','bluebird','util','path','sox','ejs','fs-extra','squel','crypto','jsforce','desk.js','to-csv','querystring','papaparse','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','api','../../config/utils','../../config/environment','../../mysqldb','status','end','json','undefined','limit','count','offset','set','apply','reject','save','update','then','error','stack','name','send','CmHopperHistory','rawAttributes','fieldName','type','key','model','map','keys','query','filters','intersection','attributes','fields','length','nolimit','order','sort','pick','filter','merge','where','options','includeAll','include','rows','show','params','catch','create','body','describe'];(function(_0x4d20e3,_0x1409c4){var _0xbcb8ac=function(_0x25dc86){while(--_0x25dc86){_0x4d20e3['push'](_0x4d20e3['shift']());}};_0xbcb8ac(++_0x1409c4);}(_0xf00f,0xec));var _0xff00=function(_0x186d17,_0x9fa8ef){_0x186d17=_0x186d17-0x0;var _0x5d4b89=_0xf00f[_0x186d17];return _0x5d4b89;};'use strict';var emlformat=require(_0xff00('0x0'));var rimraf=require('rimraf');var zipdir=require(_0xff00('0x1'));var jsonpatch=require(_0xff00('0x2'));var rp=require(_0xff00('0x3'));var moment=require(_0xff00('0x4'));var BPromise=require(_0xff00('0x5'));var Mustache=require('mustache');var util=require(_0xff00('0x6'));var path=require(_0xff00('0x7'));var sox=require(_0xff00('0x8'));var csv=require('to-csv');var ejs=require(_0xff00('0x9'));var fs=require('fs');var fs_extra=require(_0xff00('0xa'));var _=require('lodash');var squel=require(_0xff00('0xb'));var crypto=require(_0xff00('0xc'));var jsforce=require(_0xff00('0xd'));var deskjs=require(_0xff00('0xe'));var toCsv=require(_0xff00('0xf'));var querystring=require(_0xff00('0x10'));var Papa=require(_0xff00('0x11'));var Redis=require(_0xff00('0x12'));var authService=require(_0xff00('0x13'));var qs=require(_0xff00('0x14'));var as=require(_0xff00('0x15'));var hardwareService=require(_0xff00('0x16'));var logger=require(_0xff00('0x17'))(_0xff00('0x18'));var utils=require(_0xff00('0x19'));var config=require(_0xff00('0x1a'));var licenseUtil=require('../../config/license/util');var db=require(_0xff00('0x1b'))['db'];function respondWithStatusCode(_0x2b6ee4,_0x8ce972){_0x8ce972=_0x8ce972||0xcc;return function(_0x3042ad){if(_0x3042ad){return _0x2b6ee4['sendStatus'](_0x8ce972);}return _0x2b6ee4[_0xff00('0x1c')](_0x8ce972)[_0xff00('0x1d')]();};}function respondWithResult(_0x15ce1b,_0x4f42fc){_0x4f42fc=_0x4f42fc||0xc8;return function(_0xe3240){if(_0xe3240){return _0x15ce1b['status'](_0x4f42fc)[_0xff00('0x1e')](_0xe3240);}};}function respondWithFilteredResult(_0x5c3542,_0x4bae69){return function(_0x353dd3){if(_0x353dd3){var _0x3ce23b=typeof _0x4bae69['offset']===_0xff00('0x1f')&&typeof _0x4bae69[_0xff00('0x20')]===_0xff00('0x1f');var _0x4e99c9=_0x353dd3[_0xff00('0x21')];var _0x2cbfd6=_0x3ce23b?0x0:_0x4bae69[_0xff00('0x22')];var _0x241ea8=_0x3ce23b?_0x353dd3[_0xff00('0x21')]:_0x4bae69['offset']+_0x4bae69[_0xff00('0x20')];var _0x437f1a;if(_0x241ea8>=_0x4e99c9){_0x241ea8=_0x4e99c9;_0x437f1a=0xc8;}else{_0x437f1a=0xce;}_0x5c3542[_0xff00('0x1c')](_0x437f1a);return _0x5c3542[_0xff00('0x23')]('Content-Range',_0x2cbfd6+'-'+_0x241ea8+'/'+_0x4e99c9)[_0xff00('0x1e')](_0x353dd3);}return null;};}function patchUpdates(_0x2badaa){return function(_0x2b6713){try{jsonpatch[_0xff00('0x24')](_0x2b6713,_0x2badaa,!![]);}catch(_0x3ad944){return BPromise[_0xff00('0x25')](_0x3ad944);}return _0x2b6713[_0xff00('0x26')]();};}function saveUpdates(_0x12785d,_0x24486e){return function(_0x1b94cb){if(_0x1b94cb){return _0x1b94cb[_0xff00('0x27')](_0x12785d)[_0xff00('0x28')](function(_0x1f6edd){return _0x1f6edd;});}return null;};}function removeEntity(_0x37ce66,_0x45e8fe){return function(_0x4b4223){if(_0x4b4223){return _0x4b4223['destroy']()[_0xff00('0x28')](function(){_0x37ce66[_0xff00('0x1c')](0xcc)[_0xff00('0x1d')]();});}};}function handleEntityNotFound(_0x34831d,_0x1c7f01){return function(_0x17c973){if(!_0x17c973){_0x34831d['sendStatus'](0x194);}return _0x17c973;};}function handleError(_0x36336d,_0x3ec8c3){_0x3ec8c3=_0x3ec8c3||0x1f4;return function(_0x5a27af){logger[_0xff00('0x29')](_0x5a27af[_0xff00('0x2a')]);if(_0x5a27af[_0xff00('0x2b')]){delete _0x5a27af['name'];}_0x36336d[_0xff00('0x1c')](_0x3ec8c3)[_0xff00('0x2c')](_0x5a27af);};}exports['index']=function(_0x5b4455,_0x4b80c6){var _0x46ae4f={},_0x213244={},_0x4f0ee4={'count':0x0,'rows':[]};var _0x26f612=_['map'](db[_0xff00('0x2d')][_0xff00('0x2e')],function(_0x209a94){return{'name':_0x209a94[_0xff00('0x2f')],'type':_0x209a94[_0xff00('0x30')][_0xff00('0x31')]};});_0x213244[_0xff00('0x32')]=_[_0xff00('0x33')](_0x26f612,'name');_0x213244['query']=_[_0xff00('0x34')](_0x5b4455[_0xff00('0x35')]);_0x213244[_0xff00('0x36')]=_[_0xff00('0x37')](_0x213244[_0xff00('0x32')],_0x213244[_0xff00('0x35')]);_0x46ae4f[_0xff00('0x38')]=_[_0xff00('0x37')](_0x213244[_0xff00('0x32')],qs[_0xff00('0x39')](_0x5b4455[_0xff00('0x35')][_0xff00('0x39')]));_0x46ae4f['attributes']=_0x46ae4f[_0xff00('0x38')][_0xff00('0x3a')]?_0x46ae4f['attributes']:_0x213244['model'];if(!_0x5b4455[_0xff00('0x35')]['hasOwnProperty'](_0xff00('0x3b'))){_0x46ae4f['limit']=qs[_0xff00('0x20')](_0x5b4455[_0xff00('0x35')][_0xff00('0x20')]);_0x46ae4f[_0xff00('0x22')]=qs[_0xff00('0x22')](_0x5b4455[_0xff00('0x35')][_0xff00('0x22')]);}_0x46ae4f[_0xff00('0x3c')]=qs[_0xff00('0x3d')](_0x5b4455[_0xff00('0x35')][_0xff00('0x3d')]);_0x46ae4f['where']=qs[_0xff00('0x36')](_[_0xff00('0x3e')](_0x5b4455[_0xff00('0x35')],_0x213244['filters']),_0x26f612);if(_0x5b4455[_0xff00('0x35')][_0xff00('0x3f')]){_0x46ae4f['where']=_[_0xff00('0x40')](_0x46ae4f[_0xff00('0x41')],{'$or':_[_0xff00('0x33')](_0x26f612,function(_0x211f2f){if(_0x211f2f['type']!=='VIRTUAL'){var _0x3e6460={};_0x3e6460[_0x211f2f[_0xff00('0x2b')]]={'$like':'%'+_0x5b4455[_0xff00('0x35')][_0xff00('0x3f')]+'%'};return _0x3e6460;}})});}_0x46ae4f=_[_0xff00('0x40')]({},_0x46ae4f,_0x5b4455[_0xff00('0x42')]);var _0x46d7b7={'where':_0x46ae4f['where']};return db[_0xff00('0x2d')]['count'](_0x46d7b7)[_0xff00('0x28')](function(_0x4643fa){_0x4f0ee4[_0xff00('0x21')]=_0x4643fa;if(_0x5b4455[_0xff00('0x35')][_0xff00('0x43')]){_0x46ae4f[_0xff00('0x44')]=[{'all':!![]}];}return db['CmHopperHistory']['findAll'](_0x46ae4f);})['then'](function(_0xc73369){_0x4f0ee4[_0xff00('0x45')]=_0xc73369;return _0x4f0ee4;})['then'](respondWithFilteredResult(_0x4b80c6,_0x46ae4f))['catch'](handleError(_0x4b80c6,null));};exports[_0xff00('0x46')]=function(_0x5eef53,_0x5c65c6){var _0x52171a={'raw':!![],'where':{'id':_0x5eef53[_0xff00('0x47')]['id']}},_0x1166a5={};_0x1166a5[_0xff00('0x32')]=_[_0xff00('0x34')](db['CmHopperHistory'][_0xff00('0x2e')]);_0x1166a5['query']=_[_0xff00('0x34')](_0x5eef53[_0xff00('0x35')]);_0x1166a5['filters']=_['intersection'](_0x1166a5[_0xff00('0x32')],_0x1166a5[_0xff00('0x35')]);_0x52171a[_0xff00('0x38')]=_['intersection'](_0x1166a5[_0xff00('0x32')],qs[_0xff00('0x39')](_0x5eef53[_0xff00('0x35')][_0xff00('0x39')]));_0x52171a[_0xff00('0x38')]=_0x52171a['attributes'][_0xff00('0x3a')]?_0x52171a[_0xff00('0x38')]:_0x1166a5[_0xff00('0x32')];if(_0x5eef53[_0xff00('0x35')][_0xff00('0x43')]){_0x52171a[_0xff00('0x44')]=[{'all':!![]}];}_0x52171a=_[_0xff00('0x40')]({},_0x52171a,_0x5eef53[_0xff00('0x42')]);return db[_0xff00('0x2d')]['find'](_0x52171a)[_0xff00('0x28')](handleEntityNotFound(_0x5c65c6,null))['then'](respondWithResult(_0x5c65c6,null))[_0xff00('0x48')](handleError(_0x5c65c6,null));};exports[_0xff00('0x49')]=function(_0x557eea,_0x3ebdfd){return db[_0xff00('0x2d')][_0xff00('0x49')](_0x557eea[_0xff00('0x4a')],{})[_0xff00('0x28')](respondWithResult(_0x3ebdfd,0xc9))[_0xff00('0x48')](handleError(_0x3ebdfd,null));};exports['describe']=function(_0x29fb12,_0x495b2e){return db[_0xff00('0x2d')][_0xff00('0x4b')]()[_0xff00('0x28')](respondWithResult(_0x495b2e,null))[_0xff00('0x48')](handleError(_0x495b2e,null));};exports[_0xff00('0x27')]=function(_0x2d0662,_0x422bd6){if(_0x2d0662[_0xff00('0x4a')][_0xff00('0x4c')]){delete _0x2d0662[_0xff00('0x4a')][_0xff00('0x4c')];}return db[_0xff00('0x2d')][_0xff00('0x4d')]({'where':{'uniqueid':_0x2d0662[_0xff00('0x47')]['id']}})[_0xff00('0x28')](handleEntityNotFound(_0x422bd6,null))[_0xff00('0x28')](saveUpdates(_0x2d0662[_0xff00('0x4a')],null))[_0xff00('0x28')](respondWithResult(_0x422bd6,null))[_0xff00('0x48')](handleError(_0x422bd6,null));};