Built motion from commit d6d69adf.|2.6.33
[motion2.git] / server / api / openchannelQueueReport / openchannelQueueReport.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 _0x567f=['json','apply','reject','update','then','destroy','error','stack','name','send','index','map','OpenchannelQueueReport','rawAttributes','fieldName','type','model','query','keys','filters','intersection','attributes','fields','hasOwnProperty','order','sort','where','VIRTUAL','filter','merge','options','includeAll','include','findAll','rows','catch','show','params','length','find','create','body','describe','eml-format','rimraf','zip-dir','request-promise','bluebird','mustache','util','to-csv','ejs','fs-extra','lodash','squel','crypto','jsforce','desk.js','querystring','papaparse','ioredis','../../components/parsers/qs','../../config/license/hardware','../../config/logger','../../config/utils','../../config/environment','../../config/license/util','../../mysqldb','sendStatus','status','offset','undefined','limit','count','Content-Range'];(function(_0x88df1b,_0xda41dd){var _0x24af06=function(_0x5014a0){while(--_0x5014a0){_0x88df1b['push'](_0x88df1b['shift']());}};_0x24af06(++_0xda41dd);}(_0x567f,0xc1));var _0xf567=function(_0x49536b,_0x2abe5d){_0x49536b=_0x49536b-0x0;var _0x30de59=_0x567f[_0x49536b];return _0x30de59;};'use strict';var emlformat=require(_0xf567('0x0'));var rimraf=require(_0xf567('0x1'));var zipdir=require(_0xf567('0x2'));var jsonpatch=require('fast-json-patch');var rp=require(_0xf567('0x3'));var moment=require('moment');var BPromise=require(_0xf567('0x4'));var Mustache=require(_0xf567('0x5'));var util=require(_0xf567('0x6'));var path=require('path');var sox=require('sox');var csv=require(_0xf567('0x7'));var ejs=require(_0xf567('0x8'));var fs=require('fs');var fs_extra=require(_0xf567('0x9'));var _=require(_0xf567('0xa'));var squel=require(_0xf567('0xb'));var crypto=require(_0xf567('0xc'));var jsforce=require(_0xf567('0xd'));var deskjs=require(_0xf567('0xe'));var toCsv=require(_0xf567('0x7'));var querystring=require(_0xf567('0xf'));var Papa=require(_0xf567('0x10'));var Redis=require(_0xf567('0x11'));var authService=require('../../components/auth/service');var qs=require(_0xf567('0x12'));var as=require('../../components/parsers/advancedSearch');var hardwareService=require(_0xf567('0x13'));var logger=require(_0xf567('0x14'))('api');var utils=require(_0xf567('0x15'));var config=require(_0xf567('0x16'));var licenseUtil=require(_0xf567('0x17'));var db=require(_0xf567('0x18'))['db'];function respondWithStatusCode(_0x4ee2f0,_0x3ac9d9){_0x3ac9d9=_0x3ac9d9||0xcc;return function(_0x51828d){if(_0x51828d){return _0x4ee2f0[_0xf567('0x19')](_0x3ac9d9);}return _0x4ee2f0[_0xf567('0x1a')](_0x3ac9d9)['end']();};}function respondWithResult(_0x534602,_0x936626){_0x936626=_0x936626||0xc8;return function(_0x21991b){if(_0x21991b){return _0x534602[_0xf567('0x1a')](_0x936626)['json'](_0x21991b);}};}function respondWithFilteredResult(_0x3c0898,_0xf40b9f){return function(_0x37efa8){if(_0x37efa8){var _0x496143=typeof _0xf40b9f[_0xf567('0x1b')]===_0xf567('0x1c')&&typeof _0xf40b9f[_0xf567('0x1d')]==='undefined';var _0x5ad745=_0x37efa8[_0xf567('0x1e')];var _0x340a36=_0x496143?0x0:_0xf40b9f[_0xf567('0x1b')];var _0x173c1e=_0x496143?_0x37efa8[_0xf567('0x1e')]:_0xf40b9f[_0xf567('0x1b')]+_0xf40b9f[_0xf567('0x1d')];var _0x428bf8;if(_0x173c1e>=_0x5ad745){_0x173c1e=_0x5ad745;_0x428bf8=0xc8;}else{_0x428bf8=0xce;}_0x3c0898[_0xf567('0x1a')](_0x428bf8);return _0x3c0898['set'](_0xf567('0x1f'),_0x340a36+'-'+_0x173c1e+'/'+_0x5ad745)[_0xf567('0x20')](_0x37efa8);}return null;};}function patchUpdates(_0x46ee1a){return function(_0x216677){try{jsonpatch[_0xf567('0x21')](_0x216677,_0x46ee1a,!![]);}catch(_0x1d0091){return BPromise[_0xf567('0x22')](_0x1d0091);}return _0x216677['save']();};}function saveUpdates(_0x76fdd5,_0x20fad7){return function(_0x1644a7){if(_0x1644a7){return _0x1644a7[_0xf567('0x23')](_0x76fdd5)[_0xf567('0x24')](function(_0x58147a){return _0x58147a;});}return null;};}function removeEntity(_0x5bb6a7,_0x101af1){return function(_0x54730d){if(_0x54730d){return _0x54730d[_0xf567('0x25')]()[_0xf567('0x24')](function(){_0x5bb6a7[_0xf567('0x1a')](0xcc)['end']();});}};}function handleEntityNotFound(_0x3a7fd8,_0x46e12b){return function(_0x6741b7){if(!_0x6741b7){_0x3a7fd8[_0xf567('0x19')](0x194);}return _0x6741b7;};}function handleError(_0x27bfbe,_0x1413aa){_0x1413aa=_0x1413aa||0x1f4;return function(_0x421e9e){logger[_0xf567('0x26')](_0x421e9e[_0xf567('0x27')]);if(_0x421e9e['name']){delete _0x421e9e[_0xf567('0x28')];}_0x27bfbe[_0xf567('0x1a')](_0x1413aa)[_0xf567('0x29')](_0x421e9e);};}exports[_0xf567('0x2a')]=function(_0x3d5813,_0x201d5d){var _0x3255d2={},_0x338a26={},_0x40003e={'count':0x0,'rows':[]};var _0x16810f=_[_0xf567('0x2b')](db[_0xf567('0x2c')][_0xf567('0x2d')],function(_0x44c13f){return{'name':_0x44c13f[_0xf567('0x2e')],'type':_0x44c13f[_0xf567('0x2f')]['key']};});_0x338a26[_0xf567('0x30')]=_[_0xf567('0x2b')](_0x16810f,_0xf567('0x28'));_0x338a26[_0xf567('0x31')]=_[_0xf567('0x32')](_0x3d5813[_0xf567('0x31')]);_0x338a26[_0xf567('0x33')]=_[_0xf567('0x34')](_0x338a26['model'],_0x338a26[_0xf567('0x31')]);_0x3255d2[_0xf567('0x35')]=_['intersection'](_0x338a26['model'],qs[_0xf567('0x36')](_0x3d5813[_0xf567('0x31')]['fields']));_0x3255d2[_0xf567('0x35')]=_0x3255d2['attributes']['length']?_0x3255d2[_0xf567('0x35')]:_0x338a26[_0xf567('0x30')];if(!_0x3d5813[_0xf567('0x31')][_0xf567('0x37')]('nolimit')){_0x3255d2[_0xf567('0x1d')]=qs['limit'](_0x3d5813[_0xf567('0x31')][_0xf567('0x1d')]);_0x3255d2[_0xf567('0x1b')]=qs[_0xf567('0x1b')](_0x3d5813[_0xf567('0x31')][_0xf567('0x1b')]);}_0x3255d2[_0xf567('0x38')]=qs[_0xf567('0x39')](_0x3d5813[_0xf567('0x31')][_0xf567('0x39')]);_0x3255d2[_0xf567('0x3a')]=qs[_0xf567('0x33')](_['pick'](_0x3d5813['query'],_0x338a26[_0xf567('0x33')]),_0x16810f);if(_0x3d5813['query']['filter']){_0x3255d2[_0xf567('0x3a')]=_['merge'](_0x3255d2[_0xf567('0x3a')],{'$or':_[_0xf567('0x2b')](_0x16810f,function(_0x5df27f){if(_0x5df27f[_0xf567('0x2f')]!==_0xf567('0x3b')){var _0x3600d5={};_0x3600d5[_0x5df27f[_0xf567('0x28')]]={'$like':'%'+_0x3d5813['query'][_0xf567('0x3c')]+'%'};return _0x3600d5;}})});}_0x3255d2=_[_0xf567('0x3d')]({},_0x3255d2,_0x3d5813[_0xf567('0x3e')]);var _0x6a7404={'where':_0x3255d2['where']};return db[_0xf567('0x2c')][_0xf567('0x1e')](_0x6a7404)['then'](function(_0x3046e8){_0x40003e[_0xf567('0x1e')]=_0x3046e8;if(_0x3d5813['query'][_0xf567('0x3f')]){_0x3255d2[_0xf567('0x40')]=[{'all':!![]}];}return db['OpenchannelQueueReport'][_0xf567('0x41')](_0x3255d2);})['then'](function(_0x46d6a1){_0x40003e[_0xf567('0x42')]=_0x46d6a1;return _0x40003e;})['then'](respondWithFilteredResult(_0x201d5d,_0x3255d2))[_0xf567('0x43')](handleError(_0x201d5d,null));};exports[_0xf567('0x44')]=function(_0x474fdb,_0x3a73d1){var _0x2e2e92={'raw':!![],'where':{'id':_0x474fdb[_0xf567('0x45')]['id']}},_0x45c4cc={};_0x45c4cc[_0xf567('0x30')]=_[_0xf567('0x32')](db[_0xf567('0x2c')]['rawAttributes']);_0x45c4cc[_0xf567('0x31')]=_[_0xf567('0x32')](_0x474fdb['query']);_0x45c4cc['filters']=_[_0xf567('0x34')](_0x45c4cc[_0xf567('0x30')],_0x45c4cc['query']);_0x2e2e92[_0xf567('0x35')]=_[_0xf567('0x34')](_0x45c4cc['model'],qs[_0xf567('0x36')](_0x474fdb['query'][_0xf567('0x36')]));_0x2e2e92[_0xf567('0x35')]=_0x2e2e92[_0xf567('0x35')][_0xf567('0x46')]?_0x2e2e92[_0xf567('0x35')]:_0x45c4cc[_0xf567('0x30')];if(_0x474fdb[_0xf567('0x31')]['includeAll']){_0x2e2e92[_0xf567('0x40')]=[{'all':!![]}];}_0x2e2e92=_[_0xf567('0x3d')]({},_0x2e2e92,_0x474fdb[_0xf567('0x3e')]);return db[_0xf567('0x2c')][_0xf567('0x47')](_0x2e2e92)[_0xf567('0x24')](handleEntityNotFound(_0x3a73d1,null))[_0xf567('0x24')](respondWithResult(_0x3a73d1,null))[_0xf567('0x43')](handleError(_0x3a73d1,null));};exports['create']=function(_0x82c694,_0x4896d4){return db[_0xf567('0x2c')][_0xf567('0x48')](_0x82c694[_0xf567('0x49')],{})[_0xf567('0x24')](respondWithResult(_0x4896d4,0xc9))['catch'](handleError(_0x4896d4,null));};exports['update']=function(_0x26f8e0,_0x2b3a91){if(_0x26f8e0[_0xf567('0x49')]['id']){delete _0x26f8e0[_0xf567('0x49')]['id'];}return db[_0xf567('0x2c')][_0xf567('0x47')]({'where':{'id':_0x26f8e0['params']['id']}})['then'](handleEntityNotFound(_0x2b3a91,null))[_0xf567('0x24')](saveUpdates(_0x26f8e0['body'],null))['then'](respondWithResult(_0x2b3a91,null))[_0xf567('0x43')](handleError(_0x2b3a91,null));};exports[_0xf567('0x25')]=function(_0x534348,_0x498c7b){return db[_0xf567('0x2c')]['find']({'where':{'id':_0x534348['params']['id']}})['then'](handleEntityNotFound(_0x498c7b,null))[_0xf567('0x24')](removeEntity(_0x498c7b,null))[_0xf567('0x43')](handleError(_0x498c7b,null));};exports['describe']=function(_0x4e49c1,_0x4c4d1f){return db[_0xf567('0x2c')][_0xf567('0x4a')]()[_0xf567('0x24')](respondWithResult(_0x4c4d1f,null))[_0xf567('0x43')](handleError(_0x4c4d1f,null));};