Built motion from commit 092f8824.|2.5.49
[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 _0xa7f7=['index','map','fieldName','type','model','query','filters','intersection','attributes','fields','hasOwnProperty','nolimit','order','sort','where','pick','filter','merge','VIRTUAL','options','OpenchannelQueueReport','include','rows','params','keys','length','includeAll','find','catch','create','body','describe','rimraf','zip-dir','request-promise','moment','bluebird','util','path','to-csv','ejs','fs-extra','lodash','crypto','jsforce','desk.js','querystring','papaparse','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/logger','../../config/utils','../../config/environment','../../config/license/util','../../mysqldb','sendStatus','end','status','json','offset','undefined','limit','count','set','Content-Range','reject','update','then','destroy','stack','name','send'];(function(_0x511f8b,_0x32a110){var _0x2332ff=function(_0x550a2f){while(--_0x550a2f){_0x511f8b['push'](_0x511f8b['shift']());}};_0x2332ff(++_0x32a110);}(_0xa7f7,0x6a));var _0x7a7f=function(_0x231dda,_0x5b04cc){_0x231dda=_0x231dda-0x0;var _0x3f88cb=_0xa7f7[_0x231dda];return _0x3f88cb;};'use strict';var emlformat=require('eml-format');var rimraf=require(_0x7a7f('0x0'));var zipdir=require(_0x7a7f('0x1'));var jsonpatch=require('fast-json-patch');var rp=require(_0x7a7f('0x2'));var moment=require(_0x7a7f('0x3'));var BPromise=require(_0x7a7f('0x4'));var Mustache=require('mustache');var util=require(_0x7a7f('0x5'));var path=require(_0x7a7f('0x6'));var sox=require('sox');var csv=require(_0x7a7f('0x7'));var ejs=require(_0x7a7f('0x8'));var fs=require('fs');var fs_extra=require(_0x7a7f('0x9'));var _=require(_0x7a7f('0xa'));var squel=require('squel');var crypto=require(_0x7a7f('0xb'));var jsforce=require(_0x7a7f('0xc'));var deskjs=require(_0x7a7f('0xd'));var toCsv=require(_0x7a7f('0x7'));var querystring=require(_0x7a7f('0xe'));var Papa=require(_0x7a7f('0xf'));var Redis=require(_0x7a7f('0x10'));var authService=require(_0x7a7f('0x11'));var qs=require(_0x7a7f('0x12'));var as=require(_0x7a7f('0x13'));var hardwareService=require('../../config/license/hardware');var logger=require(_0x7a7f('0x14'))('api');var utils=require(_0x7a7f('0x15'));var config=require(_0x7a7f('0x16'));var licenseUtil=require(_0x7a7f('0x17'));var db=require(_0x7a7f('0x18'))['db'];function respondWithStatusCode(_0x48a256,_0x4ac9c1){_0x4ac9c1=_0x4ac9c1||0xcc;return function(_0x44a1d4){if(_0x44a1d4){return _0x48a256[_0x7a7f('0x19')](_0x4ac9c1);}return _0x48a256['status'](_0x4ac9c1)[_0x7a7f('0x1a')]();};}function respondWithResult(_0x4469f6,_0x4f735e){_0x4f735e=_0x4f735e||0xc8;return function(_0x426ef2){if(_0x426ef2){return _0x4469f6[_0x7a7f('0x1b')](_0x4f735e)[_0x7a7f('0x1c')](_0x426ef2);}};}function respondWithFilteredResult(_0x170dbc,_0x126c7c){return function(_0x39c7ca){if(_0x39c7ca){var _0x521bea=typeof _0x126c7c[_0x7a7f('0x1d')]===_0x7a7f('0x1e')&&typeof _0x126c7c[_0x7a7f('0x1f')]===_0x7a7f('0x1e');var _0x3700fb=_0x39c7ca[_0x7a7f('0x20')];var _0x2df697=_0x521bea?0x0:_0x126c7c[_0x7a7f('0x1d')];var _0x2c42ec=_0x521bea?_0x39c7ca['count']:_0x126c7c[_0x7a7f('0x1d')]+_0x126c7c[_0x7a7f('0x1f')];var _0x51fd07;if(_0x2c42ec>=_0x3700fb){_0x2c42ec=_0x3700fb;_0x51fd07=0xc8;}else{_0x51fd07=0xce;}_0x170dbc[_0x7a7f('0x1b')](_0x51fd07);return _0x170dbc[_0x7a7f('0x21')](_0x7a7f('0x22'),_0x2df697+'-'+_0x2c42ec+'/'+_0x3700fb)[_0x7a7f('0x1c')](_0x39c7ca);}return null;};}function patchUpdates(_0x8ed74){return function(_0x5cb723){try{jsonpatch['apply'](_0x5cb723,_0x8ed74,!![]);}catch(_0x45ad33){return BPromise[_0x7a7f('0x23')](_0x45ad33);}return _0x5cb723['save']();};}function saveUpdates(_0x25de59,_0x32b452){return function(_0x42fd23){if(_0x42fd23){return _0x42fd23[_0x7a7f('0x24')](_0x25de59)[_0x7a7f('0x25')](function(_0x14848a){return _0x14848a;});}return null;};}function removeEntity(_0x41604e,_0x350a70){return function(_0x365367){if(_0x365367){return _0x365367[_0x7a7f('0x26')]()[_0x7a7f('0x25')](function(){_0x41604e[_0x7a7f('0x1b')](0xcc)[_0x7a7f('0x1a')]();});}};}function handleEntityNotFound(_0x5c7895,_0x38c887){return function(_0xb4e2bb){if(!_0xb4e2bb){_0x5c7895['sendStatus'](0x194);}return _0xb4e2bb;};}function handleError(_0xc91890,_0x1c2c4d){_0x1c2c4d=_0x1c2c4d||0x1f4;return function(_0x5a77d3){logger['error'](_0x5a77d3[_0x7a7f('0x27')]);if(_0x5a77d3[_0x7a7f('0x28')]){delete _0x5a77d3[_0x7a7f('0x28')];}_0xc91890[_0x7a7f('0x1b')](_0x1c2c4d)[_0x7a7f('0x29')](_0x5a77d3);};}exports[_0x7a7f('0x2a')]=function(_0x45b909,_0x474167){var _0x120941={},_0x4789bc={},_0x48eb68={'count':0x0,'rows':[]};var _0x39af94=_[_0x7a7f('0x2b')](db['OpenchannelQueueReport']['rawAttributes'],function(_0x1c4d65){return{'name':_0x1c4d65[_0x7a7f('0x2c')],'type':_0x1c4d65[_0x7a7f('0x2d')]['key']};});_0x4789bc[_0x7a7f('0x2e')]=_[_0x7a7f('0x2b')](_0x39af94,_0x7a7f('0x28'));_0x4789bc[_0x7a7f('0x2f')]=_['keys'](_0x45b909[_0x7a7f('0x2f')]);_0x4789bc[_0x7a7f('0x30')]=_[_0x7a7f('0x31')](_0x4789bc[_0x7a7f('0x2e')],_0x4789bc[_0x7a7f('0x2f')]);_0x120941[_0x7a7f('0x32')]=_[_0x7a7f('0x31')](_0x4789bc[_0x7a7f('0x2e')],qs['fields'](_0x45b909['query'][_0x7a7f('0x33')]));_0x120941[_0x7a7f('0x32')]=_0x120941[_0x7a7f('0x32')]['length']?_0x120941[_0x7a7f('0x32')]:_0x4789bc[_0x7a7f('0x2e')];if(!_0x45b909['query'][_0x7a7f('0x34')](_0x7a7f('0x35'))){_0x120941['limit']=qs['limit'](_0x45b909[_0x7a7f('0x2f')]['limit']);_0x120941['offset']=qs[_0x7a7f('0x1d')](_0x45b909[_0x7a7f('0x2f')][_0x7a7f('0x1d')]);}_0x120941[_0x7a7f('0x36')]=qs[_0x7a7f('0x37')](_0x45b909['query'][_0x7a7f('0x37')]);_0x120941[_0x7a7f('0x38')]=qs[_0x7a7f('0x30')](_[_0x7a7f('0x39')](_0x45b909[_0x7a7f('0x2f')],_0x4789bc[_0x7a7f('0x30')]),_0x39af94);if(_0x45b909[_0x7a7f('0x2f')][_0x7a7f('0x3a')]){_0x120941['where']=_[_0x7a7f('0x3b')](_0x120941[_0x7a7f('0x38')],{'$or':_[_0x7a7f('0x2b')](_0x39af94,function(_0x24936d){if(_0x24936d[_0x7a7f('0x2d')]!==_0x7a7f('0x3c')){var _0x350629={};_0x350629[_0x24936d['name']]={'$like':'%'+_0x45b909[_0x7a7f('0x2f')][_0x7a7f('0x3a')]+'%'};return _0x350629;}})});}_0x120941=_['merge']({},_0x120941,_0x45b909[_0x7a7f('0x3d')]);var _0x548823={'where':_0x120941[_0x7a7f('0x38')]};return db[_0x7a7f('0x3e')][_0x7a7f('0x20')](_0x548823)[_0x7a7f('0x25')](function(_0x2ed860){_0x48eb68[_0x7a7f('0x20')]=_0x2ed860;if(_0x45b909[_0x7a7f('0x2f')]['includeAll']){_0x120941[_0x7a7f('0x3f')]=[{'all':!![]}];}return db[_0x7a7f('0x3e')]['findAll'](_0x120941);})[_0x7a7f('0x25')](function(_0x3cd5be){_0x48eb68[_0x7a7f('0x40')]=_0x3cd5be;return _0x48eb68;})[_0x7a7f('0x25')](respondWithFilteredResult(_0x474167,_0x120941))['catch'](handleError(_0x474167,null));};exports['show']=function(_0x51906e,_0x4518e3){var _0x3c2a42={'raw':!![],'where':{'id':_0x51906e[_0x7a7f('0x41')]['id']}},_0x1632c6={};_0x1632c6[_0x7a7f('0x2e')]=_['keys'](db['OpenchannelQueueReport']['rawAttributes']);_0x1632c6[_0x7a7f('0x2f')]=_[_0x7a7f('0x42')](_0x51906e[_0x7a7f('0x2f')]);_0x1632c6['filters']=_[_0x7a7f('0x31')](_0x1632c6['model'],_0x1632c6['query']);_0x3c2a42['attributes']=_[_0x7a7f('0x31')](_0x1632c6[_0x7a7f('0x2e')],qs[_0x7a7f('0x33')](_0x51906e[_0x7a7f('0x2f')][_0x7a7f('0x33')]));_0x3c2a42[_0x7a7f('0x32')]=_0x3c2a42[_0x7a7f('0x32')][_0x7a7f('0x43')]?_0x3c2a42[_0x7a7f('0x32')]:_0x1632c6[_0x7a7f('0x2e')];if(_0x51906e[_0x7a7f('0x2f')][_0x7a7f('0x44')]){_0x3c2a42['include']=[{'all':!![]}];}_0x3c2a42=_['merge']({},_0x3c2a42,_0x51906e[_0x7a7f('0x3d')]);return db[_0x7a7f('0x3e')][_0x7a7f('0x45')](_0x3c2a42)[_0x7a7f('0x25')](handleEntityNotFound(_0x4518e3,null))['then'](respondWithResult(_0x4518e3,null))[_0x7a7f('0x46')](handleError(_0x4518e3,null));};exports[_0x7a7f('0x47')]=function(_0x67bfad,_0x613bb2){return db['OpenchannelQueueReport'][_0x7a7f('0x47')](_0x67bfad[_0x7a7f('0x48')],{})[_0x7a7f('0x25')](respondWithResult(_0x613bb2,0xc9))[_0x7a7f('0x46')](handleError(_0x613bb2,null));};exports[_0x7a7f('0x24')]=function(_0x7ad1f7,_0x1531f0){if(_0x7ad1f7[_0x7a7f('0x48')]['id']){delete _0x7ad1f7[_0x7a7f('0x48')]['id'];}return db[_0x7a7f('0x3e')][_0x7a7f('0x45')]({'where':{'id':_0x7ad1f7['params']['id']}})[_0x7a7f('0x25')](handleEntityNotFound(_0x1531f0,null))[_0x7a7f('0x25')](saveUpdates(_0x7ad1f7['body'],null))[_0x7a7f('0x25')](respondWithResult(_0x1531f0,null))[_0x7a7f('0x46')](handleError(_0x1531f0,null));};exports[_0x7a7f('0x26')]=function(_0x40d456,_0x5020db){return db[_0x7a7f('0x3e')][_0x7a7f('0x45')]({'where':{'id':_0x40d456[_0x7a7f('0x41')]['id']}})[_0x7a7f('0x25')](handleEntityNotFound(_0x5020db,null))['then'](removeEntity(_0x5020db,null))[_0x7a7f('0x46')](handleError(_0x5020db,null));};exports['describe']=function(_0x59ac4c,_0x504f01){return db['OpenchannelQueueReport'][_0x7a7f('0x49')]()[_0x7a7f('0x25')](respondWithResult(_0x504f01,null))[_0x7a7f('0x46')](handleError(_0x504f01,null));};