39053eb058667743efe4605aa86c08a95c360726
[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 _0x6d6f=['crypto','jsforce','querystring','papaparse','ioredis','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/utils','../../config/environment','../../config/license/util','sendStatus','status','end','json','offset','undefined','limit','count','set','Content-Range','apply','reject','save','update','destroy','then','stack','name','send','index','map','VoiceQueuesLog','rawAttributes','type','key','model','keys','query','filters','intersection','attributes','fields','length','nolimit','order','sort','where','pick','filter','options','includeAll','include','findAll','rows','show','params','catch','create','body','find','eml-format','rimraf','fast-json-patch','request-promise','bluebird','mustache','path','to-csv','ejs','lodash','squel'];(function(_0x1481ad,_0x2d3888){var _0x5ef3cb=function(_0x1992ef){while(--_0x1992ef){_0x1481ad['push'](_0x1481ad['shift']());}};_0x5ef3cb(++_0x2d3888);}(_0x6d6f,0x1e6));var _0xf6d6=function(_0x2ee790,_0x5a8661){_0x2ee790=_0x2ee790-0x0;var _0x5a54a5=_0x6d6f[_0x2ee790];return _0x5a54a5;};'use strict';var emlformat=require(_0xf6d6('0x0'));var rimraf=require(_0xf6d6('0x1'));var zipdir=require('zip-dir');var jsonpatch=require(_0xf6d6('0x2'));var rp=require(_0xf6d6('0x3'));var moment=require('moment');var BPromise=require(_0xf6d6('0x4'));var Mustache=require(_0xf6d6('0x5'));var util=require('util');var path=require(_0xf6d6('0x6'));var sox=require('sox');var csv=require(_0xf6d6('0x7'));var ejs=require(_0xf6d6('0x8'));var fs=require('fs');var fs_extra=require('fs-extra');var _=require(_0xf6d6('0x9'));var squel=require(_0xf6d6('0xa'));var crypto=require(_0xf6d6('0xb'));var jsforce=require(_0xf6d6('0xc'));var deskjs=require('desk.js');var toCsv=require(_0xf6d6('0x7'));var querystring=require(_0xf6d6('0xd'));var Papa=require(_0xf6d6('0xe'));var Redis=require(_0xf6d6('0xf'));var authService=require('../../components/auth/service');var qs=require('../../components/parsers/qs');var as=require(_0xf6d6('0x10'));var hardwareService=require(_0xf6d6('0x11'));var logger=require('../../config/logger')('api');var utils=require(_0xf6d6('0x12'));var config=require(_0xf6d6('0x13'));var licenseUtil=require(_0xf6d6('0x14'));var db=require('../../mysqldb')['db'];function respondWithStatusCode(_0x4b1e6c,_0x486d03){_0x486d03=_0x486d03||0xcc;return function(_0x437e69){if(_0x437e69){return _0x4b1e6c[_0xf6d6('0x15')](_0x486d03);}return _0x4b1e6c[_0xf6d6('0x16')](_0x486d03)[_0xf6d6('0x17')]();};}function respondWithResult(_0x45aa60,_0x6c9801){_0x6c9801=_0x6c9801||0xc8;return function(_0x44e021){if(_0x44e021){return _0x45aa60[_0xf6d6('0x16')](_0x6c9801)[_0xf6d6('0x18')](_0x44e021);}};}function respondWithFilteredResult(_0x596b7a,_0xd1ea56){return function(_0xa9d0d){if(_0xa9d0d){var _0x5ab8e2=typeof _0xd1ea56[_0xf6d6('0x19')]===_0xf6d6('0x1a')&&typeof _0xd1ea56[_0xf6d6('0x1b')]==='undefined';var _0x50610b=_0xa9d0d[_0xf6d6('0x1c')];var _0x4cbb15=_0x5ab8e2?0x0:_0xd1ea56[_0xf6d6('0x19')];var _0x5c68f7=_0x5ab8e2?_0xa9d0d[_0xf6d6('0x1c')]:_0xd1ea56[_0xf6d6('0x19')]+_0xd1ea56[_0xf6d6('0x1b')];var _0x5cf23f;if(_0x5c68f7>=_0x50610b){_0x5c68f7=_0x50610b;_0x5cf23f=0xc8;}else{_0x5cf23f=0xce;}_0x596b7a[_0xf6d6('0x16')](_0x5cf23f);return _0x596b7a[_0xf6d6('0x1d')](_0xf6d6('0x1e'),_0x4cbb15+'-'+_0x5c68f7+'/'+_0x50610b)['json'](_0xa9d0d);}return null;};}function patchUpdates(_0x36decf){return function(_0x38cd68){try{jsonpatch[_0xf6d6('0x1f')](_0x38cd68,_0x36decf,!![]);}catch(_0xa3deec){return BPromise[_0xf6d6('0x20')](_0xa3deec);}return _0x38cd68[_0xf6d6('0x21')]();};}function saveUpdates(_0x37d538,_0x142e89){return function(_0x3fad3){if(_0x3fad3){return _0x3fad3[_0xf6d6('0x22')](_0x37d538)['then'](function(_0x5785da){return _0x5785da;});}return null;};}function removeEntity(_0x48a3ea,_0x5f4b8e){return function(_0x49db23){if(_0x49db23){return _0x49db23[_0xf6d6('0x23')]()[_0xf6d6('0x24')](function(){_0x48a3ea['status'](0xcc)[_0xf6d6('0x17')]();});}};}function handleEntityNotFound(_0x5a19d3,_0x3db7cf){return function(_0xa811b7){if(!_0xa811b7){_0x5a19d3['sendStatus'](0x194);}return _0xa811b7;};}function handleError(_0x3e427b,_0x5903f4){_0x5903f4=_0x5903f4||0x1f4;return function(_0x58755e){logger['error'](_0x58755e[_0xf6d6('0x25')]);if(_0x58755e[_0xf6d6('0x26')]){delete _0x58755e['name'];}_0x3e427b['status'](_0x5903f4)[_0xf6d6('0x27')](_0x58755e);};}exports[_0xf6d6('0x28')]=function(_0x123ba4,_0x40ff97){var _0x49222d={},_0x1705eb={},_0x48e670={'count':0x0,'rows':[]};var _0x540258=_[_0xf6d6('0x29')](db[_0xf6d6('0x2a')][_0xf6d6('0x2b')],function(_0x88f6b6){return{'name':_0x88f6b6['fieldName'],'type':_0x88f6b6[_0xf6d6('0x2c')][_0xf6d6('0x2d')]};});_0x1705eb[_0xf6d6('0x2e')]=_[_0xf6d6('0x29')](_0x540258,_0xf6d6('0x26'));_0x1705eb['query']=_[_0xf6d6('0x2f')](_0x123ba4[_0xf6d6('0x30')]);_0x1705eb[_0xf6d6('0x31')]=_[_0xf6d6('0x32')](_0x1705eb[_0xf6d6('0x2e')],_0x1705eb[_0xf6d6('0x30')]);_0x49222d[_0xf6d6('0x33')]=_[_0xf6d6('0x32')](_0x1705eb[_0xf6d6('0x2e')],qs[_0xf6d6('0x34')](_0x123ba4[_0xf6d6('0x30')][_0xf6d6('0x34')]));_0x49222d[_0xf6d6('0x33')]=_0x49222d[_0xf6d6('0x33')][_0xf6d6('0x35')]?_0x49222d['attributes']:_0x1705eb[_0xf6d6('0x2e')];if(!_0x123ba4[_0xf6d6('0x30')]['hasOwnProperty'](_0xf6d6('0x36'))){_0x49222d['limit']=qs[_0xf6d6('0x1b')](_0x123ba4[_0xf6d6('0x30')][_0xf6d6('0x1b')]);_0x49222d['offset']=qs[_0xf6d6('0x19')](_0x123ba4['query'][_0xf6d6('0x19')]);}_0x49222d[_0xf6d6('0x37')]=qs[_0xf6d6('0x38')](_0x123ba4[_0xf6d6('0x30')][_0xf6d6('0x38')]);_0x49222d[_0xf6d6('0x39')]=qs[_0xf6d6('0x31')](_[_0xf6d6('0x3a')](_0x123ba4[_0xf6d6('0x30')],_0x1705eb[_0xf6d6('0x31')]),_0x540258);if(_0x123ba4[_0xf6d6('0x30')][_0xf6d6('0x3b')]){_0x49222d[_0xf6d6('0x39')]=_['merge'](_0x49222d['where'],{'$or':_[_0xf6d6('0x29')](_0x540258,function(_0x570bfd){if(_0x570bfd[_0xf6d6('0x2c')]!=='VIRTUAL'){var _0x268e8a={};_0x268e8a[_0x570bfd[_0xf6d6('0x26')]]={'$like':'%'+_0x123ba4[_0xf6d6('0x30')][_0xf6d6('0x3b')]+'%'};return _0x268e8a;}})});}_0x49222d=_['merge']({},_0x49222d,_0x123ba4[_0xf6d6('0x3c')]);var _0x1c8cce={'where':_0x49222d[_0xf6d6('0x39')]};return db[_0xf6d6('0x2a')]['count'](_0x1c8cce)['then'](function(_0xe3c175){_0x48e670['count']=_0xe3c175;if(_0x123ba4[_0xf6d6('0x30')][_0xf6d6('0x3d')]){_0x49222d[_0xf6d6('0x3e')]=[{'all':!![]}];}return db[_0xf6d6('0x2a')][_0xf6d6('0x3f')](_0x49222d);})[_0xf6d6('0x24')](function(_0x48287e){_0x48e670[_0xf6d6('0x40')]=_0x48287e;return _0x48e670;})[_0xf6d6('0x24')](respondWithFilteredResult(_0x40ff97,_0x49222d))['catch'](handleError(_0x40ff97,null));};exports[_0xf6d6('0x41')]=function(_0x4fa933,_0x1373fd){var _0x279e44={'raw':!![],'where':{'id':_0x4fa933[_0xf6d6('0x42')]['id']}},_0x2e4d40={};_0x2e4d40[_0xf6d6('0x2e')]=_[_0xf6d6('0x2f')](db['VoiceQueuesLog'][_0xf6d6('0x2b')]);_0x2e4d40[_0xf6d6('0x30')]=_[_0xf6d6('0x2f')](_0x4fa933[_0xf6d6('0x30')]);_0x2e4d40[_0xf6d6('0x31')]=_['intersection'](_0x2e4d40[_0xf6d6('0x2e')],_0x2e4d40[_0xf6d6('0x30')]);_0x279e44['attributes']=_[_0xf6d6('0x32')](_0x2e4d40['model'],qs[_0xf6d6('0x34')](_0x4fa933[_0xf6d6('0x30')]['fields']));_0x279e44[_0xf6d6('0x33')]=_0x279e44['attributes'][_0xf6d6('0x35')]?_0x279e44[_0xf6d6('0x33')]:_0x2e4d40['model'];if(_0x4fa933['query'][_0xf6d6('0x3d')]){_0x279e44[_0xf6d6('0x3e')]=[{'all':!![]}];}_0x279e44=_['merge']({},_0x279e44,_0x4fa933['options']);return db[_0xf6d6('0x2a')]['find'](_0x279e44)['then'](handleEntityNotFound(_0x1373fd,null))['then'](respondWithResult(_0x1373fd,null))[_0xf6d6('0x43')](handleError(_0x1373fd,null));};exports[_0xf6d6('0x44')]=function(_0x29003a,_0x1b7c00){return db[_0xf6d6('0x2a')]['create'](_0x29003a[_0xf6d6('0x45')],{})[_0xf6d6('0x24')](respondWithResult(_0x1b7c00,0xc9))[_0xf6d6('0x43')](handleError(_0x1b7c00,null));};exports['update']=function(_0x476dcd,_0x591226){if(_0x476dcd['body']['id']){delete _0x476dcd[_0xf6d6('0x45')]['id'];}return db['VoiceQueuesLog']['find']({'where':{'id':_0x476dcd['params']['id']}})[_0xf6d6('0x24')](handleEntityNotFound(_0x591226,null))[_0xf6d6('0x24')](saveUpdates(_0x476dcd['body'],null))['then'](respondWithResult(_0x591226,null))[_0xf6d6('0x43')](handleError(_0x591226,null));};exports['destroy']=function(_0x342d37,_0x1a488b){return db[_0xf6d6('0x2a')][_0xf6d6('0x46')]({'where':{'id':_0x342d37[_0xf6d6('0x42')]['id']}})[_0xf6d6('0x24')](handleEntityNotFound(_0x1a488b,null))['then'](removeEntity(_0x1a488b,null))[_0xf6d6('0x43')](handleError(_0x1a488b,null));};