Built motion from commit 5ae82ce5.|2.6.7
[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 _0xfb9f=['catch','show','params','rawAttributes','include','create','body','find','destroy','describe','eml-format','zip-dir','fast-json-patch','request-promise','bluebird','util','path','sox','to-csv','ejs','fs-extra','lodash','crypto','desk.js','querystring','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/utils','../../mysqldb','status','end','offset','undefined','limit','count','set','Content-Range','json','apply','reject','save','update','then','sendStatus','error','stack','name','send','index','fieldName','type','key','model','map','query','keys','filters','intersection','fields','attributes','length','hasOwnProperty','nolimit','order','sort','where','pick','filter','options','OpenchannelQueueReport','findAll','rows'];(function(_0x469c6c,_0x5daf29){var _0x2e9b29=function(_0x143263){while(--_0x143263){_0x469c6c['push'](_0x469c6c['shift']());}};_0x2e9b29(++_0x5daf29);}(_0xfb9f,0x17c));var _0xffb9=function(_0x52b50b,_0x5d60b8){_0x52b50b=_0x52b50b-0x0;var _0x41d66c=_0xfb9f[_0x52b50b];return _0x41d66c;};'use strict';var emlformat=require(_0xffb9('0x0'));var rimraf=require('rimraf');var zipdir=require(_0xffb9('0x1'));var jsonpatch=require(_0xffb9('0x2'));var rp=require(_0xffb9('0x3'));var moment=require('moment');var BPromise=require(_0xffb9('0x4'));var Mustache=require('mustache');var util=require(_0xffb9('0x5'));var path=require(_0xffb9('0x6'));var sox=require(_0xffb9('0x7'));var csv=require(_0xffb9('0x8'));var ejs=require(_0xffb9('0x9'));var fs=require('fs');var fs_extra=require(_0xffb9('0xa'));var _=require(_0xffb9('0xb'));var squel=require('squel');var crypto=require(_0xffb9('0xc'));var jsforce=require('jsforce');var deskjs=require(_0xffb9('0xd'));var toCsv=require('to-csv');var querystring=require(_0xffb9('0xe'));var Papa=require('papaparse');var Redis=require('ioredis');var authService=require(_0xffb9('0xf'));var qs=require(_0xffb9('0x10'));var as=require(_0xffb9('0x11'));var hardwareService=require(_0xffb9('0x12'));var logger=require('../../config/logger')('api');var utils=require(_0xffb9('0x13'));var config=require('../../config/environment');var licenseUtil=require('../../config/license/util');var db=require(_0xffb9('0x14'))['db'];function respondWithStatusCode(_0x1aafe0,_0x43e25f){_0x43e25f=_0x43e25f||0xcc;return function(_0x1ebdaf){if(_0x1ebdaf){return _0x1aafe0['sendStatus'](_0x43e25f);}return _0x1aafe0[_0xffb9('0x15')](_0x43e25f)[_0xffb9('0x16')]();};}function respondWithResult(_0x15ddab,_0x41877f){_0x41877f=_0x41877f||0xc8;return function(_0x11f103){if(_0x11f103){return _0x15ddab['status'](_0x41877f)['json'](_0x11f103);}};}function respondWithFilteredResult(_0x3e8fec,_0x518ef5){return function(_0x401fae){if(_0x401fae){var _0x4df98a=typeof _0x518ef5[_0xffb9('0x17')]===_0xffb9('0x18')&&typeof _0x518ef5[_0xffb9('0x19')]===_0xffb9('0x18');var _0xdae423=_0x401fae[_0xffb9('0x1a')];var _0x474ace=_0x4df98a?0x0:_0x518ef5[_0xffb9('0x17')];var _0x2fcb02=_0x4df98a?_0x401fae[_0xffb9('0x1a')]:_0x518ef5[_0xffb9('0x17')]+_0x518ef5[_0xffb9('0x19')];var _0x5b8c71;if(_0x2fcb02>=_0xdae423){_0x2fcb02=_0xdae423;_0x5b8c71=0xc8;}else{_0x5b8c71=0xce;}_0x3e8fec[_0xffb9('0x15')](_0x5b8c71);return _0x3e8fec[_0xffb9('0x1b')](_0xffb9('0x1c'),_0x474ace+'-'+_0x2fcb02+'/'+_0xdae423)[_0xffb9('0x1d')](_0x401fae);}return null;};}function patchUpdates(_0x3926ef){return function(_0x16357e){try{jsonpatch[_0xffb9('0x1e')](_0x16357e,_0x3926ef,!![]);}catch(_0x31809f){return BPromise[_0xffb9('0x1f')](_0x31809f);}return _0x16357e[_0xffb9('0x20')]();};}function saveUpdates(_0xfaa361,_0x4e2c0c){return function(_0x108011){if(_0x108011){return _0x108011[_0xffb9('0x21')](_0xfaa361)[_0xffb9('0x22')](function(_0x29ec0c){return _0x29ec0c;});}return null;};}function removeEntity(_0x546bc7,_0x8168f5){return function(_0x185c56){if(_0x185c56){return _0x185c56['destroy']()[_0xffb9('0x22')](function(){_0x546bc7[_0xffb9('0x15')](0xcc)[_0xffb9('0x16')]();});}};}function handleEntityNotFound(_0x1fc1bc,_0x5077cb){return function(_0x5b5db0){if(!_0x5b5db0){_0x1fc1bc[_0xffb9('0x23')](0x194);}return _0x5b5db0;};}function handleError(_0x3727a9,_0x122789){_0x122789=_0x122789||0x1f4;return function(_0x292615){logger[_0xffb9('0x24')](_0x292615[_0xffb9('0x25')]);if(_0x292615[_0xffb9('0x26')]){delete _0x292615[_0xffb9('0x26')];}_0x3727a9[_0xffb9('0x15')](_0x122789)[_0xffb9('0x27')](_0x292615);};}exports[_0xffb9('0x28')]=function(_0x5e73bd,_0x627ccb){var _0x2a970c={},_0x483afa={},_0x7310d9={'count':0x0,'rows':[]};var _0x3e33d2=_['map'](db['OpenchannelQueueReport']['rawAttributes'],function(_0x5ada83){return{'name':_0x5ada83[_0xffb9('0x29')],'type':_0x5ada83[_0xffb9('0x2a')][_0xffb9('0x2b')]};});_0x483afa[_0xffb9('0x2c')]=_[_0xffb9('0x2d')](_0x3e33d2,'name');_0x483afa[_0xffb9('0x2e')]=_[_0xffb9('0x2f')](_0x5e73bd[_0xffb9('0x2e')]);_0x483afa[_0xffb9('0x30')]=_[_0xffb9('0x31')](_0x483afa[_0xffb9('0x2c')],_0x483afa[_0xffb9('0x2e')]);_0x2a970c['attributes']=_['intersection'](_0x483afa[_0xffb9('0x2c')],qs[_0xffb9('0x32')](_0x5e73bd['query']['fields']));_0x2a970c[_0xffb9('0x33')]=_0x2a970c[_0xffb9('0x33')][_0xffb9('0x34')]?_0x2a970c[_0xffb9('0x33')]:_0x483afa['model'];if(!_0x5e73bd[_0xffb9('0x2e')][_0xffb9('0x35')](_0xffb9('0x36'))){_0x2a970c['limit']=qs[_0xffb9('0x19')](_0x5e73bd['query'][_0xffb9('0x19')]);_0x2a970c['offset']=qs['offset'](_0x5e73bd[_0xffb9('0x2e')][_0xffb9('0x17')]);}_0x2a970c[_0xffb9('0x37')]=qs[_0xffb9('0x38')](_0x5e73bd['query']['sort']);_0x2a970c[_0xffb9('0x39')]=qs[_0xffb9('0x30')](_[_0xffb9('0x3a')](_0x5e73bd[_0xffb9('0x2e')],_0x483afa['filters']),_0x3e33d2);if(_0x5e73bd[_0xffb9('0x2e')]['filter']){_0x2a970c[_0xffb9('0x39')]=_['merge'](_0x2a970c[_0xffb9('0x39')],{'$or':_['map'](_0x3e33d2,function(_0x2f9619){if(_0x2f9619['type']!=='VIRTUAL'){var _0x2cbf00={};_0x2cbf00[_0x2f9619[_0xffb9('0x26')]]={'$like':'%'+_0x5e73bd[_0xffb9('0x2e')][_0xffb9('0x3b')]+'%'};return _0x2cbf00;}})});}_0x2a970c=_['merge']({},_0x2a970c,_0x5e73bd[_0xffb9('0x3c')]);var _0x16ea9f={'where':_0x2a970c[_0xffb9('0x39')]};return db[_0xffb9('0x3d')][_0xffb9('0x1a')](_0x16ea9f)[_0xffb9('0x22')](function(_0x1e4fba){_0x7310d9[_0xffb9('0x1a')]=_0x1e4fba;if(_0x5e73bd['query']['includeAll']){_0x2a970c['include']=[{'all':!![]}];}return db['OpenchannelQueueReport'][_0xffb9('0x3e')](_0x2a970c);})[_0xffb9('0x22')](function(_0x8623ff){_0x7310d9[_0xffb9('0x3f')]=_0x8623ff;return _0x7310d9;})['then'](respondWithFilteredResult(_0x627ccb,_0x2a970c))[_0xffb9('0x40')](handleError(_0x627ccb,null));};exports[_0xffb9('0x41')]=function(_0x50c167,_0xfaab07){var _0x2644be={'raw':!![],'where':{'id':_0x50c167[_0xffb9('0x42')]['id']}},_0x417720={};_0x417720['model']=_['keys'](db[_0xffb9('0x3d')][_0xffb9('0x43')]);_0x417720[_0xffb9('0x2e')]=_[_0xffb9('0x2f')](_0x50c167['query']);_0x417720['filters']=_[_0xffb9('0x31')](_0x417720[_0xffb9('0x2c')],_0x417720[_0xffb9('0x2e')]);_0x2644be[_0xffb9('0x33')]=_[_0xffb9('0x31')](_0x417720[_0xffb9('0x2c')],qs[_0xffb9('0x32')](_0x50c167[_0xffb9('0x2e')]['fields']));_0x2644be[_0xffb9('0x33')]=_0x2644be[_0xffb9('0x33')][_0xffb9('0x34')]?_0x2644be['attributes']:_0x417720[_0xffb9('0x2c')];if(_0x50c167[_0xffb9('0x2e')]['includeAll']){_0x2644be[_0xffb9('0x44')]=[{'all':!![]}];}_0x2644be=_['merge']({},_0x2644be,_0x50c167[_0xffb9('0x3c')]);return db[_0xffb9('0x3d')]['find'](_0x2644be)[_0xffb9('0x22')](handleEntityNotFound(_0xfaab07,null))['then'](respondWithResult(_0xfaab07,null))[_0xffb9('0x40')](handleError(_0xfaab07,null));};exports[_0xffb9('0x45')]=function(_0x53b911,_0x4b6907){return db[_0xffb9('0x3d')][_0xffb9('0x45')](_0x53b911[_0xffb9('0x46')],{})[_0xffb9('0x22')](respondWithResult(_0x4b6907,0xc9))[_0xffb9('0x40')](handleError(_0x4b6907,null));};exports[_0xffb9('0x21')]=function(_0x53653c,_0x710bf9){if(_0x53653c[_0xffb9('0x46')]['id']){delete _0x53653c[_0xffb9('0x46')]['id'];}return db[_0xffb9('0x3d')][_0xffb9('0x47')]({'where':{'id':_0x53653c[_0xffb9('0x42')]['id']}})['then'](handleEntityNotFound(_0x710bf9,null))[_0xffb9('0x22')](saveUpdates(_0x53653c['body'],null))[_0xffb9('0x22')](respondWithResult(_0x710bf9,null))[_0xffb9('0x40')](handleError(_0x710bf9,null));};exports[_0xffb9('0x48')]=function(_0x118f16,_0x3e29b7){return db[_0xffb9('0x3d')][_0xffb9('0x47')]({'where':{'id':_0x118f16[_0xffb9('0x42')]['id']}})[_0xffb9('0x22')](handleEntityNotFound(_0x3e29b7,null))[_0xffb9('0x22')](removeEntity(_0x3e29b7,null))[_0xffb9('0x40')](handleError(_0x3e29b7,null));};exports[_0xffb9('0x49')]=function(_0x5d75de,_0x316de2){return db['OpenchannelQueueReport'][_0xffb9('0x49')]()['then'](respondWithResult(_0x316de2,null))[_0xffb9('0x40')](handleError(_0x316de2,null));};