4479d62f90e3c800231a1bedfbdbf381d19a0749
[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 _0xcf1c=['filters','intersection','fields','length','attributes','nolimit','limit','order','sort','where','pick','filter','merge','VIRTUAL','options','OpenchannelQueueReport','includeAll','include','rows','catch','show','params','keys','find','create','body','describe','html-pdf','eml-format','zip-dir','fast-json-patch','request-promise','moment','path','to-csv','ejs','lodash','squel','crypto','jsforce','desk.js','querystring','papaparse','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','api','../../config/license/util','../../mysqldb','end','status','count','offset','Content-Range','reject','update','destroy','then','sendStatus','error','stack','name','send','index','map','rawAttributes','fieldName','type','key','model','query'];(function(_0x3a0512,_0x2f78ea){var _0x1a8fd7=function(_0x48cbaa){while(--_0x48cbaa){_0x3a0512['push'](_0x3a0512['shift']());}};_0x1a8fd7(++_0x2f78ea);}(_0xcf1c,0x18d));var _0xccf1=function(_0x28578d,_0xcf5cf0){_0x28578d=_0x28578d-0x0;var _0x524826=_0xcf1c[_0x28578d];return _0x524826;};'use strict';var pdf=require(_0xccf1('0x0'));var emlformat=require(_0xccf1('0x1'));var rimraf=require('rimraf');var zipdir=require(_0xccf1('0x2'));var jsonpatch=require(_0xccf1('0x3'));var rp=require(_0xccf1('0x4'));var moment=require(_0xccf1('0x5'));var BPromise=require('bluebird');var Mustache=require('mustache');var util=require('util');var path=require(_0xccf1('0x6'));var sox=require('sox');var csv=require(_0xccf1('0x7'));var ejs=require(_0xccf1('0x8'));var fs=require('fs');var _=require(_0xccf1('0x9'));var squel=require(_0xccf1('0xa'));var crypto=require(_0xccf1('0xb'));var jsforce=require(_0xccf1('0xc'));var deskjs=require(_0xccf1('0xd'));var toCsv=require(_0xccf1('0x7'));var querystring=require(_0xccf1('0xe'));var Papa=require(_0xccf1('0xf'));var Redis=require(_0xccf1('0x10'));var authService=require(_0xccf1('0x11'));var qs=require(_0xccf1('0x12'));var as=require(_0xccf1('0x13'));var hardwareService=require(_0xccf1('0x14'));var logger=require(_0xccf1('0x15'))(_0xccf1('0x16'));var utils=require('../../config/utils');var config=require('../../config/environment');var licenseUtil=require(_0xccf1('0x17'));var db=require(_0xccf1('0x18'))['db'];function respondWithStatusCode(_0x1bbfb0,_0x3789c2){_0x3789c2=_0x3789c2||0xcc;return function(_0x3da424){if(_0x3da424){return _0x1bbfb0['sendStatus'](_0x3789c2);}return _0x1bbfb0['status'](_0x3789c2)[_0xccf1('0x19')]();};}function respondWithResult(_0x5578a6,_0x1170e1){_0x1170e1=_0x1170e1||0xc8;return function(_0x44b68a){if(_0x44b68a){return _0x5578a6[_0xccf1('0x1a')](_0x1170e1)['json'](_0x44b68a);}};}function respondWithFilteredResult(_0x1e8fc0,_0x537996){return function(_0x4e91cd){if(_0x4e91cd){var _0x1ceb48=_0x4e91cd[_0xccf1('0x1b')],_0x381da9=_0x537996[_0xccf1('0x1c')],_0x4193b6=_0x537996[_0xccf1('0x1c')]+_0x537996['limit'],_0xf0f09a;if(_0x4193b6>=_0x1ceb48){_0x4193b6=_0x1ceb48;_0xf0f09a=0xc8;}else{_0xf0f09a=0xce;}_0x1e8fc0[_0xccf1('0x1a')](_0xf0f09a);return _0x1e8fc0['set'](_0xccf1('0x1d'),_0x381da9+'-'+_0x4193b6+'/'+_0x1ceb48)['json'](_0x4e91cd);}return null;};}function patchUpdates(_0x3fb83b){return function(_0x3a1635){try{jsonpatch['apply'](_0x3a1635,_0x3fb83b,!![]);}catch(_0xe8b544){return BPromise[_0xccf1('0x1e')](_0xe8b544);}return _0x3a1635['save']();};}function saveUpdates(_0x55d721,_0x4bcb98){return function(_0x43c982){if(_0x43c982){return _0x43c982[_0xccf1('0x1f')](_0x55d721)['then'](function(_0x4d4666){return _0x4d4666;});}return null;};}function removeEntity(_0x18b7a3,_0xb819a6){return function(_0x43d622){if(_0x43d622){return _0x43d622[_0xccf1('0x20')]()[_0xccf1('0x21')](function(){_0x18b7a3[_0xccf1('0x1a')](0xcc)[_0xccf1('0x19')]();});}};}function handleEntityNotFound(_0x396bcb,_0x75b9f6){return function(_0x4a4de5){if(!_0x4a4de5){_0x396bcb[_0xccf1('0x22')](0x194);}return _0x4a4de5;};}function handleError(_0x7434d9,_0x13be17){_0x13be17=_0x13be17||0x1f4;return function(_0x2c9e07){logger[_0xccf1('0x23')](_0x2c9e07[_0xccf1('0x24')]);if(_0x2c9e07[_0xccf1('0x25')]){delete _0x2c9e07[_0xccf1('0x25')];}_0x7434d9[_0xccf1('0x1a')](_0x13be17)[_0xccf1('0x26')](_0x2c9e07);};}exports[_0xccf1('0x27')]=function(_0x46a584,_0x300da5){var _0x5e82d0={},_0x22101e={},_0x183319={'count':0x0,'rows':[]};var _0x3fa621=_[_0xccf1('0x28')](db['OpenchannelQueueReport'][_0xccf1('0x29')],function(_0x2e3c50){return{'name':_0x2e3c50[_0xccf1('0x2a')],'type':_0x2e3c50[_0xccf1('0x2b')][_0xccf1('0x2c')]};});_0x22101e[_0xccf1('0x2d')]=_[_0xccf1('0x28')](_0x3fa621,_0xccf1('0x25'));_0x22101e[_0xccf1('0x2e')]=_['keys'](_0x46a584[_0xccf1('0x2e')]);_0x22101e[_0xccf1('0x2f')]=_[_0xccf1('0x30')](_0x22101e[_0xccf1('0x2d')],_0x22101e[_0xccf1('0x2e')]);_0x5e82d0['attributes']=_[_0xccf1('0x30')](_0x22101e[_0xccf1('0x2d')],qs[_0xccf1('0x31')](_0x46a584[_0xccf1('0x2e')][_0xccf1('0x31')]));_0x5e82d0['attributes']=_0x5e82d0['attributes'][_0xccf1('0x32')]?_0x5e82d0[_0xccf1('0x33')]:_0x22101e[_0xccf1('0x2d')];if(!_0x46a584[_0xccf1('0x2e')]['hasOwnProperty'](_0xccf1('0x34'))){_0x5e82d0[_0xccf1('0x35')]=qs[_0xccf1('0x35')](_0x46a584[_0xccf1('0x2e')][_0xccf1('0x35')]);_0x5e82d0[_0xccf1('0x1c')]=qs[_0xccf1('0x1c')](_0x46a584['query'][_0xccf1('0x1c')]);}_0x5e82d0[_0xccf1('0x36')]=qs[_0xccf1('0x37')](_0x46a584[_0xccf1('0x2e')][_0xccf1('0x37')]);_0x5e82d0[_0xccf1('0x38')]=qs[_0xccf1('0x2f')](_[_0xccf1('0x39')](_0x46a584[_0xccf1('0x2e')],_0x22101e[_0xccf1('0x2f')]),_0x3fa621);if(_0x46a584[_0xccf1('0x2e')][_0xccf1('0x3a')]){_0x5e82d0['where']=_[_0xccf1('0x3b')](_0x5e82d0[_0xccf1('0x38')],{'$or':_['map'](_0x3fa621,function(_0x2b1de1){if(_0x2b1de1[_0xccf1('0x2b')]!==_0xccf1('0x3c')){var _0x456922={};_0x456922[_0x2b1de1[_0xccf1('0x25')]]={'$like':'%'+_0x46a584[_0xccf1('0x2e')][_0xccf1('0x3a')]+'%'};return _0x456922;}})});}_0x5e82d0=_[_0xccf1('0x3b')]({},_0x5e82d0,_0x46a584[_0xccf1('0x3d')]);var _0x1f5ebf={'where':_0x5e82d0['where']};return db[_0xccf1('0x3e')]['count'](_0x1f5ebf)['then'](function(_0x2afd62){_0x183319[_0xccf1('0x1b')]=_0x2afd62;if(_0x46a584['query'][_0xccf1('0x3f')]){_0x5e82d0[_0xccf1('0x40')]=[{'all':!![]}];}return db['OpenchannelQueueReport']['findAll'](_0x5e82d0);})[_0xccf1('0x21')](function(_0x2c6a32){_0x183319[_0xccf1('0x41')]=_0x2c6a32;return _0x183319;})[_0xccf1('0x21')](respondWithFilteredResult(_0x300da5,_0x5e82d0))[_0xccf1('0x42')](handleError(_0x300da5,null));};exports[_0xccf1('0x43')]=function(_0x284be0,_0x2c02f2){var _0x52d09d={'raw':!![],'where':{'id':_0x284be0[_0xccf1('0x44')]['id']}},_0x8174b4={};_0x8174b4[_0xccf1('0x2d')]=_[_0xccf1('0x45')](db['OpenchannelQueueReport'][_0xccf1('0x29')]);_0x8174b4[_0xccf1('0x2e')]=_[_0xccf1('0x45')](_0x284be0['query']);_0x8174b4['filters']=_[_0xccf1('0x30')](_0x8174b4[_0xccf1('0x2d')],_0x8174b4['query']);_0x52d09d[_0xccf1('0x33')]=_['intersection'](_0x8174b4[_0xccf1('0x2d')],qs[_0xccf1('0x31')](_0x284be0[_0xccf1('0x2e')][_0xccf1('0x31')]));_0x52d09d[_0xccf1('0x33')]=_0x52d09d[_0xccf1('0x33')][_0xccf1('0x32')]?_0x52d09d[_0xccf1('0x33')]:_0x8174b4[_0xccf1('0x2d')];if(_0x284be0[_0xccf1('0x2e')][_0xccf1('0x3f')]){_0x52d09d[_0xccf1('0x40')]=[{'all':!![]}];}_0x52d09d=_[_0xccf1('0x3b')]({},_0x52d09d,_0x284be0['options']);return db[_0xccf1('0x3e')][_0xccf1('0x46')](_0x52d09d)[_0xccf1('0x21')](handleEntityNotFound(_0x2c02f2,null))[_0xccf1('0x21')](respondWithResult(_0x2c02f2,null))[_0xccf1('0x42')](handleError(_0x2c02f2,null));};exports[_0xccf1('0x47')]=function(_0x453472,_0x292183){return db[_0xccf1('0x3e')][_0xccf1('0x47')](_0x453472['body'],{})[_0xccf1('0x21')](respondWithResult(_0x292183,0xc9))[_0xccf1('0x42')](handleError(_0x292183,null));};exports[_0xccf1('0x1f')]=function(_0x43d76a,_0x9a4221){if(_0x43d76a[_0xccf1('0x48')]['id']){delete _0x43d76a['body']['id'];}return db['OpenchannelQueueReport'][_0xccf1('0x46')]({'where':{'id':_0x43d76a[_0xccf1('0x44')]['id']}})['then'](handleEntityNotFound(_0x9a4221,null))['then'](saveUpdates(_0x43d76a[_0xccf1('0x48')],null))[_0xccf1('0x21')](respondWithResult(_0x9a4221,null))[_0xccf1('0x42')](handleError(_0x9a4221,null));};exports[_0xccf1('0x20')]=function(_0x11ef95,_0x1a7d83){return db['OpenchannelQueueReport']['find']({'where':{'id':_0x11ef95[_0xccf1('0x44')]['id']}})[_0xccf1('0x21')](handleEntityNotFound(_0x1a7d83,null))['then'](removeEntity(_0x1a7d83,null))[_0xccf1('0x42')](handleError(_0x1a7d83,null));};exports[_0xccf1('0x49')]=function(_0x114da9,_0x48014f){return db[_0xccf1('0x3e')]['describe']()['then'](respondWithResult(_0x48014f,null))[_0xccf1('0x42')](handleError(_0x48014f,null));};