3ab674ad4201c4e2ea5ff114c78f8c529ea8ef5e
[motion2.git] / server / api / voiceQueuesLog / voiceQueuesLog.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 _0x39cd=['offset','undefined','limit','count','set','Content-Range','apply','reject','then','destroy','stack','name','send','index','map','VoiceQueuesLog','rawAttributes','fieldName','key','model','query','filters','attributes','intersection','fields','hasOwnProperty','sort','where','pick','type','VIRTUAL','filter','merge','options','includeAll','findAll','rows','show','keys','length','include','find','create','body','params','catch','rimraf','zip-dir','request-promise','moment','bluebird','mustache','sox','to-csv','ejs','fs-extra','lodash','squel','crypto','papaparse','../../components/auth/service','../../components/parsers/qs','../../config/license/hardware','../../config/logger','api','../../config/utils','../../config/environment','../../mysqldb','sendStatus','status','end','json'];(function(_0x4ccbe2,_0x11eacf){var _0x134525=function(_0x5c9da9){while(--_0x5c9da9){_0x4ccbe2['push'](_0x4ccbe2['shift']());}};_0x134525(++_0x11eacf);}(_0x39cd,0xbe));var _0xd39c=function(_0x59ee6f,_0x450239){_0x59ee6f=_0x59ee6f-0x0;var _0x4c0979=_0x39cd[_0x59ee6f];return _0x4c0979;};'use strict';var emlformat=require('eml-format');var rimraf=require(_0xd39c('0x0'));var zipdir=require(_0xd39c('0x1'));var jsonpatch=require('fast-json-patch');var rp=require(_0xd39c('0x2'));var moment=require(_0xd39c('0x3'));var BPromise=require(_0xd39c('0x4'));var Mustache=require(_0xd39c('0x5'));var util=require('util');var path=require('path');var sox=require(_0xd39c('0x6'));var csv=require(_0xd39c('0x7'));var ejs=require(_0xd39c('0x8'));var fs=require('fs');var fs_extra=require(_0xd39c('0x9'));var _=require(_0xd39c('0xa'));var squel=require(_0xd39c('0xb'));var crypto=require(_0xd39c('0xc'));var jsforce=require('jsforce');var deskjs=require('desk.js');var toCsv=require(_0xd39c('0x7'));var querystring=require('querystring');var Papa=require(_0xd39c('0xd'));var Redis=require('ioredis');var authService=require(_0xd39c('0xe'));var qs=require(_0xd39c('0xf'));var as=require('../../components/parsers/advancedSearch');var hardwareService=require(_0xd39c('0x10'));var logger=require(_0xd39c('0x11'))(_0xd39c('0x12'));var utils=require(_0xd39c('0x13'));var config=require(_0xd39c('0x14'));var licenseUtil=require('../../config/license/util');var db=require(_0xd39c('0x15'))['db'];function respondWithStatusCode(_0x10b037,_0x3b7265){_0x3b7265=_0x3b7265||0xcc;return function(_0x4c8f02){if(_0x4c8f02){return _0x10b037[_0xd39c('0x16')](_0x3b7265);}return _0x10b037[_0xd39c('0x17')](_0x3b7265)[_0xd39c('0x18')]();};}function respondWithResult(_0x104a6a,_0x253f71){_0x253f71=_0x253f71||0xc8;return function(_0x232fbd){if(_0x232fbd){return _0x104a6a[_0xd39c('0x17')](_0x253f71)[_0xd39c('0x19')](_0x232fbd);}};}function respondWithFilteredResult(_0xbaae95,_0x2d899e){return function(_0x4d75cf){if(_0x4d75cf){var _0xba2ea8=typeof _0x2d899e[_0xd39c('0x1a')]===_0xd39c('0x1b')&&typeof _0x2d899e[_0xd39c('0x1c')]===_0xd39c('0x1b');var _0x12290e=_0x4d75cf[_0xd39c('0x1d')];var _0x5d9715=_0xba2ea8?0x0:_0x2d899e[_0xd39c('0x1a')];var _0x402fee=_0xba2ea8?_0x4d75cf[_0xd39c('0x1d')]:_0x2d899e[_0xd39c('0x1a')]+_0x2d899e['limit'];var _0x5543d2;if(_0x402fee>=_0x12290e){_0x402fee=_0x12290e;_0x5543d2=0xc8;}else{_0x5543d2=0xce;}_0xbaae95['status'](_0x5543d2);return _0xbaae95[_0xd39c('0x1e')](_0xd39c('0x1f'),_0x5d9715+'-'+_0x402fee+'/'+_0x12290e)[_0xd39c('0x19')](_0x4d75cf);}return null;};}function patchUpdates(_0x2ec3ef){return function(_0x50fb40){try{jsonpatch[_0xd39c('0x20')](_0x50fb40,_0x2ec3ef,!![]);}catch(_0x36a47e){return BPromise[_0xd39c('0x21')](_0x36a47e);}return _0x50fb40['save']();};}function saveUpdates(_0x50d44f,_0x371955){return function(_0x149968){if(_0x149968){return _0x149968['update'](_0x50d44f)[_0xd39c('0x22')](function(_0x1024eb){return _0x1024eb;});}return null;};}function removeEntity(_0x41bcf0,_0x1bf309){return function(_0x1dad8e){if(_0x1dad8e){return _0x1dad8e[_0xd39c('0x23')]()[_0xd39c('0x22')](function(){_0x41bcf0[_0xd39c('0x17')](0xcc)[_0xd39c('0x18')]();});}};}function handleEntityNotFound(_0x585735,_0x4ded10){return function(_0x5e4777){if(!_0x5e4777){_0x585735[_0xd39c('0x16')](0x194);}return _0x5e4777;};}function handleError(_0x5bcc81,_0x3a59e0){_0x3a59e0=_0x3a59e0||0x1f4;return function(_0x3e8d62){logger['error'](_0x3e8d62[_0xd39c('0x24')]);if(_0x3e8d62[_0xd39c('0x25')]){delete _0x3e8d62['name'];}_0x5bcc81[_0xd39c('0x17')](_0x3a59e0)[_0xd39c('0x26')](_0x3e8d62);};}exports[_0xd39c('0x27')]=function(_0x176a6f,_0x9745e6){var _0x5b8042={},_0x3573e0={},_0x2d1cd9={'count':0x0,'rows':[]};var _0x4f49bc=_[_0xd39c('0x28')](db[_0xd39c('0x29')][_0xd39c('0x2a')],function(_0x34ca85){return{'name':_0x34ca85[_0xd39c('0x2b')],'type':_0x34ca85['type'][_0xd39c('0x2c')]};});_0x3573e0[_0xd39c('0x2d')]=_[_0xd39c('0x28')](_0x4f49bc,_0xd39c('0x25'));_0x3573e0[_0xd39c('0x2e')]=_['keys'](_0x176a6f['query']);_0x3573e0[_0xd39c('0x2f')]=_['intersection'](_0x3573e0[_0xd39c('0x2d')],_0x3573e0[_0xd39c('0x2e')]);_0x5b8042[_0xd39c('0x30')]=_[_0xd39c('0x31')](_0x3573e0[_0xd39c('0x2d')],qs['fields'](_0x176a6f['query'][_0xd39c('0x32')]));_0x5b8042['attributes']=_0x5b8042['attributes']['length']?_0x5b8042[_0xd39c('0x30')]:_0x3573e0[_0xd39c('0x2d')];if(!_0x176a6f[_0xd39c('0x2e')][_0xd39c('0x33')]('nolimit')){_0x5b8042[_0xd39c('0x1c')]=qs[_0xd39c('0x1c')](_0x176a6f[_0xd39c('0x2e')]['limit']);_0x5b8042[_0xd39c('0x1a')]=qs['offset'](_0x176a6f['query'][_0xd39c('0x1a')]);}_0x5b8042['order']=qs[_0xd39c('0x34')](_0x176a6f['query']['sort']);_0x5b8042[_0xd39c('0x35')]=qs[_0xd39c('0x2f')](_[_0xd39c('0x36')](_0x176a6f[_0xd39c('0x2e')],_0x3573e0[_0xd39c('0x2f')]),_0x4f49bc);if(_0x176a6f[_0xd39c('0x2e')]['filter']){_0x5b8042[_0xd39c('0x35')]=_['merge'](_0x5b8042[_0xd39c('0x35')],{'$or':_['map'](_0x4f49bc,function(_0x12edf1){if(_0x12edf1[_0xd39c('0x37')]!==_0xd39c('0x38')){var _0x5aca85={};_0x5aca85[_0x12edf1['name']]={'$like':'%'+_0x176a6f[_0xd39c('0x2e')][_0xd39c('0x39')]+'%'};return _0x5aca85;}})});}_0x5b8042=_[_0xd39c('0x3a')]({},_0x5b8042,_0x176a6f[_0xd39c('0x3b')]);var _0x1d4457={'where':_0x5b8042[_0xd39c('0x35')]};return db[_0xd39c('0x29')][_0xd39c('0x1d')](_0x1d4457)[_0xd39c('0x22')](function(_0x128e24){_0x2d1cd9[_0xd39c('0x1d')]=_0x128e24;if(_0x176a6f[_0xd39c('0x2e')][_0xd39c('0x3c')]){_0x5b8042['include']=[{'all':!![]}];}return db[_0xd39c('0x29')][_0xd39c('0x3d')](_0x5b8042);})[_0xd39c('0x22')](function(_0x21ee7b){_0x2d1cd9[_0xd39c('0x3e')]=_0x21ee7b;return _0x2d1cd9;})['then'](respondWithFilteredResult(_0x9745e6,_0x5b8042))['catch'](handleError(_0x9745e6,null));};exports[_0xd39c('0x3f')]=function(_0x56f6d8,_0x515601){var _0xd9da60={'raw':!![],'where':{'id':_0x56f6d8['params']['id']}},_0x29bd61={};_0x29bd61[_0xd39c('0x2d')]=_[_0xd39c('0x40')](db['VoiceQueuesLog'][_0xd39c('0x2a')]);_0x29bd61[_0xd39c('0x2e')]=_[_0xd39c('0x40')](_0x56f6d8[_0xd39c('0x2e')]);_0x29bd61[_0xd39c('0x2f')]=_['intersection'](_0x29bd61[_0xd39c('0x2d')],_0x29bd61[_0xd39c('0x2e')]);_0xd9da60[_0xd39c('0x30')]=_['intersection'](_0x29bd61[_0xd39c('0x2d')],qs[_0xd39c('0x32')](_0x56f6d8[_0xd39c('0x2e')][_0xd39c('0x32')]));_0xd9da60['attributes']=_0xd9da60[_0xd39c('0x30')][_0xd39c('0x41')]?_0xd9da60['attributes']:_0x29bd61['model'];if(_0x56f6d8['query'][_0xd39c('0x3c')]){_0xd9da60[_0xd39c('0x42')]=[{'all':!![]}];}_0xd9da60=_[_0xd39c('0x3a')]({},_0xd9da60,_0x56f6d8['options']);return db[_0xd39c('0x29')][_0xd39c('0x43')](_0xd9da60)[_0xd39c('0x22')](handleEntityNotFound(_0x515601,null))['then'](respondWithResult(_0x515601,null))['catch'](handleError(_0x515601,null));};exports['create']=function(_0xf97a6c,_0x31443d){return db['VoiceQueuesLog'][_0xd39c('0x44')](_0xf97a6c[_0xd39c('0x45')],{})[_0xd39c('0x22')](respondWithResult(_0x31443d,0xc9))['catch'](handleError(_0x31443d,null));};exports['update']=function(_0x1510d9,_0x2dc337){if(_0x1510d9[_0xd39c('0x45')]['id']){delete _0x1510d9[_0xd39c('0x45')]['id'];}return db['VoiceQueuesLog']['find']({'where':{'id':_0x1510d9[_0xd39c('0x46')]['id']}})['then'](handleEntityNotFound(_0x2dc337,null))[_0xd39c('0x22')](saveUpdates(_0x1510d9[_0xd39c('0x45')],null))[_0xd39c('0x22')](respondWithResult(_0x2dc337,null))['catch'](handleError(_0x2dc337,null));};exports[_0xd39c('0x23')]=function(_0x3bb49f,_0x545567){return db['VoiceQueuesLog'][_0xd39c('0x43')]({'where':{'id':_0x3bb49f[_0xd39c('0x46')]['id']}})['then'](handleEntityNotFound(_0x545567,null))[_0xd39c('0x22')](removeEntity(_0x545567,null))[_0xd39c('0x47')](handleError(_0x545567,null));};