Built motion from commit (unavailable).|2.5.14
[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 _0x15f1=['include','options','find','body','describe','html-pdf','eml-format','rimraf','zip-dir','request-promise','moment','util','path','sox','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/utils','../../config/environment','../../config/license/util','../../mysqldb','end','status','json','offset','limit','Content-Range','save','update','then','destroy','sendStatus','stack','name','send','index','map','ChatQueueReport','rawAttributes','fieldName','type','key','model','query','intersection','fields','attributes','length','hasOwnProperty','nolimit','order','sort','where','pick','filter','VIRTUAL','merge','count','findAll','rows','catch','show','params','keys','filters','includeAll'];(function(_0x332299,_0x247952){var _0x5f4d5b=function(_0x5398bb){while(--_0x5398bb){_0x332299['push'](_0x332299['shift']());}};_0x5f4d5b(++_0x247952);}(_0x15f1,0x190));var _0x115f=function(_0x16837f,_0x5bf229){_0x16837f=_0x16837f-0x0;var _0x9eccc9=_0x15f1[_0x16837f];return _0x9eccc9;};'use strict';var pdf=require(_0x115f('0x0'));var emlformat=require(_0x115f('0x1'));var rimraf=require(_0x115f('0x2'));var zipdir=require(_0x115f('0x3'));var jsonpatch=require('fast-json-patch');var rp=require(_0x115f('0x4'));var moment=require(_0x115f('0x5'));var BPromise=require('bluebird');var Mustache=require('mustache');var util=require(_0x115f('0x6'));var path=require(_0x115f('0x7'));var sox=require(_0x115f('0x8'));var csv=require(_0x115f('0x9'));var ejs=require(_0x115f('0xa'));var fs=require('fs');var _=require(_0x115f('0xb'));var squel=require(_0x115f('0xc'));var crypto=require(_0x115f('0xd'));var jsforce=require(_0x115f('0xe'));var deskjs=require(_0x115f('0xf'));var toCsv=require(_0x115f('0x9'));var querystring=require(_0x115f('0x10'));var Papa=require(_0x115f('0x11'));var Redis=require(_0x115f('0x12'));var authService=require(_0x115f('0x13'));var qs=require(_0x115f('0x14'));var as=require(_0x115f('0x15'));var hardwareService=require(_0x115f('0x16'));var logger=require(_0x115f('0x17'))(_0x115f('0x18'));var utils=require(_0x115f('0x19'));var config=require(_0x115f('0x1a'));var licenseUtil=require(_0x115f('0x1b'));var db=require(_0x115f('0x1c'))['db'];function respondWithStatusCode(_0x365fc1,_0x3c39e1){_0x3c39e1=_0x3c39e1||0xcc;return function(_0x54e5fd){if(_0x54e5fd){return _0x365fc1['sendStatus'](_0x3c39e1);}return _0x365fc1['status'](_0x3c39e1)[_0x115f('0x1d')]();};}function respondWithResult(_0x387856,_0x81c1ca){_0x81c1ca=_0x81c1ca||0xc8;return function(_0x54edce){if(_0x54edce){return _0x387856[_0x115f('0x1e')](_0x81c1ca)[_0x115f('0x1f')](_0x54edce);}};}function respondWithFilteredResult(_0x1c297b,_0x1ae501){return function(_0x5c0893){if(_0x5c0893){var _0x2daeeb=_0x5c0893['count'],_0x3f6702=_0x1ae501[_0x115f('0x20')],_0x436899=_0x1ae501[_0x115f('0x20')]+_0x1ae501[_0x115f('0x21')],_0x10be93;if(_0x436899>=_0x2daeeb){_0x436899=_0x2daeeb;_0x10be93=0xc8;}else{_0x10be93=0xce;}_0x1c297b[_0x115f('0x1e')](_0x10be93);return _0x1c297b['set'](_0x115f('0x22'),_0x3f6702+'-'+_0x436899+'/'+_0x2daeeb)[_0x115f('0x1f')](_0x5c0893);}return null;};}function patchUpdates(_0x1c4ce7){return function(_0x589593){try{jsonpatch['apply'](_0x589593,_0x1c4ce7,!![]);}catch(_0x2eae3a){return BPromise['reject'](_0x2eae3a);}return _0x589593[_0x115f('0x23')]();};}function saveUpdates(_0x151a18,_0x20be38){return function(_0x2aaf20){if(_0x2aaf20){return _0x2aaf20[_0x115f('0x24')](_0x151a18)[_0x115f('0x25')](function(_0x1bfb9c){return _0x1bfb9c;});}return null;};}function removeEntity(_0xa7896,_0x347e3c){return function(_0x2e0518){if(_0x2e0518){return _0x2e0518[_0x115f('0x26')]()[_0x115f('0x25')](function(){_0xa7896[_0x115f('0x1e')](0xcc)[_0x115f('0x1d')]();});}};}function handleEntityNotFound(_0x2e18e9,_0x31035e){return function(_0x4b09f5){if(!_0x4b09f5){_0x2e18e9[_0x115f('0x27')](0x194);}return _0x4b09f5;};}function handleError(_0x2965e2,_0x229147){_0x229147=_0x229147||0x1f4;return function(_0x2ffd0e){logger['error'](_0x2ffd0e[_0x115f('0x28')]);if(_0x2ffd0e[_0x115f('0x29')]){delete _0x2ffd0e[_0x115f('0x29')];}_0x2965e2['status'](_0x229147)[_0x115f('0x2a')](_0x2ffd0e);};}exports[_0x115f('0x2b')]=function(_0x4c75f6,_0x3c0bf1){var _0x17dfed={},_0x3f2354={},_0x1ee2b5={'count':0x0,'rows':[]};var _0x42a119=_[_0x115f('0x2c')](db[_0x115f('0x2d')][_0x115f('0x2e')],function(_0x43fd23){return{'name':_0x43fd23[_0x115f('0x2f')],'type':_0x43fd23[_0x115f('0x30')][_0x115f('0x31')]};});_0x3f2354[_0x115f('0x32')]=_[_0x115f('0x2c')](_0x42a119,_0x115f('0x29'));_0x3f2354[_0x115f('0x33')]=_['keys'](_0x4c75f6[_0x115f('0x33')]);_0x3f2354['filters']=_[_0x115f('0x34')](_0x3f2354['model'],_0x3f2354[_0x115f('0x33')]);_0x17dfed['attributes']=_[_0x115f('0x34')](_0x3f2354[_0x115f('0x32')],qs['fields'](_0x4c75f6['query'][_0x115f('0x35')]));_0x17dfed[_0x115f('0x36')]=_0x17dfed['attributes'][_0x115f('0x37')]?_0x17dfed['attributes']:_0x3f2354[_0x115f('0x32')];if(!_0x4c75f6[_0x115f('0x33')][_0x115f('0x38')](_0x115f('0x39'))){_0x17dfed[_0x115f('0x21')]=qs[_0x115f('0x21')](_0x4c75f6['query'][_0x115f('0x21')]);_0x17dfed[_0x115f('0x20')]=qs[_0x115f('0x20')](_0x4c75f6['query'][_0x115f('0x20')]);}_0x17dfed[_0x115f('0x3a')]=qs[_0x115f('0x3b')](_0x4c75f6[_0x115f('0x33')]['sort']);_0x17dfed[_0x115f('0x3c')]=qs['filters'](_[_0x115f('0x3d')](_0x4c75f6[_0x115f('0x33')],_0x3f2354['filters']),_0x42a119);if(_0x4c75f6[_0x115f('0x33')][_0x115f('0x3e')]){_0x17dfed[_0x115f('0x3c')]=_['merge'](_0x17dfed[_0x115f('0x3c')],{'$or':_[_0x115f('0x2c')](_0x42a119,function(_0x3d7ed7){if(_0x3d7ed7['type']!==_0x115f('0x3f')){var _0x16cc8b={};_0x16cc8b[_0x3d7ed7['name']]={'$like':'%'+_0x4c75f6[_0x115f('0x33')]['filter']+'%'};return _0x16cc8b;}})});}_0x17dfed=_[_0x115f('0x40')]({},_0x17dfed,_0x4c75f6['options']);var _0x3895ee={'where':_0x17dfed[_0x115f('0x3c')]};return db[_0x115f('0x2d')][_0x115f('0x41')](_0x3895ee)['then'](function(_0x53cba8){_0x1ee2b5[_0x115f('0x41')]=_0x53cba8;if(_0x4c75f6['query']['includeAll']){_0x17dfed['include']=[{'all':!![]}];}return db[_0x115f('0x2d')][_0x115f('0x42')](_0x17dfed);})['then'](function(_0x55e6fa){_0x1ee2b5[_0x115f('0x43')]=_0x55e6fa;return _0x1ee2b5;})[_0x115f('0x25')](respondWithFilteredResult(_0x3c0bf1,_0x17dfed))[_0x115f('0x44')](handleError(_0x3c0bf1,null));};exports[_0x115f('0x45')]=function(_0x44689c,_0xafb744){var _0x1ef71d={'raw':!![],'where':{'id':_0x44689c[_0x115f('0x46')]['id']}},_0x3e7cb4={};_0x3e7cb4[_0x115f('0x32')]=_[_0x115f('0x47')](db['ChatQueueReport'][_0x115f('0x2e')]);_0x3e7cb4[_0x115f('0x33')]=_['keys'](_0x44689c['query']);_0x3e7cb4[_0x115f('0x48')]=_[_0x115f('0x34')](_0x3e7cb4['model'],_0x3e7cb4[_0x115f('0x33')]);_0x1ef71d['attributes']=_[_0x115f('0x34')](_0x3e7cb4[_0x115f('0x32')],qs['fields'](_0x44689c[_0x115f('0x33')][_0x115f('0x35')]));_0x1ef71d['attributes']=_0x1ef71d[_0x115f('0x36')]['length']?_0x1ef71d[_0x115f('0x36')]:_0x3e7cb4[_0x115f('0x32')];if(_0x44689c[_0x115f('0x33')][_0x115f('0x49')]){_0x1ef71d[_0x115f('0x4a')]=[{'all':!![]}];}_0x1ef71d=_[_0x115f('0x40')]({},_0x1ef71d,_0x44689c[_0x115f('0x4b')]);return db[_0x115f('0x2d')][_0x115f('0x4c')](_0x1ef71d)[_0x115f('0x25')](handleEntityNotFound(_0xafb744,null))['then'](respondWithResult(_0xafb744,null))[_0x115f('0x44')](handleError(_0xafb744,null));};exports['create']=function(_0x6aaae6,_0x17d3ca){return db[_0x115f('0x2d')]['create'](_0x6aaae6[_0x115f('0x4d')],{})[_0x115f('0x25')](respondWithResult(_0x17d3ca,0xc9))[_0x115f('0x44')](handleError(_0x17d3ca,null));};exports['update']=function(_0x524a5b,_0x40c14b){if(_0x524a5b[_0x115f('0x4d')]['id']){delete _0x524a5b[_0x115f('0x4d')]['id'];}return db[_0x115f('0x2d')]['find']({'where':{'id':_0x524a5b[_0x115f('0x46')]['id']}})['then'](handleEntityNotFound(_0x40c14b,null))[_0x115f('0x25')](saveUpdates(_0x524a5b[_0x115f('0x4d')],null))[_0x115f('0x25')](respondWithResult(_0x40c14b,null))[_0x115f('0x44')](handleError(_0x40c14b,null));};exports[_0x115f('0x26')]=function(_0x431b13,_0x47b41c){return db[_0x115f('0x2d')]['find']({'where':{'id':_0x431b13[_0x115f('0x46')]['id']}})[_0x115f('0x25')](handleEntityNotFound(_0x47b41c,null))[_0x115f('0x25')](removeEntity(_0x47b41c,null))[_0x115f('0x44')](handleError(_0x47b41c,null));};exports[_0x115f('0x4e')]=function(_0x279843,_0x502303){return db[_0x115f('0x2d')]['describe']()[_0x115f('0x25')](respondWithResult(_0x502303,null))[_0x115f('0x44')](handleError(_0x502303,null));};