c45b02701f40e8e2dc992c8eb62a165f5a08ec26
[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 _0xb94f=['../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','api','../../config/utils','../../config/environment','../../mysqldb','json','offset','limit','undefined','count','set','Content-Range','apply','reject','save','update','then','sendStatus','error','stack','name','send','index','map','ChatQueueReport','fieldName','type','key','model','query','keys','intersection','fields','attributes','length','hasOwnProperty','order','sort','where','filters','filter','merge','options','includeAll','include','findAll','catch','params','find','create','body','destroy','describe','eml-format','rimraf','fast-json-patch','request-promise','moment','util','path','sox','to-csv','ejs','fs-extra','lodash','crypto','jsforce','desk.js','querystring','papaparse','ioredis'];(function(_0x2ecfb6,_0xdca940){var _0x10d9c2=function(_0x56cfae){while(--_0x56cfae){_0x2ecfb6['push'](_0x2ecfb6['shift']());}};_0x10d9c2(++_0xdca940);}(_0xb94f,0x112));var _0xfb94=function(_0x29632e,_0x5ecba4){_0x29632e=_0x29632e-0x0;var _0x426e04=_0xb94f[_0x29632e];return _0x426e04;};'use strict';var emlformat=require(_0xfb94('0x0'));var rimraf=require(_0xfb94('0x1'));var zipdir=require('zip-dir');var jsonpatch=require(_0xfb94('0x2'));var rp=require(_0xfb94('0x3'));var moment=require(_0xfb94('0x4'));var BPromise=require('bluebird');var Mustache=require('mustache');var util=require(_0xfb94('0x5'));var path=require(_0xfb94('0x6'));var sox=require(_0xfb94('0x7'));var csv=require(_0xfb94('0x8'));var ejs=require(_0xfb94('0x9'));var fs=require('fs');var fs_extra=require(_0xfb94('0xa'));var _=require(_0xfb94('0xb'));var squel=require('squel');var crypto=require(_0xfb94('0xc'));var jsforce=require(_0xfb94('0xd'));var deskjs=require(_0xfb94('0xe'));var toCsv=require('to-csv');var querystring=require(_0xfb94('0xf'));var Papa=require(_0xfb94('0x10'));var Redis=require(_0xfb94('0x11'));var authService=require('../../components/auth/service');var qs=require(_0xfb94('0x12'));var as=require(_0xfb94('0x13'));var hardwareService=require(_0xfb94('0x14'));var logger=require('../../config/logger')(_0xfb94('0x15'));var utils=require(_0xfb94('0x16'));var config=require(_0xfb94('0x17'));var licenseUtil=require('../../config/license/util');var db=require(_0xfb94('0x18'))['db'];function respondWithStatusCode(_0x2ceb04,_0x5bf890){_0x5bf890=_0x5bf890||0xcc;return function(_0x2c98f6){if(_0x2c98f6){return _0x2ceb04['sendStatus'](_0x5bf890);}return _0x2ceb04['status'](_0x5bf890)['end']();};}function respondWithResult(_0x392c2a,_0x5b0773){_0x5b0773=_0x5b0773||0xc8;return function(_0x380ac5){if(_0x380ac5){return _0x392c2a['status'](_0x5b0773)[_0xfb94('0x19')](_0x380ac5);}};}function respondWithFilteredResult(_0x48cf9f,_0x2bfb58){return function(_0x229935){if(_0x229935){var _0x31ec83=typeof _0x2bfb58[_0xfb94('0x1a')]==='undefined'&&typeof _0x2bfb58[_0xfb94('0x1b')]===_0xfb94('0x1c');var _0x5dcf2f=_0x229935[_0xfb94('0x1d')];var _0x28136b=_0x31ec83?0x0:_0x2bfb58[_0xfb94('0x1a')];var _0x184717=_0x31ec83?_0x229935['count']:_0x2bfb58[_0xfb94('0x1a')]+_0x2bfb58[_0xfb94('0x1b')];var _0x8ed6f2;if(_0x184717>=_0x5dcf2f){_0x184717=_0x5dcf2f;_0x8ed6f2=0xc8;}else{_0x8ed6f2=0xce;}_0x48cf9f['status'](_0x8ed6f2);return _0x48cf9f[_0xfb94('0x1e')](_0xfb94('0x1f'),_0x28136b+'-'+_0x184717+'/'+_0x5dcf2f)[_0xfb94('0x19')](_0x229935);}return null;};}function patchUpdates(_0x3fb7f6){return function(_0x3d6dd7){try{jsonpatch[_0xfb94('0x20')](_0x3d6dd7,_0x3fb7f6,!![]);}catch(_0x40918e){return BPromise[_0xfb94('0x21')](_0x40918e);}return _0x3d6dd7[_0xfb94('0x22')]();};}function saveUpdates(_0x21d652,_0x31e4bc){return function(_0x47a82e){if(_0x47a82e){return _0x47a82e[_0xfb94('0x23')](_0x21d652)['then'](function(_0x106e73){return _0x106e73;});}return null;};}function removeEntity(_0x26549c,_0x28c407){return function(_0x153455){if(_0x153455){return _0x153455['destroy']()[_0xfb94('0x24')](function(){_0x26549c['status'](0xcc)['end']();});}};}function handleEntityNotFound(_0x4437a4,_0x187b6a){return function(_0x4ef4aa){if(!_0x4ef4aa){_0x4437a4[_0xfb94('0x25')](0x194);}return _0x4ef4aa;};}function handleError(_0x27ed0e,_0x2b26e5){_0x2b26e5=_0x2b26e5||0x1f4;return function(_0x3fe1d2){logger[_0xfb94('0x26')](_0x3fe1d2[_0xfb94('0x27')]);if(_0x3fe1d2[_0xfb94('0x28')]){delete _0x3fe1d2['name'];}_0x27ed0e['status'](_0x2b26e5)[_0xfb94('0x29')](_0x3fe1d2);};}exports[_0xfb94('0x2a')]=function(_0x1c1bef,_0x940b4b){var _0xa90a42={},_0xee4f64={},_0x5df7c4={'count':0x0,'rows':[]};var _0x223459=_[_0xfb94('0x2b')](db[_0xfb94('0x2c')]['rawAttributes'],function(_0x5ebbf8){return{'name':_0x5ebbf8[_0xfb94('0x2d')],'type':_0x5ebbf8[_0xfb94('0x2e')][_0xfb94('0x2f')]};});_0xee4f64[_0xfb94('0x30')]=_[_0xfb94('0x2b')](_0x223459,_0xfb94('0x28'));_0xee4f64[_0xfb94('0x31')]=_[_0xfb94('0x32')](_0x1c1bef[_0xfb94('0x31')]);_0xee4f64['filters']=_[_0xfb94('0x33')](_0xee4f64['model'],_0xee4f64['query']);_0xa90a42['attributes']=_['intersection'](_0xee4f64[_0xfb94('0x30')],qs['fields'](_0x1c1bef['query'][_0xfb94('0x34')]));_0xa90a42[_0xfb94('0x35')]=_0xa90a42['attributes'][_0xfb94('0x36')]?_0xa90a42[_0xfb94('0x35')]:_0xee4f64[_0xfb94('0x30')];if(!_0x1c1bef[_0xfb94('0x31')][_0xfb94('0x37')]('nolimit')){_0xa90a42[_0xfb94('0x1b')]=qs[_0xfb94('0x1b')](_0x1c1bef[_0xfb94('0x31')][_0xfb94('0x1b')]);_0xa90a42[_0xfb94('0x1a')]=qs[_0xfb94('0x1a')](_0x1c1bef[_0xfb94('0x31')][_0xfb94('0x1a')]);}_0xa90a42[_0xfb94('0x38')]=qs[_0xfb94('0x39')](_0x1c1bef[_0xfb94('0x31')][_0xfb94('0x39')]);_0xa90a42[_0xfb94('0x3a')]=qs[_0xfb94('0x3b')](_['pick'](_0x1c1bef[_0xfb94('0x31')],_0xee4f64[_0xfb94('0x3b')]),_0x223459);if(_0x1c1bef[_0xfb94('0x31')][_0xfb94('0x3c')]){_0xa90a42[_0xfb94('0x3a')]=_[_0xfb94('0x3d')](_0xa90a42[_0xfb94('0x3a')],{'$or':_[_0xfb94('0x2b')](_0x223459,function(_0x5251aa){if(_0x5251aa['type']!=='VIRTUAL'){var _0x40a5c4={};_0x40a5c4[_0x5251aa[_0xfb94('0x28')]]={'$like':'%'+_0x1c1bef[_0xfb94('0x31')][_0xfb94('0x3c')]+'%'};return _0x40a5c4;}})});}_0xa90a42=_[_0xfb94('0x3d')]({},_0xa90a42,_0x1c1bef[_0xfb94('0x3e')]);var _0x169471={'where':_0xa90a42['where']};return db['ChatQueueReport'][_0xfb94('0x1d')](_0x169471)[_0xfb94('0x24')](function(_0x3c4f60){_0x5df7c4[_0xfb94('0x1d')]=_0x3c4f60;if(_0x1c1bef[_0xfb94('0x31')][_0xfb94('0x3f')]){_0xa90a42[_0xfb94('0x40')]=[{'all':!![]}];}return db['ChatQueueReport'][_0xfb94('0x41')](_0xa90a42);})['then'](function(_0x34f4dc){_0x5df7c4['rows']=_0x34f4dc;return _0x5df7c4;})['then'](respondWithFilteredResult(_0x940b4b,_0xa90a42))[_0xfb94('0x42')](handleError(_0x940b4b,null));};exports['show']=function(_0x341239,_0x28ef95){var _0x21895f={'raw':!![],'where':{'id':_0x341239[_0xfb94('0x43')]['id']}},_0x4cce17={};_0x4cce17[_0xfb94('0x30')]=_[_0xfb94('0x32')](db[_0xfb94('0x2c')]['rawAttributes']);_0x4cce17[_0xfb94('0x31')]=_[_0xfb94('0x32')](_0x341239[_0xfb94('0x31')]);_0x4cce17[_0xfb94('0x3b')]=_[_0xfb94('0x33')](_0x4cce17[_0xfb94('0x30')],_0x4cce17[_0xfb94('0x31')]);_0x21895f[_0xfb94('0x35')]=_[_0xfb94('0x33')](_0x4cce17[_0xfb94('0x30')],qs[_0xfb94('0x34')](_0x341239[_0xfb94('0x31')][_0xfb94('0x34')]));_0x21895f[_0xfb94('0x35')]=_0x21895f['attributes'][_0xfb94('0x36')]?_0x21895f['attributes']:_0x4cce17[_0xfb94('0x30')];if(_0x341239['query'][_0xfb94('0x3f')]){_0x21895f[_0xfb94('0x40')]=[{'all':!![]}];}_0x21895f=_['merge']({},_0x21895f,_0x341239[_0xfb94('0x3e')]);return db[_0xfb94('0x2c')][_0xfb94('0x44')](_0x21895f)[_0xfb94('0x24')](handleEntityNotFound(_0x28ef95,null))[_0xfb94('0x24')](respondWithResult(_0x28ef95,null))['catch'](handleError(_0x28ef95,null));};exports[_0xfb94('0x45')]=function(_0x41d28e,_0x552972){return db[_0xfb94('0x2c')][_0xfb94('0x45')](_0x41d28e['body'],{})[_0xfb94('0x24')](respondWithResult(_0x552972,0xc9))[_0xfb94('0x42')](handleError(_0x552972,null));};exports[_0xfb94('0x23')]=function(_0x576e12,_0xdca7bd){if(_0x576e12[_0xfb94('0x46')]['id']){delete _0x576e12['body']['id'];}return db[_0xfb94('0x2c')][_0xfb94('0x44')]({'where':{'id':_0x576e12[_0xfb94('0x43')]['id']}})[_0xfb94('0x24')](handleEntityNotFound(_0xdca7bd,null))[_0xfb94('0x24')](saveUpdates(_0x576e12[_0xfb94('0x46')],null))[_0xfb94('0x24')](respondWithResult(_0xdca7bd,null))['catch'](handleError(_0xdca7bd,null));};exports[_0xfb94('0x47')]=function(_0x54812a,_0x5129cc){return db['ChatQueueReport'][_0xfb94('0x44')]({'where':{'id':_0x54812a['params']['id']}})[_0xfb94('0x24')](handleEntityNotFound(_0x5129cc,null))[_0xfb94('0x24')](removeEntity(_0x5129cc,null))[_0xfb94('0x42')](handleError(_0x5129cc,null));};exports[_0xfb94('0x48')]=function(_0x48d736,_0x4791dd){return db[_0xfb94('0x2c')][_0xfb94('0x48')]()[_0xfb94('0x24')](respondWithResult(_0x4791dd,null))[_0xfb94('0x42')](handleError(_0x4791dd,null));};