Built motion from commit b0a9a629.|2.6.33
[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 _0x6f83=['stack','name','send','index','map','rawAttributes','fieldName','type','key','model','query','keys','attributes','intersection','fields','length','hasOwnProperty','order','sort','where','filters','filter','merge','options','ChatQueueReport','count','includeAll','findAll','rows','catch','show','params','include','find','create','body','describe','rimraf','zip-dir','request-promise','moment','bluebird','mustache','util','path','sox','to-csv','ejs','fs-extra','lodash','squel','crypto','jsforce','desk.js','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','api','../../config/utils','../../config/environment','../../config/license/util','sendStatus','end','status','json','offset','undefined','limit','set','Content-Range','apply','reject','then','destroy','error'];(function(_0x56baac,_0x3de33a){var _0x5b1c1f=function(_0x504359){while(--_0x504359){_0x56baac['push'](_0x56baac['shift']());}};_0x5b1c1f(++_0x3de33a);}(_0x6f83,0x72));var _0x36f8=function(_0x289e33,_0x4b74b8){_0x289e33=_0x289e33-0x0;var _0x352078=_0x6f83[_0x289e33];return _0x352078;};'use strict';var emlformat=require('eml-format');var rimraf=require(_0x36f8('0x0'));var zipdir=require(_0x36f8('0x1'));var jsonpatch=require('fast-json-patch');var rp=require(_0x36f8('0x2'));var moment=require(_0x36f8('0x3'));var BPromise=require(_0x36f8('0x4'));var Mustache=require(_0x36f8('0x5'));var util=require(_0x36f8('0x6'));var path=require(_0x36f8('0x7'));var sox=require(_0x36f8('0x8'));var csv=require(_0x36f8('0x9'));var ejs=require(_0x36f8('0xa'));var fs=require('fs');var fs_extra=require(_0x36f8('0xb'));var _=require(_0x36f8('0xc'));var squel=require(_0x36f8('0xd'));var crypto=require(_0x36f8('0xe'));var jsforce=require(_0x36f8('0xf'));var deskjs=require(_0x36f8('0x10'));var toCsv=require(_0x36f8('0x9'));var querystring=require('querystring');var Papa=require('papaparse');var Redis=require('ioredis');var authService=require(_0x36f8('0x11'));var qs=require(_0x36f8('0x12'));var as=require(_0x36f8('0x13'));var hardwareService=require(_0x36f8('0x14'));var logger=require(_0x36f8('0x15'))(_0x36f8('0x16'));var utils=require(_0x36f8('0x17'));var config=require(_0x36f8('0x18'));var licenseUtil=require(_0x36f8('0x19'));var db=require('../../mysqldb')['db'];function respondWithStatusCode(_0x71e1ab,_0x196122){_0x196122=_0x196122||0xcc;return function(_0x166a1c){if(_0x166a1c){return _0x71e1ab[_0x36f8('0x1a')](_0x196122);}return _0x71e1ab['status'](_0x196122)[_0x36f8('0x1b')]();};}function respondWithResult(_0x189e22,_0x40a1c0){_0x40a1c0=_0x40a1c0||0xc8;return function(_0x5a8556){if(_0x5a8556){return _0x189e22[_0x36f8('0x1c')](_0x40a1c0)[_0x36f8('0x1d')](_0x5a8556);}};}function respondWithFilteredResult(_0x1ba051,_0x5048e0){return function(_0x429efc){if(_0x429efc){var _0x3e3281=typeof _0x5048e0[_0x36f8('0x1e')]===_0x36f8('0x1f')&&typeof _0x5048e0['limit']==='undefined';var _0x3f9947=_0x429efc['count'];var _0x517cba=_0x3e3281?0x0:_0x5048e0[_0x36f8('0x1e')];var _0x3d6a3c=_0x3e3281?_0x429efc['count']:_0x5048e0[_0x36f8('0x1e')]+_0x5048e0[_0x36f8('0x20')];var _0x290e63;if(_0x3d6a3c>=_0x3f9947){_0x3d6a3c=_0x3f9947;_0x290e63=0xc8;}else{_0x290e63=0xce;}_0x1ba051[_0x36f8('0x1c')](_0x290e63);return _0x1ba051[_0x36f8('0x21')](_0x36f8('0x22'),_0x517cba+'-'+_0x3d6a3c+'/'+_0x3f9947)[_0x36f8('0x1d')](_0x429efc);}return null;};}function patchUpdates(_0x16b9e8){return function(_0x283fd0){try{jsonpatch[_0x36f8('0x23')](_0x283fd0,_0x16b9e8,!![]);}catch(_0x26fc64){return BPromise[_0x36f8('0x24')](_0x26fc64);}return _0x283fd0['save']();};}function saveUpdates(_0xefe5b2,_0x42d203){return function(_0x41ccc3){if(_0x41ccc3){return _0x41ccc3['update'](_0xefe5b2)[_0x36f8('0x25')](function(_0x52b5ac){return _0x52b5ac;});}return null;};}function removeEntity(_0x362eae,_0x206075){return function(_0x4d2cd9){if(_0x4d2cd9){return _0x4d2cd9[_0x36f8('0x26')]()['then'](function(){_0x362eae[_0x36f8('0x1c')](0xcc)[_0x36f8('0x1b')]();});}};}function handleEntityNotFound(_0xb2acc5,_0x2eeb82){return function(_0x6740e1){if(!_0x6740e1){_0xb2acc5[_0x36f8('0x1a')](0x194);}return _0x6740e1;};}function handleError(_0x59291b,_0x462fd2){_0x462fd2=_0x462fd2||0x1f4;return function(_0xb2bbfd){logger[_0x36f8('0x27')](_0xb2bbfd[_0x36f8('0x28')]);if(_0xb2bbfd[_0x36f8('0x29')]){delete _0xb2bbfd[_0x36f8('0x29')];}_0x59291b[_0x36f8('0x1c')](_0x462fd2)[_0x36f8('0x2a')](_0xb2bbfd);};}exports[_0x36f8('0x2b')]=function(_0x51a2a1,_0x449882){var _0x1f67ea={},_0x3f01a6={},_0x328be8={'count':0x0,'rows':[]};var _0x191cdc=_[_0x36f8('0x2c')](db['ChatQueueReport'][_0x36f8('0x2d')],function(_0x302745){return{'name':_0x302745[_0x36f8('0x2e')],'type':_0x302745[_0x36f8('0x2f')][_0x36f8('0x30')]};});_0x3f01a6[_0x36f8('0x31')]=_[_0x36f8('0x2c')](_0x191cdc,_0x36f8('0x29'));_0x3f01a6[_0x36f8('0x32')]=_[_0x36f8('0x33')](_0x51a2a1[_0x36f8('0x32')]);_0x3f01a6['filters']=_['intersection'](_0x3f01a6['model'],_0x3f01a6[_0x36f8('0x32')]);_0x1f67ea[_0x36f8('0x34')]=_[_0x36f8('0x35')](_0x3f01a6['model'],qs[_0x36f8('0x36')](_0x51a2a1[_0x36f8('0x32')][_0x36f8('0x36')]));_0x1f67ea[_0x36f8('0x34')]=_0x1f67ea[_0x36f8('0x34')][_0x36f8('0x37')]?_0x1f67ea[_0x36f8('0x34')]:_0x3f01a6[_0x36f8('0x31')];if(!_0x51a2a1[_0x36f8('0x32')][_0x36f8('0x38')]('nolimit')){_0x1f67ea[_0x36f8('0x20')]=qs[_0x36f8('0x20')](_0x51a2a1[_0x36f8('0x32')][_0x36f8('0x20')]);_0x1f67ea[_0x36f8('0x1e')]=qs['offset'](_0x51a2a1[_0x36f8('0x32')][_0x36f8('0x1e')]);}_0x1f67ea[_0x36f8('0x39')]=qs['sort'](_0x51a2a1[_0x36f8('0x32')][_0x36f8('0x3a')]);_0x1f67ea[_0x36f8('0x3b')]=qs[_0x36f8('0x3c')](_['pick'](_0x51a2a1['query'],_0x3f01a6[_0x36f8('0x3c')]),_0x191cdc);if(_0x51a2a1[_0x36f8('0x32')][_0x36f8('0x3d')]){_0x1f67ea[_0x36f8('0x3b')]=_[_0x36f8('0x3e')](_0x1f67ea[_0x36f8('0x3b')],{'$or':_[_0x36f8('0x2c')](_0x191cdc,function(_0x598db5){if(_0x598db5[_0x36f8('0x2f')]!=='VIRTUAL'){var _0x258c27={};_0x258c27[_0x598db5[_0x36f8('0x29')]]={'$like':'%'+_0x51a2a1[_0x36f8('0x32')]['filter']+'%'};return _0x258c27;}})});}_0x1f67ea=_['merge']({},_0x1f67ea,_0x51a2a1[_0x36f8('0x3f')]);var _0x245a27={'where':_0x1f67ea[_0x36f8('0x3b')]};return db[_0x36f8('0x40')][_0x36f8('0x41')](_0x245a27)[_0x36f8('0x25')](function(_0x437218){_0x328be8[_0x36f8('0x41')]=_0x437218;if(_0x51a2a1[_0x36f8('0x32')][_0x36f8('0x42')]){_0x1f67ea['include']=[{'all':!![]}];}return db[_0x36f8('0x40')][_0x36f8('0x43')](_0x1f67ea);})[_0x36f8('0x25')](function(_0x1e97de){_0x328be8[_0x36f8('0x44')]=_0x1e97de;return _0x328be8;})['then'](respondWithFilteredResult(_0x449882,_0x1f67ea))[_0x36f8('0x45')](handleError(_0x449882,null));};exports[_0x36f8('0x46')]=function(_0x3e1700,_0x53aa30){var _0x10e763={'raw':!![],'where':{'id':_0x3e1700[_0x36f8('0x47')]['id']}},_0x3b9d5e={};_0x3b9d5e[_0x36f8('0x31')]=_[_0x36f8('0x33')](db['ChatQueueReport'][_0x36f8('0x2d')]);_0x3b9d5e[_0x36f8('0x32')]=_[_0x36f8('0x33')](_0x3e1700[_0x36f8('0x32')]);_0x3b9d5e[_0x36f8('0x3c')]=_[_0x36f8('0x35')](_0x3b9d5e[_0x36f8('0x31')],_0x3b9d5e[_0x36f8('0x32')]);_0x10e763['attributes']=_[_0x36f8('0x35')](_0x3b9d5e['model'],qs[_0x36f8('0x36')](_0x3e1700[_0x36f8('0x32')]['fields']));_0x10e763[_0x36f8('0x34')]=_0x10e763[_0x36f8('0x34')]['length']?_0x10e763['attributes']:_0x3b9d5e[_0x36f8('0x31')];if(_0x3e1700[_0x36f8('0x32')][_0x36f8('0x42')]){_0x10e763[_0x36f8('0x48')]=[{'all':!![]}];}_0x10e763=_[_0x36f8('0x3e')]({},_0x10e763,_0x3e1700['options']);return db['ChatQueueReport'][_0x36f8('0x49')](_0x10e763)[_0x36f8('0x25')](handleEntityNotFound(_0x53aa30,null))[_0x36f8('0x25')](respondWithResult(_0x53aa30,null))[_0x36f8('0x45')](handleError(_0x53aa30,null));};exports[_0x36f8('0x4a')]=function(_0x5085ac,_0x4b324d){return db[_0x36f8('0x40')][_0x36f8('0x4a')](_0x5085ac[_0x36f8('0x4b')],{})[_0x36f8('0x25')](respondWithResult(_0x4b324d,0xc9))[_0x36f8('0x45')](handleError(_0x4b324d,null));};exports['update']=function(_0x8e0950,_0x488b41){if(_0x8e0950[_0x36f8('0x4b')]['id']){delete _0x8e0950[_0x36f8('0x4b')]['id'];}return db[_0x36f8('0x40')]['find']({'where':{'id':_0x8e0950[_0x36f8('0x47')]['id']}})[_0x36f8('0x25')](handleEntityNotFound(_0x488b41,null))[_0x36f8('0x25')](saveUpdates(_0x8e0950[_0x36f8('0x4b')],null))[_0x36f8('0x25')](respondWithResult(_0x488b41,null))['catch'](handleError(_0x488b41,null));};exports[_0x36f8('0x26')]=function(_0x4bacdb,_0x5b38da){return db['ChatQueueReport'][_0x36f8('0x49')]({'where':{'id':_0x4bacdb[_0x36f8('0x47')]['id']}})[_0x36f8('0x25')](handleEntityNotFound(_0x5b38da,null))[_0x36f8('0x25')](removeEntity(_0x5b38da,null))[_0x36f8('0x45')](handleError(_0x5b38da,null));};exports['describe']=function(_0x4a2489,_0x1f6bc6){return db[_0x36f8('0x40')][_0x36f8('0x4c')]()[_0x36f8('0x25')](respondWithResult(_0x1f6bc6,null))['catch'](handleError(_0x1f6bc6,null));};