a755111ebc620ed539bf272724ca4cce41e80122
[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 _0x77f7=['name','send','index','map','ChatQueueReport','fieldName','type','key','model','query','keys','filters','attributes','intersection','fields','length','hasOwnProperty','nolimit','order','sort','where','pick','filter','merge','options','includeAll','include','findAll','rows','params','rawAttributes','catch','body','find','describe','eml-format','rimraf','zip-dir','fast-json-patch','request-promise','moment','bluebird','mustache','util','to-csv','ejs','fs-extra','lodash','squel','crypto','jsforce','desk.js','querystring','ioredis','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/logger','api','../../config/utils','../../config/license/util','../../mysqldb','sendStatus','end','status','json','undefined','limit','count','offset','set','Content-Range','apply','reject','save','update','then','destroy'];(function(_0x4c7f8b,_0x35650d){var _0x5c4c0e=function(_0x3f2350){while(--_0x3f2350){_0x4c7f8b['push'](_0x4c7f8b['shift']());}};_0x5c4c0e(++_0x35650d);}(_0x77f7,0xbd));var _0x777f=function(_0x2b0314,_0xfcb580){_0x2b0314=_0x2b0314-0x0;var _0x18c8fb=_0x77f7[_0x2b0314];return _0x18c8fb;};'use strict';var emlformat=require(_0x777f('0x0'));var rimraf=require(_0x777f('0x1'));var zipdir=require(_0x777f('0x2'));var jsonpatch=require(_0x777f('0x3'));var rp=require(_0x777f('0x4'));var moment=require(_0x777f('0x5'));var BPromise=require(_0x777f('0x6'));var Mustache=require(_0x777f('0x7'));var util=require(_0x777f('0x8'));var path=require('path');var sox=require('sox');var csv=require(_0x777f('0x9'));var ejs=require(_0x777f('0xa'));var fs=require('fs');var fs_extra=require(_0x777f('0xb'));var _=require(_0x777f('0xc'));var squel=require(_0x777f('0xd'));var crypto=require(_0x777f('0xe'));var jsforce=require(_0x777f('0xf'));var deskjs=require(_0x777f('0x10'));var toCsv=require(_0x777f('0x9'));var querystring=require(_0x777f('0x11'));var Papa=require('papaparse');var Redis=require(_0x777f('0x12'));var authService=require('../../components/auth/service');var qs=require(_0x777f('0x13'));var as=require(_0x777f('0x14'));var hardwareService=require('../../config/license/hardware');var logger=require(_0x777f('0x15'))(_0x777f('0x16'));var utils=require(_0x777f('0x17'));var config=require('../../config/environment');var licenseUtil=require(_0x777f('0x18'));var db=require(_0x777f('0x19'))['db'];function respondWithStatusCode(_0x285bf7,_0x30f31b){_0x30f31b=_0x30f31b||0xcc;return function(_0xee481c){if(_0xee481c){return _0x285bf7[_0x777f('0x1a')](_0x30f31b);}return _0x285bf7['status'](_0x30f31b)[_0x777f('0x1b')]();};}function respondWithResult(_0x2cef15,_0x5468c0){_0x5468c0=_0x5468c0||0xc8;return function(_0x36652d){if(_0x36652d){return _0x2cef15[_0x777f('0x1c')](_0x5468c0)[_0x777f('0x1d')](_0x36652d);}};}function respondWithFilteredResult(_0x43d45a,_0xf4d60b){return function(_0x217e98){if(_0x217e98){var _0x41855a=typeof _0xf4d60b['offset']===_0x777f('0x1e')&&typeof _0xf4d60b[_0x777f('0x1f')]===_0x777f('0x1e');var _0x1ef1c5=_0x217e98[_0x777f('0x20')];var _0x3aeb58=_0x41855a?0x0:_0xf4d60b[_0x777f('0x21')];var _0x4e1153=_0x41855a?_0x217e98['count']:_0xf4d60b[_0x777f('0x21')]+_0xf4d60b[_0x777f('0x1f')];var _0x31f786;if(_0x4e1153>=_0x1ef1c5){_0x4e1153=_0x1ef1c5;_0x31f786=0xc8;}else{_0x31f786=0xce;}_0x43d45a[_0x777f('0x1c')](_0x31f786);return _0x43d45a[_0x777f('0x22')](_0x777f('0x23'),_0x3aeb58+'-'+_0x4e1153+'/'+_0x1ef1c5)[_0x777f('0x1d')](_0x217e98);}return null;};}function patchUpdates(_0x143f3d){return function(_0x5d31f1){try{jsonpatch[_0x777f('0x24')](_0x5d31f1,_0x143f3d,!![]);}catch(_0x5637d0){return BPromise[_0x777f('0x25')](_0x5637d0);}return _0x5d31f1[_0x777f('0x26')]();};}function saveUpdates(_0x1cc281,_0x38e32f){return function(_0x3a0c1d){if(_0x3a0c1d){return _0x3a0c1d[_0x777f('0x27')](_0x1cc281)[_0x777f('0x28')](function(_0x5732c6){return _0x5732c6;});}return null;};}function removeEntity(_0x780490,_0x17f1ed){return function(_0x5089ba){if(_0x5089ba){return _0x5089ba[_0x777f('0x29')]()['then'](function(){_0x780490[_0x777f('0x1c')](0xcc)[_0x777f('0x1b')]();});}};}function handleEntityNotFound(_0x109a8e,_0x3fe93d){return function(_0x43a7c1){if(!_0x43a7c1){_0x109a8e[_0x777f('0x1a')](0x194);}return _0x43a7c1;};}function handleError(_0x2c9edc,_0x1c0984){_0x1c0984=_0x1c0984||0x1f4;return function(_0x104b86){logger['error'](_0x104b86['stack']);if(_0x104b86[_0x777f('0x2a')]){delete _0x104b86[_0x777f('0x2a')];}_0x2c9edc[_0x777f('0x1c')](_0x1c0984)[_0x777f('0x2b')](_0x104b86);};}exports[_0x777f('0x2c')]=function(_0x32007e,_0x221dda){var _0x5b0504={},_0x2ebed8={},_0x3940cb={'count':0x0,'rows':[]};var _0x5b78b8=_[_0x777f('0x2d')](db[_0x777f('0x2e')]['rawAttributes'],function(_0x502924){return{'name':_0x502924[_0x777f('0x2f')],'type':_0x502924[_0x777f('0x30')][_0x777f('0x31')]};});_0x2ebed8[_0x777f('0x32')]=_[_0x777f('0x2d')](_0x5b78b8,_0x777f('0x2a'));_0x2ebed8[_0x777f('0x33')]=_[_0x777f('0x34')](_0x32007e[_0x777f('0x33')]);_0x2ebed8[_0x777f('0x35')]=_['intersection'](_0x2ebed8[_0x777f('0x32')],_0x2ebed8[_0x777f('0x33')]);_0x5b0504[_0x777f('0x36')]=_[_0x777f('0x37')](_0x2ebed8[_0x777f('0x32')],qs[_0x777f('0x38')](_0x32007e['query'][_0x777f('0x38')]));_0x5b0504[_0x777f('0x36')]=_0x5b0504['attributes'][_0x777f('0x39')]?_0x5b0504['attributes']:_0x2ebed8['model'];if(!_0x32007e[_0x777f('0x33')][_0x777f('0x3a')](_0x777f('0x3b'))){_0x5b0504[_0x777f('0x1f')]=qs[_0x777f('0x1f')](_0x32007e[_0x777f('0x33')][_0x777f('0x1f')]);_0x5b0504[_0x777f('0x21')]=qs['offset'](_0x32007e['query'][_0x777f('0x21')]);}_0x5b0504[_0x777f('0x3c')]=qs[_0x777f('0x3d')](_0x32007e[_0x777f('0x33')][_0x777f('0x3d')]);_0x5b0504[_0x777f('0x3e')]=qs[_0x777f('0x35')](_[_0x777f('0x3f')](_0x32007e['query'],_0x2ebed8[_0x777f('0x35')]),_0x5b78b8);if(_0x32007e[_0x777f('0x33')][_0x777f('0x40')]){_0x5b0504[_0x777f('0x3e')]=_[_0x777f('0x41')](_0x5b0504[_0x777f('0x3e')],{'$or':_[_0x777f('0x2d')](_0x5b78b8,function(_0x1f32ad){if(_0x1f32ad['type']!=='VIRTUAL'){var _0x19795e={};_0x19795e[_0x1f32ad['name']]={'$like':'%'+_0x32007e[_0x777f('0x33')][_0x777f('0x40')]+'%'};return _0x19795e;}})});}_0x5b0504=_[_0x777f('0x41')]({},_0x5b0504,_0x32007e[_0x777f('0x42')]);var _0x2727d0={'where':_0x5b0504['where']};return db[_0x777f('0x2e')][_0x777f('0x20')](_0x2727d0)[_0x777f('0x28')](function(_0x3a5d34){_0x3940cb[_0x777f('0x20')]=_0x3a5d34;if(_0x32007e['query'][_0x777f('0x43')]){_0x5b0504[_0x777f('0x44')]=[{'all':!![]}];}return db[_0x777f('0x2e')][_0x777f('0x45')](_0x5b0504);})[_0x777f('0x28')](function(_0x43e53d){_0x3940cb[_0x777f('0x46')]=_0x43e53d;return _0x3940cb;})[_0x777f('0x28')](respondWithFilteredResult(_0x221dda,_0x5b0504))['catch'](handleError(_0x221dda,null));};exports['show']=function(_0x2924e9,_0x4a4eb6){var _0x5ac30a={'raw':!![],'where':{'id':_0x2924e9[_0x777f('0x47')]['id']}},_0xdfb525={};_0xdfb525[_0x777f('0x32')]=_['keys'](db['ChatQueueReport'][_0x777f('0x48')]);_0xdfb525[_0x777f('0x33')]=_[_0x777f('0x34')](_0x2924e9[_0x777f('0x33')]);_0xdfb525['filters']=_[_0x777f('0x37')](_0xdfb525[_0x777f('0x32')],_0xdfb525[_0x777f('0x33')]);_0x5ac30a[_0x777f('0x36')]=_[_0x777f('0x37')](_0xdfb525[_0x777f('0x32')],qs[_0x777f('0x38')](_0x2924e9[_0x777f('0x33')][_0x777f('0x38')]));_0x5ac30a[_0x777f('0x36')]=_0x5ac30a[_0x777f('0x36')][_0x777f('0x39')]?_0x5ac30a[_0x777f('0x36')]:_0xdfb525[_0x777f('0x32')];if(_0x2924e9[_0x777f('0x33')]['includeAll']){_0x5ac30a[_0x777f('0x44')]=[{'all':!![]}];}_0x5ac30a=_[_0x777f('0x41')]({},_0x5ac30a,_0x2924e9[_0x777f('0x42')]);return db[_0x777f('0x2e')]['find'](_0x5ac30a)[_0x777f('0x28')](handleEntityNotFound(_0x4a4eb6,null))[_0x777f('0x28')](respondWithResult(_0x4a4eb6,null))[_0x777f('0x49')](handleError(_0x4a4eb6,null));};exports['create']=function(_0x486664,_0x364d41){return db['ChatQueueReport']['create'](_0x486664[_0x777f('0x4a')],{})[_0x777f('0x28')](respondWithResult(_0x364d41,0xc9))[_0x777f('0x49')](handleError(_0x364d41,null));};exports[_0x777f('0x27')]=function(_0x3ba76d,_0x45ea24){if(_0x3ba76d[_0x777f('0x4a')]['id']){delete _0x3ba76d[_0x777f('0x4a')]['id'];}return db['ChatQueueReport'][_0x777f('0x4b')]({'where':{'id':_0x3ba76d[_0x777f('0x47')]['id']}})[_0x777f('0x28')](handleEntityNotFound(_0x45ea24,null))[_0x777f('0x28')](saveUpdates(_0x3ba76d[_0x777f('0x4a')],null))[_0x777f('0x28')](respondWithResult(_0x45ea24,null))[_0x777f('0x49')](handleError(_0x45ea24,null));};exports[_0x777f('0x29')]=function(_0x124fc5,_0x145cbb){return db[_0x777f('0x2e')][_0x777f('0x4b')]({'where':{'id':_0x124fc5[_0x777f('0x47')]['id']}})[_0x777f('0x28')](handleEntityNotFound(_0x145cbb,null))[_0x777f('0x28')](removeEntity(_0x145cbb,null))[_0x777f('0x49')](handleError(_0x145cbb,null));};exports[_0x777f('0x4c')]=function(_0x4d9f46,_0x126b50){return db['ChatQueueReport'][_0x777f('0x4c')]()[_0x777f('0x28')](respondWithResult(_0x126b50,null))[_0x777f('0x49')](handleError(_0x126b50,null));};