Built motion from commit (unavailable).|2.5.14
[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 _0x3b50=['describe','body','uniqueid','html-pdf','eml-format','rimraf','request-promise','mustache','util','path','sox','to-csv','ejs','crypto','jsforce','desk.js','querystring','papaparse','ioredis','../../components/auth/service','../../config/license/hardware','../../config/logger','api','../../config/utils','../../config/environment','../../config/license/util','../../mysqldb','sendStatus','end','status','json','count','offset','set','Content-Range','apply','save','update','destroy','then','stack','name','send','index','map','CmHopperHistory','fieldName','type','key','query','keys','intersection','model','attributes','fields','length','hasOwnProperty','nolimit','limit','sort','where','pick','filters','filter','merge','VIRTUAL','options','includeAll','include','catch','show','params','rawAttributes','find','create'];(function(_0x53ebec,_0x2b6254){var _0x441f4f=function(_0x120ca1){while(--_0x120ca1){_0x53ebec['push'](_0x53ebec['shift']());}};_0x441f4f(++_0x2b6254);}(_0x3b50,0x12f));var _0x03b5=function(_0x3de8a4,_0x289a5c){_0x3de8a4=_0x3de8a4-0x0;var _0x4635cf=_0x3b50[_0x3de8a4];return _0x4635cf;};'use strict';var pdf=require(_0x03b5('0x0'));var emlformat=require(_0x03b5('0x1'));var rimraf=require(_0x03b5('0x2'));var zipdir=require('zip-dir');var jsonpatch=require('fast-json-patch');var rp=require(_0x03b5('0x3'));var moment=require('moment');var BPromise=require('bluebird');var Mustache=require(_0x03b5('0x4'));var util=require(_0x03b5('0x5'));var path=require(_0x03b5('0x6'));var sox=require(_0x03b5('0x7'));var csv=require(_0x03b5('0x8'));var ejs=require(_0x03b5('0x9'));var fs=require('fs');var _=require('lodash');var squel=require('squel');var crypto=require(_0x03b5('0xa'));var jsforce=require(_0x03b5('0xb'));var deskjs=require(_0x03b5('0xc'));var toCsv=require('to-csv');var querystring=require(_0x03b5('0xd'));var Papa=require(_0x03b5('0xe'));var Redis=require(_0x03b5('0xf'));var authService=require(_0x03b5('0x10'));var qs=require('../../components/parsers/qs');var as=require('../../components/parsers/advancedSearch');var hardwareService=require(_0x03b5('0x11'));var logger=require(_0x03b5('0x12'))(_0x03b5('0x13'));var utils=require(_0x03b5('0x14'));var config=require(_0x03b5('0x15'));var licenseUtil=require(_0x03b5('0x16'));var db=require(_0x03b5('0x17'))['db'];function respondWithStatusCode(_0x128e29,_0x5a24d8){_0x5a24d8=_0x5a24d8||0xcc;return function(_0x3c0931){if(_0x3c0931){return _0x128e29[_0x03b5('0x18')](_0x5a24d8);}return _0x128e29['status'](_0x5a24d8)[_0x03b5('0x19')]();};}function respondWithResult(_0x40cb40,_0x48e077){_0x48e077=_0x48e077||0xc8;return function(_0x3c7623){if(_0x3c7623){return _0x40cb40[_0x03b5('0x1a')](_0x48e077)[_0x03b5('0x1b')](_0x3c7623);}};}function respondWithFilteredResult(_0x15df45,_0x3c82d1){return function(_0x4fe248){if(_0x4fe248){var _0x1c6c00=_0x4fe248[_0x03b5('0x1c')],_0x34df56=_0x3c82d1[_0x03b5('0x1d')],_0x3a1b8b=_0x3c82d1[_0x03b5('0x1d')]+_0x3c82d1['limit'],_0x3327fc;if(_0x3a1b8b>=_0x1c6c00){_0x3a1b8b=_0x1c6c00;_0x3327fc=0xc8;}else{_0x3327fc=0xce;}_0x15df45[_0x03b5('0x1a')](_0x3327fc);return _0x15df45[_0x03b5('0x1e')](_0x03b5('0x1f'),_0x34df56+'-'+_0x3a1b8b+'/'+_0x1c6c00)['json'](_0x4fe248);}return null;};}function patchUpdates(_0x136b0b){return function(_0x1b4f35){try{jsonpatch[_0x03b5('0x20')](_0x1b4f35,_0x136b0b,!![]);}catch(_0x4de4b9){return BPromise['reject'](_0x4de4b9);}return _0x1b4f35[_0x03b5('0x21')]();};}function saveUpdates(_0x37fd03,_0x58207e){return function(_0x2eec1f){if(_0x2eec1f){return _0x2eec1f[_0x03b5('0x22')](_0x37fd03)['then'](function(_0x1074e4){return _0x1074e4;});}return null;};}function removeEntity(_0x85b760,_0x16c1f0){return function(_0x2bfd28){if(_0x2bfd28){return _0x2bfd28[_0x03b5('0x23')]()[_0x03b5('0x24')](function(){_0x85b760[_0x03b5('0x1a')](0xcc)[_0x03b5('0x19')]();});}};}function handleEntityNotFound(_0x16cf9b,_0xe8e3b4){return function(_0x3033cc){if(!_0x3033cc){_0x16cf9b[_0x03b5('0x18')](0x194);}return _0x3033cc;};}function handleError(_0x513345,_0x13ccde){_0x13ccde=_0x13ccde||0x1f4;return function(_0x39ac7b){logger['error'](_0x39ac7b[_0x03b5('0x25')]);if(_0x39ac7b['name']){delete _0x39ac7b[_0x03b5('0x26')];}_0x513345[_0x03b5('0x1a')](_0x13ccde)[_0x03b5('0x27')](_0x39ac7b);};}exports[_0x03b5('0x28')]=function(_0x268fab,_0x452ad4){var _0x1c8f8a={},_0x346dbf={},_0x90e30f={'count':0x0,'rows':[]};var _0x1f0ec9=_[_0x03b5('0x29')](db[_0x03b5('0x2a')]['rawAttributes'],function(_0x5526a5){return{'name':_0x5526a5[_0x03b5('0x2b')],'type':_0x5526a5[_0x03b5('0x2c')][_0x03b5('0x2d')]};});_0x346dbf['model']=_[_0x03b5('0x29')](_0x1f0ec9,_0x03b5('0x26'));_0x346dbf[_0x03b5('0x2e')]=_[_0x03b5('0x2f')](_0x268fab[_0x03b5('0x2e')]);_0x346dbf['filters']=_[_0x03b5('0x30')](_0x346dbf[_0x03b5('0x31')],_0x346dbf[_0x03b5('0x2e')]);_0x1c8f8a[_0x03b5('0x32')]=_[_0x03b5('0x30')](_0x346dbf[_0x03b5('0x31')],qs[_0x03b5('0x33')](_0x268fab[_0x03b5('0x2e')][_0x03b5('0x33')]));_0x1c8f8a['attributes']=_0x1c8f8a['attributes'][_0x03b5('0x34')]?_0x1c8f8a[_0x03b5('0x32')]:_0x346dbf[_0x03b5('0x31')];if(!_0x268fab[_0x03b5('0x2e')][_0x03b5('0x35')](_0x03b5('0x36'))){_0x1c8f8a[_0x03b5('0x37')]=qs[_0x03b5('0x37')](_0x268fab['query'][_0x03b5('0x37')]);_0x1c8f8a[_0x03b5('0x1d')]=qs[_0x03b5('0x1d')](_0x268fab[_0x03b5('0x2e')][_0x03b5('0x1d')]);}_0x1c8f8a['order']=qs[_0x03b5('0x38')](_0x268fab['query']['sort']);_0x1c8f8a[_0x03b5('0x39')]=qs['filters'](_[_0x03b5('0x3a')](_0x268fab[_0x03b5('0x2e')],_0x346dbf[_0x03b5('0x3b')]),_0x1f0ec9);if(_0x268fab['query'][_0x03b5('0x3c')]){_0x1c8f8a[_0x03b5('0x39')]=_[_0x03b5('0x3d')](_0x1c8f8a['where'],{'$or':_[_0x03b5('0x29')](_0x1f0ec9,function(_0x228fd9){if(_0x228fd9['type']!==_0x03b5('0x3e')){var _0x3577d7={};_0x3577d7[_0x228fd9[_0x03b5('0x26')]]={'$like':'%'+_0x268fab['query'][_0x03b5('0x3c')]+'%'};return _0x3577d7;}})});}_0x1c8f8a=_[_0x03b5('0x3d')]({},_0x1c8f8a,_0x268fab[_0x03b5('0x3f')]);var _0x27aa47={'where':_0x1c8f8a[_0x03b5('0x39')]};return db[_0x03b5('0x2a')][_0x03b5('0x1c')](_0x27aa47)['then'](function(_0xfe4bf6){_0x90e30f[_0x03b5('0x1c')]=_0xfe4bf6;if(_0x268fab[_0x03b5('0x2e')][_0x03b5('0x40')]){_0x1c8f8a[_0x03b5('0x41')]=[{'all':!![]}];}return db[_0x03b5('0x2a')]['findAll'](_0x1c8f8a);})[_0x03b5('0x24')](function(_0x5e3256){_0x90e30f['rows']=_0x5e3256;return _0x90e30f;})[_0x03b5('0x24')](respondWithFilteredResult(_0x452ad4,_0x1c8f8a))[_0x03b5('0x42')](handleError(_0x452ad4,null));};exports[_0x03b5('0x43')]=function(_0x1dec05,_0x1c55b6){var _0x149ff7={'raw':!![],'where':{'id':_0x1dec05[_0x03b5('0x44')]['id']}},_0x307b20={};_0x307b20[_0x03b5('0x31')]=_[_0x03b5('0x2f')](db['CmHopperHistory'][_0x03b5('0x45')]);_0x307b20[_0x03b5('0x2e')]=_[_0x03b5('0x2f')](_0x1dec05['query']);_0x307b20['filters']=_[_0x03b5('0x30')](_0x307b20['model'],_0x307b20[_0x03b5('0x2e')]);_0x149ff7[_0x03b5('0x32')]=_[_0x03b5('0x30')](_0x307b20[_0x03b5('0x31')],qs[_0x03b5('0x33')](_0x1dec05[_0x03b5('0x2e')]['fields']));_0x149ff7['attributes']=_0x149ff7[_0x03b5('0x32')]['length']?_0x149ff7['attributes']:_0x307b20[_0x03b5('0x31')];if(_0x1dec05['query'][_0x03b5('0x40')]){_0x149ff7['include']=[{'all':!![]}];}_0x149ff7=_[_0x03b5('0x3d')]({},_0x149ff7,_0x1dec05[_0x03b5('0x3f')]);return db['CmHopperHistory'][_0x03b5('0x46')](_0x149ff7)[_0x03b5('0x24')](handleEntityNotFound(_0x1c55b6,null))['then'](respondWithResult(_0x1c55b6,null))['catch'](handleError(_0x1c55b6,null));};exports[_0x03b5('0x47')]=function(_0x33989c,_0x144e38){return db['CmHopperHistory']['create'](_0x33989c['body'],{})[_0x03b5('0x24')](respondWithResult(_0x144e38,0xc9))[_0x03b5('0x42')](handleError(_0x144e38,null));};exports[_0x03b5('0x48')]=function(_0x3d2b6a,_0x3a6195){return db[_0x03b5('0x2a')][_0x03b5('0x48')]()['then'](respondWithResult(_0x3a6195,null))['catch'](handleError(_0x3a6195,null));};exports[_0x03b5('0x22')]=function(_0x112b73,_0x5f2c6b){if(_0x112b73[_0x03b5('0x49')][_0x03b5('0x4a')]){delete _0x112b73[_0x03b5('0x49')]['uniqueid'];}return db[_0x03b5('0x2a')]['find']({'where':{'uniqueid':_0x112b73[_0x03b5('0x44')]['id']}})['then'](handleEntityNotFound(_0x5f2c6b,null))['then'](saveUpdates(_0x112b73[_0x03b5('0x49')],null))['then'](respondWithResult(_0x5f2c6b,null))['catch'](handleError(_0x5f2c6b,null));};