f2a409a36a1d59c95ca88c389ccb6810991c73ee
[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 _0xb573=['merge','VIRTUAL','options','includeAll','include','findAll','rows','show','intersection','length','catch','create','body','describe','uniqueid','find','html-pdf','eml-format','rimraf','request-promise','bluebird','mustache','util','sox','to-csv','ejs','crypto','desk.js','querystring','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','api','../../config/utils','../../config/environment','../../config/license/util','../../mysqldb','sendStatus','status','end','count','offset','limit','set','Content-Range','json','apply','reject','save','update','destroy','then','error','name','send','index','map','CmHopperHistory','rawAttributes','type','key','query','keys','filters','model','attributes','fields','hasOwnProperty','nolimit','order','where','pick','filter'];(function(_0x4dc7b9,_0x319d5a){var _0x3ab114=function(_0x51a9df){while(--_0x51a9df){_0x4dc7b9['push'](_0x4dc7b9['shift']());}};_0x3ab114(++_0x319d5a);}(_0xb573,0x18c));var _0x3b57=function(_0x3dd15e,_0x1f0015){_0x3dd15e=_0x3dd15e-0x0;var _0x231fd0=_0xb573[_0x3dd15e];return _0x231fd0;};'use strict';var pdf=require(_0x3b57('0x0'));var emlformat=require(_0x3b57('0x1'));var rimraf=require(_0x3b57('0x2'));var zipdir=require('zip-dir');var jsonpatch=require('fast-json-patch');var rp=require(_0x3b57('0x3'));var moment=require('moment');var BPromise=require(_0x3b57('0x4'));var Mustache=require(_0x3b57('0x5'));var util=require(_0x3b57('0x6'));var path=require('path');var sox=require(_0x3b57('0x7'));var csv=require(_0x3b57('0x8'));var ejs=require(_0x3b57('0x9'));var fs=require('fs');var _=require('lodash');var squel=require('squel');var crypto=require(_0x3b57('0xa'));var jsforce=require('jsforce');var deskjs=require(_0x3b57('0xb'));var toCsv=require(_0x3b57('0x8'));var querystring=require(_0x3b57('0xc'));var Papa=require('papaparse');var Redis=require(_0x3b57('0xd'));var authService=require(_0x3b57('0xe'));var qs=require(_0x3b57('0xf'));var as=require(_0x3b57('0x10'));var hardwareService=require(_0x3b57('0x11'));var logger=require(_0x3b57('0x12'))(_0x3b57('0x13'));var utils=require(_0x3b57('0x14'));var config=require(_0x3b57('0x15'));var licenseUtil=require(_0x3b57('0x16'));var db=require(_0x3b57('0x17'))['db'];function respondWithStatusCode(_0x31603c,_0x143cd7){_0x143cd7=_0x143cd7||0xcc;return function(_0x3c2f3d){if(_0x3c2f3d){return _0x31603c[_0x3b57('0x18')](_0x143cd7);}return _0x31603c[_0x3b57('0x19')](_0x143cd7)[_0x3b57('0x1a')]();};}function respondWithResult(_0x391797,_0x49fbeb){_0x49fbeb=_0x49fbeb||0xc8;return function(_0x3626a9){if(_0x3626a9){return _0x391797[_0x3b57('0x19')](_0x49fbeb)['json'](_0x3626a9);}};}function respondWithFilteredResult(_0x41ab2a,_0x50171){return function(_0x1af032){if(_0x1af032){var _0x3cad32=_0x1af032[_0x3b57('0x1b')],_0x2437fd=_0x50171[_0x3b57('0x1c')],_0x57820c=_0x50171['offset']+_0x50171[_0x3b57('0x1d')],_0x5328de;if(_0x57820c>=_0x3cad32){_0x57820c=_0x3cad32;_0x5328de=0xc8;}else{_0x5328de=0xce;}_0x41ab2a[_0x3b57('0x19')](_0x5328de);return _0x41ab2a[_0x3b57('0x1e')](_0x3b57('0x1f'),_0x2437fd+'-'+_0x57820c+'/'+_0x3cad32)[_0x3b57('0x20')](_0x1af032);}return null;};}function patchUpdates(_0x59442b){return function(_0x47dd7e){try{jsonpatch[_0x3b57('0x21')](_0x47dd7e,_0x59442b,!![]);}catch(_0x30bf77){return BPromise[_0x3b57('0x22')](_0x30bf77);}return _0x47dd7e[_0x3b57('0x23')]();};}function saveUpdates(_0x37879b,_0x246ed0){return function(_0x6944ab){if(_0x6944ab){return _0x6944ab[_0x3b57('0x24')](_0x37879b)['then'](function(_0x1f8831){return _0x1f8831;});}return null;};}function removeEntity(_0x5ae266,_0x359f5f){return function(_0x3612ee){if(_0x3612ee){return _0x3612ee[_0x3b57('0x25')]()[_0x3b57('0x26')](function(){_0x5ae266[_0x3b57('0x19')](0xcc)[_0x3b57('0x1a')]();});}};}function handleEntityNotFound(_0x13b620,_0x5e67f6){return function(_0x59a883){if(!_0x59a883){_0x13b620[_0x3b57('0x18')](0x194);}return _0x59a883;};}function handleError(_0x441bd5,_0x1f2601){_0x1f2601=_0x1f2601||0x1f4;return function(_0x1dfd7b){logger[_0x3b57('0x27')](_0x1dfd7b['stack']);if(_0x1dfd7b[_0x3b57('0x28')]){delete _0x1dfd7b[_0x3b57('0x28')];}_0x441bd5[_0x3b57('0x19')](_0x1f2601)[_0x3b57('0x29')](_0x1dfd7b);};}exports[_0x3b57('0x2a')]=function(_0x27a901,_0x30b6a8){var _0x6e135={},_0x57a213={},_0x47d790={'count':0x0,'rows':[]};var _0xf3ffda=_[_0x3b57('0x2b')](db[_0x3b57('0x2c')][_0x3b57('0x2d')],function(_0x5eb5ff){return{'name':_0x5eb5ff['fieldName'],'type':_0x5eb5ff[_0x3b57('0x2e')][_0x3b57('0x2f')]};});_0x57a213['model']=_[_0x3b57('0x2b')](_0xf3ffda,_0x3b57('0x28'));_0x57a213[_0x3b57('0x30')]=_[_0x3b57('0x31')](_0x27a901[_0x3b57('0x30')]);_0x57a213[_0x3b57('0x32')]=_['intersection'](_0x57a213[_0x3b57('0x33')],_0x57a213['query']);_0x6e135[_0x3b57('0x34')]=_['intersection'](_0x57a213[_0x3b57('0x33')],qs[_0x3b57('0x35')](_0x27a901[_0x3b57('0x30')]['fields']));_0x6e135['attributes']=_0x6e135[_0x3b57('0x34')]['length']?_0x6e135['attributes']:_0x57a213[_0x3b57('0x33')];if(!_0x27a901[_0x3b57('0x30')][_0x3b57('0x36')](_0x3b57('0x37'))){_0x6e135['limit']=qs[_0x3b57('0x1d')](_0x27a901[_0x3b57('0x30')]['limit']);_0x6e135[_0x3b57('0x1c')]=qs[_0x3b57('0x1c')](_0x27a901[_0x3b57('0x30')][_0x3b57('0x1c')]);}_0x6e135[_0x3b57('0x38')]=qs['sort'](_0x27a901[_0x3b57('0x30')]['sort']);_0x6e135[_0x3b57('0x39')]=qs[_0x3b57('0x32')](_[_0x3b57('0x3a')](_0x27a901['query'],_0x57a213[_0x3b57('0x32')]),_0xf3ffda);if(_0x27a901[_0x3b57('0x30')][_0x3b57('0x3b')]){_0x6e135['where']=_[_0x3b57('0x3c')](_0x6e135[_0x3b57('0x39')],{'$or':_[_0x3b57('0x2b')](_0xf3ffda,function(_0x5ccec0){if(_0x5ccec0[_0x3b57('0x2e')]!==_0x3b57('0x3d')){var _0x545806={};_0x545806[_0x5ccec0[_0x3b57('0x28')]]={'$like':'%'+_0x27a901[_0x3b57('0x30')][_0x3b57('0x3b')]+'%'};return _0x545806;}})});}_0x6e135=_[_0x3b57('0x3c')]({},_0x6e135,_0x27a901[_0x3b57('0x3e')]);var _0x24620a={'where':_0x6e135['where']};return db[_0x3b57('0x2c')]['count'](_0x24620a)[_0x3b57('0x26')](function(_0x3f6d29){_0x47d790[_0x3b57('0x1b')]=_0x3f6d29;if(_0x27a901[_0x3b57('0x30')][_0x3b57('0x3f')]){_0x6e135[_0x3b57('0x40')]=[{'all':!![]}];}return db[_0x3b57('0x2c')][_0x3b57('0x41')](_0x6e135);})[_0x3b57('0x26')](function(_0x228261){_0x47d790[_0x3b57('0x42')]=_0x228261;return _0x47d790;})['then'](respondWithFilteredResult(_0x30b6a8,_0x6e135))['catch'](handleError(_0x30b6a8,null));};exports[_0x3b57('0x43')]=function(_0x211d26,_0x197c85){var _0x4f4f50={'raw':!![],'where':{'id':_0x211d26['params']['id']}},_0x86dacb={};_0x86dacb[_0x3b57('0x33')]=_[_0x3b57('0x31')](db[_0x3b57('0x2c')][_0x3b57('0x2d')]);_0x86dacb[_0x3b57('0x30')]=_['keys'](_0x211d26['query']);_0x86dacb[_0x3b57('0x32')]=_[_0x3b57('0x44')](_0x86dacb[_0x3b57('0x33')],_0x86dacb[_0x3b57('0x30')]);_0x4f4f50[_0x3b57('0x34')]=_[_0x3b57('0x44')](_0x86dacb[_0x3b57('0x33')],qs[_0x3b57('0x35')](_0x211d26['query'][_0x3b57('0x35')]));_0x4f4f50[_0x3b57('0x34')]=_0x4f4f50['attributes'][_0x3b57('0x45')]?_0x4f4f50[_0x3b57('0x34')]:_0x86dacb[_0x3b57('0x33')];if(_0x211d26[_0x3b57('0x30')]['includeAll']){_0x4f4f50[_0x3b57('0x40')]=[{'all':!![]}];}_0x4f4f50=_[_0x3b57('0x3c')]({},_0x4f4f50,_0x211d26[_0x3b57('0x3e')]);return db['CmHopperHistory']['find'](_0x4f4f50)[_0x3b57('0x26')](handleEntityNotFound(_0x197c85,null))[_0x3b57('0x26')](respondWithResult(_0x197c85,null))[_0x3b57('0x46')](handleError(_0x197c85,null));};exports[_0x3b57('0x47')]=function(_0x4bff93,_0x4af4c1){return db['CmHopperHistory'][_0x3b57('0x47')](_0x4bff93[_0x3b57('0x48')],{})[_0x3b57('0x26')](respondWithResult(_0x4af4c1,0xc9))[_0x3b57('0x46')](handleError(_0x4af4c1,null));};exports[_0x3b57('0x49')]=function(_0x299858,_0x1b85e0){return db[_0x3b57('0x2c')][_0x3b57('0x49')]()[_0x3b57('0x26')](respondWithResult(_0x1b85e0,null))[_0x3b57('0x46')](handleError(_0x1b85e0,null));};exports[_0x3b57('0x24')]=function(_0x34a8c9,_0x4b6940){if(_0x34a8c9[_0x3b57('0x48')][_0x3b57('0x4a')]){delete _0x34a8c9[_0x3b57('0x48')][_0x3b57('0x4a')];}return db['CmHopperHistory'][_0x3b57('0x4b')]({'where':{'uniqueid':_0x34a8c9['params']['id']}})[_0x3b57('0x26')](handleEntityNotFound(_0x4b6940,null))[_0x3b57('0x26')](saveUpdates(_0x34a8c9[_0x3b57('0x48')],null))[_0x3b57('0x26')](respondWithResult(_0x4b6940,null))[_0x3b57('0x46')](handleError(_0x4b6940,null));};