605a6c845bc1526ec783c43f6e253d4613fd1031
[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 _0xf693=['fs-extra','lodash','crypto','jsforce','desk.js','papaparse','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','api','../../config/utils','../../config/environment','../../config/license/util','../../mysqldb','status','end','json','offset','undefined','limit','count','set','apply','reject','update','then','destroy','sendStatus','error','stack','name','send','index','map','OpenchannelQueueReport','fieldName','type','key','keys','filters','intersection','model','query','attributes','fields','length','hasOwnProperty','order','sort','pick','filter','merge','where','VIRTUAL','options','includeAll','findAll','rows','catch','show','include','find','create','body','params','describe','eml-format','zip-dir','fast-json-patch','request-promise','moment','bluebird','mustache','util','path','sox','to-csv','ejs'];(function(_0xcd6f70,_0x3089a7){var _0x3ff788=function(_0x496b89){while(--_0x496b89){_0xcd6f70['push'](_0xcd6f70['shift']());}};_0x3ff788(++_0x3089a7);}(_0xf693,0x1da));var _0x3f69=function(_0x1fab5d,_0x5af2b6){_0x1fab5d=_0x1fab5d-0x0;var _0x2c755f=_0xf693[_0x1fab5d];return _0x2c755f;};'use strict';var emlformat=require(_0x3f69('0x0'));var rimraf=require('rimraf');var zipdir=require(_0x3f69('0x1'));var jsonpatch=require(_0x3f69('0x2'));var rp=require(_0x3f69('0x3'));var moment=require(_0x3f69('0x4'));var BPromise=require(_0x3f69('0x5'));var Mustache=require(_0x3f69('0x6'));var util=require(_0x3f69('0x7'));var path=require(_0x3f69('0x8'));var sox=require(_0x3f69('0x9'));var csv=require(_0x3f69('0xa'));var ejs=require(_0x3f69('0xb'));var fs=require('fs');var fs_extra=require(_0x3f69('0xc'));var _=require(_0x3f69('0xd'));var squel=require('squel');var crypto=require(_0x3f69('0xe'));var jsforce=require(_0x3f69('0xf'));var deskjs=require(_0x3f69('0x10'));var toCsv=require(_0x3f69('0xa'));var querystring=require('querystring');var Papa=require(_0x3f69('0x11'));var Redis=require(_0x3f69('0x12'));var authService=require(_0x3f69('0x13'));var qs=require(_0x3f69('0x14'));var as=require(_0x3f69('0x15'));var hardwareService=require(_0x3f69('0x16'));var logger=require(_0x3f69('0x17'))(_0x3f69('0x18'));var utils=require(_0x3f69('0x19'));var config=require(_0x3f69('0x1a'));var licenseUtil=require(_0x3f69('0x1b'));var db=require(_0x3f69('0x1c'))['db'];function respondWithStatusCode(_0x206e28,_0x59273a){_0x59273a=_0x59273a||0xcc;return function(_0x12516e){if(_0x12516e){return _0x206e28['sendStatus'](_0x59273a);}return _0x206e28[_0x3f69('0x1d')](_0x59273a)[_0x3f69('0x1e')]();};}function respondWithResult(_0x5cfcf3,_0x49ac9f){_0x49ac9f=_0x49ac9f||0xc8;return function(_0x1bc4fb){if(_0x1bc4fb){return _0x5cfcf3[_0x3f69('0x1d')](_0x49ac9f)[_0x3f69('0x1f')](_0x1bc4fb);}};}function respondWithFilteredResult(_0x33df7d,_0x4b066d){return function(_0x371682){if(_0x371682){var _0x5b5a1b=typeof _0x4b066d[_0x3f69('0x20')]===_0x3f69('0x21')&&typeof _0x4b066d[_0x3f69('0x22')]==='undefined';var _0x52eea8=_0x371682[_0x3f69('0x23')];var _0x3ff6a4=_0x5b5a1b?0x0:_0x4b066d['offset'];var _0x581c6d=_0x5b5a1b?_0x371682[_0x3f69('0x23')]:_0x4b066d[_0x3f69('0x20')]+_0x4b066d[_0x3f69('0x22')];var _0x3e0a35;if(_0x581c6d>=_0x52eea8){_0x581c6d=_0x52eea8;_0x3e0a35=0xc8;}else{_0x3e0a35=0xce;}_0x33df7d[_0x3f69('0x1d')](_0x3e0a35);return _0x33df7d[_0x3f69('0x24')]('Content-Range',_0x3ff6a4+'-'+_0x581c6d+'/'+_0x52eea8)[_0x3f69('0x1f')](_0x371682);}return null;};}function patchUpdates(_0x3e166b){return function(_0x30e65d){try{jsonpatch[_0x3f69('0x25')](_0x30e65d,_0x3e166b,!![]);}catch(_0x2709fa){return BPromise[_0x3f69('0x26')](_0x2709fa);}return _0x30e65d['save']();};}function saveUpdates(_0x19d09d,_0x3173ed){return function(_0x48ca57){if(_0x48ca57){return _0x48ca57[_0x3f69('0x27')](_0x19d09d)[_0x3f69('0x28')](function(_0xf55046){return _0xf55046;});}return null;};}function removeEntity(_0x5e178c,_0x1a8472){return function(_0x17fcd0){if(_0x17fcd0){return _0x17fcd0[_0x3f69('0x29')]()[_0x3f69('0x28')](function(){_0x5e178c['status'](0xcc)[_0x3f69('0x1e')]();});}};}function handleEntityNotFound(_0x359141,_0x2ce56d){return function(_0x5b6cfa){if(!_0x5b6cfa){_0x359141[_0x3f69('0x2a')](0x194);}return _0x5b6cfa;};}function handleError(_0x26f3a2,_0x30dd9f){_0x30dd9f=_0x30dd9f||0x1f4;return function(_0x32e552){logger[_0x3f69('0x2b')](_0x32e552[_0x3f69('0x2c')]);if(_0x32e552['name']){delete _0x32e552[_0x3f69('0x2d')];}_0x26f3a2[_0x3f69('0x1d')](_0x30dd9f)[_0x3f69('0x2e')](_0x32e552);};}exports[_0x3f69('0x2f')]=function(_0x308e74,_0x1fd251){var _0x288da2={},_0x387f62={},_0x11531e={'count':0x0,'rows':[]};var _0x305256=_[_0x3f69('0x30')](db[_0x3f69('0x31')]['rawAttributes'],function(_0x3f9dcc){return{'name':_0x3f9dcc[_0x3f69('0x32')],'type':_0x3f9dcc[_0x3f69('0x33')][_0x3f69('0x34')]};});_0x387f62['model']=_['map'](_0x305256,_0x3f69('0x2d'));_0x387f62['query']=_[_0x3f69('0x35')](_0x308e74['query']);_0x387f62[_0x3f69('0x36')]=_[_0x3f69('0x37')](_0x387f62[_0x3f69('0x38')],_0x387f62[_0x3f69('0x39')]);_0x288da2[_0x3f69('0x3a')]=_[_0x3f69('0x37')](_0x387f62[_0x3f69('0x38')],qs[_0x3f69('0x3b')](_0x308e74[_0x3f69('0x39')][_0x3f69('0x3b')]));_0x288da2[_0x3f69('0x3a')]=_0x288da2['attributes'][_0x3f69('0x3c')]?_0x288da2[_0x3f69('0x3a')]:_0x387f62[_0x3f69('0x38')];if(!_0x308e74[_0x3f69('0x39')][_0x3f69('0x3d')]('nolimit')){_0x288da2['limit']=qs[_0x3f69('0x22')](_0x308e74[_0x3f69('0x39')][_0x3f69('0x22')]);_0x288da2[_0x3f69('0x20')]=qs[_0x3f69('0x20')](_0x308e74[_0x3f69('0x39')]['offset']);}_0x288da2[_0x3f69('0x3e')]=qs[_0x3f69('0x3f')](_0x308e74['query'][_0x3f69('0x3f')]);_0x288da2['where']=qs[_0x3f69('0x36')](_[_0x3f69('0x40')](_0x308e74[_0x3f69('0x39')],_0x387f62['filters']),_0x305256);if(_0x308e74['query'][_0x3f69('0x41')]){_0x288da2['where']=_[_0x3f69('0x42')](_0x288da2[_0x3f69('0x43')],{'$or':_[_0x3f69('0x30')](_0x305256,function(_0x575532){if(_0x575532['type']!==_0x3f69('0x44')){var _0x1e372f={};_0x1e372f[_0x575532[_0x3f69('0x2d')]]={'$like':'%'+_0x308e74[_0x3f69('0x39')][_0x3f69('0x41')]+'%'};return _0x1e372f;}})});}_0x288da2=_[_0x3f69('0x42')]({},_0x288da2,_0x308e74[_0x3f69('0x45')]);var _0x24c4e5={'where':_0x288da2[_0x3f69('0x43')]};return db[_0x3f69('0x31')]['count'](_0x24c4e5)['then'](function(_0x30f51b){_0x11531e[_0x3f69('0x23')]=_0x30f51b;if(_0x308e74[_0x3f69('0x39')][_0x3f69('0x46')]){_0x288da2['include']=[{'all':!![]}];}return db['OpenchannelQueueReport'][_0x3f69('0x47')](_0x288da2);})[_0x3f69('0x28')](function(_0x391b60){_0x11531e[_0x3f69('0x48')]=_0x391b60;return _0x11531e;})[_0x3f69('0x28')](respondWithFilteredResult(_0x1fd251,_0x288da2))[_0x3f69('0x49')](handleError(_0x1fd251,null));};exports[_0x3f69('0x4a')]=function(_0x39104a,_0x1bded7){var _0x484587={'raw':!![],'where':{'id':_0x39104a['params']['id']}},_0x1794b1={};_0x1794b1[_0x3f69('0x38')]=_[_0x3f69('0x35')](db[_0x3f69('0x31')]['rawAttributes']);_0x1794b1[_0x3f69('0x39')]=_['keys'](_0x39104a['query']);_0x1794b1[_0x3f69('0x36')]=_[_0x3f69('0x37')](_0x1794b1[_0x3f69('0x38')],_0x1794b1[_0x3f69('0x39')]);_0x484587[_0x3f69('0x3a')]=_[_0x3f69('0x37')](_0x1794b1[_0x3f69('0x38')],qs['fields'](_0x39104a['query'][_0x3f69('0x3b')]));_0x484587['attributes']=_0x484587['attributes'][_0x3f69('0x3c')]?_0x484587['attributes']:_0x1794b1[_0x3f69('0x38')];if(_0x39104a[_0x3f69('0x39')][_0x3f69('0x46')]){_0x484587[_0x3f69('0x4b')]=[{'all':!![]}];}_0x484587=_[_0x3f69('0x42')]({},_0x484587,_0x39104a[_0x3f69('0x45')]);return db[_0x3f69('0x31')][_0x3f69('0x4c')](_0x484587)[_0x3f69('0x28')](handleEntityNotFound(_0x1bded7,null))[_0x3f69('0x28')](respondWithResult(_0x1bded7,null))[_0x3f69('0x49')](handleError(_0x1bded7,null));};exports[_0x3f69('0x4d')]=function(_0x5e0484,_0x404db0){return db[_0x3f69('0x31')][_0x3f69('0x4d')](_0x5e0484[_0x3f69('0x4e')],{})[_0x3f69('0x28')](respondWithResult(_0x404db0,0xc9))[_0x3f69('0x49')](handleError(_0x404db0,null));};exports['update']=function(_0x152a06,_0x3bc3af){if(_0x152a06['body']['id']){delete _0x152a06[_0x3f69('0x4e')]['id'];}return db[_0x3f69('0x31')][_0x3f69('0x4c')]({'where':{'id':_0x152a06[_0x3f69('0x4f')]['id']}})['then'](handleEntityNotFound(_0x3bc3af,null))[_0x3f69('0x28')](saveUpdates(_0x152a06[_0x3f69('0x4e')],null))['then'](respondWithResult(_0x3bc3af,null))[_0x3f69('0x49')](handleError(_0x3bc3af,null));};exports[_0x3f69('0x29')]=function(_0x44ffc4,_0x19fadc){return db[_0x3f69('0x31')]['find']({'where':{'id':_0x44ffc4['params']['id']}})[_0x3f69('0x28')](handleEntityNotFound(_0x19fadc,null))['then'](removeEntity(_0x19fadc,null))[_0x3f69('0x49')](handleError(_0x19fadc,null));};exports['describe']=function(_0x3f658f,_0x2d5e67){return db[_0x3f69('0x31')][_0x3f69('0x50')]()[_0x3f69('0x28')](respondWithResult(_0x2d5e67,null))[_0x3f69('0x49')](handleError(_0x2d5e67,null));};