1bdf6990c36d25b702aee4b20d080f97c2c8822d
[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 _0x8f24=['fs-extra','lodash','crypto','jsforce','desk.js','querystring','papaparse','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/utils','../../config/environment','../../config/license/util','../../mysqldb','sendStatus','status','end','json','offset','limit','undefined','count','set','apply','save','then','error','stack','name','send','map','OpenchannelQueueReport','rawAttributes','fieldName','key','query','keys','filters','model','attributes','intersection','fields','length','nolimit','order','sort','where','pick','filter','merge','type','VIRTUAL','includeAll','include','rows','catch','show','params','options','find','create','update','body','describe','bluebird','mustache','util','path','sox','to-csv','ejs'];(function(_0x58617b,_0x408203){var _0x13cd73=function(_0x522127){while(--_0x522127){_0x58617b['push'](_0x58617b['shift']());}};_0x13cd73(++_0x408203);}(_0x8f24,0x119));var _0x48f2=function(_0x2531ab,_0x17ab19){_0x2531ab=_0x2531ab-0x0;var _0x482d25=_0x8f24[_0x2531ab];return _0x482d25;};'use strict';var emlformat=require('eml-format');var rimraf=require('rimraf');var zipdir=require('zip-dir');var jsonpatch=require('fast-json-patch');var rp=require('request-promise');var moment=require('moment');var BPromise=require(_0x48f2('0x0'));var Mustache=require(_0x48f2('0x1'));var util=require(_0x48f2('0x2'));var path=require(_0x48f2('0x3'));var sox=require(_0x48f2('0x4'));var csv=require(_0x48f2('0x5'));var ejs=require(_0x48f2('0x6'));var fs=require('fs');var fs_extra=require(_0x48f2('0x7'));var _=require(_0x48f2('0x8'));var squel=require('squel');var crypto=require(_0x48f2('0x9'));var jsforce=require(_0x48f2('0xa'));var deskjs=require(_0x48f2('0xb'));var toCsv=require('to-csv');var querystring=require(_0x48f2('0xc'));var Papa=require(_0x48f2('0xd'));var Redis=require(_0x48f2('0xe'));var authService=require(_0x48f2('0xf'));var qs=require(_0x48f2('0x10'));var as=require(_0x48f2('0x11'));var hardwareService=require('../../config/license/hardware');var logger=require('../../config/logger')('api');var utils=require(_0x48f2('0x12'));var config=require(_0x48f2('0x13'));var licenseUtil=require(_0x48f2('0x14'));var db=require(_0x48f2('0x15'))['db'];function respondWithStatusCode(_0x18891c,_0x1188a2){_0x1188a2=_0x1188a2||0xcc;return function(_0x2408fc){if(_0x2408fc){return _0x18891c[_0x48f2('0x16')](_0x1188a2);}return _0x18891c[_0x48f2('0x17')](_0x1188a2)[_0x48f2('0x18')]();};}function respondWithResult(_0x37729d,_0x538ea7){_0x538ea7=_0x538ea7||0xc8;return function(_0x4a7a86){if(_0x4a7a86){return _0x37729d['status'](_0x538ea7)[_0x48f2('0x19')](_0x4a7a86);}};}function respondWithFilteredResult(_0x35e12f,_0x2704bd){return function(_0x3eb222){if(_0x3eb222){var _0x1b9fd7=typeof _0x2704bd[_0x48f2('0x1a')]==='undefined'&&typeof _0x2704bd[_0x48f2('0x1b')]===_0x48f2('0x1c');var _0x5613c0=_0x3eb222[_0x48f2('0x1d')];var _0x208b22=_0x1b9fd7?0x0:_0x2704bd[_0x48f2('0x1a')];var _0x199deb=_0x1b9fd7?_0x3eb222[_0x48f2('0x1d')]:_0x2704bd[_0x48f2('0x1a')]+_0x2704bd['limit'];var _0x32fc66;if(_0x199deb>=_0x5613c0){_0x199deb=_0x5613c0;_0x32fc66=0xc8;}else{_0x32fc66=0xce;}_0x35e12f[_0x48f2('0x17')](_0x32fc66);return _0x35e12f[_0x48f2('0x1e')]('Content-Range',_0x208b22+'-'+_0x199deb+'/'+_0x5613c0)[_0x48f2('0x19')](_0x3eb222);}return null;};}function patchUpdates(_0x21ecb2){return function(_0x263394){try{jsonpatch[_0x48f2('0x1f')](_0x263394,_0x21ecb2,!![]);}catch(_0x107685){return BPromise['reject'](_0x107685);}return _0x263394[_0x48f2('0x20')]();};}function saveUpdates(_0x432171,_0x437287){return function(_0x34162b){if(_0x34162b){return _0x34162b['update'](_0x432171)[_0x48f2('0x21')](function(_0x28ea77){return _0x28ea77;});}return null;};}function removeEntity(_0x3b00c7,_0x4aaae3){return function(_0x2cba1d){if(_0x2cba1d){return _0x2cba1d['destroy']()[_0x48f2('0x21')](function(){_0x3b00c7[_0x48f2('0x17')](0xcc)[_0x48f2('0x18')]();});}};}function handleEntityNotFound(_0xd9db48,_0x3a6d63){return function(_0x1f10f4){if(!_0x1f10f4){_0xd9db48[_0x48f2('0x16')](0x194);}return _0x1f10f4;};}function handleError(_0x2a4d64,_0xb563cc){_0xb563cc=_0xb563cc||0x1f4;return function(_0x50b805){logger[_0x48f2('0x22')](_0x50b805[_0x48f2('0x23')]);if(_0x50b805['name']){delete _0x50b805[_0x48f2('0x24')];}_0x2a4d64[_0x48f2('0x17')](_0xb563cc)[_0x48f2('0x25')](_0x50b805);};}exports['index']=function(_0x330d33,_0x35688a){var _0x3ebf73={},_0x1cb52b={},_0x144469={'count':0x0,'rows':[]};var _0x483019=_[_0x48f2('0x26')](db[_0x48f2('0x27')][_0x48f2('0x28')],function(_0x22d620){return{'name':_0x22d620[_0x48f2('0x29')],'type':_0x22d620['type'][_0x48f2('0x2a')]};});_0x1cb52b['model']=_[_0x48f2('0x26')](_0x483019,_0x48f2('0x24'));_0x1cb52b[_0x48f2('0x2b')]=_[_0x48f2('0x2c')](_0x330d33[_0x48f2('0x2b')]);_0x1cb52b[_0x48f2('0x2d')]=_['intersection'](_0x1cb52b[_0x48f2('0x2e')],_0x1cb52b[_0x48f2('0x2b')]);_0x3ebf73[_0x48f2('0x2f')]=_[_0x48f2('0x30')](_0x1cb52b[_0x48f2('0x2e')],qs['fields'](_0x330d33[_0x48f2('0x2b')][_0x48f2('0x31')]));_0x3ebf73[_0x48f2('0x2f')]=_0x3ebf73[_0x48f2('0x2f')][_0x48f2('0x32')]?_0x3ebf73[_0x48f2('0x2f')]:_0x1cb52b[_0x48f2('0x2e')];if(!_0x330d33['query']['hasOwnProperty'](_0x48f2('0x33'))){_0x3ebf73['limit']=qs[_0x48f2('0x1b')](_0x330d33[_0x48f2('0x2b')][_0x48f2('0x1b')]);_0x3ebf73['offset']=qs[_0x48f2('0x1a')](_0x330d33[_0x48f2('0x2b')][_0x48f2('0x1a')]);}_0x3ebf73[_0x48f2('0x34')]=qs[_0x48f2('0x35')](_0x330d33[_0x48f2('0x2b')][_0x48f2('0x35')]);_0x3ebf73[_0x48f2('0x36')]=qs[_0x48f2('0x2d')](_[_0x48f2('0x37')](_0x330d33[_0x48f2('0x2b')],_0x1cb52b[_0x48f2('0x2d')]),_0x483019);if(_0x330d33[_0x48f2('0x2b')][_0x48f2('0x38')]){_0x3ebf73[_0x48f2('0x36')]=_[_0x48f2('0x39')](_0x3ebf73['where'],{'$or':_[_0x48f2('0x26')](_0x483019,function(_0x12e82a){if(_0x12e82a[_0x48f2('0x3a')]!==_0x48f2('0x3b')){var _0x127502={};_0x127502[_0x12e82a[_0x48f2('0x24')]]={'$like':'%'+_0x330d33['query'][_0x48f2('0x38')]+'%'};return _0x127502;}})});}_0x3ebf73=_[_0x48f2('0x39')]({},_0x3ebf73,_0x330d33['options']);var _0x2fdf8f={'where':_0x3ebf73[_0x48f2('0x36')]};return db[_0x48f2('0x27')][_0x48f2('0x1d')](_0x2fdf8f)[_0x48f2('0x21')](function(_0x48409d){_0x144469['count']=_0x48409d;if(_0x330d33[_0x48f2('0x2b')][_0x48f2('0x3c')]){_0x3ebf73[_0x48f2('0x3d')]=[{'all':!![]}];}return db['OpenchannelQueueReport']['findAll'](_0x3ebf73);})[_0x48f2('0x21')](function(_0x228bb6){_0x144469[_0x48f2('0x3e')]=_0x228bb6;return _0x144469;})[_0x48f2('0x21')](respondWithFilteredResult(_0x35688a,_0x3ebf73))[_0x48f2('0x3f')](handleError(_0x35688a,null));};exports[_0x48f2('0x40')]=function(_0x549947,_0x4660fa){var _0x3901ea={'raw':!![],'where':{'id':_0x549947[_0x48f2('0x41')]['id']}},_0x46e569={};_0x46e569['model']=_[_0x48f2('0x2c')](db[_0x48f2('0x27')][_0x48f2('0x28')]);_0x46e569['query']=_[_0x48f2('0x2c')](_0x549947[_0x48f2('0x2b')]);_0x46e569[_0x48f2('0x2d')]=_[_0x48f2('0x30')](_0x46e569['model'],_0x46e569[_0x48f2('0x2b')]);_0x3901ea['attributes']=_[_0x48f2('0x30')](_0x46e569[_0x48f2('0x2e')],qs['fields'](_0x549947[_0x48f2('0x2b')]['fields']));_0x3901ea[_0x48f2('0x2f')]=_0x3901ea[_0x48f2('0x2f')][_0x48f2('0x32')]?_0x3901ea['attributes']:_0x46e569['model'];if(_0x549947['query'][_0x48f2('0x3c')]){_0x3901ea[_0x48f2('0x3d')]=[{'all':!![]}];}_0x3901ea=_[_0x48f2('0x39')]({},_0x3901ea,_0x549947[_0x48f2('0x42')]);return db[_0x48f2('0x27')][_0x48f2('0x43')](_0x3901ea)['then'](handleEntityNotFound(_0x4660fa,null))['then'](respondWithResult(_0x4660fa,null))['catch'](handleError(_0x4660fa,null));};exports[_0x48f2('0x44')]=function(_0x1c9b1a,_0x1f0053){return db[_0x48f2('0x27')][_0x48f2('0x44')](_0x1c9b1a['body'],{})[_0x48f2('0x21')](respondWithResult(_0x1f0053,0xc9))['catch'](handleError(_0x1f0053,null));};exports[_0x48f2('0x45')]=function(_0xee2bd5,_0x27d188){if(_0xee2bd5[_0x48f2('0x46')]['id']){delete _0xee2bd5[_0x48f2('0x46')]['id'];}return db['OpenchannelQueueReport'][_0x48f2('0x43')]({'where':{'id':_0xee2bd5[_0x48f2('0x41')]['id']}})[_0x48f2('0x21')](handleEntityNotFound(_0x27d188,null))['then'](saveUpdates(_0xee2bd5[_0x48f2('0x46')],null))['then'](respondWithResult(_0x27d188,null))[_0x48f2('0x3f')](handleError(_0x27d188,null));};exports['destroy']=function(_0x12932a,_0x1af2c3){return db[_0x48f2('0x27')][_0x48f2('0x43')]({'where':{'id':_0x12932a[_0x48f2('0x41')]['id']}})[_0x48f2('0x21')](handleEntityNotFound(_0x1af2c3,null))[_0x48f2('0x21')](removeEntity(_0x1af2c3,null))[_0x48f2('0x3f')](handleError(_0x1af2c3,null));};exports['describe']=function(_0x33ddb2,_0x16ae08){return db[_0x48f2('0x27')][_0x48f2('0x47')]()[_0x48f2('0x21')](respondWithResult(_0x16ae08,null))[_0x48f2('0x3f')](handleError(_0x16ae08,null));};