10db003afba240ac949393a104c07843d0bbc0b5
[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 _0x2bd6=['reject','save','update','then','destroy','stack','name','send','index','map','OpenchannelQueueReport','rawAttributes','type','key','model','query','filters','intersection','fields','attributes','length','hasOwnProperty','nolimit','order','sort','pick','filter','where','merge','VIRTUAL','options','count','includeAll','include','findAll','rows','catch','show','params','keys','find','create','body','describe','html-pdf','eml-format','rimraf','zip-dir','fast-json-patch','moment','bluebird','mustache','path','ejs','lodash','crypto','jsforce','to-csv','querystring','papaparse','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','api','../../config/license/util','../../mysqldb','sendStatus','end','json','offset','limit','status','Content-Range'];(function(_0xce639,_0x6954df){var _0x357855=function(_0x26e8af){while(--_0x26e8af){_0xce639['push'](_0xce639['shift']());}};_0x357855(++_0x6954df);}(_0x2bd6,0x1f4));var _0x62bd=function(_0x3e112d,_0x2bb132){_0x3e112d=_0x3e112d-0x0;var _0x531c31=_0x2bd6[_0x3e112d];return _0x531c31;};'use strict';var pdf=require(_0x62bd('0x0'));var emlformat=require(_0x62bd('0x1'));var rimraf=require(_0x62bd('0x2'));var zipdir=require(_0x62bd('0x3'));var jsonpatch=require(_0x62bd('0x4'));var rp=require('request-promise');var moment=require(_0x62bd('0x5'));var BPromise=require(_0x62bd('0x6'));var Mustache=require(_0x62bd('0x7'));var util=require('util');var path=require(_0x62bd('0x8'));var sox=require('sox');var csv=require('to-csv');var ejs=require(_0x62bd('0x9'));var fs=require('fs');var _=require(_0x62bd('0xa'));var squel=require('squel');var crypto=require(_0x62bd('0xb'));var jsforce=require(_0x62bd('0xc'));var deskjs=require('desk.js');var toCsv=require(_0x62bd('0xd'));var querystring=require(_0x62bd('0xe'));var Papa=require(_0x62bd('0xf'));var Redis=require(_0x62bd('0x10'));var authService=require(_0x62bd('0x11'));var qs=require(_0x62bd('0x12'));var as=require(_0x62bd('0x13'));var hardwareService=require(_0x62bd('0x14'));var logger=require(_0x62bd('0x15'))(_0x62bd('0x16'));var utils=require('../../config/utils');var config=require('../../config/environment');var licenseUtil=require(_0x62bd('0x17'));var db=require(_0x62bd('0x18'))['db'];function respondWithStatusCode(_0x32941d,_0x7acd92){_0x7acd92=_0x7acd92||0xcc;return function(_0x2b1c2e){if(_0x2b1c2e){return _0x32941d[_0x62bd('0x19')](_0x7acd92);}return _0x32941d['status'](_0x7acd92)[_0x62bd('0x1a')]();};}function respondWithResult(_0x5d42f8,_0x1b751c){_0x1b751c=_0x1b751c||0xc8;return function(_0x5dc408){if(_0x5dc408){return _0x5d42f8['status'](_0x1b751c)[_0x62bd('0x1b')](_0x5dc408);}};}function respondWithFilteredResult(_0x397a41,_0x5260f9){return function(_0x3073e1){if(_0x3073e1){var _0x1d178b=_0x3073e1['count'],_0x3e2133=_0x5260f9[_0x62bd('0x1c')],_0x1a815e=_0x5260f9[_0x62bd('0x1c')]+_0x5260f9[_0x62bd('0x1d')],_0x16f723;if(_0x1a815e>=_0x1d178b){_0x1a815e=_0x1d178b;_0x16f723=0xc8;}else{_0x16f723=0xce;}_0x397a41[_0x62bd('0x1e')](_0x16f723);return _0x397a41['set'](_0x62bd('0x1f'),_0x3e2133+'-'+_0x1a815e+'/'+_0x1d178b)[_0x62bd('0x1b')](_0x3073e1);}return null;};}function patchUpdates(_0x204ac1){return function(_0x21613e){try{jsonpatch['apply'](_0x21613e,_0x204ac1,!![]);}catch(_0xb4953c){return BPromise[_0x62bd('0x20')](_0xb4953c);}return _0x21613e[_0x62bd('0x21')]();};}function saveUpdates(_0x2298d9,_0x482bff){return function(_0x3f8dc1){if(_0x3f8dc1){return _0x3f8dc1[_0x62bd('0x22')](_0x2298d9)[_0x62bd('0x23')](function(_0xa6bae9){return _0xa6bae9;});}return null;};}function removeEntity(_0x5ec823,_0x2d1d56){return function(_0x3bc39c){if(_0x3bc39c){return _0x3bc39c[_0x62bd('0x24')]()[_0x62bd('0x23')](function(){_0x5ec823[_0x62bd('0x1e')](0xcc)[_0x62bd('0x1a')]();});}};}function handleEntityNotFound(_0x245628,_0x304cf0){return function(_0x364258){if(!_0x364258){_0x245628[_0x62bd('0x19')](0x194);}return _0x364258;};}function handleError(_0xe02ab1,_0x2f5c03){_0x2f5c03=_0x2f5c03||0x1f4;return function(_0x45e4f2){logger['error'](_0x45e4f2[_0x62bd('0x25')]);if(_0x45e4f2[_0x62bd('0x26')]){delete _0x45e4f2['name'];}_0xe02ab1[_0x62bd('0x1e')](_0x2f5c03)[_0x62bd('0x27')](_0x45e4f2);};}exports[_0x62bd('0x28')]=function(_0x56890f,_0x191063){var _0x205d78={},_0x43add5={},_0x28ac58={'count':0x0,'rows':[]};var _0x2820f5=_[_0x62bd('0x29')](db[_0x62bd('0x2a')][_0x62bd('0x2b')],function(_0x532515){return{'name':_0x532515['fieldName'],'type':_0x532515[_0x62bd('0x2c')][_0x62bd('0x2d')]};});_0x43add5[_0x62bd('0x2e')]=_[_0x62bd('0x29')](_0x2820f5,_0x62bd('0x26'));_0x43add5[_0x62bd('0x2f')]=_['keys'](_0x56890f[_0x62bd('0x2f')]);_0x43add5[_0x62bd('0x30')]=_[_0x62bd('0x31')](_0x43add5[_0x62bd('0x2e')],_0x43add5[_0x62bd('0x2f')]);_0x205d78['attributes']=_[_0x62bd('0x31')](_0x43add5['model'],qs['fields'](_0x56890f[_0x62bd('0x2f')][_0x62bd('0x32')]));_0x205d78[_0x62bd('0x33')]=_0x205d78[_0x62bd('0x33')][_0x62bd('0x34')]?_0x205d78['attributes']:_0x43add5[_0x62bd('0x2e')];if(!_0x56890f[_0x62bd('0x2f')][_0x62bd('0x35')](_0x62bd('0x36'))){_0x205d78[_0x62bd('0x1d')]=qs[_0x62bd('0x1d')](_0x56890f[_0x62bd('0x2f')][_0x62bd('0x1d')]);_0x205d78[_0x62bd('0x1c')]=qs['offset'](_0x56890f[_0x62bd('0x2f')]['offset']);}_0x205d78[_0x62bd('0x37')]=qs['sort'](_0x56890f[_0x62bd('0x2f')][_0x62bd('0x38')]);_0x205d78['where']=qs[_0x62bd('0x30')](_[_0x62bd('0x39')](_0x56890f[_0x62bd('0x2f')],_0x43add5[_0x62bd('0x30')]),_0x2820f5);if(_0x56890f[_0x62bd('0x2f')][_0x62bd('0x3a')]){_0x205d78[_0x62bd('0x3b')]=_[_0x62bd('0x3c')](_0x205d78['where'],{'$or':_['map'](_0x2820f5,function(_0x1f4f7c){if(_0x1f4f7c[_0x62bd('0x2c')]!==_0x62bd('0x3d')){var _0x9b24a9={};_0x9b24a9[_0x1f4f7c[_0x62bd('0x26')]]={'$like':'%'+_0x56890f[_0x62bd('0x2f')][_0x62bd('0x3a')]+'%'};return _0x9b24a9;}})});}_0x205d78=_['merge']({},_0x205d78,_0x56890f[_0x62bd('0x3e')]);var _0x51ab8b={'where':_0x205d78[_0x62bd('0x3b')]};return db[_0x62bd('0x2a')][_0x62bd('0x3f')](_0x51ab8b)[_0x62bd('0x23')](function(_0x27b580){_0x28ac58['count']=_0x27b580;if(_0x56890f[_0x62bd('0x2f')][_0x62bd('0x40')]){_0x205d78[_0x62bd('0x41')]=[{'all':!![]}];}return db['OpenchannelQueueReport'][_0x62bd('0x42')](_0x205d78);})['then'](function(_0xa282f1){_0x28ac58[_0x62bd('0x43')]=_0xa282f1;return _0x28ac58;})[_0x62bd('0x23')](respondWithFilteredResult(_0x191063,_0x205d78))[_0x62bd('0x44')](handleError(_0x191063,null));};exports[_0x62bd('0x45')]=function(_0x33c7cf,_0x428211){var _0x411019={'raw':!![],'where':{'id':_0x33c7cf[_0x62bd('0x46')]['id']}},_0x42973a={};_0x42973a[_0x62bd('0x2e')]=_['keys'](db[_0x62bd('0x2a')][_0x62bd('0x2b')]);_0x42973a[_0x62bd('0x2f')]=_[_0x62bd('0x47')](_0x33c7cf[_0x62bd('0x2f')]);_0x42973a[_0x62bd('0x30')]=_[_0x62bd('0x31')](_0x42973a[_0x62bd('0x2e')],_0x42973a[_0x62bd('0x2f')]);_0x411019[_0x62bd('0x33')]=_[_0x62bd('0x31')](_0x42973a[_0x62bd('0x2e')],qs[_0x62bd('0x32')](_0x33c7cf[_0x62bd('0x2f')][_0x62bd('0x32')]));_0x411019['attributes']=_0x411019['attributes'][_0x62bd('0x34')]?_0x411019['attributes']:_0x42973a[_0x62bd('0x2e')];if(_0x33c7cf[_0x62bd('0x2f')][_0x62bd('0x40')]){_0x411019[_0x62bd('0x41')]=[{'all':!![]}];}_0x411019=_[_0x62bd('0x3c')]({},_0x411019,_0x33c7cf[_0x62bd('0x3e')]);return db[_0x62bd('0x2a')][_0x62bd('0x48')](_0x411019)['then'](handleEntityNotFound(_0x428211,null))['then'](respondWithResult(_0x428211,null))[_0x62bd('0x44')](handleError(_0x428211,null));};exports[_0x62bd('0x49')]=function(_0x37991c,_0x3d0d52){return db['OpenchannelQueueReport'][_0x62bd('0x49')](_0x37991c[_0x62bd('0x4a')],{})[_0x62bd('0x23')](respondWithResult(_0x3d0d52,0xc9))[_0x62bd('0x44')](handleError(_0x3d0d52,null));};exports[_0x62bd('0x22')]=function(_0x3b05f0,_0x51ce41){if(_0x3b05f0[_0x62bd('0x4a')]['id']){delete _0x3b05f0[_0x62bd('0x4a')]['id'];}return db[_0x62bd('0x2a')][_0x62bd('0x48')]({'where':{'id':_0x3b05f0[_0x62bd('0x46')]['id']}})[_0x62bd('0x23')](handleEntityNotFound(_0x51ce41,null))['then'](saveUpdates(_0x3b05f0['body'],null))['then'](respondWithResult(_0x51ce41,null))[_0x62bd('0x44')](handleError(_0x51ce41,null));};exports[_0x62bd('0x24')]=function(_0x4f9f45,_0x39df7f){return db[_0x62bd('0x2a')][_0x62bd('0x48')]({'where':{'id':_0x4f9f45['params']['id']}})['then'](handleEntityNotFound(_0x39df7f,null))[_0x62bd('0x23')](removeEntity(_0x39df7f,null))[_0x62bd('0x44')](handleError(_0x39df7f,null));};exports[_0x62bd('0x4b')]=function(_0xcdb38b,_0x4cebae){return db['OpenchannelQueueReport'][_0x62bd('0x4b')]()[_0x62bd('0x23')](respondWithResult(_0x4cebae,null))['catch'](handleError(_0x4cebae,null));};