fdcb43b33bbacc8ca139d216b6cea3a56f366b7a
[motion2.git] / server / api / chatQueueReport / chatQueueReport.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 _0x806b=['end','status','json','offset','limit','undefined','count','set','Content-Range','apply','save','then','destroy','error','send','index','map','rawAttributes','fieldName','type','key','model','query','keys','intersection','attributes','fields','length','hasOwnProperty','nolimit','order','sort','where','pick','filters','filter','merge','VIRTUAL','name','options','ChatQueueReport','includeAll','include','findAll','rows','catch','show','find','body','params','describe','eml-format','rimraf','zip-dir','fast-json-patch','request-promise','moment','bluebird','mustache','path','sox','to-csv','ejs','lodash','squel','jsforce','desk.js','querystring','ioredis','../../components/parsers/qs','../../config/license/hardware','api','../../config/utils','../../config/environment','../../mysqldb','sendStatus'];(function(_0x4de94d,_0xdd6680){var _0x5a74f5=function(_0x3e7181){while(--_0x3e7181){_0x4de94d['push'](_0x4de94d['shift']());}};_0x5a74f5(++_0xdd6680);}(_0x806b,0x163));var _0xb806=function(_0x146d5c,_0x589288){_0x146d5c=_0x146d5c-0x0;var _0x21af6f=_0x806b[_0x146d5c];return _0x21af6f;};'use strict';var emlformat=require(_0xb806('0x0'));var rimraf=require(_0xb806('0x1'));var zipdir=require(_0xb806('0x2'));var jsonpatch=require(_0xb806('0x3'));var rp=require(_0xb806('0x4'));var moment=require(_0xb806('0x5'));var BPromise=require(_0xb806('0x6'));var Mustache=require(_0xb806('0x7'));var util=require('util');var path=require(_0xb806('0x8'));var sox=require(_0xb806('0x9'));var csv=require(_0xb806('0xa'));var ejs=require(_0xb806('0xb'));var fs=require('fs');var fs_extra=require('fs-extra');var _=require(_0xb806('0xc'));var squel=require(_0xb806('0xd'));var crypto=require('crypto');var jsforce=require(_0xb806('0xe'));var deskjs=require(_0xb806('0xf'));var toCsv=require(_0xb806('0xa'));var querystring=require(_0xb806('0x10'));var Papa=require('papaparse');var Redis=require(_0xb806('0x11'));var authService=require('../../components/auth/service');var qs=require(_0xb806('0x12'));var as=require('../../components/parsers/advancedSearch');var hardwareService=require(_0xb806('0x13'));var logger=require('../../config/logger')(_0xb806('0x14'));var utils=require(_0xb806('0x15'));var config=require(_0xb806('0x16'));var licenseUtil=require('../../config/license/util');var db=require(_0xb806('0x17'))['db'];function respondWithStatusCode(_0x5e83e3,_0x5f46d4){_0x5f46d4=_0x5f46d4||0xcc;return function(_0x2b2f90){if(_0x2b2f90){return _0x5e83e3[_0xb806('0x18')](_0x5f46d4);}return _0x5e83e3['status'](_0x5f46d4)[_0xb806('0x19')]();};}function respondWithResult(_0x4394c5,_0x58fdc3){_0x58fdc3=_0x58fdc3||0xc8;return function(_0x282777){if(_0x282777){return _0x4394c5[_0xb806('0x1a')](_0x58fdc3)[_0xb806('0x1b')](_0x282777);}};}function respondWithFilteredResult(_0x1a3258,_0x3d7ef9){return function(_0x49b02c){if(_0x49b02c){var _0x549bb6=typeof _0x3d7ef9[_0xb806('0x1c')]==='undefined'&&typeof _0x3d7ef9[_0xb806('0x1d')]===_0xb806('0x1e');var _0x2fd643=_0x49b02c[_0xb806('0x1f')];var _0x5375c1=_0x549bb6?0x0:_0x3d7ef9[_0xb806('0x1c')];var _0x1e17d2=_0x549bb6?_0x49b02c[_0xb806('0x1f')]:_0x3d7ef9[_0xb806('0x1c')]+_0x3d7ef9[_0xb806('0x1d')];var _0x21ed1d;if(_0x1e17d2>=_0x2fd643){_0x1e17d2=_0x2fd643;_0x21ed1d=0xc8;}else{_0x21ed1d=0xce;}_0x1a3258['status'](_0x21ed1d);return _0x1a3258[_0xb806('0x20')](_0xb806('0x21'),_0x5375c1+'-'+_0x1e17d2+'/'+_0x2fd643)['json'](_0x49b02c);}return null;};}function patchUpdates(_0x34b1fa){return function(_0x2dbb8a){try{jsonpatch[_0xb806('0x22')](_0x2dbb8a,_0x34b1fa,!![]);}catch(_0x1f2841){return BPromise['reject'](_0x1f2841);}return _0x2dbb8a[_0xb806('0x23')]();};}function saveUpdates(_0x44e06e,_0x201f1f){return function(_0x49ae70){if(_0x49ae70){return _0x49ae70['update'](_0x44e06e)[_0xb806('0x24')](function(_0x2130ef){return _0x2130ef;});}return null;};}function removeEntity(_0x52f12d,_0x570837){return function(_0x4e5dac){if(_0x4e5dac){return _0x4e5dac[_0xb806('0x25')]()['then'](function(){_0x52f12d['status'](0xcc)[_0xb806('0x19')]();});}};}function handleEntityNotFound(_0x3c4556,_0x3c6d4a){return function(_0x425956){if(!_0x425956){_0x3c4556[_0xb806('0x18')](0x194);}return _0x425956;};}function handleError(_0x2f8443,_0x3494c5){_0x3494c5=_0x3494c5||0x1f4;return function(_0xcd8bb7){logger[_0xb806('0x26')](_0xcd8bb7['stack']);if(_0xcd8bb7['name']){delete _0xcd8bb7['name'];}_0x2f8443['status'](_0x3494c5)[_0xb806('0x27')](_0xcd8bb7);};}exports[_0xb806('0x28')]=function(_0x512571,_0x35a540){var _0x1d34ba={},_0x34d9e1={},_0x538ce4={'count':0x0,'rows':[]};var _0x1ad3da=_[_0xb806('0x29')](db['ChatQueueReport'][_0xb806('0x2a')],function(_0x4fd393){return{'name':_0x4fd393[_0xb806('0x2b')],'type':_0x4fd393[_0xb806('0x2c')][_0xb806('0x2d')]};});_0x34d9e1[_0xb806('0x2e')]=_[_0xb806('0x29')](_0x1ad3da,'name');_0x34d9e1[_0xb806('0x2f')]=_[_0xb806('0x30')](_0x512571[_0xb806('0x2f')]);_0x34d9e1['filters']=_[_0xb806('0x31')](_0x34d9e1[_0xb806('0x2e')],_0x34d9e1['query']);_0x1d34ba[_0xb806('0x32')]=_['intersection'](_0x34d9e1[_0xb806('0x2e')],qs[_0xb806('0x33')](_0x512571[_0xb806('0x2f')][_0xb806('0x33')]));_0x1d34ba[_0xb806('0x32')]=_0x1d34ba['attributes'][_0xb806('0x34')]?_0x1d34ba[_0xb806('0x32')]:_0x34d9e1[_0xb806('0x2e')];if(!_0x512571[_0xb806('0x2f')][_0xb806('0x35')](_0xb806('0x36'))){_0x1d34ba[_0xb806('0x1d')]=qs[_0xb806('0x1d')](_0x512571[_0xb806('0x2f')]['limit']);_0x1d34ba[_0xb806('0x1c')]=qs[_0xb806('0x1c')](_0x512571[_0xb806('0x2f')][_0xb806('0x1c')]);}_0x1d34ba[_0xb806('0x37')]=qs[_0xb806('0x38')](_0x512571[_0xb806('0x2f')][_0xb806('0x38')]);_0x1d34ba[_0xb806('0x39')]=qs['filters'](_[_0xb806('0x3a')](_0x512571[_0xb806('0x2f')],_0x34d9e1[_0xb806('0x3b')]),_0x1ad3da);if(_0x512571[_0xb806('0x2f')][_0xb806('0x3c')]){_0x1d34ba[_0xb806('0x39')]=_[_0xb806('0x3d')](_0x1d34ba[_0xb806('0x39')],{'$or':_[_0xb806('0x29')](_0x1ad3da,function(_0x176383){if(_0x176383[_0xb806('0x2c')]!==_0xb806('0x3e')){var _0x3b209e={};_0x3b209e[_0x176383[_0xb806('0x3f')]]={'$like':'%'+_0x512571[_0xb806('0x2f')]['filter']+'%'};return _0x3b209e;}})});}_0x1d34ba=_[_0xb806('0x3d')]({},_0x1d34ba,_0x512571[_0xb806('0x40')]);var _0x20b9e1={'where':_0x1d34ba[_0xb806('0x39')]};return db[_0xb806('0x41')][_0xb806('0x1f')](_0x20b9e1)[_0xb806('0x24')](function(_0x2e9ff8){_0x538ce4[_0xb806('0x1f')]=_0x2e9ff8;if(_0x512571[_0xb806('0x2f')][_0xb806('0x42')]){_0x1d34ba[_0xb806('0x43')]=[{'all':!![]}];}return db[_0xb806('0x41')][_0xb806('0x44')](_0x1d34ba);})[_0xb806('0x24')](function(_0x6d103f){_0x538ce4[_0xb806('0x45')]=_0x6d103f;return _0x538ce4;})[_0xb806('0x24')](respondWithFilteredResult(_0x35a540,_0x1d34ba))[_0xb806('0x46')](handleError(_0x35a540,null));};exports[_0xb806('0x47')]=function(_0x3f0973,_0x361fe6){var _0x58477c={'raw':!![],'where':{'id':_0x3f0973['params']['id']}},_0x52662f={};_0x52662f['model']=_[_0xb806('0x30')](db['ChatQueueReport'][_0xb806('0x2a')]);_0x52662f[_0xb806('0x2f')]=_[_0xb806('0x30')](_0x3f0973[_0xb806('0x2f')]);_0x52662f[_0xb806('0x3b')]=_[_0xb806('0x31')](_0x52662f['model'],_0x52662f['query']);_0x58477c[_0xb806('0x32')]=_[_0xb806('0x31')](_0x52662f[_0xb806('0x2e')],qs[_0xb806('0x33')](_0x3f0973[_0xb806('0x2f')]['fields']));_0x58477c['attributes']=_0x58477c[_0xb806('0x32')][_0xb806('0x34')]?_0x58477c[_0xb806('0x32')]:_0x52662f['model'];if(_0x3f0973[_0xb806('0x2f')]['includeAll']){_0x58477c[_0xb806('0x43')]=[{'all':!![]}];}_0x58477c=_['merge']({},_0x58477c,_0x3f0973['options']);return db['ChatQueueReport'][_0xb806('0x48')](_0x58477c)['then'](handleEntityNotFound(_0x361fe6,null))['then'](respondWithResult(_0x361fe6,null))['catch'](handleError(_0x361fe6,null));};exports['create']=function(_0x71bc6e,_0x3e45eb){return db[_0xb806('0x41')]['create'](_0x71bc6e[_0xb806('0x49')],{})['then'](respondWithResult(_0x3e45eb,0xc9))[_0xb806('0x46')](handleError(_0x3e45eb,null));};exports['update']=function(_0x517855,_0x34743e){if(_0x517855[_0xb806('0x49')]['id']){delete _0x517855[_0xb806('0x49')]['id'];}return db[_0xb806('0x41')][_0xb806('0x48')]({'where':{'id':_0x517855[_0xb806('0x4a')]['id']}})[_0xb806('0x24')](handleEntityNotFound(_0x34743e,null))[_0xb806('0x24')](saveUpdates(_0x517855[_0xb806('0x49')],null))['then'](respondWithResult(_0x34743e,null))[_0xb806('0x46')](handleError(_0x34743e,null));};exports[_0xb806('0x25')]=function(_0x242b53,_0xa4547){return db['ChatQueueReport']['find']({'where':{'id':_0x242b53[_0xb806('0x4a')]['id']}})[_0xb806('0x24')](handleEntityNotFound(_0xa4547,null))[_0xb806('0x24')](removeEntity(_0xa4547,null))[_0xb806('0x46')](handleError(_0xa4547,null));};exports['describe']=function(_0x5285c1,_0x1fca8e){return db[_0xb806('0x41')][_0xb806('0x4b')]()[_0xb806('0x24')](respondWithResult(_0x1fca8e,null))[_0xb806('0x46')](handleError(_0x1fca8e,null));};