Built motion from commit efa66e19.|2.6.22
[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 _0x91f2=['index','rawAttributes','type','model','map','query','keys','intersection','fields','attributes','hasOwnProperty','nolimit','sort','filters','where','VIRTUAL','filter','options','OpenchannelQueueReport','includeAll','include','findAll','rows','catch','show','params','merge','create','body','update','find','describe','eml-format','rimraf','zip-dir','moment','bluebird','mustache','path','sox','ejs','fs-extra','lodash','squel','crypto','jsforce','to-csv','querystring','papaparse','ioredis','../../components/parsers/advancedSearch','api','../../config/utils','../../config/environment','../../config/license/util','../../mysqldb','sendStatus','status','end','json','offset','limit','undefined','count','set','Content-Range','apply','reject','save','then','destroy','error','stack','name','send'];(function(_0x31368f,_0x21735d){var _0x5c59f6=function(_0x1a7606){while(--_0x1a7606){_0x31368f['push'](_0x31368f['shift']());}};_0x5c59f6(++_0x21735d);}(_0x91f2,0x197));var _0x291f=function(_0x2e4d88,_0x288f33){_0x2e4d88=_0x2e4d88-0x0;var _0x1c6eb1=_0x91f2[_0x2e4d88];return _0x1c6eb1;};'use strict';var emlformat=require(_0x291f('0x0'));var rimraf=require(_0x291f('0x1'));var zipdir=require(_0x291f('0x2'));var jsonpatch=require('fast-json-patch');var rp=require('request-promise');var moment=require(_0x291f('0x3'));var BPromise=require(_0x291f('0x4'));var Mustache=require(_0x291f('0x5'));var util=require('util');var path=require(_0x291f('0x6'));var sox=require(_0x291f('0x7'));var csv=require('to-csv');var ejs=require(_0x291f('0x8'));var fs=require('fs');var fs_extra=require(_0x291f('0x9'));var _=require(_0x291f('0xa'));var squel=require(_0x291f('0xb'));var crypto=require(_0x291f('0xc'));var jsforce=require(_0x291f('0xd'));var deskjs=require('desk.js');var toCsv=require(_0x291f('0xe'));var querystring=require(_0x291f('0xf'));var Papa=require(_0x291f('0x10'));var Redis=require(_0x291f('0x11'));var authService=require('../../components/auth/service');var qs=require('../../components/parsers/qs');var as=require(_0x291f('0x12'));var hardwareService=require('../../config/license/hardware');var logger=require('../../config/logger')(_0x291f('0x13'));var utils=require(_0x291f('0x14'));var config=require(_0x291f('0x15'));var licenseUtil=require(_0x291f('0x16'));var db=require(_0x291f('0x17'))['db'];function respondWithStatusCode(_0x2979f4,_0x13a61e){_0x13a61e=_0x13a61e||0xcc;return function(_0x385c26){if(_0x385c26){return _0x2979f4[_0x291f('0x18')](_0x13a61e);}return _0x2979f4[_0x291f('0x19')](_0x13a61e)[_0x291f('0x1a')]();};}function respondWithResult(_0x58e3cd,_0x31594){_0x31594=_0x31594||0xc8;return function(_0x497082){if(_0x497082){return _0x58e3cd['status'](_0x31594)[_0x291f('0x1b')](_0x497082);}};}function respondWithFilteredResult(_0x1e374f,_0x4332f7){return function(_0x4a5e07){if(_0x4a5e07){var _0x5ccae0=typeof _0x4332f7[_0x291f('0x1c')]==='undefined'&&typeof _0x4332f7[_0x291f('0x1d')]===_0x291f('0x1e');var _0x53661e=_0x4a5e07[_0x291f('0x1f')];var _0x1787c2=_0x5ccae0?0x0:_0x4332f7[_0x291f('0x1c')];var _0x5104bd=_0x5ccae0?_0x4a5e07[_0x291f('0x1f')]:_0x4332f7[_0x291f('0x1c')]+_0x4332f7[_0x291f('0x1d')];var _0x6ab60f;if(_0x5104bd>=_0x53661e){_0x5104bd=_0x53661e;_0x6ab60f=0xc8;}else{_0x6ab60f=0xce;}_0x1e374f['status'](_0x6ab60f);return _0x1e374f[_0x291f('0x20')](_0x291f('0x21'),_0x1787c2+'-'+_0x5104bd+'/'+_0x53661e)[_0x291f('0x1b')](_0x4a5e07);}return null;};}function patchUpdates(_0x47ee4b){return function(_0x3a5893){try{jsonpatch[_0x291f('0x22')](_0x3a5893,_0x47ee4b,!![]);}catch(_0x48b622){return BPromise[_0x291f('0x23')](_0x48b622);}return _0x3a5893[_0x291f('0x24')]();};}function saveUpdates(_0x685662,_0x3a2bf1){return function(_0x33ca23){if(_0x33ca23){return _0x33ca23['update'](_0x685662)[_0x291f('0x25')](function(_0x5c6127){return _0x5c6127;});}return null;};}function removeEntity(_0x3ef69b,_0x23b607){return function(_0xe502bb){if(_0xe502bb){return _0xe502bb[_0x291f('0x26')]()[_0x291f('0x25')](function(){_0x3ef69b[_0x291f('0x19')](0xcc)[_0x291f('0x1a')]();});}};}function handleEntityNotFound(_0x19ff81,_0x635ad4){return function(_0x1247b0){if(!_0x1247b0){_0x19ff81[_0x291f('0x18')](0x194);}return _0x1247b0;};}function handleError(_0x458fd6,_0x35bc35){_0x35bc35=_0x35bc35||0x1f4;return function(_0x2523ed){logger[_0x291f('0x27')](_0x2523ed[_0x291f('0x28')]);if(_0x2523ed[_0x291f('0x29')]){delete _0x2523ed[_0x291f('0x29')];}_0x458fd6[_0x291f('0x19')](_0x35bc35)[_0x291f('0x2a')](_0x2523ed);};}exports[_0x291f('0x2b')]=function(_0x1f885c,_0x165d3f){var _0x2db58e={},_0x552268={},_0x27654c={'count':0x0,'rows':[]};var _0x3400a9=_['map'](db['OpenchannelQueueReport'][_0x291f('0x2c')],function(_0x32e31e){return{'name':_0x32e31e['fieldName'],'type':_0x32e31e[_0x291f('0x2d')]['key']};});_0x552268[_0x291f('0x2e')]=_[_0x291f('0x2f')](_0x3400a9,_0x291f('0x29'));_0x552268[_0x291f('0x30')]=_[_0x291f('0x31')](_0x1f885c[_0x291f('0x30')]);_0x552268['filters']=_[_0x291f('0x32')](_0x552268[_0x291f('0x2e')],_0x552268[_0x291f('0x30')]);_0x2db58e['attributes']=_[_0x291f('0x32')](_0x552268[_0x291f('0x2e')],qs[_0x291f('0x33')](_0x1f885c[_0x291f('0x30')][_0x291f('0x33')]));_0x2db58e[_0x291f('0x34')]=_0x2db58e[_0x291f('0x34')]['length']?_0x2db58e['attributes']:_0x552268[_0x291f('0x2e')];if(!_0x1f885c[_0x291f('0x30')][_0x291f('0x35')](_0x291f('0x36'))){_0x2db58e[_0x291f('0x1d')]=qs[_0x291f('0x1d')](_0x1f885c[_0x291f('0x30')][_0x291f('0x1d')]);_0x2db58e[_0x291f('0x1c')]=qs[_0x291f('0x1c')](_0x1f885c[_0x291f('0x30')]['offset']);}_0x2db58e['order']=qs[_0x291f('0x37')](_0x1f885c[_0x291f('0x30')]['sort']);_0x2db58e['where']=qs['filters'](_['pick'](_0x1f885c[_0x291f('0x30')],_0x552268[_0x291f('0x38')]),_0x3400a9);if(_0x1f885c['query']['filter']){_0x2db58e[_0x291f('0x39')]=_['merge'](_0x2db58e['where'],{'$or':_[_0x291f('0x2f')](_0x3400a9,function(_0x55b6c3){if(_0x55b6c3[_0x291f('0x2d')]!==_0x291f('0x3a')){var _0x5c88e3={};_0x5c88e3[_0x55b6c3[_0x291f('0x29')]]={'$like':'%'+_0x1f885c[_0x291f('0x30')][_0x291f('0x3b')]+'%'};return _0x5c88e3;}})});}_0x2db58e=_['merge']({},_0x2db58e,_0x1f885c[_0x291f('0x3c')]);var _0x4d8b09={'where':_0x2db58e[_0x291f('0x39')]};return db[_0x291f('0x3d')][_0x291f('0x1f')](_0x4d8b09)[_0x291f('0x25')](function(_0x1422f4){_0x27654c[_0x291f('0x1f')]=_0x1422f4;if(_0x1f885c[_0x291f('0x30')][_0x291f('0x3e')]){_0x2db58e[_0x291f('0x3f')]=[{'all':!![]}];}return db['OpenchannelQueueReport'][_0x291f('0x40')](_0x2db58e);})[_0x291f('0x25')](function(_0x535de4){_0x27654c[_0x291f('0x41')]=_0x535de4;return _0x27654c;})[_0x291f('0x25')](respondWithFilteredResult(_0x165d3f,_0x2db58e))[_0x291f('0x42')](handleError(_0x165d3f,null));};exports[_0x291f('0x43')]=function(_0x228297,_0x3a469c){var _0x318481={'raw':!![],'where':{'id':_0x228297[_0x291f('0x44')]['id']}},_0xdcc576={};_0xdcc576[_0x291f('0x2e')]=_['keys'](db['OpenchannelQueueReport'][_0x291f('0x2c')]);_0xdcc576[_0x291f('0x30')]=_['keys'](_0x228297['query']);_0xdcc576[_0x291f('0x38')]=_['intersection'](_0xdcc576[_0x291f('0x2e')],_0xdcc576[_0x291f('0x30')]);_0x318481[_0x291f('0x34')]=_['intersection'](_0xdcc576[_0x291f('0x2e')],qs[_0x291f('0x33')](_0x228297[_0x291f('0x30')][_0x291f('0x33')]));_0x318481[_0x291f('0x34')]=_0x318481[_0x291f('0x34')]['length']?_0x318481[_0x291f('0x34')]:_0xdcc576[_0x291f('0x2e')];if(_0x228297[_0x291f('0x30')][_0x291f('0x3e')]){_0x318481[_0x291f('0x3f')]=[{'all':!![]}];}_0x318481=_[_0x291f('0x45')]({},_0x318481,_0x228297['options']);return db['OpenchannelQueueReport']['find'](_0x318481)[_0x291f('0x25')](handleEntityNotFound(_0x3a469c,null))['then'](respondWithResult(_0x3a469c,null))['catch'](handleError(_0x3a469c,null));};exports['create']=function(_0x36e5fd,_0x819a1){return db[_0x291f('0x3d')][_0x291f('0x46')](_0x36e5fd[_0x291f('0x47')],{})['then'](respondWithResult(_0x819a1,0xc9))[_0x291f('0x42')](handleError(_0x819a1,null));};exports[_0x291f('0x48')]=function(_0x3b3d72,_0x393f16){if(_0x3b3d72[_0x291f('0x47')]['id']){delete _0x3b3d72['body']['id'];}return db[_0x291f('0x3d')][_0x291f('0x49')]({'where':{'id':_0x3b3d72['params']['id']}})['then'](handleEntityNotFound(_0x393f16,null))[_0x291f('0x25')](saveUpdates(_0x3b3d72['body'],null))[_0x291f('0x25')](respondWithResult(_0x393f16,null))[_0x291f('0x42')](handleError(_0x393f16,null));};exports[_0x291f('0x26')]=function(_0x27b345,_0x1e6deb){return db[_0x291f('0x3d')]['find']({'where':{'id':_0x27b345[_0x291f('0x44')]['id']}})[_0x291f('0x25')](handleEntityNotFound(_0x1e6deb,null))[_0x291f('0x25')](removeEntity(_0x1e6deb,null))[_0x291f('0x42')](handleError(_0x1e6deb,null));};exports[_0x291f('0x4a')]=function(_0x2c31b2,_0x1e4254){return db['OpenchannelQueueReport'][_0x291f('0x4a')]()[_0x291f('0x25')](respondWithResult(_0x1e4254,null))[_0x291f('0x42')](handleError(_0x1e4254,null));};