b56c163db370453bcd522645c0b3604dfc5bc0c5
[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 _0x953f=['type','key','model','map','query','keys','filters','intersection','attributes','fields','length','hasOwnProperty','order','sort','where','pick','filter','merge','VIRTUAL','VoiceQueuesLog','count','includeAll','include','rows','catch','show','params','options','find','create','body','eml-format','rimraf','fast-json-patch','request-promise','moment','bluebird','util','sox','to-csv','ejs','lodash','squel','jsforce','desk.js','papaparse','ioredis','../../components/auth/service','../../components/parsers/qs','../../config/logger','api','../../config/utils','../../config/environment','../../config/license/util','../../mysqldb','status','end','limit','undefined','offset','set','Content-Range','apply','reject','update','destroy','then','sendStatus','stack','name','index','rawAttributes','fieldName'];(function(_0x252d0f,_0x2897cd){var _0x3c85e5=function(_0xa857e6){while(--_0xa857e6){_0x252d0f['push'](_0x252d0f['shift']());}};_0x3c85e5(++_0x2897cd);}(_0x953f,0x143));var _0xf953=function(_0x51020b,_0x38c2c7){_0x51020b=_0x51020b-0x0;var _0x371e47=_0x953f[_0x51020b];return _0x371e47;};'use strict';var emlformat=require(_0xf953('0x0'));var rimraf=require(_0xf953('0x1'));var zipdir=require('zip-dir');var jsonpatch=require(_0xf953('0x2'));var rp=require(_0xf953('0x3'));var moment=require(_0xf953('0x4'));var BPromise=require(_0xf953('0x5'));var Mustache=require('mustache');var util=require(_0xf953('0x6'));var path=require('path');var sox=require(_0xf953('0x7'));var csv=require(_0xf953('0x8'));var ejs=require(_0xf953('0x9'));var fs=require('fs');var fs_extra=require('fs-extra');var _=require(_0xf953('0xa'));var squel=require(_0xf953('0xb'));var crypto=require('crypto');var jsforce=require(_0xf953('0xc'));var deskjs=require(_0xf953('0xd'));var toCsv=require(_0xf953('0x8'));var querystring=require('querystring');var Papa=require(_0xf953('0xe'));var Redis=require(_0xf953('0xf'));var authService=require(_0xf953('0x10'));var qs=require(_0xf953('0x11'));var as=require('../../components/parsers/advancedSearch');var hardwareService=require('../../config/license/hardware');var logger=require(_0xf953('0x12'))(_0xf953('0x13'));var utils=require(_0xf953('0x14'));var config=require(_0xf953('0x15'));var licenseUtil=require(_0xf953('0x16'));var db=require(_0xf953('0x17'))['db'];function respondWithStatusCode(_0x2eda47,_0x4f7220){_0x4f7220=_0x4f7220||0xcc;return function(_0x5f04cc){if(_0x5f04cc){return _0x2eda47['sendStatus'](_0x4f7220);}return _0x2eda47[_0xf953('0x18')](_0x4f7220)[_0xf953('0x19')]();};}function respondWithResult(_0x20adca,_0x111291){_0x111291=_0x111291||0xc8;return function(_0x28374f){if(_0x28374f){return _0x20adca[_0xf953('0x18')](_0x111291)['json'](_0x28374f);}};}function respondWithFilteredResult(_0x4e8916,_0xa85710){return function(_0x842feb){if(_0x842feb){var _0x1780a7=typeof _0xa85710['offset']==='undefined'&&typeof _0xa85710[_0xf953('0x1a')]===_0xf953('0x1b');var _0x268edc=_0x842feb['count'];var _0x23201e=_0x1780a7?0x0:_0xa85710[_0xf953('0x1c')];var _0x314fc2=_0x1780a7?_0x842feb['count']:_0xa85710[_0xf953('0x1c')]+_0xa85710[_0xf953('0x1a')];var _0x4ffc6c;if(_0x314fc2>=_0x268edc){_0x314fc2=_0x268edc;_0x4ffc6c=0xc8;}else{_0x4ffc6c=0xce;}_0x4e8916[_0xf953('0x18')](_0x4ffc6c);return _0x4e8916[_0xf953('0x1d')](_0xf953('0x1e'),_0x23201e+'-'+_0x314fc2+'/'+_0x268edc)['json'](_0x842feb);}return null;};}function patchUpdates(_0x2c0a4c){return function(_0x1ed411){try{jsonpatch[_0xf953('0x1f')](_0x1ed411,_0x2c0a4c,!![]);}catch(_0x130eca){return BPromise[_0xf953('0x20')](_0x130eca);}return _0x1ed411['save']();};}function saveUpdates(_0x3e9134,_0x20d94a){return function(_0x134fe6){if(_0x134fe6){return _0x134fe6[_0xf953('0x21')](_0x3e9134)['then'](function(_0x104c5f){return _0x104c5f;});}return null;};}function removeEntity(_0x58bed0,_0x4b9839){return function(_0x36dca9){if(_0x36dca9){return _0x36dca9[_0xf953('0x22')]()[_0xf953('0x23')](function(){_0x58bed0[_0xf953('0x18')](0xcc)[_0xf953('0x19')]();});}};}function handleEntityNotFound(_0x44a3c0,_0x30a247){return function(_0x6cea92){if(!_0x6cea92){_0x44a3c0[_0xf953('0x24')](0x194);}return _0x6cea92;};}function handleError(_0x4aa9b8,_0x571f60){_0x571f60=_0x571f60||0x1f4;return function(_0x2eb158){logger['error'](_0x2eb158[_0xf953('0x25')]);if(_0x2eb158[_0xf953('0x26')]){delete _0x2eb158[_0xf953('0x26')];}_0x4aa9b8['status'](_0x571f60)['send'](_0x2eb158);};}exports[_0xf953('0x27')]=function(_0x5af455,_0x77da34){var _0x42e5e7={},_0x56b5b6={},_0x55ac4a={'count':0x0,'rows':[]};var _0x3a840b=_['map'](db['VoiceQueuesLog'][_0xf953('0x28')],function(_0x581bef){return{'name':_0x581bef[_0xf953('0x29')],'type':_0x581bef[_0xf953('0x2a')][_0xf953('0x2b')]};});_0x56b5b6[_0xf953('0x2c')]=_[_0xf953('0x2d')](_0x3a840b,_0xf953('0x26'));_0x56b5b6[_0xf953('0x2e')]=_[_0xf953('0x2f')](_0x5af455['query']);_0x56b5b6[_0xf953('0x30')]=_[_0xf953('0x31')](_0x56b5b6[_0xf953('0x2c')],_0x56b5b6['query']);_0x42e5e7[_0xf953('0x32')]=_[_0xf953('0x31')](_0x56b5b6[_0xf953('0x2c')],qs[_0xf953('0x33')](_0x5af455[_0xf953('0x2e')][_0xf953('0x33')]));_0x42e5e7['attributes']=_0x42e5e7[_0xf953('0x32')][_0xf953('0x34')]?_0x42e5e7[_0xf953('0x32')]:_0x56b5b6[_0xf953('0x2c')];if(!_0x5af455['query'][_0xf953('0x35')]('nolimit')){_0x42e5e7[_0xf953('0x1a')]=qs[_0xf953('0x1a')](_0x5af455[_0xf953('0x2e')][_0xf953('0x1a')]);_0x42e5e7[_0xf953('0x1c')]=qs['offset'](_0x5af455['query'][_0xf953('0x1c')]);}_0x42e5e7[_0xf953('0x36')]=qs[_0xf953('0x37')](_0x5af455[_0xf953('0x2e')]['sort']);_0x42e5e7[_0xf953('0x38')]=qs[_0xf953('0x30')](_[_0xf953('0x39')](_0x5af455['query'],_0x56b5b6['filters']),_0x3a840b);if(_0x5af455[_0xf953('0x2e')][_0xf953('0x3a')]){_0x42e5e7[_0xf953('0x38')]=_[_0xf953('0x3b')](_0x42e5e7['where'],{'$or':_[_0xf953('0x2d')](_0x3a840b,function(_0x59cd7f){if(_0x59cd7f['type']!==_0xf953('0x3c')){var _0x2c761f={};_0x2c761f[_0x59cd7f[_0xf953('0x26')]]={'$like':'%'+_0x5af455['query'][_0xf953('0x3a')]+'%'};return _0x2c761f;}})});}_0x42e5e7=_[_0xf953('0x3b')]({},_0x42e5e7,_0x5af455['options']);var _0x3b97bb={'where':_0x42e5e7[_0xf953('0x38')]};return db[_0xf953('0x3d')]['count'](_0x3b97bb)['then'](function(_0x28e30a){_0x55ac4a[_0xf953('0x3e')]=_0x28e30a;if(_0x5af455[_0xf953('0x2e')][_0xf953('0x3f')]){_0x42e5e7[_0xf953('0x40')]=[{'all':!![]}];}return db['VoiceQueuesLog']['findAll'](_0x42e5e7);})[_0xf953('0x23')](function(_0x5131eb){_0x55ac4a[_0xf953('0x41')]=_0x5131eb;return _0x55ac4a;})[_0xf953('0x23')](respondWithFilteredResult(_0x77da34,_0x42e5e7))[_0xf953('0x42')](handleError(_0x77da34,null));};exports[_0xf953('0x43')]=function(_0x36092f,_0x524e7f){var _0x4c276a={'raw':!![],'where':{'id':_0x36092f[_0xf953('0x44')]['id']}},_0x65a79={};_0x65a79['model']=_[_0xf953('0x2f')](db['VoiceQueuesLog'][_0xf953('0x28')]);_0x65a79[_0xf953('0x2e')]=_[_0xf953('0x2f')](_0x36092f['query']);_0x65a79['filters']=_['intersection'](_0x65a79[_0xf953('0x2c')],_0x65a79[_0xf953('0x2e')]);_0x4c276a[_0xf953('0x32')]=_['intersection'](_0x65a79['model'],qs['fields'](_0x36092f['query']['fields']));_0x4c276a[_0xf953('0x32')]=_0x4c276a[_0xf953('0x32')][_0xf953('0x34')]?_0x4c276a[_0xf953('0x32')]:_0x65a79[_0xf953('0x2c')];if(_0x36092f[_0xf953('0x2e')][_0xf953('0x3f')]){_0x4c276a['include']=[{'all':!![]}];}_0x4c276a=_[_0xf953('0x3b')]({},_0x4c276a,_0x36092f[_0xf953('0x45')]);return db[_0xf953('0x3d')][_0xf953('0x46')](_0x4c276a)[_0xf953('0x23')](handleEntityNotFound(_0x524e7f,null))[_0xf953('0x23')](respondWithResult(_0x524e7f,null))['catch'](handleError(_0x524e7f,null));};exports['create']=function(_0x129d76,_0x33a2cd){return db[_0xf953('0x3d')][_0xf953('0x47')](_0x129d76[_0xf953('0x48')],{})[_0xf953('0x23')](respondWithResult(_0x33a2cd,0xc9))[_0xf953('0x42')](handleError(_0x33a2cd,null));};exports[_0xf953('0x21')]=function(_0x2282d9,_0x16b690){if(_0x2282d9[_0xf953('0x48')]['id']){delete _0x2282d9[_0xf953('0x48')]['id'];}return db[_0xf953('0x3d')]['find']({'where':{'id':_0x2282d9[_0xf953('0x44')]['id']}})['then'](handleEntityNotFound(_0x16b690,null))[_0xf953('0x23')](saveUpdates(_0x2282d9[_0xf953('0x48')],null))[_0xf953('0x23')](respondWithResult(_0x16b690,null))[_0xf953('0x42')](handleError(_0x16b690,null));};exports[_0xf953('0x22')]=function(_0x1b7737,_0x1919af){return db[_0xf953('0x3d')][_0xf953('0x46')]({'where':{'id':_0x1b7737[_0xf953('0x44')]['id']}})[_0xf953('0x23')](handleEntityNotFound(_0x1919af,null))[_0xf953('0x23')](removeEntity(_0x1919af,null))[_0xf953('0x42')](handleError(_0x1919af,null));};