0c06324bf778708570910a5a19e0e52bda50109c
[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 _0xf427=['to-csv','ejs','fs-extra','lodash','crypto','jsforce','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/utils','../../config/environment','end','json','undefined','limit','count','offset','status','set','apply','reject','update','then','destroy','error','stack','name','map','OpenchannelQueueReport','type','key','model','query','keys','filters','attributes','intersection','fields','length','hasOwnProperty','nolimit','sort','where','pick','filter','VIRTUAL','merge','options','includeAll','include','params','find','create','body','catch','describe','eml-format','rimraf','zip-dir','fast-json-patch','request-promise','bluebird','mustache','path','sox'];(function(_0x17e9fa,_0x266b4d){var _0x594f93=function(_0x40bcca){while(--_0x40bcca){_0x17e9fa['push'](_0x17e9fa['shift']());}};_0x594f93(++_0x266b4d);}(_0xf427,0x7b));var _0x7f42=function(_0x2c75ad,_0x88fd95){_0x2c75ad=_0x2c75ad-0x0;var _0x43a37e=_0xf427[_0x2c75ad];return _0x43a37e;};'use strict';var emlformat=require(_0x7f42('0x0'));var rimraf=require(_0x7f42('0x1'));var zipdir=require(_0x7f42('0x2'));var jsonpatch=require(_0x7f42('0x3'));var rp=require(_0x7f42('0x4'));var moment=require('moment');var BPromise=require(_0x7f42('0x5'));var Mustache=require(_0x7f42('0x6'));var util=require('util');var path=require(_0x7f42('0x7'));var sox=require(_0x7f42('0x8'));var csv=require(_0x7f42('0x9'));var ejs=require(_0x7f42('0xa'));var fs=require('fs');var fs_extra=require(_0x7f42('0xb'));var _=require(_0x7f42('0xc'));var squel=require('squel');var crypto=require(_0x7f42('0xd'));var jsforce=require(_0x7f42('0xe'));var deskjs=require('desk.js');var toCsv=require(_0x7f42('0x9'));var querystring=require('querystring');var Papa=require('papaparse');var Redis=require(_0x7f42('0xf'));var authService=require(_0x7f42('0x10'));var qs=require(_0x7f42('0x11'));var as=require(_0x7f42('0x12'));var hardwareService=require('../../config/license/hardware');var logger=require('../../config/logger')('api');var utils=require(_0x7f42('0x13'));var config=require(_0x7f42('0x14'));var licenseUtil=require('../../config/license/util');var db=require('../../mysqldb')['db'];function respondWithStatusCode(_0x1aa217,_0x392a40){_0x392a40=_0x392a40||0xcc;return function(_0x24b404){if(_0x24b404){return _0x1aa217['sendStatus'](_0x392a40);}return _0x1aa217['status'](_0x392a40)[_0x7f42('0x15')]();};}function respondWithResult(_0xcbea7e,_0x432001){_0x432001=_0x432001||0xc8;return function(_0xff2463){if(_0xff2463){return _0xcbea7e['status'](_0x432001)[_0x7f42('0x16')](_0xff2463);}};}function respondWithFilteredResult(_0x16365d,_0x4fc58f){return function(_0xa172eb){if(_0xa172eb){var _0xbed035=typeof _0x4fc58f['offset']===_0x7f42('0x17')&&typeof _0x4fc58f[_0x7f42('0x18')]===_0x7f42('0x17');var _0x2515a9=_0xa172eb[_0x7f42('0x19')];var _0x4f9cf8=_0xbed035?0x0:_0x4fc58f[_0x7f42('0x1a')];var _0x3b5a28=_0xbed035?_0xa172eb['count']:_0x4fc58f[_0x7f42('0x1a')]+_0x4fc58f['limit'];var _0x221af6;if(_0x3b5a28>=_0x2515a9){_0x3b5a28=_0x2515a9;_0x221af6=0xc8;}else{_0x221af6=0xce;}_0x16365d[_0x7f42('0x1b')](_0x221af6);return _0x16365d[_0x7f42('0x1c')]('Content-Range',_0x4f9cf8+'-'+_0x3b5a28+'/'+_0x2515a9)[_0x7f42('0x16')](_0xa172eb);}return null;};}function patchUpdates(_0x3cfa08){return function(_0x2ab117){try{jsonpatch[_0x7f42('0x1d')](_0x2ab117,_0x3cfa08,!![]);}catch(_0x3b7d78){return BPromise[_0x7f42('0x1e')](_0x3b7d78);}return _0x2ab117['save']();};}function saveUpdates(_0x475cf2,_0x843ea9){return function(_0x2e11d6){if(_0x2e11d6){return _0x2e11d6[_0x7f42('0x1f')](_0x475cf2)[_0x7f42('0x20')](function(_0x51b15d){return _0x51b15d;});}return null;};}function removeEntity(_0x450651,_0x4445a5){return function(_0x221258){if(_0x221258){return _0x221258[_0x7f42('0x21')]()[_0x7f42('0x20')](function(){_0x450651['status'](0xcc)[_0x7f42('0x15')]();});}};}function handleEntityNotFound(_0x1809f7,_0x3ff5a6){return function(_0x45076d){if(!_0x45076d){_0x1809f7['sendStatus'](0x194);}return _0x45076d;};}function handleError(_0x15d5fb,_0x5c3148){_0x5c3148=_0x5c3148||0x1f4;return function(_0x505509){logger[_0x7f42('0x22')](_0x505509[_0x7f42('0x23')]);if(_0x505509[_0x7f42('0x24')]){delete _0x505509['name'];}_0x15d5fb[_0x7f42('0x1b')](_0x5c3148)['send'](_0x505509);};}exports['index']=function(_0x4f2f87,_0xb053d6){var _0x14a033={},_0x33e223={},_0x3b68b9={'count':0x0,'rows':[]};var _0x5de977=_[_0x7f42('0x25')](db[_0x7f42('0x26')]['rawAttributes'],function(_0x4f4911){return{'name':_0x4f4911['fieldName'],'type':_0x4f4911[_0x7f42('0x27')][_0x7f42('0x28')]};});_0x33e223[_0x7f42('0x29')]=_[_0x7f42('0x25')](_0x5de977,'name');_0x33e223[_0x7f42('0x2a')]=_[_0x7f42('0x2b')](_0x4f2f87['query']);_0x33e223[_0x7f42('0x2c')]=_['intersection'](_0x33e223['model'],_0x33e223[_0x7f42('0x2a')]);_0x14a033[_0x7f42('0x2d')]=_[_0x7f42('0x2e')](_0x33e223['model'],qs[_0x7f42('0x2f')](_0x4f2f87['query'][_0x7f42('0x2f')]));_0x14a033['attributes']=_0x14a033[_0x7f42('0x2d')][_0x7f42('0x30')]?_0x14a033['attributes']:_0x33e223['model'];if(!_0x4f2f87[_0x7f42('0x2a')][_0x7f42('0x31')](_0x7f42('0x32'))){_0x14a033[_0x7f42('0x18')]=qs[_0x7f42('0x18')](_0x4f2f87[_0x7f42('0x2a')][_0x7f42('0x18')]);_0x14a033[_0x7f42('0x1a')]=qs[_0x7f42('0x1a')](_0x4f2f87['query'][_0x7f42('0x1a')]);}_0x14a033['order']=qs[_0x7f42('0x33')](_0x4f2f87['query'][_0x7f42('0x33')]);_0x14a033[_0x7f42('0x34')]=qs['filters'](_[_0x7f42('0x35')](_0x4f2f87['query'],_0x33e223['filters']),_0x5de977);if(_0x4f2f87[_0x7f42('0x2a')][_0x7f42('0x36')]){_0x14a033[_0x7f42('0x34')]=_['merge'](_0x14a033['where'],{'$or':_[_0x7f42('0x25')](_0x5de977,function(_0x5e9ae9){if(_0x5e9ae9['type']!==_0x7f42('0x37')){var _0x51fac9={};_0x51fac9[_0x5e9ae9[_0x7f42('0x24')]]={'$like':'%'+_0x4f2f87[_0x7f42('0x2a')][_0x7f42('0x36')]+'%'};return _0x51fac9;}})});}_0x14a033=_[_0x7f42('0x38')]({},_0x14a033,_0x4f2f87[_0x7f42('0x39')]);var _0x3f7d69={'where':_0x14a033[_0x7f42('0x34')]};return db[_0x7f42('0x26')][_0x7f42('0x19')](_0x3f7d69)[_0x7f42('0x20')](function(_0x5343b6){_0x3b68b9[_0x7f42('0x19')]=_0x5343b6;if(_0x4f2f87[_0x7f42('0x2a')][_0x7f42('0x3a')]){_0x14a033[_0x7f42('0x3b')]=[{'all':!![]}];}return db[_0x7f42('0x26')]['findAll'](_0x14a033);})[_0x7f42('0x20')](function(_0x50bca3){_0x3b68b9['rows']=_0x50bca3;return _0x3b68b9;})[_0x7f42('0x20')](respondWithFilteredResult(_0xb053d6,_0x14a033))['catch'](handleError(_0xb053d6,null));};exports['show']=function(_0x5623a3,_0x5f35d1){var _0x1031dd={'raw':!![],'where':{'id':_0x5623a3[_0x7f42('0x3c')]['id']}},_0x47d403={};_0x47d403['model']=_[_0x7f42('0x2b')](db[_0x7f42('0x26')]['rawAttributes']);_0x47d403[_0x7f42('0x2a')]=_[_0x7f42('0x2b')](_0x5623a3[_0x7f42('0x2a')]);_0x47d403[_0x7f42('0x2c')]=_[_0x7f42('0x2e')](_0x47d403['model'],_0x47d403[_0x7f42('0x2a')]);_0x1031dd[_0x7f42('0x2d')]=_[_0x7f42('0x2e')](_0x47d403['model'],qs[_0x7f42('0x2f')](_0x5623a3['query']['fields']));_0x1031dd[_0x7f42('0x2d')]=_0x1031dd[_0x7f42('0x2d')]['length']?_0x1031dd[_0x7f42('0x2d')]:_0x47d403[_0x7f42('0x29')];if(_0x5623a3[_0x7f42('0x2a')][_0x7f42('0x3a')]){_0x1031dd['include']=[{'all':!![]}];}_0x1031dd=_['merge']({},_0x1031dd,_0x5623a3['options']);return db[_0x7f42('0x26')][_0x7f42('0x3d')](_0x1031dd)[_0x7f42('0x20')](handleEntityNotFound(_0x5f35d1,null))[_0x7f42('0x20')](respondWithResult(_0x5f35d1,null))['catch'](handleError(_0x5f35d1,null));};exports[_0x7f42('0x3e')]=function(_0x2abf34,_0x1baec9){return db[_0x7f42('0x26')][_0x7f42('0x3e')](_0x2abf34[_0x7f42('0x3f')],{})['then'](respondWithResult(_0x1baec9,0xc9))[_0x7f42('0x40')](handleError(_0x1baec9,null));};exports[_0x7f42('0x1f')]=function(_0x226e75,_0x1ab96e){if(_0x226e75[_0x7f42('0x3f')]['id']){delete _0x226e75[_0x7f42('0x3f')]['id'];}return db['OpenchannelQueueReport']['find']({'where':{'id':_0x226e75['params']['id']}})[_0x7f42('0x20')](handleEntityNotFound(_0x1ab96e,null))[_0x7f42('0x20')](saveUpdates(_0x226e75[_0x7f42('0x3f')],null))['then'](respondWithResult(_0x1ab96e,null))[_0x7f42('0x40')](handleError(_0x1ab96e,null));};exports[_0x7f42('0x21')]=function(_0x4374a1,_0x14c1fc){return db[_0x7f42('0x26')][_0x7f42('0x3d')]({'where':{'id':_0x4374a1[_0x7f42('0x3c')]['id']}})['then'](handleEntityNotFound(_0x14c1fc,null))['then'](removeEntity(_0x14c1fc,null))[_0x7f42('0x40')](handleError(_0x14c1fc,null));};exports[_0x7f42('0x41')]=function(_0x4b90d7,_0x5b9eb1){return db[_0x7f42('0x26')][_0x7f42('0x41')]()[_0x7f42('0x20')](respondWithResult(_0x5b9eb1,null))[_0x7f42('0x40')](handleError(_0x5b9eb1,null));};