47e132e2da535654487434a3cf5625a48dec22c9
[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 _0xa4fb=['sort','where','pick','filter','type','VIRTUAL','merge','options','includeAll','findAll','rows','catch','show','params','rawAttributes','include','find','create','body','describe','html-pdf','eml-format','rimraf','zip-dir','moment','bluebird','mustache','path','sox','to-csv','ejs','lodash','squel','crypto','jsforce','desk.js','papaparse','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','api','../../config/environment','../../config/license/util','../../mysqldb','sendStatus','status','end','json','count','offset','limit','Content-Range','apply','reject','save','update','destroy','then','error','stack','send','index','OpenchannelQueueReport','fieldName','key','model','map','name','query','keys','filters','intersection','attributes','fields','length','hasOwnProperty','nolimit'];(function(_0x21a9d9,_0x4d5ac8){var _0x46adce=function(_0xfdd336){while(--_0xfdd336){_0x21a9d9['push'](_0x21a9d9['shift']());}};_0x46adce(++_0x4d5ac8);}(_0xa4fb,0x150));var _0xba4f=function(_0x349367,_0x1cede2){_0x349367=_0x349367-0x0;var _0x14179b=_0xa4fb[_0x349367];return _0x14179b;};'use strict';var pdf=require(_0xba4f('0x0'));var emlformat=require(_0xba4f('0x1'));var rimraf=require(_0xba4f('0x2'));var zipdir=require(_0xba4f('0x3'));var jsonpatch=require('fast-json-patch');var rp=require('request-promise');var moment=require(_0xba4f('0x4'));var BPromise=require(_0xba4f('0x5'));var Mustache=require(_0xba4f('0x6'));var util=require('util');var path=require(_0xba4f('0x7'));var sox=require(_0xba4f('0x8'));var csv=require(_0xba4f('0x9'));var ejs=require(_0xba4f('0xa'));var fs=require('fs');var _=require(_0xba4f('0xb'));var squel=require(_0xba4f('0xc'));var crypto=require(_0xba4f('0xd'));var jsforce=require(_0xba4f('0xe'));var deskjs=require(_0xba4f('0xf'));var toCsv=require(_0xba4f('0x9'));var querystring=require('querystring');var Papa=require(_0xba4f('0x10'));var Redis=require('ioredis');var authService=require(_0xba4f('0x11'));var qs=require(_0xba4f('0x12'));var as=require(_0xba4f('0x13'));var hardwareService=require(_0xba4f('0x14'));var logger=require(_0xba4f('0x15'))(_0xba4f('0x16'));var utils=require('../../config/utils');var config=require(_0xba4f('0x17'));var licenseUtil=require(_0xba4f('0x18'));var db=require(_0xba4f('0x19'))['db'];function respondWithStatusCode(_0x35a461,_0x3a0216){_0x3a0216=_0x3a0216||0xcc;return function(_0x2e4e37){if(_0x2e4e37){return _0x35a461[_0xba4f('0x1a')](_0x3a0216);}return _0x35a461[_0xba4f('0x1b')](_0x3a0216)[_0xba4f('0x1c')]();};}function respondWithResult(_0xbccef6,_0x4b9e86){_0x4b9e86=_0x4b9e86||0xc8;return function(_0x4200a5){if(_0x4200a5){return _0xbccef6[_0xba4f('0x1b')](_0x4b9e86)[_0xba4f('0x1d')](_0x4200a5);}};}function respondWithFilteredResult(_0x5b9334,_0x5ad1e3){return function(_0x5a1e59){if(_0x5a1e59){var _0x26d144=_0x5a1e59[_0xba4f('0x1e')],_0x104caf=_0x5ad1e3[_0xba4f('0x1f')],_0xc0a442=_0x5ad1e3['offset']+_0x5ad1e3[_0xba4f('0x20')],_0x218dea;if(_0xc0a442>=_0x26d144){_0xc0a442=_0x26d144;_0x218dea=0xc8;}else{_0x218dea=0xce;}_0x5b9334[_0xba4f('0x1b')](_0x218dea);return _0x5b9334['set'](_0xba4f('0x21'),_0x104caf+'-'+_0xc0a442+'/'+_0x26d144)['json'](_0x5a1e59);}return null;};}function patchUpdates(_0x666124){return function(_0x11e784){try{jsonpatch[_0xba4f('0x22')](_0x11e784,_0x666124,!![]);}catch(_0x30581b){return BPromise[_0xba4f('0x23')](_0x30581b);}return _0x11e784[_0xba4f('0x24')]();};}function saveUpdates(_0x516024,_0x254ef9){return function(_0x44e6c2){if(_0x44e6c2){return _0x44e6c2[_0xba4f('0x25')](_0x516024)['then'](function(_0x17592f){return _0x17592f;});}return null;};}function removeEntity(_0x5a3ed0,_0x4bdddc){return function(_0x2a7f19){if(_0x2a7f19){return _0x2a7f19[_0xba4f('0x26')]()[_0xba4f('0x27')](function(){_0x5a3ed0[_0xba4f('0x1b')](0xcc)[_0xba4f('0x1c')]();});}};}function handleEntityNotFound(_0x277f93,_0x1e9b4f){return function(_0x5b9899){if(!_0x5b9899){_0x277f93['sendStatus'](0x194);}return _0x5b9899;};}function handleError(_0xd65629,_0x420099){_0x420099=_0x420099||0x1f4;return function(_0x3fa60b){logger[_0xba4f('0x28')](_0x3fa60b[_0xba4f('0x29')]);if(_0x3fa60b['name']){delete _0x3fa60b['name'];}_0xd65629[_0xba4f('0x1b')](_0x420099)[_0xba4f('0x2a')](_0x3fa60b);};}exports[_0xba4f('0x2b')]=function(_0x294be5,_0x2053d7){var _0x326443={},_0x16c6da={},_0xf3dd94={'count':0x0,'rows':[]};var _0x270012=_['map'](db[_0xba4f('0x2c')]['rawAttributes'],function(_0x9f5d82){return{'name':_0x9f5d82[_0xba4f('0x2d')],'type':_0x9f5d82['type'][_0xba4f('0x2e')]};});_0x16c6da[_0xba4f('0x2f')]=_[_0xba4f('0x30')](_0x270012,_0xba4f('0x31'));_0x16c6da[_0xba4f('0x32')]=_[_0xba4f('0x33')](_0x294be5[_0xba4f('0x32')]);_0x16c6da[_0xba4f('0x34')]=_[_0xba4f('0x35')](_0x16c6da[_0xba4f('0x2f')],_0x16c6da[_0xba4f('0x32')]);_0x326443[_0xba4f('0x36')]=_[_0xba4f('0x35')](_0x16c6da[_0xba4f('0x2f')],qs[_0xba4f('0x37')](_0x294be5[_0xba4f('0x32')][_0xba4f('0x37')]));_0x326443['attributes']=_0x326443[_0xba4f('0x36')][_0xba4f('0x38')]?_0x326443[_0xba4f('0x36')]:_0x16c6da[_0xba4f('0x2f')];if(!_0x294be5['query'][_0xba4f('0x39')](_0xba4f('0x3a'))){_0x326443[_0xba4f('0x20')]=qs[_0xba4f('0x20')](_0x294be5[_0xba4f('0x32')]['limit']);_0x326443['offset']=qs['offset'](_0x294be5['query'][_0xba4f('0x1f')]);}_0x326443['order']=qs['sort'](_0x294be5[_0xba4f('0x32')][_0xba4f('0x3b')]);_0x326443[_0xba4f('0x3c')]=qs[_0xba4f('0x34')](_[_0xba4f('0x3d')](_0x294be5[_0xba4f('0x32')],_0x16c6da[_0xba4f('0x34')]),_0x270012);if(_0x294be5[_0xba4f('0x32')][_0xba4f('0x3e')]){_0x326443[_0xba4f('0x3c')]=_['merge'](_0x326443[_0xba4f('0x3c')],{'$or':_['map'](_0x270012,function(_0x1cef6f){if(_0x1cef6f[_0xba4f('0x3f')]!==_0xba4f('0x40')){var _0x5d2700={};_0x5d2700[_0x1cef6f[_0xba4f('0x31')]]={'$like':'%'+_0x294be5[_0xba4f('0x32')]['filter']+'%'};return _0x5d2700;}})});}_0x326443=_[_0xba4f('0x41')]({},_0x326443,_0x294be5[_0xba4f('0x42')]);var _0xd7efa6={'where':_0x326443['where']};return db[_0xba4f('0x2c')][_0xba4f('0x1e')](_0xd7efa6)[_0xba4f('0x27')](function(_0x249748){_0xf3dd94['count']=_0x249748;if(_0x294be5['query'][_0xba4f('0x43')]){_0x326443['include']=[{'all':!![]}];}return db[_0xba4f('0x2c')][_0xba4f('0x44')](_0x326443);})[_0xba4f('0x27')](function(_0x226c19){_0xf3dd94[_0xba4f('0x45')]=_0x226c19;return _0xf3dd94;})[_0xba4f('0x27')](respondWithFilteredResult(_0x2053d7,_0x326443))[_0xba4f('0x46')](handleError(_0x2053d7,null));};exports[_0xba4f('0x47')]=function(_0x9e1543,_0x45c860){var _0x348a38={'raw':!![],'where':{'id':_0x9e1543[_0xba4f('0x48')]['id']}},_0x3b3b91={};_0x3b3b91[_0xba4f('0x2f')]=_['keys'](db[_0xba4f('0x2c')][_0xba4f('0x49')]);_0x3b3b91[_0xba4f('0x32')]=_['keys'](_0x9e1543[_0xba4f('0x32')]);_0x3b3b91[_0xba4f('0x34')]=_[_0xba4f('0x35')](_0x3b3b91['model'],_0x3b3b91['query']);_0x348a38[_0xba4f('0x36')]=_['intersection'](_0x3b3b91[_0xba4f('0x2f')],qs['fields'](_0x9e1543[_0xba4f('0x32')]['fields']));_0x348a38[_0xba4f('0x36')]=_0x348a38[_0xba4f('0x36')][_0xba4f('0x38')]?_0x348a38[_0xba4f('0x36')]:_0x3b3b91[_0xba4f('0x2f')];if(_0x9e1543['query'][_0xba4f('0x43')]){_0x348a38[_0xba4f('0x4a')]=[{'all':!![]}];}_0x348a38=_['merge']({},_0x348a38,_0x9e1543[_0xba4f('0x42')]);return db[_0xba4f('0x2c')][_0xba4f('0x4b')](_0x348a38)[_0xba4f('0x27')](handleEntityNotFound(_0x45c860,null))[_0xba4f('0x27')](respondWithResult(_0x45c860,null))[_0xba4f('0x46')](handleError(_0x45c860,null));};exports[_0xba4f('0x4c')]=function(_0x4fe97f,_0x8d4774){return db[_0xba4f('0x2c')][_0xba4f('0x4c')](_0x4fe97f[_0xba4f('0x4d')],{})[_0xba4f('0x27')](respondWithResult(_0x8d4774,0xc9))[_0xba4f('0x46')](handleError(_0x8d4774,null));};exports['update']=function(_0x3f0eb,_0x11f508){if(_0x3f0eb[_0xba4f('0x4d')]['id']){delete _0x3f0eb[_0xba4f('0x4d')]['id'];}return db[_0xba4f('0x2c')][_0xba4f('0x4b')]({'where':{'id':_0x3f0eb[_0xba4f('0x48')]['id']}})[_0xba4f('0x27')](handleEntityNotFound(_0x11f508,null))[_0xba4f('0x27')](saveUpdates(_0x3f0eb[_0xba4f('0x4d')],null))[_0xba4f('0x27')](respondWithResult(_0x11f508,null))[_0xba4f('0x46')](handleError(_0x11f508,null));};exports[_0xba4f('0x26')]=function(_0x15703a,_0x37c0c1){return db['OpenchannelQueueReport'][_0xba4f('0x4b')]({'where':{'id':_0x15703a['params']['id']}})[_0xba4f('0x27')](handleEntityNotFound(_0x37c0c1,null))['then'](removeEntity(_0x37c0c1,null))[_0xba4f('0x46')](handleError(_0x37c0c1,null));};exports['describe']=function(_0x430130,_0x208013){return db[_0xba4f('0x2c')][_0xba4f('0x4e')]()[_0xba4f('0x27')](respondWithResult(_0x208013,null))['catch'](handleError(_0x208013,null));};