813b3c0f3398218b7864a0b3660be776d443ca6d
[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 _0x404f=['ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','api','../../config/utils','../../config/environment','../../config/license/util','../../mysqldb','sendStatus','status','end','json','count','offset','set','Content-Range','apply','save','update','then','destroy','error','stack','name','send','index','map','VoiceQueuesLog','rawAttributes','model','query','keys','filters','intersection','attributes','fields','length','hasOwnProperty','nolimit','limit','sort','where','pick','filter','merge','VIRTUAL','options','includeAll','include','findAll','rows','catch','show','params','find','create','body','fast-json-patch','request-promise','moment','bluebird','util','path','sox','to-csv','ejs','lodash','squel','jsforce','querystring','papaparse'];(function(_0x3dd15e,_0x1f0015){var _0x231fd0=function(_0x4f680a){while(--_0x4f680a){_0x3dd15e['push'](_0x3dd15e['shift']());}};_0x231fd0(++_0x1f0015);}(_0x404f,0x116));var _0xf404=function(_0x3b1f56,_0x1ddd65){_0x3b1f56=_0x3b1f56-0x0;var _0xe8288c=_0x404f[_0x3b1f56];return _0xe8288c;};'use strict';var pdf=require('html-pdf');var emlformat=require('eml-format');var rimraf=require('rimraf');var zipdir=require('zip-dir');var jsonpatch=require(_0xf404('0x0'));var rp=require(_0xf404('0x1'));var moment=require(_0xf404('0x2'));var BPromise=require(_0xf404('0x3'));var Mustache=require('mustache');var util=require(_0xf404('0x4'));var path=require(_0xf404('0x5'));var sox=require(_0xf404('0x6'));var csv=require(_0xf404('0x7'));var ejs=require(_0xf404('0x8'));var fs=require('fs');var _=require(_0xf404('0x9'));var squel=require(_0xf404('0xa'));var crypto=require('crypto');var jsforce=require(_0xf404('0xb'));var deskjs=require('desk.js');var toCsv=require(_0xf404('0x7'));var querystring=require(_0xf404('0xc'));var Papa=require(_0xf404('0xd'));var Redis=require(_0xf404('0xe'));var authService=require(_0xf404('0xf'));var qs=require(_0xf404('0x10'));var as=require(_0xf404('0x11'));var hardwareService=require(_0xf404('0x12'));var logger=require('../../config/logger')(_0xf404('0x13'));var utils=require(_0xf404('0x14'));var config=require(_0xf404('0x15'));var licenseUtil=require(_0xf404('0x16'));var db=require(_0xf404('0x17'))['db'];function respondWithStatusCode(_0x1a3366,_0x17639c){_0x17639c=_0x17639c||0xcc;return function(_0x1a0358){if(_0x1a0358){return _0x1a3366[_0xf404('0x18')](_0x17639c);}return _0x1a3366[_0xf404('0x19')](_0x17639c)[_0xf404('0x1a')]();};}function respondWithResult(_0x4e78bc,_0x32ef8e){_0x32ef8e=_0x32ef8e||0xc8;return function(_0x45a9e6){if(_0x45a9e6){return _0x4e78bc[_0xf404('0x19')](_0x32ef8e)[_0xf404('0x1b')](_0x45a9e6);}};}function respondWithFilteredResult(_0x35b453,_0x1bc880){return function(_0x2b6635){if(_0x2b6635){var _0x2ba55a=_0x2b6635[_0xf404('0x1c')],_0x397f5f=_0x1bc880['offset'],_0x2c04bd=_0x1bc880[_0xf404('0x1d')]+_0x1bc880['limit'],_0x1827b5;if(_0x2c04bd>=_0x2ba55a){_0x2c04bd=_0x2ba55a;_0x1827b5=0xc8;}else{_0x1827b5=0xce;}_0x35b453['status'](_0x1827b5);return _0x35b453[_0xf404('0x1e')](_0xf404('0x1f'),_0x397f5f+'-'+_0x2c04bd+'/'+_0x2ba55a)[_0xf404('0x1b')](_0x2b6635);}return null;};}function patchUpdates(_0x2d0a83){return function(_0x30372e){try{jsonpatch[_0xf404('0x20')](_0x30372e,_0x2d0a83,!![]);}catch(_0x41c32e){return BPromise['reject'](_0x41c32e);}return _0x30372e[_0xf404('0x21')]();};}function saveUpdates(_0x2ea46e,_0x211bfa){return function(_0xee579c){if(_0xee579c){return _0xee579c[_0xf404('0x22')](_0x2ea46e)[_0xf404('0x23')](function(_0x456600){return _0x456600;});}return null;};}function removeEntity(_0x20eb2b,_0x5e3d4b){return function(_0x4a209c){if(_0x4a209c){return _0x4a209c[_0xf404('0x24')]()['then'](function(){_0x20eb2b[_0xf404('0x19')](0xcc)[_0xf404('0x1a')]();});}};}function handleEntityNotFound(_0x1d5e2c,_0x192897){return function(_0x44d2a7){if(!_0x44d2a7){_0x1d5e2c[_0xf404('0x18')](0x194);}return _0x44d2a7;};}function handleError(_0x27e3a6,_0x31a1c1){_0x31a1c1=_0x31a1c1||0x1f4;return function(_0x41335d){logger[_0xf404('0x25')](_0x41335d[_0xf404('0x26')]);if(_0x41335d[_0xf404('0x27')]){delete _0x41335d[_0xf404('0x27')];}_0x27e3a6['status'](_0x31a1c1)[_0xf404('0x28')](_0x41335d);};}exports[_0xf404('0x29')]=function(_0x239fc2,_0x5b3d61){var _0xc1da2e={},_0x213cef={},_0x3ccc0b={'count':0x0,'rows':[]};var _0x389643=_[_0xf404('0x2a')](db[_0xf404('0x2b')][_0xf404('0x2c')],function(_0x33e371){return{'name':_0x33e371['fieldName'],'type':_0x33e371['type']['key']};});_0x213cef[_0xf404('0x2d')]=_[_0xf404('0x2a')](_0x389643,_0xf404('0x27'));_0x213cef[_0xf404('0x2e')]=_[_0xf404('0x2f')](_0x239fc2[_0xf404('0x2e')]);_0x213cef[_0xf404('0x30')]=_[_0xf404('0x31')](_0x213cef[_0xf404('0x2d')],_0x213cef[_0xf404('0x2e')]);_0xc1da2e[_0xf404('0x32')]=_['intersection'](_0x213cef['model'],qs[_0xf404('0x33')](_0x239fc2[_0xf404('0x2e')][_0xf404('0x33')]));_0xc1da2e[_0xf404('0x32')]=_0xc1da2e[_0xf404('0x32')][_0xf404('0x34')]?_0xc1da2e['attributes']:_0x213cef['model'];if(!_0x239fc2[_0xf404('0x2e')][_0xf404('0x35')](_0xf404('0x36'))){_0xc1da2e[_0xf404('0x37')]=qs[_0xf404('0x37')](_0x239fc2[_0xf404('0x2e')][_0xf404('0x37')]);_0xc1da2e[_0xf404('0x1d')]=qs[_0xf404('0x1d')](_0x239fc2[_0xf404('0x2e')][_0xf404('0x1d')]);}_0xc1da2e['order']=qs[_0xf404('0x38')](_0x239fc2[_0xf404('0x2e')][_0xf404('0x38')]);_0xc1da2e[_0xf404('0x39')]=qs[_0xf404('0x30')](_[_0xf404('0x3a')](_0x239fc2['query'],_0x213cef[_0xf404('0x30')]),_0x389643);if(_0x239fc2['query'][_0xf404('0x3b')]){_0xc1da2e[_0xf404('0x39')]=_[_0xf404('0x3c')](_0xc1da2e['where'],{'$or':_[_0xf404('0x2a')](_0x389643,function(_0x521fe7){if(_0x521fe7['type']!==_0xf404('0x3d')){var _0x2a389d={};_0x2a389d[_0x521fe7[_0xf404('0x27')]]={'$like':'%'+_0x239fc2[_0xf404('0x2e')][_0xf404('0x3b')]+'%'};return _0x2a389d;}})});}_0xc1da2e=_[_0xf404('0x3c')]({},_0xc1da2e,_0x239fc2[_0xf404('0x3e')]);var _0x4eeced={'where':_0xc1da2e[_0xf404('0x39')]};return db[_0xf404('0x2b')][_0xf404('0x1c')](_0x4eeced)[_0xf404('0x23')](function(_0x24aa11){_0x3ccc0b[_0xf404('0x1c')]=_0x24aa11;if(_0x239fc2[_0xf404('0x2e')][_0xf404('0x3f')]){_0xc1da2e[_0xf404('0x40')]=[{'all':!![]}];}return db[_0xf404('0x2b')][_0xf404('0x41')](_0xc1da2e);})[_0xf404('0x23')](function(_0x23d343){_0x3ccc0b[_0xf404('0x42')]=_0x23d343;return _0x3ccc0b;})[_0xf404('0x23')](respondWithFilteredResult(_0x5b3d61,_0xc1da2e))[_0xf404('0x43')](handleError(_0x5b3d61,null));};exports[_0xf404('0x44')]=function(_0xc589fb,_0x387e34){var _0x34a6cf={'raw':!![],'where':{'id':_0xc589fb[_0xf404('0x45')]['id']}},_0x5e6fd1={};_0x5e6fd1['model']=_['keys'](db[_0xf404('0x2b')][_0xf404('0x2c')]);_0x5e6fd1[_0xf404('0x2e')]=_['keys'](_0xc589fb[_0xf404('0x2e')]);_0x5e6fd1[_0xf404('0x30')]=_[_0xf404('0x31')](_0x5e6fd1[_0xf404('0x2d')],_0x5e6fd1[_0xf404('0x2e')]);_0x34a6cf['attributes']=_[_0xf404('0x31')](_0x5e6fd1[_0xf404('0x2d')],qs[_0xf404('0x33')](_0xc589fb['query'][_0xf404('0x33')]));_0x34a6cf[_0xf404('0x32')]=_0x34a6cf['attributes']['length']?_0x34a6cf[_0xf404('0x32')]:_0x5e6fd1[_0xf404('0x2d')];if(_0xc589fb[_0xf404('0x2e')]['includeAll']){_0x34a6cf[_0xf404('0x40')]=[{'all':!![]}];}_0x34a6cf=_[_0xf404('0x3c')]({},_0x34a6cf,_0xc589fb[_0xf404('0x3e')]);return db[_0xf404('0x2b')][_0xf404('0x46')](_0x34a6cf)[_0xf404('0x23')](handleEntityNotFound(_0x387e34,null))[_0xf404('0x23')](respondWithResult(_0x387e34,null))['catch'](handleError(_0x387e34,null));};exports[_0xf404('0x47')]=function(_0x4bc613,_0x218cc2){return db['VoiceQueuesLog']['create'](_0x4bc613['body'],{})[_0xf404('0x23')](respondWithResult(_0x218cc2,0xc9))[_0xf404('0x43')](handleError(_0x218cc2,null));};exports[_0xf404('0x22')]=function(_0x324fd2,_0xf236af){if(_0x324fd2[_0xf404('0x48')]['id']){delete _0x324fd2[_0xf404('0x48')]['id'];}return db[_0xf404('0x2b')]['find']({'where':{'id':_0x324fd2[_0xf404('0x45')]['id']}})['then'](handleEntityNotFound(_0xf236af,null))[_0xf404('0x23')](saveUpdates(_0x324fd2[_0xf404('0x48')],null))[_0xf404('0x23')](respondWithResult(_0xf236af,null))[_0xf404('0x43')](handleError(_0xf236af,null));};exports[_0xf404('0x24')]=function(_0x2b341a,_0x3e5c1b){return db['VoiceQueuesLog'][_0xf404('0x46')]({'where':{'id':_0x2b341a[_0xf404('0x45')]['id']}})[_0xf404('0x23')](handleEntityNotFound(_0x3e5c1b,null))['then'](removeEntity(_0x3e5c1b,null))[_0xf404('0x43')](handleError(_0x3e5c1b,null));};