Built motion from commit 753c950e.|2.5.42
[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 _0x510e=['fields','length','hasOwnProperty','nolimit','order','sort','where','filter','merge','options','includeAll','include','findAll','catch','show','params','find','body','describe','eml-format','rimraf','zip-dir','fast-json-patch','request-promise','moment','bluebird','mustache','util','sox','to-csv','ejs','fs-extra','lodash','squel','crypto','jsforce','desk.js','querystring','papaparse','ioredis','../../components/auth/service','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','api','../../config/utils','../../config/environment','../../mysqldb','sendStatus','status','end','json','offset','undefined','limit','count','set','Content-Range','reject','update','then','destroy','error','stack','name','send','index','ChatQueueReport','rawAttributes','fieldName','type','key','model','map','query','keys','filters','intersection','attributes'];(function(_0x555e25,_0x7bf2c8){var _0x5633b6=function(_0x73d246){while(--_0x73d246){_0x555e25['push'](_0x555e25['shift']());}};_0x5633b6(++_0x7bf2c8);}(_0x510e,0x1ed));var _0xe510=function(_0x49d41c,_0x2bdc35){_0x49d41c=_0x49d41c-0x0;var _0xb64c5f=_0x510e[_0x49d41c];return _0xb64c5f;};'use strict';var emlformat=require(_0xe510('0x0'));var rimraf=require(_0xe510('0x1'));var zipdir=require(_0xe510('0x2'));var jsonpatch=require(_0xe510('0x3'));var rp=require(_0xe510('0x4'));var moment=require(_0xe510('0x5'));var BPromise=require(_0xe510('0x6'));var Mustache=require(_0xe510('0x7'));var util=require(_0xe510('0x8'));var path=require('path');var sox=require(_0xe510('0x9'));var csv=require(_0xe510('0xa'));var ejs=require(_0xe510('0xb'));var fs=require('fs');var fs_extra=require(_0xe510('0xc'));var _=require(_0xe510('0xd'));var squel=require(_0xe510('0xe'));var crypto=require(_0xe510('0xf'));var jsforce=require(_0xe510('0x10'));var deskjs=require(_0xe510('0x11'));var toCsv=require(_0xe510('0xa'));var querystring=require(_0xe510('0x12'));var Papa=require(_0xe510('0x13'));var Redis=require(_0xe510('0x14'));var authService=require(_0xe510('0x15'));var qs=require('../../components/parsers/qs');var as=require(_0xe510('0x16'));var hardwareService=require(_0xe510('0x17'));var logger=require(_0xe510('0x18'))(_0xe510('0x19'));var utils=require(_0xe510('0x1a'));var config=require(_0xe510('0x1b'));var licenseUtil=require('../../config/license/util');var db=require(_0xe510('0x1c'))['db'];function respondWithStatusCode(_0x2168b2,_0x55ee64){_0x55ee64=_0x55ee64||0xcc;return function(_0x261832){if(_0x261832){return _0x2168b2[_0xe510('0x1d')](_0x55ee64);}return _0x2168b2[_0xe510('0x1e')](_0x55ee64)[_0xe510('0x1f')]();};}function respondWithResult(_0x351376,_0x1b399f){_0x1b399f=_0x1b399f||0xc8;return function(_0x3af96e){if(_0x3af96e){return _0x351376[_0xe510('0x1e')](_0x1b399f)[_0xe510('0x20')](_0x3af96e);}};}function respondWithFilteredResult(_0x538d55,_0x8150a7){return function(_0x52feea){if(_0x52feea){var _0x574ce5=typeof _0x8150a7[_0xe510('0x21')]===_0xe510('0x22')&&typeof _0x8150a7[_0xe510('0x23')]===_0xe510('0x22');var _0x9b92b0=_0x52feea[_0xe510('0x24')];var _0x268736=_0x574ce5?0x0:_0x8150a7[_0xe510('0x21')];var _0x48e676=_0x574ce5?_0x52feea[_0xe510('0x24')]:_0x8150a7[_0xe510('0x21')]+_0x8150a7[_0xe510('0x23')];var _0x4dd3d8;if(_0x48e676>=_0x9b92b0){_0x48e676=_0x9b92b0;_0x4dd3d8=0xc8;}else{_0x4dd3d8=0xce;}_0x538d55[_0xe510('0x1e')](_0x4dd3d8);return _0x538d55[_0xe510('0x25')](_0xe510('0x26'),_0x268736+'-'+_0x48e676+'/'+_0x9b92b0)['json'](_0x52feea);}return null;};}function patchUpdates(_0xd3237){return function(_0x212e3e){try{jsonpatch['apply'](_0x212e3e,_0xd3237,!![]);}catch(_0x269596){return BPromise[_0xe510('0x27')](_0x269596);}return _0x212e3e['save']();};}function saveUpdates(_0x25b523,_0x460d28){return function(_0x4a0c3d){if(_0x4a0c3d){return _0x4a0c3d[_0xe510('0x28')](_0x25b523)[_0xe510('0x29')](function(_0x2ba74a){return _0x2ba74a;});}return null;};}function removeEntity(_0x2ea51b,_0xc6ffae){return function(_0x4c034f){if(_0x4c034f){return _0x4c034f[_0xe510('0x2a')]()['then'](function(){_0x2ea51b['status'](0xcc)['end']();});}};}function handleEntityNotFound(_0x4425ee,_0x26988f){return function(_0x5abf44){if(!_0x5abf44){_0x4425ee[_0xe510('0x1d')](0x194);}return _0x5abf44;};}function handleError(_0x59d10b,_0x11ed03){_0x11ed03=_0x11ed03||0x1f4;return function(_0x45ea1e){logger[_0xe510('0x2b')](_0x45ea1e[_0xe510('0x2c')]);if(_0x45ea1e[_0xe510('0x2d')]){delete _0x45ea1e[_0xe510('0x2d')];}_0x59d10b[_0xe510('0x1e')](_0x11ed03)[_0xe510('0x2e')](_0x45ea1e);};}exports[_0xe510('0x2f')]=function(_0x2aff62,_0x92bfa3){var _0x5dcdb3={},_0xf5a2fb={},_0x1ea081={'count':0x0,'rows':[]};var _0x49a33f=_['map'](db[_0xe510('0x30')][_0xe510('0x31')],function(_0x538e31){return{'name':_0x538e31[_0xe510('0x32')],'type':_0x538e31[_0xe510('0x33')][_0xe510('0x34')]};});_0xf5a2fb[_0xe510('0x35')]=_[_0xe510('0x36')](_0x49a33f,'name');_0xf5a2fb[_0xe510('0x37')]=_[_0xe510('0x38')](_0x2aff62[_0xe510('0x37')]);_0xf5a2fb[_0xe510('0x39')]=_[_0xe510('0x3a')](_0xf5a2fb[_0xe510('0x35')],_0xf5a2fb[_0xe510('0x37')]);_0x5dcdb3[_0xe510('0x3b')]=_[_0xe510('0x3a')](_0xf5a2fb[_0xe510('0x35')],qs['fields'](_0x2aff62[_0xe510('0x37')][_0xe510('0x3c')]));_0x5dcdb3[_0xe510('0x3b')]=_0x5dcdb3[_0xe510('0x3b')][_0xe510('0x3d')]?_0x5dcdb3[_0xe510('0x3b')]:_0xf5a2fb[_0xe510('0x35')];if(!_0x2aff62[_0xe510('0x37')][_0xe510('0x3e')](_0xe510('0x3f'))){_0x5dcdb3[_0xe510('0x23')]=qs[_0xe510('0x23')](_0x2aff62[_0xe510('0x37')][_0xe510('0x23')]);_0x5dcdb3[_0xe510('0x21')]=qs[_0xe510('0x21')](_0x2aff62[_0xe510('0x37')]['offset']);}_0x5dcdb3[_0xe510('0x40')]=qs[_0xe510('0x41')](_0x2aff62['query'][_0xe510('0x41')]);_0x5dcdb3[_0xe510('0x42')]=qs['filters'](_['pick'](_0x2aff62[_0xe510('0x37')],_0xf5a2fb[_0xe510('0x39')]),_0x49a33f);if(_0x2aff62[_0xe510('0x37')][_0xe510('0x43')]){_0x5dcdb3['where']=_[_0xe510('0x44')](_0x5dcdb3['where'],{'$or':_[_0xe510('0x36')](_0x49a33f,function(_0x2bec4b){if(_0x2bec4b[_0xe510('0x33')]!=='VIRTUAL'){var _0x31ef35={};_0x31ef35[_0x2bec4b[_0xe510('0x2d')]]={'$like':'%'+_0x2aff62[_0xe510('0x37')][_0xe510('0x43')]+'%'};return _0x31ef35;}})});}_0x5dcdb3=_[_0xe510('0x44')]({},_0x5dcdb3,_0x2aff62[_0xe510('0x45')]);var _0x266f2a={'where':_0x5dcdb3[_0xe510('0x42')]};return db[_0xe510('0x30')][_0xe510('0x24')](_0x266f2a)[_0xe510('0x29')](function(_0x1e3912){_0x1ea081[_0xe510('0x24')]=_0x1e3912;if(_0x2aff62[_0xe510('0x37')][_0xe510('0x46')]){_0x5dcdb3[_0xe510('0x47')]=[{'all':!![]}];}return db[_0xe510('0x30')][_0xe510('0x48')](_0x5dcdb3);})[_0xe510('0x29')](function(_0x5a92f4){_0x1ea081['rows']=_0x5a92f4;return _0x1ea081;})['then'](respondWithFilteredResult(_0x92bfa3,_0x5dcdb3))[_0xe510('0x49')](handleError(_0x92bfa3,null));};exports[_0xe510('0x4a')]=function(_0x198615,_0x251e86){var _0x58f6af={'raw':!![],'where':{'id':_0x198615[_0xe510('0x4b')]['id']}},_0x59a603={};_0x59a603[_0xe510('0x35')]=_['keys'](db[_0xe510('0x30')][_0xe510('0x31')]);_0x59a603['query']=_[_0xe510('0x38')](_0x198615[_0xe510('0x37')]);_0x59a603[_0xe510('0x39')]=_[_0xe510('0x3a')](_0x59a603['model'],_0x59a603[_0xe510('0x37')]);_0x58f6af[_0xe510('0x3b')]=_[_0xe510('0x3a')](_0x59a603['model'],qs[_0xe510('0x3c')](_0x198615[_0xe510('0x37')]['fields']));_0x58f6af[_0xe510('0x3b')]=_0x58f6af[_0xe510('0x3b')][_0xe510('0x3d')]?_0x58f6af['attributes']:_0x59a603[_0xe510('0x35')];if(_0x198615['query'][_0xe510('0x46')]){_0x58f6af[_0xe510('0x47')]=[{'all':!![]}];}_0x58f6af=_[_0xe510('0x44')]({},_0x58f6af,_0x198615[_0xe510('0x45')]);return db['ChatQueueReport'][_0xe510('0x4c')](_0x58f6af)['then'](handleEntityNotFound(_0x251e86,null))[_0xe510('0x29')](respondWithResult(_0x251e86,null))['catch'](handleError(_0x251e86,null));};exports['create']=function(_0x5acee9,_0x684d19){return db['ChatQueueReport']['create'](_0x5acee9['body'],{})[_0xe510('0x29')](respondWithResult(_0x684d19,0xc9))[_0xe510('0x49')](handleError(_0x684d19,null));};exports[_0xe510('0x28')]=function(_0x38ccc1,_0x4cce42){if(_0x38ccc1[_0xe510('0x4d')]['id']){delete _0x38ccc1[_0xe510('0x4d')]['id'];}return db[_0xe510('0x30')][_0xe510('0x4c')]({'where':{'id':_0x38ccc1['params']['id']}})['then'](handleEntityNotFound(_0x4cce42,null))['then'](saveUpdates(_0x38ccc1[_0xe510('0x4d')],null))[_0xe510('0x29')](respondWithResult(_0x4cce42,null))[_0xe510('0x49')](handleError(_0x4cce42,null));};exports[_0xe510('0x2a')]=function(_0x992fa4,_0x4f1d42){return db[_0xe510('0x30')]['find']({'where':{'id':_0x992fa4[_0xe510('0x4b')]['id']}})['then'](handleEntityNotFound(_0x4f1d42,null))['then'](removeEntity(_0x4f1d42,null))[_0xe510('0x49')](handleError(_0x4f1d42,null));};exports[_0xe510('0x4e')]=function(_0x58409b,_0x199f5f){return db[_0xe510('0x30')][_0xe510('0x4e')]()[_0xe510('0x29')](respondWithResult(_0x199f5f,null))[_0xe510('0x49')](handleError(_0x199f5f,null));};