Built motion from commit bab6f49e.|2.6.17
[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 _0x37bb=['name','send','map','CmHopperHistory','rawAttributes','fieldName','key','model','keys','filters','intersection','query','attributes','fields','length','hasOwnProperty','nolimit','order','sort','where','pick','filter','merge','type','VIRTUAL','options','count','includeAll','include','findAll','rows','catch','show','params','find','create','body','uniqueid','eml-format','rimraf','fast-json-patch','request-promise','moment','bluebird','mustache','sox','to-csv','ejs','fs-extra','squel','jsforce','desk.js','papaparse','../../components/auth/service','../../components/parsers/advancedSearch','../../config/logger','api','../../config/utils','sendStatus','status','end','json','offset','undefined','limit','apply','reject','update','then','destroy','error','stack'];(function(_0x3bd52b,_0xbbc735){var _0x1e5b89=function(_0x29ccc3){while(--_0x29ccc3){_0x3bd52b['push'](_0x3bd52b['shift']());}};_0x1e5b89(++_0xbbc735);}(_0x37bb,0x1d6));var _0xb37b=function(_0xa12f62,_0x2a9308){_0xa12f62=_0xa12f62-0x0;var _0x20b437=_0x37bb[_0xa12f62];return _0x20b437;};'use strict';var emlformat=require(_0xb37b('0x0'));var rimraf=require(_0xb37b('0x1'));var zipdir=require('zip-dir');var jsonpatch=require(_0xb37b('0x2'));var rp=require(_0xb37b('0x3'));var moment=require(_0xb37b('0x4'));var BPromise=require(_0xb37b('0x5'));var Mustache=require(_0xb37b('0x6'));var util=require('util');var path=require('path');var sox=require(_0xb37b('0x7'));var csv=require(_0xb37b('0x8'));var ejs=require(_0xb37b('0x9'));var fs=require('fs');var fs_extra=require(_0xb37b('0xa'));var _=require('lodash');var squel=require(_0xb37b('0xb'));var crypto=require('crypto');var jsforce=require(_0xb37b('0xc'));var deskjs=require(_0xb37b('0xd'));var toCsv=require('to-csv');var querystring=require('querystring');var Papa=require(_0xb37b('0xe'));var Redis=require('ioredis');var authService=require(_0xb37b('0xf'));var qs=require('../../components/parsers/qs');var as=require(_0xb37b('0x10'));var hardwareService=require('../../config/license/hardware');var logger=require(_0xb37b('0x11'))(_0xb37b('0x12'));var utils=require(_0xb37b('0x13'));var config=require('../../config/environment');var licenseUtil=require('../../config/license/util');var db=require('../../mysqldb')['db'];function respondWithStatusCode(_0x3be230,_0x16f1e6){_0x16f1e6=_0x16f1e6||0xcc;return function(_0x2bfafc){if(_0x2bfafc){return _0x3be230[_0xb37b('0x14')](_0x16f1e6);}return _0x3be230[_0xb37b('0x15')](_0x16f1e6)[_0xb37b('0x16')]();};}function respondWithResult(_0x527d2f,_0x30838e){_0x30838e=_0x30838e||0xc8;return function(_0x20327b){if(_0x20327b){return _0x527d2f[_0xb37b('0x15')](_0x30838e)[_0xb37b('0x17')](_0x20327b);}};}function respondWithFilteredResult(_0x85f55f,_0x3630c4){return function(_0x4431cd){if(_0x4431cd){var _0x3a4f9b=typeof _0x3630c4[_0xb37b('0x18')]===_0xb37b('0x19')&&typeof _0x3630c4[_0xb37b('0x1a')]==='undefined';var _0x57556d=_0x4431cd['count'];var _0x83e181=_0x3a4f9b?0x0:_0x3630c4[_0xb37b('0x18')];var _0x47ea8e=_0x3a4f9b?_0x4431cd['count']:_0x3630c4[_0xb37b('0x18')]+_0x3630c4['limit'];var _0x397d0b;if(_0x47ea8e>=_0x57556d){_0x47ea8e=_0x57556d;_0x397d0b=0xc8;}else{_0x397d0b=0xce;}_0x85f55f[_0xb37b('0x15')](_0x397d0b);return _0x85f55f['set']('Content-Range',_0x83e181+'-'+_0x47ea8e+'/'+_0x57556d)[_0xb37b('0x17')](_0x4431cd);}return null;};}function patchUpdates(_0x2a4f1d){return function(_0xf4c27){try{jsonpatch[_0xb37b('0x1b')](_0xf4c27,_0x2a4f1d,!![]);}catch(_0x3420ac){return BPromise[_0xb37b('0x1c')](_0x3420ac);}return _0xf4c27['save']();};}function saveUpdates(_0x46fa9d,_0x429561){return function(_0x64ba9){if(_0x64ba9){return _0x64ba9[_0xb37b('0x1d')](_0x46fa9d)[_0xb37b('0x1e')](function(_0x4c64e7){return _0x4c64e7;});}return null;};}function removeEntity(_0x165e68,_0x4a6b32){return function(_0x40c561){if(_0x40c561){return _0x40c561[_0xb37b('0x1f')]()['then'](function(){_0x165e68['status'](0xcc)['end']();});}};}function handleEntityNotFound(_0x472584,_0x2d4e44){return function(_0x3349c6){if(!_0x3349c6){_0x472584['sendStatus'](0x194);}return _0x3349c6;};}function handleError(_0x285b6a,_0x305004){_0x305004=_0x305004||0x1f4;return function(_0x4d22bb){logger[_0xb37b('0x20')](_0x4d22bb[_0xb37b('0x21')]);if(_0x4d22bb[_0xb37b('0x22')]){delete _0x4d22bb[_0xb37b('0x22')];}_0x285b6a[_0xb37b('0x15')](_0x305004)[_0xb37b('0x23')](_0x4d22bb);};}exports['index']=function(_0x4941b,_0x122588){var _0x1d1d0f={},_0x23daf3={},_0x43909c={'count':0x0,'rows':[]};var _0x901e9b=_[_0xb37b('0x24')](db[_0xb37b('0x25')][_0xb37b('0x26')],function(_0x3b5dd1){return{'name':_0x3b5dd1[_0xb37b('0x27')],'type':_0x3b5dd1['type'][_0xb37b('0x28')]};});_0x23daf3[_0xb37b('0x29')]=_['map'](_0x901e9b,_0xb37b('0x22'));_0x23daf3['query']=_[_0xb37b('0x2a')](_0x4941b['query']);_0x23daf3[_0xb37b('0x2b')]=_[_0xb37b('0x2c')](_0x23daf3[_0xb37b('0x29')],_0x23daf3[_0xb37b('0x2d')]);_0x1d1d0f[_0xb37b('0x2e')]=_[_0xb37b('0x2c')](_0x23daf3[_0xb37b('0x29')],qs['fields'](_0x4941b[_0xb37b('0x2d')][_0xb37b('0x2f')]));_0x1d1d0f[_0xb37b('0x2e')]=_0x1d1d0f[_0xb37b('0x2e')][_0xb37b('0x30')]?_0x1d1d0f[_0xb37b('0x2e')]:_0x23daf3['model'];if(!_0x4941b[_0xb37b('0x2d')][_0xb37b('0x31')](_0xb37b('0x32'))){_0x1d1d0f[_0xb37b('0x1a')]=qs[_0xb37b('0x1a')](_0x4941b[_0xb37b('0x2d')][_0xb37b('0x1a')]);_0x1d1d0f['offset']=qs['offset'](_0x4941b[_0xb37b('0x2d')][_0xb37b('0x18')]);}_0x1d1d0f[_0xb37b('0x33')]=qs[_0xb37b('0x34')](_0x4941b[_0xb37b('0x2d')]['sort']);_0x1d1d0f[_0xb37b('0x35')]=qs[_0xb37b('0x2b')](_[_0xb37b('0x36')](_0x4941b[_0xb37b('0x2d')],_0x23daf3[_0xb37b('0x2b')]),_0x901e9b);if(_0x4941b['query'][_0xb37b('0x37')]){_0x1d1d0f[_0xb37b('0x35')]=_[_0xb37b('0x38')](_0x1d1d0f[_0xb37b('0x35')],{'$or':_[_0xb37b('0x24')](_0x901e9b,function(_0x3d8d66){if(_0x3d8d66[_0xb37b('0x39')]!==_0xb37b('0x3a')){var _0x131c0c={};_0x131c0c[_0x3d8d66[_0xb37b('0x22')]]={'$like':'%'+_0x4941b[_0xb37b('0x2d')]['filter']+'%'};return _0x131c0c;}})});}_0x1d1d0f=_[_0xb37b('0x38')]({},_0x1d1d0f,_0x4941b[_0xb37b('0x3b')]);var _0x392014={'where':_0x1d1d0f[_0xb37b('0x35')]};return db['CmHopperHistory'][_0xb37b('0x3c')](_0x392014)[_0xb37b('0x1e')](function(_0x53108c){_0x43909c[_0xb37b('0x3c')]=_0x53108c;if(_0x4941b[_0xb37b('0x2d')][_0xb37b('0x3d')]){_0x1d1d0f[_0xb37b('0x3e')]=[{'all':!![]}];}return db['CmHopperHistory'][_0xb37b('0x3f')](_0x1d1d0f);})[_0xb37b('0x1e')](function(_0x451da5){_0x43909c[_0xb37b('0x40')]=_0x451da5;return _0x43909c;})['then'](respondWithFilteredResult(_0x122588,_0x1d1d0f))[_0xb37b('0x41')](handleError(_0x122588,null));};exports[_0xb37b('0x42')]=function(_0x28427f,_0x58c91e){var _0x1a5a9c={'raw':!![],'where':{'id':_0x28427f[_0xb37b('0x43')]['id']}},_0x337f80={};_0x337f80['model']=_[_0xb37b('0x2a')](db[_0xb37b('0x25')]['rawAttributes']);_0x337f80[_0xb37b('0x2d')]=_[_0xb37b('0x2a')](_0x28427f[_0xb37b('0x2d')]);_0x337f80[_0xb37b('0x2b')]=_['intersection'](_0x337f80[_0xb37b('0x29')],_0x337f80['query']);_0x1a5a9c[_0xb37b('0x2e')]=_[_0xb37b('0x2c')](_0x337f80[_0xb37b('0x29')],qs[_0xb37b('0x2f')](_0x28427f[_0xb37b('0x2d')][_0xb37b('0x2f')]));_0x1a5a9c['attributes']=_0x1a5a9c[_0xb37b('0x2e')]['length']?_0x1a5a9c['attributes']:_0x337f80[_0xb37b('0x29')];if(_0x28427f[_0xb37b('0x2d')][_0xb37b('0x3d')]){_0x1a5a9c[_0xb37b('0x3e')]=[{'all':!![]}];}_0x1a5a9c=_['merge']({},_0x1a5a9c,_0x28427f[_0xb37b('0x3b')]);return db[_0xb37b('0x25')][_0xb37b('0x44')](_0x1a5a9c)[_0xb37b('0x1e')](handleEntityNotFound(_0x58c91e,null))[_0xb37b('0x1e')](respondWithResult(_0x58c91e,null))[_0xb37b('0x41')](handleError(_0x58c91e,null));};exports['create']=function(_0x1929b7,_0x214887){return db[_0xb37b('0x25')][_0xb37b('0x45')](_0x1929b7[_0xb37b('0x46')],{})['then'](respondWithResult(_0x214887,0xc9))[_0xb37b('0x41')](handleError(_0x214887,null));};exports['describe']=function(_0x51c46a,_0xf539ef){return db['CmHopperHistory']['describe']()[_0xb37b('0x1e')](respondWithResult(_0xf539ef,null))[_0xb37b('0x41')](handleError(_0xf539ef,null));};exports[_0xb37b('0x1d')]=function(_0x5451be,_0x3cb611){if(_0x5451be[_0xb37b('0x46')][_0xb37b('0x47')]){delete _0x5451be[_0xb37b('0x46')][_0xb37b('0x47')];}return db[_0xb37b('0x25')][_0xb37b('0x44')]({'where':{'uniqueid':_0x5451be[_0xb37b('0x43')]['id']}})['then'](handleEntityNotFound(_0x3cb611,null))['then'](saveUpdates(_0x5451be[_0xb37b('0x46')],null))[_0xb37b('0x1e')](respondWithResult(_0x3cb611,null))[_0xb37b('0x41')](handleError(_0x3cb611,null));};