Built motion from commit (unavailable).|2.4.18
[motion2.git] / server / api / chatQueueReport / chatQueueReport.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 _0x06ae=['../../config/license/hardware','../../config/logger','../../config/environment','../../mysqldb','sendStatus','status','end','offset','limit','set','Content-Range','json','apply','reject','save','update','then','destroy','error','stack','name','index','map','rawAttributes','fieldName','type','key','query','keys','filters','intersection','model','attributes','fields','length','hasOwnProperty','nolimit','sort','where','pick','filter','VIRTUAL','merge','ChatQueueReport','count','includeAll','findAll','rows','show','params','options','find','catch','create','body','describe','eml-format','rimraf','zip-dir','request-promise','moment','bluebird','mustache','sox','lodash','crypto','desk.js','to-csv','querystring','../../components/auth/service'];(function(_0x14add3,_0x13ce8d){var _0x4a174f=function(_0x2b3ed7){while(--_0x2b3ed7){_0x14add3['push'](_0x14add3['shift']());}};_0x4a174f(++_0x13ce8d);}(_0x06ae,0x7e));var _0xe06a=function(_0x2dafbe,_0x5d04de){_0x2dafbe=_0x2dafbe-0x0;var _0x58a45a=_0x06ae[_0x2dafbe];return _0x58a45a;};'use strict';var pdf=require('html-pdf');var emlformat=require(_0xe06a('0x0'));var rimraf=require(_0xe06a('0x1'));var zipdir=require(_0xe06a('0x2'));var jsonpatch=require('fast-json-patch');var rp=require(_0xe06a('0x3'));var moment=require(_0xe06a('0x4'));var BPromise=require(_0xe06a('0x5'));var Mustache=require(_0xe06a('0x6'));var util=require('util');var path=require('path');var sox=require(_0xe06a('0x7'));var csv=require('to-csv');var ejs=require('ejs');var fs=require('fs');var _=require(_0xe06a('0x8'));var squel=require('squel');var crypto=require(_0xe06a('0x9'));var jsforce=require('jsforce');var deskjs=require(_0xe06a('0xa'));var toCsv=require(_0xe06a('0xb'));var querystring=require(_0xe06a('0xc'));var Papa=require('papaparse');var Redis=require('ioredis');var authService=require(_0xe06a('0xd'));var qs=require('../../components/parsers/qs');var as=require('../../components/parsers/advancedSearch');var hardwareService=require(_0xe06a('0xe'));var logger=require(_0xe06a('0xf'))('api');var utils=require('../../config/utils');var config=require(_0xe06a('0x10'));var db=require(_0xe06a('0x11'))['db'];function respondWithStatusCode(_0x465853,_0x2aadcb){_0x2aadcb=_0x2aadcb||0xcc;return function(_0x3e2d42){if(_0x3e2d42){return _0x465853[_0xe06a('0x12')](_0x2aadcb);}return _0x465853[_0xe06a('0x13')](_0x2aadcb)[_0xe06a('0x14')]();};}function respondWithResult(_0x5806f0,_0x4d7618){_0x4d7618=_0x4d7618||0xc8;return function(_0x459824){if(_0x459824){return _0x5806f0[_0xe06a('0x13')](_0x4d7618)['json'](_0x459824);}};}function respondWithFilteredResult(_0x30559b,_0x1a0f40){return function(_0x26f7c1){if(_0x26f7c1){var _0x274428=_0x26f7c1['count'],_0x5a3926=_0x1a0f40[_0xe06a('0x15')],_0x4263a4=_0x1a0f40[_0xe06a('0x15')]+_0x1a0f40[_0xe06a('0x16')],_0x3e5deb;if(_0x4263a4>=_0x274428){_0x4263a4=_0x274428;_0x3e5deb=0xc8;}else{_0x3e5deb=0xce;}_0x30559b['status'](_0x3e5deb);return _0x30559b[_0xe06a('0x17')](_0xe06a('0x18'),_0x5a3926+'-'+_0x4263a4+'/'+_0x274428)[_0xe06a('0x19')](_0x26f7c1);}return null;};}function patchUpdates(_0x1bfd89){return function(_0x3d8f28){try{jsonpatch[_0xe06a('0x1a')](_0x3d8f28,_0x1bfd89,!![]);}catch(_0xcd6589){return BPromise[_0xe06a('0x1b')](_0xcd6589);}return _0x3d8f28[_0xe06a('0x1c')]();};}function saveUpdates(_0x300766,_0x3b5603){return function(_0x570570){if(_0x570570){return _0x570570[_0xe06a('0x1d')](_0x300766)[_0xe06a('0x1e')](function(_0x43d974){return _0x43d974;});}return null;};}function removeEntity(_0x5c0b03,_0x5b1469){return function(_0x263caf){if(_0x263caf){return _0x263caf[_0xe06a('0x1f')]()[_0xe06a('0x1e')](function(){_0x5c0b03[_0xe06a('0x13')](0xcc)[_0xe06a('0x14')]();});}};}function handleEntityNotFound(_0x5c9b6f,_0x313a7e){return function(_0x5662be){if(!_0x5662be){_0x5c9b6f['sendStatus'](0x194);}return _0x5662be;};}function handleError(_0x3ad548,_0x5564b0){_0x5564b0=_0x5564b0||0x1f4;return function(_0x4d7852){logger[_0xe06a('0x20')](_0x4d7852[_0xe06a('0x21')]);if(_0x4d7852['name']){delete _0x4d7852[_0xe06a('0x22')];}_0x3ad548[_0xe06a('0x13')](_0x5564b0)['send'](_0x4d7852);};}exports[_0xe06a('0x23')]=function(_0x11b050,_0xe440d0){var _0x564c64={},_0xd7a0cf={},_0x65fcf8={'count':0x0,'rows':[]};var _0x4c45c3=_[_0xe06a('0x24')](db['ChatQueueReport'][_0xe06a('0x25')],function(_0x56d83f){return{'name':_0x56d83f[_0xe06a('0x26')],'type':_0x56d83f[_0xe06a('0x27')][_0xe06a('0x28')]};});_0xd7a0cf['model']=_[_0xe06a('0x24')](_0x4c45c3,_0xe06a('0x22'));_0xd7a0cf[_0xe06a('0x29')]=_[_0xe06a('0x2a')](_0x11b050[_0xe06a('0x29')]);_0xd7a0cf[_0xe06a('0x2b')]=_[_0xe06a('0x2c')](_0xd7a0cf[_0xe06a('0x2d')],_0xd7a0cf[_0xe06a('0x29')]);_0x564c64[_0xe06a('0x2e')]=_[_0xe06a('0x2c')](_0xd7a0cf[_0xe06a('0x2d')],qs[_0xe06a('0x2f')](_0x11b050['query'][_0xe06a('0x2f')]));_0x564c64[_0xe06a('0x2e')]=_0x564c64['attributes'][_0xe06a('0x30')]?_0x564c64[_0xe06a('0x2e')]:_0xd7a0cf['model'];if(!_0x11b050[_0xe06a('0x29')][_0xe06a('0x31')](_0xe06a('0x32'))){_0x564c64[_0xe06a('0x16')]=qs['limit'](_0x11b050['query']['limit']);_0x564c64[_0xe06a('0x15')]=qs[_0xe06a('0x15')](_0x11b050[_0xe06a('0x29')][_0xe06a('0x15')]);}_0x564c64['order']=qs[_0xe06a('0x33')](_0x11b050[_0xe06a('0x29')][_0xe06a('0x33')]);_0x564c64[_0xe06a('0x34')]=qs[_0xe06a('0x2b')](_[_0xe06a('0x35')](_0x11b050[_0xe06a('0x29')],_0xd7a0cf[_0xe06a('0x2b')]));if(_0x11b050[_0xe06a('0x29')][_0xe06a('0x36')]){_0x564c64[_0xe06a('0x34')]=_['merge'](_0x564c64[_0xe06a('0x34')],{'$or':_['map'](_0x4c45c3,function(_0x2e1e42){if(_0x2e1e42[_0xe06a('0x27')]!==_0xe06a('0x37')){var _0xc84aac={};_0xc84aac[_0x2e1e42['name']]={'$like':'%'+_0x11b050['query'][_0xe06a('0x36')]+'%'};return _0xc84aac;}})});}_0x564c64=_[_0xe06a('0x38')]({},_0x564c64,_0x11b050['options']);var _0x4bb127={'where':_0x564c64[_0xe06a('0x34')]};return db[_0xe06a('0x39')][_0xe06a('0x3a')](_0x4bb127)[_0xe06a('0x1e')](function(_0x1c7fc8){_0x65fcf8[_0xe06a('0x3a')]=_0x1c7fc8;if(_0x11b050[_0xe06a('0x29')][_0xe06a('0x3b')]){_0x564c64['include']=[{'all':!![]}];}return db[_0xe06a('0x39')][_0xe06a('0x3c')](_0x564c64);})[_0xe06a('0x1e')](function(_0x441752){_0x65fcf8[_0xe06a('0x3d')]=_0x441752;return _0x65fcf8;})['then'](respondWithFilteredResult(_0xe440d0,_0x564c64))['catch'](handleError(_0xe440d0,null));};exports[_0xe06a('0x3e')]=function(_0x3558e1,_0x24401c){var _0x3350ab={'raw':!![],'where':{'id':_0x3558e1[_0xe06a('0x3f')]['id']}},_0x447518={};_0x447518[_0xe06a('0x2d')]=_[_0xe06a('0x2a')](db['ChatQueueReport'][_0xe06a('0x25')]);_0x447518[_0xe06a('0x29')]=_[_0xe06a('0x2a')](_0x3558e1[_0xe06a('0x29')]);_0x447518[_0xe06a('0x2b')]=_['intersection'](_0x447518['model'],_0x447518[_0xe06a('0x29')]);_0x3350ab[_0xe06a('0x2e')]=_[_0xe06a('0x2c')](_0x447518[_0xe06a('0x2d')],qs[_0xe06a('0x2f')](_0x3558e1[_0xe06a('0x29')][_0xe06a('0x2f')]));_0x3350ab['attributes']=_0x3350ab[_0xe06a('0x2e')][_0xe06a('0x30')]?_0x3350ab[_0xe06a('0x2e')]:_0x447518[_0xe06a('0x2d')];if(_0x3558e1[_0xe06a('0x29')][_0xe06a('0x3b')]){_0x3350ab['include']=[{'all':!![]}];}_0x3350ab=_['merge']({},_0x3350ab,_0x3558e1[_0xe06a('0x40')]);return db[_0xe06a('0x39')][_0xe06a('0x41')](_0x3350ab)[_0xe06a('0x1e')](handleEntityNotFound(_0x24401c,null))[_0xe06a('0x1e')](respondWithResult(_0x24401c,null))[_0xe06a('0x42')](handleError(_0x24401c,null));};exports['create']=function(_0x56673f,_0x2cfc42){return db[_0xe06a('0x39')][_0xe06a('0x43')](_0x56673f[_0xe06a('0x44')],{})['then'](respondWithResult(_0x2cfc42,0xc9))[_0xe06a('0x42')](handleError(_0x2cfc42,null));};exports[_0xe06a('0x1d')]=function(_0xb4640c,_0x1da4d6){if(_0xb4640c[_0xe06a('0x44')]['id']){delete _0xb4640c[_0xe06a('0x44')]['id'];}return db[_0xe06a('0x39')][_0xe06a('0x41')]({'where':{'id':_0xb4640c[_0xe06a('0x3f')]['id']}})[_0xe06a('0x1e')](handleEntityNotFound(_0x1da4d6,null))[_0xe06a('0x1e')](saveUpdates(_0xb4640c[_0xe06a('0x44')],null))[_0xe06a('0x1e')](respondWithResult(_0x1da4d6,null))[_0xe06a('0x42')](handleError(_0x1da4d6,null));};exports[_0xe06a('0x1f')]=function(_0x189e5d,_0x30e09c){return db['ChatQueueReport'][_0xe06a('0x41')]({'where':{'id':_0x189e5d[_0xe06a('0x3f')]['id']}})['then'](handleEntityNotFound(_0x30e09c,null))[_0xe06a('0x1e')](removeEntity(_0x30e09c,null))[_0xe06a('0x42')](handleError(_0x30e09c,null));};exports[_0xe06a('0x45')]=function(_0x48d110,_0x56d92f){return db['ChatQueueReport']['describe']()[_0xe06a('0x1e')](respondWithResult(_0x56d92f,null))[_0xe06a('0x42')](handleError(_0x56d92f,null));};