Built motion from commit (unavailable).|2.5.13
[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 _0xf57b=['moment','bluebird','mustache','util','path','sox','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','offset','limit','set','json','reject','save','update','then','destroy','error','stack','name','index','ChatQueueReport','rawAttributes','type','model','map','keys','query','filters','intersection','fields','attributes','length','hasOwnProperty','nolimit','sort','where','filter','merge','options','count','includeAll','findAll','rows','catch','show','include','find','create','body','params','describe','html-pdf','zip-dir','request-promise'];(function(_0x4e676e,_0x2a7c6d){var _0x336a3c=function(_0x4767c4){while(--_0x4767c4){_0x4e676e['push'](_0x4e676e['shift']());}};_0x336a3c(++_0x2a7c6d);}(_0xf57b,0x121));var _0xbf57=function(_0x4490b1,_0x2b3b55){_0x4490b1=_0x4490b1-0x0;var _0x3b618e=_0xf57b[_0x4490b1];return _0x3b618e;};'use strict';var pdf=require(_0xbf57('0x0'));var emlformat=require('eml-format');var rimraf=require('rimraf');var zipdir=require(_0xbf57('0x1'));var jsonpatch=require('fast-json-patch');var rp=require(_0xbf57('0x2'));var moment=require(_0xbf57('0x3'));var BPromise=require(_0xbf57('0x4'));var Mustache=require(_0xbf57('0x5'));var util=require(_0xbf57('0x6'));var path=require(_0xbf57('0x7'));var sox=require(_0xbf57('0x8'));var csv=require(_0xbf57('0x9'));var ejs=require(_0xbf57('0xa'));var fs=require('fs');var _=require(_0xbf57('0xb'));var squel=require(_0xbf57('0xc'));var crypto=require(_0xbf57('0xd'));var jsforce=require(_0xbf57('0xe'));var deskjs=require(_0xbf57('0xf'));var toCsv=require(_0xbf57('0x9'));var querystring=require(_0xbf57('0x10'));var Papa=require(_0xbf57('0x11'));var Redis=require('ioredis');var authService=require(_0xbf57('0x12'));var qs=require(_0xbf57('0x13'));var as=require(_0xbf57('0x14'));var hardwareService=require('../../config/license/hardware');var logger=require(_0xbf57('0x15'))(_0xbf57('0x16'));var utils=require(_0xbf57('0x17'));var config=require('../../config/environment');var licenseUtil=require(_0xbf57('0x18'));var db=require(_0xbf57('0x19'))['db'];function respondWithStatusCode(_0x445fd6,_0x3a3630){_0x3a3630=_0x3a3630||0xcc;return function(_0x29d951){if(_0x29d951){return _0x445fd6[_0xbf57('0x1a')](_0x3a3630);}return _0x445fd6[_0xbf57('0x1b')](_0x3a3630)[_0xbf57('0x1c')]();};}function respondWithResult(_0x176c0a,_0x8e7b74){_0x8e7b74=_0x8e7b74||0xc8;return function(_0x40f25d){if(_0x40f25d){return _0x176c0a[_0xbf57('0x1b')](_0x8e7b74)['json'](_0x40f25d);}};}function respondWithFilteredResult(_0x5961bb,_0x4d9f30){return function(_0x2ef2cf){if(_0x2ef2cf){var _0x493918=_0x2ef2cf['count'],_0x1f7d9e=_0x4d9f30[_0xbf57('0x1d')],_0x14e8ba=_0x4d9f30[_0xbf57('0x1d')]+_0x4d9f30[_0xbf57('0x1e')],_0x4278a8;if(_0x14e8ba>=_0x493918){_0x14e8ba=_0x493918;_0x4278a8=0xc8;}else{_0x4278a8=0xce;}_0x5961bb[_0xbf57('0x1b')](_0x4278a8);return _0x5961bb[_0xbf57('0x1f')]('Content-Range',_0x1f7d9e+'-'+_0x14e8ba+'/'+_0x493918)[_0xbf57('0x20')](_0x2ef2cf);}return null;};}function patchUpdates(_0x1a9ae2){return function(_0x4dc51a){try{jsonpatch['apply'](_0x4dc51a,_0x1a9ae2,!![]);}catch(_0x5043d2){return BPromise[_0xbf57('0x21')](_0x5043d2);}return _0x4dc51a[_0xbf57('0x22')]();};}function saveUpdates(_0x2efc6e,_0x4cedcd){return function(_0x24a1a7){if(_0x24a1a7){return _0x24a1a7[_0xbf57('0x23')](_0x2efc6e)[_0xbf57('0x24')](function(_0x433536){return _0x433536;});}return null;};}function removeEntity(_0x5680f6,_0x5f2829){return function(_0x2cc925){if(_0x2cc925){return _0x2cc925[_0xbf57('0x25')]()[_0xbf57('0x24')](function(){_0x5680f6[_0xbf57('0x1b')](0xcc)['end']();});}};}function handleEntityNotFound(_0x14997e,_0xb53079){return function(_0x4d7df1){if(!_0x4d7df1){_0x14997e[_0xbf57('0x1a')](0x194);}return _0x4d7df1;};}function handleError(_0x52d1d7,_0x5a8585){_0x5a8585=_0x5a8585||0x1f4;return function(_0x982eeb){logger[_0xbf57('0x26')](_0x982eeb[_0xbf57('0x27')]);if(_0x982eeb[_0xbf57('0x28')]){delete _0x982eeb[_0xbf57('0x28')];}_0x52d1d7[_0xbf57('0x1b')](_0x5a8585)['send'](_0x982eeb);};}exports[_0xbf57('0x29')]=function(_0x353264,_0xaee786){var _0x29b34e={},_0x3c9d6e={},_0x2650fa={'count':0x0,'rows':[]};var _0x2543cd=_['map'](db[_0xbf57('0x2a')][_0xbf57('0x2b')],function(_0x1668ce){return{'name':_0x1668ce['fieldName'],'type':_0x1668ce[_0xbf57('0x2c')]['key']};});_0x3c9d6e[_0xbf57('0x2d')]=_[_0xbf57('0x2e')](_0x2543cd,_0xbf57('0x28'));_0x3c9d6e['query']=_[_0xbf57('0x2f')](_0x353264[_0xbf57('0x30')]);_0x3c9d6e[_0xbf57('0x31')]=_[_0xbf57('0x32')](_0x3c9d6e['model'],_0x3c9d6e[_0xbf57('0x30')]);_0x29b34e['attributes']=_[_0xbf57('0x32')](_0x3c9d6e['model'],qs[_0xbf57('0x33')](_0x353264['query'][_0xbf57('0x33')]));_0x29b34e[_0xbf57('0x34')]=_0x29b34e['attributes'][_0xbf57('0x35')]?_0x29b34e[_0xbf57('0x34')]:_0x3c9d6e[_0xbf57('0x2d')];if(!_0x353264[_0xbf57('0x30')][_0xbf57('0x36')](_0xbf57('0x37'))){_0x29b34e[_0xbf57('0x1e')]=qs[_0xbf57('0x1e')](_0x353264[_0xbf57('0x30')][_0xbf57('0x1e')]);_0x29b34e[_0xbf57('0x1d')]=qs[_0xbf57('0x1d')](_0x353264[_0xbf57('0x30')]['offset']);}_0x29b34e['order']=qs[_0xbf57('0x38')](_0x353264['query'][_0xbf57('0x38')]);_0x29b34e[_0xbf57('0x39')]=qs['filters'](_['pick'](_0x353264['query'],_0x3c9d6e[_0xbf57('0x31')]),_0x2543cd);if(_0x353264[_0xbf57('0x30')][_0xbf57('0x3a')]){_0x29b34e['where']=_[_0xbf57('0x3b')](_0x29b34e[_0xbf57('0x39')],{'$or':_[_0xbf57('0x2e')](_0x2543cd,function(_0x349e39){if(_0x349e39[_0xbf57('0x2c')]!=='VIRTUAL'){var _0x253fa3={};_0x253fa3[_0x349e39[_0xbf57('0x28')]]={'$like':'%'+_0x353264[_0xbf57('0x30')][_0xbf57('0x3a')]+'%'};return _0x253fa3;}})});}_0x29b34e=_[_0xbf57('0x3b')]({},_0x29b34e,_0x353264[_0xbf57('0x3c')]);var _0x46cd99={'where':_0x29b34e[_0xbf57('0x39')]};return db[_0xbf57('0x2a')][_0xbf57('0x3d')](_0x46cd99)['then'](function(_0x401d33){_0x2650fa['count']=_0x401d33;if(_0x353264[_0xbf57('0x30')][_0xbf57('0x3e')]){_0x29b34e['include']=[{'all':!![]}];}return db['ChatQueueReport'][_0xbf57('0x3f')](_0x29b34e);})['then'](function(_0x1e30c0){_0x2650fa[_0xbf57('0x40')]=_0x1e30c0;return _0x2650fa;})[_0xbf57('0x24')](respondWithFilteredResult(_0xaee786,_0x29b34e))[_0xbf57('0x41')](handleError(_0xaee786,null));};exports[_0xbf57('0x42')]=function(_0x1ca456,_0xa554ab){var _0x4a9ac1={'raw':!![],'where':{'id':_0x1ca456['params']['id']}},_0x3ba72b={};_0x3ba72b[_0xbf57('0x2d')]=_['keys'](db[_0xbf57('0x2a')][_0xbf57('0x2b')]);_0x3ba72b[_0xbf57('0x30')]=_[_0xbf57('0x2f')](_0x1ca456['query']);_0x3ba72b[_0xbf57('0x31')]=_[_0xbf57('0x32')](_0x3ba72b[_0xbf57('0x2d')],_0x3ba72b[_0xbf57('0x30')]);_0x4a9ac1[_0xbf57('0x34')]=_[_0xbf57('0x32')](_0x3ba72b['model'],qs['fields'](_0x1ca456['query']['fields']));_0x4a9ac1[_0xbf57('0x34')]=_0x4a9ac1[_0xbf57('0x34')][_0xbf57('0x35')]?_0x4a9ac1[_0xbf57('0x34')]:_0x3ba72b[_0xbf57('0x2d')];if(_0x1ca456[_0xbf57('0x30')][_0xbf57('0x3e')]){_0x4a9ac1[_0xbf57('0x43')]=[{'all':!![]}];}_0x4a9ac1=_[_0xbf57('0x3b')]({},_0x4a9ac1,_0x1ca456['options']);return db[_0xbf57('0x2a')][_0xbf57('0x44')](_0x4a9ac1)[_0xbf57('0x24')](handleEntityNotFound(_0xa554ab,null))[_0xbf57('0x24')](respondWithResult(_0xa554ab,null))[_0xbf57('0x41')](handleError(_0xa554ab,null));};exports[_0xbf57('0x45')]=function(_0xc382d8,_0x5c63a0){return db[_0xbf57('0x2a')][_0xbf57('0x45')](_0xc382d8[_0xbf57('0x46')],{})[_0xbf57('0x24')](respondWithResult(_0x5c63a0,0xc9))[_0xbf57('0x41')](handleError(_0x5c63a0,null));};exports[_0xbf57('0x23')]=function(_0x24ee5d,_0x546704){if(_0x24ee5d[_0xbf57('0x46')]['id']){delete _0x24ee5d['body']['id'];}return db[_0xbf57('0x2a')][_0xbf57('0x44')]({'where':{'id':_0x24ee5d[_0xbf57('0x47')]['id']}})['then'](handleEntityNotFound(_0x546704,null))[_0xbf57('0x24')](saveUpdates(_0x24ee5d[_0xbf57('0x46')],null))[_0xbf57('0x24')](respondWithResult(_0x546704,null))['catch'](handleError(_0x546704,null));};exports[_0xbf57('0x25')]=function(_0x516076,_0x75e2b4){return db[_0xbf57('0x2a')][_0xbf57('0x44')]({'where':{'id':_0x516076[_0xbf57('0x47')]['id']}})[_0xbf57('0x24')](handleEntityNotFound(_0x75e2b4,null))[_0xbf57('0x24')](removeEntity(_0x75e2b4,null))['catch'](handleError(_0x75e2b4,null));};exports[_0xbf57('0x48')]=function(_0x3bca45,_0x359897){return db[_0xbf57('0x2a')][_0xbf57('0x48')]()['then'](respondWithResult(_0x359897,null))[_0xbf57('0x41')](handleError(_0x359897,null));};