8e30c8f874e8bff16505b89d9281f53f2a469d58
[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 _0xa8d7=['papaparse','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/logger','api','../../config/environment','status','end','offset','undefined','limit','count','Content-Range','apply','reject','save','update','then','destroy','stack','name','send','map','VoiceQueuesLog','fieldName','key','keys','filters','model','query','attributes','intersection','fields','hasOwnProperty','nolimit','order','sort','pick','filter','where','type','merge','findAll','rows','catch','show','params','rawAttributes','length','includeAll','include','find','create','body','eml-format','rimraf','bluebird','mustache','util','path','sox','to-csv','ejs','fs-extra','squel','crypto','jsforce','querystring'];(function(_0x458a2e,_0x31f0d7){var _0x26590e=function(_0xf06a51){while(--_0xf06a51){_0x458a2e['push'](_0x458a2e['shift']());}};_0x26590e(++_0x31f0d7);}(_0xa8d7,0xc1));var _0x7a8d=function(_0x2e655a,_0x6d5799){_0x2e655a=_0x2e655a-0x0;var _0x26f13b=_0xa8d7[_0x2e655a];return _0x26f13b;};'use strict';var emlformat=require(_0x7a8d('0x0'));var rimraf=require(_0x7a8d('0x1'));var zipdir=require('zip-dir');var jsonpatch=require('fast-json-patch');var rp=require('request-promise');var moment=require('moment');var BPromise=require(_0x7a8d('0x2'));var Mustache=require(_0x7a8d('0x3'));var util=require(_0x7a8d('0x4'));var path=require(_0x7a8d('0x5'));var sox=require(_0x7a8d('0x6'));var csv=require(_0x7a8d('0x7'));var ejs=require(_0x7a8d('0x8'));var fs=require('fs');var fs_extra=require(_0x7a8d('0x9'));var _=require('lodash');var squel=require(_0x7a8d('0xa'));var crypto=require(_0x7a8d('0xb'));var jsforce=require(_0x7a8d('0xc'));var deskjs=require('desk.js');var toCsv=require(_0x7a8d('0x7'));var querystring=require(_0x7a8d('0xd'));var Papa=require(_0x7a8d('0xe'));var Redis=require('ioredis');var authService=require(_0x7a8d('0xf'));var qs=require(_0x7a8d('0x10'));var as=require(_0x7a8d('0x11'));var hardwareService=require('../../config/license/hardware');var logger=require(_0x7a8d('0x12'))(_0x7a8d('0x13'));var utils=require('../../config/utils');var config=require(_0x7a8d('0x14'));var licenseUtil=require('../../config/license/util');var db=require('../../mysqldb')['db'];function respondWithStatusCode(_0xfecd70,_0x4cf477){_0x4cf477=_0x4cf477||0xcc;return function(_0x5b1cdd){if(_0x5b1cdd){return _0xfecd70['sendStatus'](_0x4cf477);}return _0xfecd70[_0x7a8d('0x15')](_0x4cf477)[_0x7a8d('0x16')]();};}function respondWithResult(_0x53ec04,_0x265f6f){_0x265f6f=_0x265f6f||0xc8;return function(_0x26493f){if(_0x26493f){return _0x53ec04[_0x7a8d('0x15')](_0x265f6f)['json'](_0x26493f);}};}function respondWithFilteredResult(_0x5c8bc5,_0x24b86d){return function(_0x4abe02){if(_0x4abe02){var _0x28d769=typeof _0x24b86d[_0x7a8d('0x17')]===_0x7a8d('0x18')&&typeof _0x24b86d[_0x7a8d('0x19')]==='undefined';var _0x187308=_0x4abe02[_0x7a8d('0x1a')];var _0x31a8d3=_0x28d769?0x0:_0x24b86d[_0x7a8d('0x17')];var _0x37a02b=_0x28d769?_0x4abe02[_0x7a8d('0x1a')]:_0x24b86d[_0x7a8d('0x17')]+_0x24b86d['limit'];var _0x5ef9b9;if(_0x37a02b>=_0x187308){_0x37a02b=_0x187308;_0x5ef9b9=0xc8;}else{_0x5ef9b9=0xce;}_0x5c8bc5[_0x7a8d('0x15')](_0x5ef9b9);return _0x5c8bc5['set'](_0x7a8d('0x1b'),_0x31a8d3+'-'+_0x37a02b+'/'+_0x187308)['json'](_0x4abe02);}return null;};}function patchUpdates(_0x4b4885){return function(_0x3d1fff){try{jsonpatch[_0x7a8d('0x1c')](_0x3d1fff,_0x4b4885,!![]);}catch(_0x2618e6){return BPromise[_0x7a8d('0x1d')](_0x2618e6);}return _0x3d1fff[_0x7a8d('0x1e')]();};}function saveUpdates(_0x38ef9d,_0x2f7e61){return function(_0x4d24ea){if(_0x4d24ea){return _0x4d24ea[_0x7a8d('0x1f')](_0x38ef9d)[_0x7a8d('0x20')](function(_0x32a465){return _0x32a465;});}return null;};}function removeEntity(_0x44c069,_0x4428a8){return function(_0xd062d3){if(_0xd062d3){return _0xd062d3[_0x7a8d('0x21')]()[_0x7a8d('0x20')](function(){_0x44c069[_0x7a8d('0x15')](0xcc)[_0x7a8d('0x16')]();});}};}function handleEntityNotFound(_0x26b228,_0xcf90c6){return function(_0x5f5711){if(!_0x5f5711){_0x26b228['sendStatus'](0x194);}return _0x5f5711;};}function handleError(_0x10a7e8,_0x487e11){_0x487e11=_0x487e11||0x1f4;return function(_0x62682d){logger['error'](_0x62682d[_0x7a8d('0x22')]);if(_0x62682d[_0x7a8d('0x23')]){delete _0x62682d[_0x7a8d('0x23')];}_0x10a7e8['status'](_0x487e11)[_0x7a8d('0x24')](_0x62682d);};}exports['index']=function(_0x5e8233,_0x2253c4){var _0x140e85={},_0x384347={},_0x121d39={'count':0x0,'rows':[]};var _0x4ec87b=_[_0x7a8d('0x25')](db[_0x7a8d('0x26')]['rawAttributes'],function(_0x563a54){return{'name':_0x563a54[_0x7a8d('0x27')],'type':_0x563a54['type'][_0x7a8d('0x28')]};});_0x384347['model']=_[_0x7a8d('0x25')](_0x4ec87b,_0x7a8d('0x23'));_0x384347['query']=_[_0x7a8d('0x29')](_0x5e8233['query']);_0x384347[_0x7a8d('0x2a')]=_['intersection'](_0x384347[_0x7a8d('0x2b')],_0x384347[_0x7a8d('0x2c')]);_0x140e85[_0x7a8d('0x2d')]=_[_0x7a8d('0x2e')](_0x384347[_0x7a8d('0x2b')],qs[_0x7a8d('0x2f')](_0x5e8233[_0x7a8d('0x2c')]['fields']));_0x140e85['attributes']=_0x140e85[_0x7a8d('0x2d')]['length']?_0x140e85[_0x7a8d('0x2d')]:_0x384347['model'];if(!_0x5e8233[_0x7a8d('0x2c')][_0x7a8d('0x30')](_0x7a8d('0x31'))){_0x140e85[_0x7a8d('0x19')]=qs[_0x7a8d('0x19')](_0x5e8233['query'][_0x7a8d('0x19')]);_0x140e85[_0x7a8d('0x17')]=qs[_0x7a8d('0x17')](_0x5e8233[_0x7a8d('0x2c')][_0x7a8d('0x17')]);}_0x140e85[_0x7a8d('0x32')]=qs['sort'](_0x5e8233['query'][_0x7a8d('0x33')]);_0x140e85['where']=qs['filters'](_[_0x7a8d('0x34')](_0x5e8233[_0x7a8d('0x2c')],_0x384347[_0x7a8d('0x2a')]),_0x4ec87b);if(_0x5e8233['query'][_0x7a8d('0x35')]){_0x140e85['where']=_['merge'](_0x140e85[_0x7a8d('0x36')],{'$or':_[_0x7a8d('0x25')](_0x4ec87b,function(_0x604d26){if(_0x604d26[_0x7a8d('0x37')]!=='VIRTUAL'){var _0x4d447d={};_0x4d447d[_0x604d26[_0x7a8d('0x23')]]={'$like':'%'+_0x5e8233['query'][_0x7a8d('0x35')]+'%'};return _0x4d447d;}})});}_0x140e85=_[_0x7a8d('0x38')]({},_0x140e85,_0x5e8233['options']);var _0x2af452={'where':_0x140e85[_0x7a8d('0x36')]};return db[_0x7a8d('0x26')][_0x7a8d('0x1a')](_0x2af452)['then'](function(_0x52171b){_0x121d39[_0x7a8d('0x1a')]=_0x52171b;if(_0x5e8233['query']['includeAll']){_0x140e85['include']=[{'all':!![]}];}return db['VoiceQueuesLog'][_0x7a8d('0x39')](_0x140e85);})[_0x7a8d('0x20')](function(_0x22a4a9){_0x121d39[_0x7a8d('0x3a')]=_0x22a4a9;return _0x121d39;})['then'](respondWithFilteredResult(_0x2253c4,_0x140e85))[_0x7a8d('0x3b')](handleError(_0x2253c4,null));};exports[_0x7a8d('0x3c')]=function(_0xbbc4e5,_0x201c25){var _0x1e046c={'raw':!![],'where':{'id':_0xbbc4e5[_0x7a8d('0x3d')]['id']}},_0x25873b={};_0x25873b[_0x7a8d('0x2b')]=_[_0x7a8d('0x29')](db['VoiceQueuesLog'][_0x7a8d('0x3e')]);_0x25873b[_0x7a8d('0x2c')]=_[_0x7a8d('0x29')](_0xbbc4e5[_0x7a8d('0x2c')]);_0x25873b[_0x7a8d('0x2a')]=_[_0x7a8d('0x2e')](_0x25873b[_0x7a8d('0x2b')],_0x25873b[_0x7a8d('0x2c')]);_0x1e046c[_0x7a8d('0x2d')]=_[_0x7a8d('0x2e')](_0x25873b[_0x7a8d('0x2b')],qs[_0x7a8d('0x2f')](_0xbbc4e5[_0x7a8d('0x2c')][_0x7a8d('0x2f')]));_0x1e046c[_0x7a8d('0x2d')]=_0x1e046c['attributes'][_0x7a8d('0x3f')]?_0x1e046c[_0x7a8d('0x2d')]:_0x25873b['model'];if(_0xbbc4e5[_0x7a8d('0x2c')][_0x7a8d('0x40')]){_0x1e046c[_0x7a8d('0x41')]=[{'all':!![]}];}_0x1e046c=_[_0x7a8d('0x38')]({},_0x1e046c,_0xbbc4e5['options']);return db[_0x7a8d('0x26')][_0x7a8d('0x42')](_0x1e046c)[_0x7a8d('0x20')](handleEntityNotFound(_0x201c25,null))[_0x7a8d('0x20')](respondWithResult(_0x201c25,null))[_0x7a8d('0x3b')](handleError(_0x201c25,null));};exports[_0x7a8d('0x43')]=function(_0x4ade7f,_0x1ce679){return db['VoiceQueuesLog'][_0x7a8d('0x43')](_0x4ade7f[_0x7a8d('0x44')],{})[_0x7a8d('0x20')](respondWithResult(_0x1ce679,0xc9))[_0x7a8d('0x3b')](handleError(_0x1ce679,null));};exports[_0x7a8d('0x1f')]=function(_0x57e858,_0x529292){if(_0x57e858['body']['id']){delete _0x57e858[_0x7a8d('0x44')]['id'];}return db[_0x7a8d('0x26')][_0x7a8d('0x42')]({'where':{'id':_0x57e858[_0x7a8d('0x3d')]['id']}})['then'](handleEntityNotFound(_0x529292,null))[_0x7a8d('0x20')](saveUpdates(_0x57e858[_0x7a8d('0x44')],null))[_0x7a8d('0x20')](respondWithResult(_0x529292,null))[_0x7a8d('0x3b')](handleError(_0x529292,null));};exports[_0x7a8d('0x21')]=function(_0x24a318,_0x550649){return db[_0x7a8d('0x26')][_0x7a8d('0x42')]({'where':{'id':_0x24a318[_0x7a8d('0x3d')]['id']}})[_0x7a8d('0x20')](handleEntityNotFound(_0x550649,null))['then'](removeEntity(_0x550649,null))[_0x7a8d('0x3b')](handleError(_0x550649,null));};