Built motion from commit (unavailable).|2.5.9
[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 _0x8b72=['sort','where','merge','type','VIRTUAL','filter','options','includeAll','findAll','catch','params','rawAttributes','include','find','create','body','destroy','describe','rimraf','bluebird','mustache','util','path','to-csv','ejs','lodash','squel','crypto','jsforce','desk.js','querystring','papaparse','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/logger','api','../../config/utils','../../config/license/util','../../mysqldb','sendStatus','status','end','json','count','offset','set','apply','reject','update','then','error','name','send','index','map','ChatQueueReport','fieldName','key','model','query','keys','filters','intersection','attributes','fields','length','hasOwnProperty','nolimit','limit','order'];(function(_0x66f822,_0x59e727){var _0x2c01bd=function(_0x4685ed){while(--_0x4685ed){_0x66f822['push'](_0x66f822['shift']());}};_0x2c01bd(++_0x59e727);}(_0x8b72,0x175));var _0x28b7=function(_0x2b4423,_0x1b6957){_0x2b4423=_0x2b4423-0x0;var _0x1e5f03=_0x8b72[_0x2b4423];return _0x1e5f03;};'use strict';var pdf=require('html-pdf');var emlformat=require('eml-format');var rimraf=require(_0x28b7('0x0'));var zipdir=require('zip-dir');var jsonpatch=require('fast-json-patch');var rp=require('request-promise');var moment=require('moment');var BPromise=require(_0x28b7('0x1'));var Mustache=require(_0x28b7('0x2'));var util=require(_0x28b7('0x3'));var path=require(_0x28b7('0x4'));var sox=require('sox');var csv=require(_0x28b7('0x5'));var ejs=require(_0x28b7('0x6'));var fs=require('fs');var _=require(_0x28b7('0x7'));var squel=require(_0x28b7('0x8'));var crypto=require(_0x28b7('0x9'));var jsforce=require(_0x28b7('0xa'));var deskjs=require(_0x28b7('0xb'));var toCsv=require(_0x28b7('0x5'));var querystring=require(_0x28b7('0xc'));var Papa=require(_0x28b7('0xd'));var Redis=require('ioredis');var authService=require(_0x28b7('0xe'));var qs=require(_0x28b7('0xf'));var as=require(_0x28b7('0x10'));var hardwareService=require('../../config/license/hardware');var logger=require(_0x28b7('0x11'))(_0x28b7('0x12'));var utils=require(_0x28b7('0x13'));var config=require('../../config/environment');var licenseUtil=require(_0x28b7('0x14'));var db=require(_0x28b7('0x15'))['db'];function respondWithStatusCode(_0x2f4a18,_0x2662e8){_0x2662e8=_0x2662e8||0xcc;return function(_0x177004){if(_0x177004){return _0x2f4a18[_0x28b7('0x16')](_0x2662e8);}return _0x2f4a18[_0x28b7('0x17')](_0x2662e8)[_0x28b7('0x18')]();};}function respondWithResult(_0x4464ba,_0x39782e){_0x39782e=_0x39782e||0xc8;return function(_0x325330){if(_0x325330){return _0x4464ba[_0x28b7('0x17')](_0x39782e)[_0x28b7('0x19')](_0x325330);}};}function respondWithFilteredResult(_0x15b7f9,_0x3aa29d){return function(_0x2bb22d){if(_0x2bb22d){var _0x20a7f2=_0x2bb22d[_0x28b7('0x1a')],_0x69b2c2=_0x3aa29d['offset'],_0xd288dd=_0x3aa29d[_0x28b7('0x1b')]+_0x3aa29d['limit'],_0x58f17e;if(_0xd288dd>=_0x20a7f2){_0xd288dd=_0x20a7f2;_0x58f17e=0xc8;}else{_0x58f17e=0xce;}_0x15b7f9[_0x28b7('0x17')](_0x58f17e);return _0x15b7f9[_0x28b7('0x1c')]('Content-Range',_0x69b2c2+'-'+_0xd288dd+'/'+_0x20a7f2)[_0x28b7('0x19')](_0x2bb22d);}return null;};}function patchUpdates(_0x2bdae9){return function(_0x22ad5e){try{jsonpatch[_0x28b7('0x1d')](_0x22ad5e,_0x2bdae9,!![]);}catch(_0x4b14d3){return BPromise[_0x28b7('0x1e')](_0x4b14d3);}return _0x22ad5e['save']();};}function saveUpdates(_0x2bad48,_0x42d6d8){return function(_0x4d4cf1){if(_0x4d4cf1){return _0x4d4cf1[_0x28b7('0x1f')](_0x2bad48)[_0x28b7('0x20')](function(_0x4fafeb){return _0x4fafeb;});}return null;};}function removeEntity(_0x3980b5,_0x212f5e){return function(_0x45c10d){if(_0x45c10d){return _0x45c10d['destroy']()[_0x28b7('0x20')](function(){_0x3980b5[_0x28b7('0x17')](0xcc)[_0x28b7('0x18')]();});}};}function handleEntityNotFound(_0x252f3a,_0x564be8){return function(_0x3b59ce){if(!_0x3b59ce){_0x252f3a[_0x28b7('0x16')](0x194);}return _0x3b59ce;};}function handleError(_0x57f063,_0x5120f9){_0x5120f9=_0x5120f9||0x1f4;return function(_0x282b47){logger[_0x28b7('0x21')](_0x282b47['stack']);if(_0x282b47[_0x28b7('0x22')]){delete _0x282b47['name'];}_0x57f063[_0x28b7('0x17')](_0x5120f9)[_0x28b7('0x23')](_0x282b47);};}exports[_0x28b7('0x24')]=function(_0x2037c1,_0x38b596){var _0x1e2291={},_0x51e29b={},_0x60312e={'count':0x0,'rows':[]};var _0x34dfaa=_[_0x28b7('0x25')](db[_0x28b7('0x26')]['rawAttributes'],function(_0x436e4e){return{'name':_0x436e4e[_0x28b7('0x27')],'type':_0x436e4e['type'][_0x28b7('0x28')]};});_0x51e29b[_0x28b7('0x29')]=_[_0x28b7('0x25')](_0x34dfaa,_0x28b7('0x22'));_0x51e29b[_0x28b7('0x2a')]=_[_0x28b7('0x2b')](_0x2037c1[_0x28b7('0x2a')]);_0x51e29b[_0x28b7('0x2c')]=_[_0x28b7('0x2d')](_0x51e29b[_0x28b7('0x29')],_0x51e29b[_0x28b7('0x2a')]);_0x1e2291[_0x28b7('0x2e')]=_[_0x28b7('0x2d')](_0x51e29b['model'],qs[_0x28b7('0x2f')](_0x2037c1[_0x28b7('0x2a')][_0x28b7('0x2f')]));_0x1e2291[_0x28b7('0x2e')]=_0x1e2291[_0x28b7('0x2e')][_0x28b7('0x30')]?_0x1e2291[_0x28b7('0x2e')]:_0x51e29b[_0x28b7('0x29')];if(!_0x2037c1[_0x28b7('0x2a')][_0x28b7('0x31')](_0x28b7('0x32'))){_0x1e2291[_0x28b7('0x33')]=qs['limit'](_0x2037c1['query'][_0x28b7('0x33')]);_0x1e2291[_0x28b7('0x1b')]=qs[_0x28b7('0x1b')](_0x2037c1[_0x28b7('0x2a')][_0x28b7('0x1b')]);}_0x1e2291[_0x28b7('0x34')]=qs[_0x28b7('0x35')](_0x2037c1[_0x28b7('0x2a')]['sort']);_0x1e2291['where']=qs[_0x28b7('0x2c')](_['pick'](_0x2037c1[_0x28b7('0x2a')],_0x51e29b[_0x28b7('0x2c')]),_0x34dfaa);if(_0x2037c1['query']['filter']){_0x1e2291[_0x28b7('0x36')]=_[_0x28b7('0x37')](_0x1e2291[_0x28b7('0x36')],{'$or':_[_0x28b7('0x25')](_0x34dfaa,function(_0x45f629){if(_0x45f629[_0x28b7('0x38')]!==_0x28b7('0x39')){var _0x3c9de1={};_0x3c9de1[_0x45f629[_0x28b7('0x22')]]={'$like':'%'+_0x2037c1['query'][_0x28b7('0x3a')]+'%'};return _0x3c9de1;}})});}_0x1e2291=_[_0x28b7('0x37')]({},_0x1e2291,_0x2037c1[_0x28b7('0x3b')]);var _0x234744={'where':_0x1e2291['where']};return db[_0x28b7('0x26')]['count'](_0x234744)[_0x28b7('0x20')](function(_0x5e5546){_0x60312e[_0x28b7('0x1a')]=_0x5e5546;if(_0x2037c1[_0x28b7('0x2a')][_0x28b7('0x3c')]){_0x1e2291['include']=[{'all':!![]}];}return db[_0x28b7('0x26')][_0x28b7('0x3d')](_0x1e2291);})[_0x28b7('0x20')](function(_0x2ffeaa){_0x60312e['rows']=_0x2ffeaa;return _0x60312e;})[_0x28b7('0x20')](respondWithFilteredResult(_0x38b596,_0x1e2291))[_0x28b7('0x3e')](handleError(_0x38b596,null));};exports['show']=function(_0x43b04d,_0x57622f){var _0x2b1cfa={'raw':!![],'where':{'id':_0x43b04d[_0x28b7('0x3f')]['id']}},_0x235376={};_0x235376[_0x28b7('0x29')]=_[_0x28b7('0x2b')](db[_0x28b7('0x26')][_0x28b7('0x40')]);_0x235376[_0x28b7('0x2a')]=_['keys'](_0x43b04d[_0x28b7('0x2a')]);_0x235376[_0x28b7('0x2c')]=_[_0x28b7('0x2d')](_0x235376[_0x28b7('0x29')],_0x235376['query']);_0x2b1cfa[_0x28b7('0x2e')]=_[_0x28b7('0x2d')](_0x235376['model'],qs['fields'](_0x43b04d[_0x28b7('0x2a')]['fields']));_0x2b1cfa[_0x28b7('0x2e')]=_0x2b1cfa['attributes']['length']?_0x2b1cfa[_0x28b7('0x2e')]:_0x235376['model'];if(_0x43b04d[_0x28b7('0x2a')][_0x28b7('0x3c')]){_0x2b1cfa[_0x28b7('0x41')]=[{'all':!![]}];}_0x2b1cfa=_[_0x28b7('0x37')]({},_0x2b1cfa,_0x43b04d[_0x28b7('0x3b')]);return db[_0x28b7('0x26')][_0x28b7('0x42')](_0x2b1cfa)[_0x28b7('0x20')](handleEntityNotFound(_0x57622f,null))['then'](respondWithResult(_0x57622f,null))['catch'](handleError(_0x57622f,null));};exports[_0x28b7('0x43')]=function(_0x2dcbdf,_0x1ed682){return db[_0x28b7('0x26')][_0x28b7('0x43')](_0x2dcbdf[_0x28b7('0x44')],{})[_0x28b7('0x20')](respondWithResult(_0x1ed682,0xc9))['catch'](handleError(_0x1ed682,null));};exports[_0x28b7('0x1f')]=function(_0x125a62,_0x3b8389){if(_0x125a62[_0x28b7('0x44')]['id']){delete _0x125a62[_0x28b7('0x44')]['id'];}return db[_0x28b7('0x26')]['find']({'where':{'id':_0x125a62['params']['id']}})[_0x28b7('0x20')](handleEntityNotFound(_0x3b8389,null))[_0x28b7('0x20')](saveUpdates(_0x125a62[_0x28b7('0x44')],null))['then'](respondWithResult(_0x3b8389,null))['catch'](handleError(_0x3b8389,null));};exports[_0x28b7('0x45')]=function(_0x62730c,_0x1aa04d){return db[_0x28b7('0x26')][_0x28b7('0x42')]({'where':{'id':_0x62730c[_0x28b7('0x3f')]['id']}})[_0x28b7('0x20')](handleEntityNotFound(_0x1aa04d,null))[_0x28b7('0x20')](removeEntity(_0x1aa04d,null))[_0x28b7('0x3e')](handleError(_0x1aa04d,null));};exports[_0x28b7('0x46')]=function(_0x4da0d3,_0x39ffa1){return db[_0x28b7('0x26')][_0x28b7('0x46')]()[_0x28b7('0x20')](respondWithResult(_0x39ffa1,null))['catch'](handleError(_0x39ffa1,null));};