Built motion from commit da24aabd.|2.6.20
[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 _0xc77b=['fieldName','type','key','model','query','keys','filters','intersection','attributes','fields','length','sort','where','filter','merge','VIRTUAL','options','includeAll','include','OpenchannelQueueReport','findAll','rows','catch','params','find','create','body','eml-format','zip-dir','fast-json-patch','request-promise','bluebird','util','path','sox','to-csv','ejs','fs-extra','squel','crypto','jsforce','desk.js','querystring','papaparse','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','api','../../config/environment','../../config/license/util','../../mysqldb','sendStatus','status','end','json','offset','undefined','count','limit','set','apply','reject','save','then','destroy','error','name','send','index','map','rawAttributes'];(function(_0x107a14,_0x2673cc){var _0x4d97ff=function(_0x413549){while(--_0x413549){_0x107a14['push'](_0x107a14['shift']());}};_0x4d97ff(++_0x2673cc);}(_0xc77b,0xf9));var _0xbc77=function(_0x2cce17,_0x11ebcb){_0x2cce17=_0x2cce17-0x0;var _0x18aa3e=_0xc77b[_0x2cce17];return _0x18aa3e;};'use strict';var emlformat=require(_0xbc77('0x0'));var rimraf=require('rimraf');var zipdir=require(_0xbc77('0x1'));var jsonpatch=require(_0xbc77('0x2'));var rp=require(_0xbc77('0x3'));var moment=require('moment');var BPromise=require(_0xbc77('0x4'));var Mustache=require('mustache');var util=require(_0xbc77('0x5'));var path=require(_0xbc77('0x6'));var sox=require(_0xbc77('0x7'));var csv=require(_0xbc77('0x8'));var ejs=require(_0xbc77('0x9'));var fs=require('fs');var fs_extra=require(_0xbc77('0xa'));var _=require('lodash');var squel=require(_0xbc77('0xb'));var crypto=require(_0xbc77('0xc'));var jsforce=require(_0xbc77('0xd'));var deskjs=require(_0xbc77('0xe'));var toCsv=require(_0xbc77('0x8'));var querystring=require(_0xbc77('0xf'));var Papa=require(_0xbc77('0x10'));var Redis=require(_0xbc77('0x11'));var authService=require(_0xbc77('0x12'));var qs=require(_0xbc77('0x13'));var as=require(_0xbc77('0x14'));var hardwareService=require(_0xbc77('0x15'));var logger=require(_0xbc77('0x16'))(_0xbc77('0x17'));var utils=require('../../config/utils');var config=require(_0xbc77('0x18'));var licenseUtil=require(_0xbc77('0x19'));var db=require(_0xbc77('0x1a'))['db'];function respondWithStatusCode(_0xda3c4b,_0x5483f1){_0x5483f1=_0x5483f1||0xcc;return function(_0x212411){if(_0x212411){return _0xda3c4b[_0xbc77('0x1b')](_0x5483f1);}return _0xda3c4b[_0xbc77('0x1c')](_0x5483f1)[_0xbc77('0x1d')]();};}function respondWithResult(_0x25d710,_0x33d943){_0x33d943=_0x33d943||0xc8;return function(_0x327d45){if(_0x327d45){return _0x25d710[_0xbc77('0x1c')](_0x33d943)[_0xbc77('0x1e')](_0x327d45);}};}function respondWithFilteredResult(_0x4b5ad0,_0x4f01e3){return function(_0x17955d){if(_0x17955d){var _0x5ce4ff=typeof _0x4f01e3[_0xbc77('0x1f')]===_0xbc77('0x20')&&typeof _0x4f01e3['limit']==='undefined';var _0x489bca=_0x17955d[_0xbc77('0x21')];var _0x42455a=_0x5ce4ff?0x0:_0x4f01e3['offset'];var _0x1d2aee=_0x5ce4ff?_0x17955d['count']:_0x4f01e3['offset']+_0x4f01e3[_0xbc77('0x22')];var _0x16e62e;if(_0x1d2aee>=_0x489bca){_0x1d2aee=_0x489bca;_0x16e62e=0xc8;}else{_0x16e62e=0xce;}_0x4b5ad0[_0xbc77('0x1c')](_0x16e62e);return _0x4b5ad0[_0xbc77('0x23')]('Content-Range',_0x42455a+'-'+_0x1d2aee+'/'+_0x489bca)['json'](_0x17955d);}return null;};}function patchUpdates(_0x48f7f9){return function(_0x28572c){try{jsonpatch[_0xbc77('0x24')](_0x28572c,_0x48f7f9,!![]);}catch(_0x4c2346){return BPromise[_0xbc77('0x25')](_0x4c2346);}return _0x28572c[_0xbc77('0x26')]();};}function saveUpdates(_0x39b079,_0x4e5bf9){return function(_0x2851e9){if(_0x2851e9){return _0x2851e9['update'](_0x39b079)[_0xbc77('0x27')](function(_0x44c2a6){return _0x44c2a6;});}return null;};}function removeEntity(_0xfb3123,_0x5b1383){return function(_0x4ef967){if(_0x4ef967){return _0x4ef967[_0xbc77('0x28')]()[_0xbc77('0x27')](function(){_0xfb3123[_0xbc77('0x1c')](0xcc)[_0xbc77('0x1d')]();});}};}function handleEntityNotFound(_0x1c3921,_0x5a4c52){return function(_0x2e7e8a){if(!_0x2e7e8a){_0x1c3921['sendStatus'](0x194);}return _0x2e7e8a;};}function handleError(_0x547dae,_0x189495){_0x189495=_0x189495||0x1f4;return function(_0xfd4787){logger[_0xbc77('0x29')](_0xfd4787['stack']);if(_0xfd4787[_0xbc77('0x2a')]){delete _0xfd4787[_0xbc77('0x2a')];}_0x547dae[_0xbc77('0x1c')](_0x189495)[_0xbc77('0x2b')](_0xfd4787);};}exports[_0xbc77('0x2c')]=function(_0x22a8da,_0x3683ae){var _0x47307b={},_0x15065a={},_0x2447a2={'count':0x0,'rows':[]};var _0x3545ad=_[_0xbc77('0x2d')](db['OpenchannelQueueReport'][_0xbc77('0x2e')],function(_0x56ee2c){return{'name':_0x56ee2c[_0xbc77('0x2f')],'type':_0x56ee2c[_0xbc77('0x30')][_0xbc77('0x31')]};});_0x15065a[_0xbc77('0x32')]=_['map'](_0x3545ad,'name');_0x15065a[_0xbc77('0x33')]=_[_0xbc77('0x34')](_0x22a8da[_0xbc77('0x33')]);_0x15065a[_0xbc77('0x35')]=_[_0xbc77('0x36')](_0x15065a['model'],_0x15065a['query']);_0x47307b[_0xbc77('0x37')]=_['intersection'](_0x15065a['model'],qs['fields'](_0x22a8da[_0xbc77('0x33')][_0xbc77('0x38')]));_0x47307b[_0xbc77('0x37')]=_0x47307b['attributes'][_0xbc77('0x39')]?_0x47307b['attributes']:_0x15065a['model'];if(!_0x22a8da[_0xbc77('0x33')]['hasOwnProperty']('nolimit')){_0x47307b['limit']=qs['limit'](_0x22a8da['query'][_0xbc77('0x22')]);_0x47307b[_0xbc77('0x1f')]=qs[_0xbc77('0x1f')](_0x22a8da[_0xbc77('0x33')][_0xbc77('0x1f')]);}_0x47307b['order']=qs[_0xbc77('0x3a')](_0x22a8da[_0xbc77('0x33')][_0xbc77('0x3a')]);_0x47307b[_0xbc77('0x3b')]=qs['filters'](_['pick'](_0x22a8da[_0xbc77('0x33')],_0x15065a[_0xbc77('0x35')]),_0x3545ad);if(_0x22a8da[_0xbc77('0x33')][_0xbc77('0x3c')]){_0x47307b[_0xbc77('0x3b')]=_[_0xbc77('0x3d')](_0x47307b[_0xbc77('0x3b')],{'$or':_[_0xbc77('0x2d')](_0x3545ad,function(_0x4e8a5e){if(_0x4e8a5e['type']!==_0xbc77('0x3e')){var _0x52015f={};_0x52015f[_0x4e8a5e[_0xbc77('0x2a')]]={'$like':'%'+_0x22a8da[_0xbc77('0x33')]['filter']+'%'};return _0x52015f;}})});}_0x47307b=_[_0xbc77('0x3d')]({},_0x47307b,_0x22a8da[_0xbc77('0x3f')]);var _0x12a552={'where':_0x47307b[_0xbc77('0x3b')]};return db['OpenchannelQueueReport'][_0xbc77('0x21')](_0x12a552)[_0xbc77('0x27')](function(_0x52cf73){_0x2447a2[_0xbc77('0x21')]=_0x52cf73;if(_0x22a8da[_0xbc77('0x33')][_0xbc77('0x40')]){_0x47307b[_0xbc77('0x41')]=[{'all':!![]}];}return db[_0xbc77('0x42')][_0xbc77('0x43')](_0x47307b);})[_0xbc77('0x27')](function(_0x4e85ed){_0x2447a2[_0xbc77('0x44')]=_0x4e85ed;return _0x2447a2;})[_0xbc77('0x27')](respondWithFilteredResult(_0x3683ae,_0x47307b))[_0xbc77('0x45')](handleError(_0x3683ae,null));};exports['show']=function(_0x4af838,_0x25b1e1){var _0x19474a={'raw':!![],'where':{'id':_0x4af838[_0xbc77('0x46')]['id']}},_0x4fe7a1={};_0x4fe7a1[_0xbc77('0x32')]=_[_0xbc77('0x34')](db[_0xbc77('0x42')][_0xbc77('0x2e')]);_0x4fe7a1['query']=_['keys'](_0x4af838[_0xbc77('0x33')]);_0x4fe7a1['filters']=_[_0xbc77('0x36')](_0x4fe7a1[_0xbc77('0x32')],_0x4fe7a1['query']);_0x19474a['attributes']=_[_0xbc77('0x36')](_0x4fe7a1[_0xbc77('0x32')],qs[_0xbc77('0x38')](_0x4af838[_0xbc77('0x33')][_0xbc77('0x38')]));_0x19474a['attributes']=_0x19474a[_0xbc77('0x37')]['length']?_0x19474a[_0xbc77('0x37')]:_0x4fe7a1[_0xbc77('0x32')];if(_0x4af838[_0xbc77('0x33')][_0xbc77('0x40')]){_0x19474a[_0xbc77('0x41')]=[{'all':!![]}];}_0x19474a=_[_0xbc77('0x3d')]({},_0x19474a,_0x4af838['options']);return db[_0xbc77('0x42')][_0xbc77('0x47')](_0x19474a)[_0xbc77('0x27')](handleEntityNotFound(_0x25b1e1,null))['then'](respondWithResult(_0x25b1e1,null))[_0xbc77('0x45')](handleError(_0x25b1e1,null));};exports['create']=function(_0x35bf4e,_0x24c3b0){return db[_0xbc77('0x42')][_0xbc77('0x48')](_0x35bf4e[_0xbc77('0x49')],{})['then'](respondWithResult(_0x24c3b0,0xc9))['catch'](handleError(_0x24c3b0,null));};exports['update']=function(_0x208e1a,_0x48168f){if(_0x208e1a['body']['id']){delete _0x208e1a[_0xbc77('0x49')]['id'];}return db['OpenchannelQueueReport'][_0xbc77('0x47')]({'where':{'id':_0x208e1a[_0xbc77('0x46')]['id']}})['then'](handleEntityNotFound(_0x48168f,null))[_0xbc77('0x27')](saveUpdates(_0x208e1a[_0xbc77('0x49')],null))['then'](respondWithResult(_0x48168f,null))[_0xbc77('0x45')](handleError(_0x48168f,null));};exports[_0xbc77('0x28')]=function(_0x212121,_0x36837e){return db[_0xbc77('0x42')][_0xbc77('0x47')]({'where':{'id':_0x212121['params']['id']}})[_0xbc77('0x27')](handleEntityNotFound(_0x36837e,null))[_0xbc77('0x27')](removeEntity(_0x36837e,null))[_0xbc77('0x45')](handleError(_0x36837e,null));};exports['describe']=function(_0x3c6502,_0x1faa3c){return db[_0xbc77('0x42')]['describe']()[_0xbc77('0x27')](respondWithResult(_0x1faa3c,null))[_0xbc77('0x45')](handleError(_0x1faa3c,null));};