Built motion from commit (unavailable).|2.4.17
[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 _0xb98e=['path','to-csv','lodash','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','end','status','json','count','offset','limit','set','Content-Range','apply','reject','save','update','destroy','error','stack','name','send','index','map','OpenchannelQueueReport','fieldName','type','key','query','keys','filters','attributes','intersection','model','fields','length','hasOwnProperty','nolimit','order','sort','pick','filter','where','VIRTUAL','merge','options','then','includeAll','include','findAll','rows','show','params','rawAttributes','find','catch','create','body','describe','html-pdf','eml-format','fast-json-patch','request-promise','moment','mustache','util'];(function(_0x558615,_0x1eb496){var _0x1e032a=function(_0x538f1d){while(--_0x538f1d){_0x558615['push'](_0x558615['shift']());}};_0x1e032a(++_0x1eb496);}(_0xb98e,0x184));var _0xeb98=function(_0x226167,_0x11f210){_0x226167=_0x226167-0x0;var _0xe399a0=_0xb98e[_0x226167];return _0xe399a0;};'use strict';var pdf=require(_0xeb98('0x0'));var emlformat=require(_0xeb98('0x1'));var rimraf=require('rimraf');var zipdir=require('zip-dir');var jsonpatch=require(_0xeb98('0x2'));var rp=require(_0xeb98('0x3'));var moment=require(_0xeb98('0x4'));var BPromise=require('bluebird');var Mustache=require(_0xeb98('0x5'));var util=require(_0xeb98('0x6'));var path=require(_0xeb98('0x7'));var sox=require('sox');var csv=require(_0xeb98('0x8'));var ejs=require('ejs');var fs=require('fs');var _=require(_0xeb98('0x9'));var squel=require('squel');var crypto=require(_0xeb98('0xa'));var jsforce=require(_0xeb98('0xb'));var deskjs=require(_0xeb98('0xc'));var toCsv=require(_0xeb98('0x8'));var querystring=require(_0xeb98('0xd'));var Papa=require(_0xeb98('0xe'));var Redis=require(_0xeb98('0xf'));var authService=require(_0xeb98('0x10'));var qs=require('../../components/parsers/qs');var as=require(_0xeb98('0x11'));var hardwareService=require(_0xeb98('0x12'));var logger=require(_0xeb98('0x13'))(_0xeb98('0x14'));var utils=require(_0xeb98('0x15'));var config=require(_0xeb98('0x16'));var db=require(_0xeb98('0x17'))['db'];function respondWithStatusCode(_0x30cf5b,_0x2b3f9f){_0x2b3f9f=_0x2b3f9f||0xcc;return function(_0x7f5944){if(_0x7f5944){return _0x30cf5b[_0xeb98('0x18')](_0x2b3f9f);}return _0x30cf5b['status'](_0x2b3f9f)[_0xeb98('0x19')]();};}function respondWithResult(_0x3ee150,_0x55164a){_0x55164a=_0x55164a||0xc8;return function(_0x5d395c){if(_0x5d395c){return _0x3ee150[_0xeb98('0x1a')](_0x55164a)[_0xeb98('0x1b')](_0x5d395c);}};}function respondWithFilteredResult(_0x3bb77a,_0x31ff03){return function(_0xac14bc){if(_0xac14bc){var _0x29117b=_0xac14bc[_0xeb98('0x1c')],_0x33de7f=_0x31ff03[_0xeb98('0x1d')],_0x47a3ad=_0x31ff03[_0xeb98('0x1d')]+_0x31ff03[_0xeb98('0x1e')],_0x934089;if(_0x47a3ad>=_0x29117b){_0x47a3ad=_0x29117b;_0x934089=0xc8;}else{_0x934089=0xce;}_0x3bb77a[_0xeb98('0x1a')](_0x934089);return _0x3bb77a[_0xeb98('0x1f')](_0xeb98('0x20'),_0x33de7f+'-'+_0x47a3ad+'/'+_0x29117b)[_0xeb98('0x1b')](_0xac14bc);}return null;};}function patchUpdates(_0x25a13d){return function(_0xbe8e08){try{jsonpatch[_0xeb98('0x21')](_0xbe8e08,_0x25a13d,!![]);}catch(_0x5141e7){return BPromise[_0xeb98('0x22')](_0x5141e7);}return _0xbe8e08[_0xeb98('0x23')]();};}function saveUpdates(_0x4f5267,_0x56b018){return function(_0x35f4f5){if(_0x35f4f5){return _0x35f4f5[_0xeb98('0x24')](_0x4f5267)['then'](function(_0x5c35e7){return _0x5c35e7;});}return null;};}function removeEntity(_0x2ab831,_0x4e34fc){return function(_0x3e7693){if(_0x3e7693){return _0x3e7693[_0xeb98('0x25')]()['then'](function(){_0x2ab831[_0xeb98('0x1a')](0xcc)[_0xeb98('0x19')]();});}};}function handleEntityNotFound(_0x3a3566,_0x131128){return function(_0x16274e){if(!_0x16274e){_0x3a3566[_0xeb98('0x18')](0x194);}return _0x16274e;};}function handleError(_0x685a8f,_0x31928e){_0x31928e=_0x31928e||0x1f4;return function(_0x338c2c){logger[_0xeb98('0x26')](_0x338c2c[_0xeb98('0x27')]);if(_0x338c2c['name']){delete _0x338c2c[_0xeb98('0x28')];}_0x685a8f[_0xeb98('0x1a')](_0x31928e)[_0xeb98('0x29')](_0x338c2c);};}exports[_0xeb98('0x2a')]=function(_0x296f65,_0x175a0f){var _0x49ca11={},_0x151d9c={},_0x4077d7={'count':0x0,'rows':[]};var _0x3f7fdd=_[_0xeb98('0x2b')](db[_0xeb98('0x2c')]['rawAttributes'],function(_0x23dc9f){return{'name':_0x23dc9f[_0xeb98('0x2d')],'type':_0x23dc9f[_0xeb98('0x2e')][_0xeb98('0x2f')]};});_0x151d9c['model']=_[_0xeb98('0x2b')](_0x3f7fdd,_0xeb98('0x28'));_0x151d9c[_0xeb98('0x30')]=_[_0xeb98('0x31')](_0x296f65[_0xeb98('0x30')]);_0x151d9c[_0xeb98('0x32')]=_['intersection'](_0x151d9c['model'],_0x151d9c[_0xeb98('0x30')]);_0x49ca11[_0xeb98('0x33')]=_[_0xeb98('0x34')](_0x151d9c[_0xeb98('0x35')],qs[_0xeb98('0x36')](_0x296f65[_0xeb98('0x30')][_0xeb98('0x36')]));_0x49ca11[_0xeb98('0x33')]=_0x49ca11[_0xeb98('0x33')][_0xeb98('0x37')]?_0x49ca11[_0xeb98('0x33')]:_0x151d9c[_0xeb98('0x35')];if(!_0x296f65[_0xeb98('0x30')][_0xeb98('0x38')](_0xeb98('0x39'))){_0x49ca11['limit']=qs[_0xeb98('0x1e')](_0x296f65[_0xeb98('0x30')][_0xeb98('0x1e')]);_0x49ca11['offset']=qs[_0xeb98('0x1d')](_0x296f65[_0xeb98('0x30')]['offset']);}_0x49ca11[_0xeb98('0x3a')]=qs[_0xeb98('0x3b')](_0x296f65[_0xeb98('0x30')]['sort']);_0x49ca11['where']=qs[_0xeb98('0x32')](_[_0xeb98('0x3c')](_0x296f65[_0xeb98('0x30')],_0x151d9c[_0xeb98('0x32')]));if(_0x296f65['query'][_0xeb98('0x3d')]){_0x49ca11[_0xeb98('0x3e')]=_['merge'](_0x49ca11[_0xeb98('0x3e')],{'$or':_['map'](_0x3f7fdd,function(_0x166673){if(_0x166673[_0xeb98('0x2e')]!==_0xeb98('0x3f')){var _0xcd1930={};_0xcd1930[_0x166673[_0xeb98('0x28')]]={'$like':'%'+_0x296f65['query']['filter']+'%'};return _0xcd1930;}})});}_0x49ca11=_[_0xeb98('0x40')]({},_0x49ca11,_0x296f65[_0xeb98('0x41')]);var _0x1ae437={'where':_0x49ca11[_0xeb98('0x3e')]};return db[_0xeb98('0x2c')][_0xeb98('0x1c')](_0x1ae437)[_0xeb98('0x42')](function(_0x23610c){_0x4077d7[_0xeb98('0x1c')]=_0x23610c;if(_0x296f65[_0xeb98('0x30')][_0xeb98('0x43')]){_0x49ca11[_0xeb98('0x44')]=[{'all':!![]}];}return db[_0xeb98('0x2c')][_0xeb98('0x45')](_0x49ca11);})[_0xeb98('0x42')](function(_0x4abc57){_0x4077d7[_0xeb98('0x46')]=_0x4abc57;return _0x4077d7;})[_0xeb98('0x42')](respondWithFilteredResult(_0x175a0f,_0x49ca11))['catch'](handleError(_0x175a0f,null));};exports[_0xeb98('0x47')]=function(_0xb6e7f,_0x39c9c0){var _0x3e48ee={'raw':!![],'where':{'id':_0xb6e7f[_0xeb98('0x48')]['id']}},_0x212c31={};_0x212c31['model']=_['keys'](db[_0xeb98('0x2c')][_0xeb98('0x49')]);_0x212c31[_0xeb98('0x30')]=_['keys'](_0xb6e7f[_0xeb98('0x30')]);_0x212c31[_0xeb98('0x32')]=_['intersection'](_0x212c31['model'],_0x212c31[_0xeb98('0x30')]);_0x3e48ee[_0xeb98('0x33')]=_[_0xeb98('0x34')](_0x212c31[_0xeb98('0x35')],qs[_0xeb98('0x36')](_0xb6e7f['query'][_0xeb98('0x36')]));_0x3e48ee[_0xeb98('0x33')]=_0x3e48ee[_0xeb98('0x33')][_0xeb98('0x37')]?_0x3e48ee[_0xeb98('0x33')]:_0x212c31[_0xeb98('0x35')];if(_0xb6e7f[_0xeb98('0x30')][_0xeb98('0x43')]){_0x3e48ee[_0xeb98('0x44')]=[{'all':!![]}];}_0x3e48ee=_[_0xeb98('0x40')]({},_0x3e48ee,_0xb6e7f[_0xeb98('0x41')]);return db[_0xeb98('0x2c')][_0xeb98('0x4a')](_0x3e48ee)[_0xeb98('0x42')](handleEntityNotFound(_0x39c9c0,null))[_0xeb98('0x42')](respondWithResult(_0x39c9c0,null))[_0xeb98('0x4b')](handleError(_0x39c9c0,null));};exports[_0xeb98('0x4c')]=function(_0x4c9994,_0x2a14ee){return db[_0xeb98('0x2c')]['create'](_0x4c9994['body'],{})[_0xeb98('0x42')](respondWithResult(_0x2a14ee,0xc9))['catch'](handleError(_0x2a14ee,null));};exports['update']=function(_0x53d046,_0x5df96f){if(_0x53d046[_0xeb98('0x4d')]['id']){delete _0x53d046[_0xeb98('0x4d')]['id'];}return db[_0xeb98('0x2c')][_0xeb98('0x4a')]({'where':{'id':_0x53d046[_0xeb98('0x48')]['id']}})[_0xeb98('0x42')](handleEntityNotFound(_0x5df96f,null))[_0xeb98('0x42')](saveUpdates(_0x53d046[_0xeb98('0x4d')],null))[_0xeb98('0x42')](respondWithResult(_0x5df96f,null))[_0xeb98('0x4b')](handleError(_0x5df96f,null));};exports[_0xeb98('0x25')]=function(_0xcf8aa0,_0x45bdbc){return db[_0xeb98('0x2c')][_0xeb98('0x4a')]({'where':{'id':_0xcf8aa0['params']['id']}})[_0xeb98('0x42')](handleEntityNotFound(_0x45bdbc,null))[_0xeb98('0x42')](removeEntity(_0x45bdbc,null))[_0xeb98('0x4b')](handleError(_0x45bdbc,null));};exports[_0xeb98('0x4e')]=function(_0x9b8715,_0x27bf6c){return db[_0xeb98('0x2c')][_0xeb98('0x4e')]()['then'](respondWithResult(_0x27bf6c,null))['catch'](handleError(_0x27bf6c,null));};