b2d94553475a460c284f239c1edbedae73494bf8
[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 _0xce8c=['update','then','destroy','error','name','index','map','ChatQueueReport','rawAttributes','type','key','model','query','keys','intersection','attributes','fields','length','hasOwnProperty','nolimit','order','sort','where','filters','pick','filter','merge','VIRTUAL','options','includeAll','include','rows','catch','show','params','find','create','body','describe','html-pdf','eml-format','rimraf','zip-dir','fast-json-patch','request-promise','moment','bluebird','mustache','path','sox','to-csv','lodash','jsforce','desk.js','querystring','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','api','../../config/utils','../../config/license/util','../../mysqldb','sendStatus','status','end','json','count','offset','limit','set','Content-Range','apply','reject','save'];(function(_0x423a7c,_0x5efcb3){var _0x13be1c=function(_0x14e87b){while(--_0x14e87b){_0x423a7c['push'](_0x423a7c['shift']());}};_0x13be1c(++_0x5efcb3);}(_0xce8c,0x157));var _0xcce8=function(_0x3eba1e,_0x420ac5){_0x3eba1e=_0x3eba1e-0x0;var _0x312ee8=_0xce8c[_0x3eba1e];return _0x312ee8;};'use strict';var pdf=require(_0xcce8('0x0'));var emlformat=require(_0xcce8('0x1'));var rimraf=require(_0xcce8('0x2'));var zipdir=require(_0xcce8('0x3'));var jsonpatch=require(_0xcce8('0x4'));var rp=require(_0xcce8('0x5'));var moment=require(_0xcce8('0x6'));var BPromise=require(_0xcce8('0x7'));var Mustache=require(_0xcce8('0x8'));var util=require('util');var path=require(_0xcce8('0x9'));var sox=require(_0xcce8('0xa'));var csv=require(_0xcce8('0xb'));var ejs=require('ejs');var fs=require('fs');var _=require(_0xcce8('0xc'));var squel=require('squel');var crypto=require('crypto');var jsforce=require(_0xcce8('0xd'));var deskjs=require(_0xcce8('0xe'));var toCsv=require(_0xcce8('0xb'));var querystring=require(_0xcce8('0xf'));var Papa=require('papaparse');var Redis=require('ioredis');var authService=require(_0xcce8('0x10'));var qs=require(_0xcce8('0x11'));var as=require(_0xcce8('0x12'));var hardwareService=require(_0xcce8('0x13'));var logger=require(_0xcce8('0x14'))(_0xcce8('0x15'));var utils=require(_0xcce8('0x16'));var config=require('../../config/environment');var licenseUtil=require(_0xcce8('0x17'));var db=require(_0xcce8('0x18'))['db'];function respondWithStatusCode(_0x477e19,_0x1004d3){_0x1004d3=_0x1004d3||0xcc;return function(_0x4d9727){if(_0x4d9727){return _0x477e19[_0xcce8('0x19')](_0x1004d3);}return _0x477e19[_0xcce8('0x1a')](_0x1004d3)[_0xcce8('0x1b')]();};}function respondWithResult(_0x149ce3,_0x22a208){_0x22a208=_0x22a208||0xc8;return function(_0x24f974){if(_0x24f974){return _0x149ce3['status'](_0x22a208)[_0xcce8('0x1c')](_0x24f974);}};}function respondWithFilteredResult(_0x51adc7,_0x5172b1){return function(_0x4454d1){if(_0x4454d1){var _0x5911f6=_0x4454d1[_0xcce8('0x1d')],_0x53b18d=_0x5172b1[_0xcce8('0x1e')],_0x20ece5=_0x5172b1[_0xcce8('0x1e')]+_0x5172b1[_0xcce8('0x1f')],_0x34a1ca;if(_0x20ece5>=_0x5911f6){_0x20ece5=_0x5911f6;_0x34a1ca=0xc8;}else{_0x34a1ca=0xce;}_0x51adc7[_0xcce8('0x1a')](_0x34a1ca);return _0x51adc7[_0xcce8('0x20')](_0xcce8('0x21'),_0x53b18d+'-'+_0x20ece5+'/'+_0x5911f6)[_0xcce8('0x1c')](_0x4454d1);}return null;};}function patchUpdates(_0x20b6fb){return function(_0x5cfb67){try{jsonpatch[_0xcce8('0x22')](_0x5cfb67,_0x20b6fb,!![]);}catch(_0x18a1fd){return BPromise[_0xcce8('0x23')](_0x18a1fd);}return _0x5cfb67[_0xcce8('0x24')]();};}function saveUpdates(_0x4d1b90,_0x37973a){return function(_0x4e42e4){if(_0x4e42e4){return _0x4e42e4[_0xcce8('0x25')](_0x4d1b90)[_0xcce8('0x26')](function(_0x1e4339){return _0x1e4339;});}return null;};}function removeEntity(_0x8fe904,_0x2cf9eb){return function(_0x52b4dd){if(_0x52b4dd){return _0x52b4dd[_0xcce8('0x27')]()[_0xcce8('0x26')](function(){_0x8fe904[_0xcce8('0x1a')](0xcc)[_0xcce8('0x1b')]();});}};}function handleEntityNotFound(_0x5b83df,_0x13b13a){return function(_0x508bfa){if(!_0x508bfa){_0x5b83df[_0xcce8('0x19')](0x194);}return _0x508bfa;};}function handleError(_0x1b3bf9,_0x250f9b){_0x250f9b=_0x250f9b||0x1f4;return function(_0x4d7715){logger[_0xcce8('0x28')](_0x4d7715['stack']);if(_0x4d7715[_0xcce8('0x29')]){delete _0x4d7715['name'];}_0x1b3bf9['status'](_0x250f9b)['send'](_0x4d7715);};}exports[_0xcce8('0x2a')]=function(_0x56b13f,_0x3e0471){var _0x1ea0f6={},_0x31bb5a={},_0x1fa558={'count':0x0,'rows':[]};var _0x542629=_[_0xcce8('0x2b')](db[_0xcce8('0x2c')][_0xcce8('0x2d')],function(_0x3292f2){return{'name':_0x3292f2['fieldName'],'type':_0x3292f2[_0xcce8('0x2e')][_0xcce8('0x2f')]};});_0x31bb5a[_0xcce8('0x30')]=_[_0xcce8('0x2b')](_0x542629,_0xcce8('0x29'));_0x31bb5a[_0xcce8('0x31')]=_[_0xcce8('0x32')](_0x56b13f[_0xcce8('0x31')]);_0x31bb5a['filters']=_[_0xcce8('0x33')](_0x31bb5a[_0xcce8('0x30')],_0x31bb5a[_0xcce8('0x31')]);_0x1ea0f6[_0xcce8('0x34')]=_['intersection'](_0x31bb5a[_0xcce8('0x30')],qs[_0xcce8('0x35')](_0x56b13f[_0xcce8('0x31')][_0xcce8('0x35')]));_0x1ea0f6[_0xcce8('0x34')]=_0x1ea0f6[_0xcce8('0x34')][_0xcce8('0x36')]?_0x1ea0f6[_0xcce8('0x34')]:_0x31bb5a['model'];if(!_0x56b13f['query'][_0xcce8('0x37')](_0xcce8('0x38'))){_0x1ea0f6[_0xcce8('0x1f')]=qs[_0xcce8('0x1f')](_0x56b13f[_0xcce8('0x31')][_0xcce8('0x1f')]);_0x1ea0f6[_0xcce8('0x1e')]=qs['offset'](_0x56b13f[_0xcce8('0x31')][_0xcce8('0x1e')]);}_0x1ea0f6[_0xcce8('0x39')]=qs[_0xcce8('0x3a')](_0x56b13f[_0xcce8('0x31')]['sort']);_0x1ea0f6[_0xcce8('0x3b')]=qs[_0xcce8('0x3c')](_[_0xcce8('0x3d')](_0x56b13f[_0xcce8('0x31')],_0x31bb5a[_0xcce8('0x3c')]),_0x542629);if(_0x56b13f[_0xcce8('0x31')][_0xcce8('0x3e')]){_0x1ea0f6['where']=_[_0xcce8('0x3f')](_0x1ea0f6['where'],{'$or':_[_0xcce8('0x2b')](_0x542629,function(_0x121a85){if(_0x121a85['type']!==_0xcce8('0x40')){var _0x3b0872={};_0x3b0872[_0x121a85['name']]={'$like':'%'+_0x56b13f['query'][_0xcce8('0x3e')]+'%'};return _0x3b0872;}})});}_0x1ea0f6=_[_0xcce8('0x3f')]({},_0x1ea0f6,_0x56b13f[_0xcce8('0x41')]);var _0x3d3ce3={'where':_0x1ea0f6[_0xcce8('0x3b')]};return db[_0xcce8('0x2c')][_0xcce8('0x1d')](_0x3d3ce3)[_0xcce8('0x26')](function(_0x483745){_0x1fa558[_0xcce8('0x1d')]=_0x483745;if(_0x56b13f['query'][_0xcce8('0x42')]){_0x1ea0f6[_0xcce8('0x43')]=[{'all':!![]}];}return db['ChatQueueReport']['findAll'](_0x1ea0f6);})[_0xcce8('0x26')](function(_0x84450b){_0x1fa558[_0xcce8('0x44')]=_0x84450b;return _0x1fa558;})['then'](respondWithFilteredResult(_0x3e0471,_0x1ea0f6))[_0xcce8('0x45')](handleError(_0x3e0471,null));};exports[_0xcce8('0x46')]=function(_0x4e60c4,_0x47cec8){var _0x3d6d0c={'raw':!![],'where':{'id':_0x4e60c4[_0xcce8('0x47')]['id']}},_0x567fa3={};_0x567fa3['model']=_[_0xcce8('0x32')](db[_0xcce8('0x2c')]['rawAttributes']);_0x567fa3[_0xcce8('0x31')]=_[_0xcce8('0x32')](_0x4e60c4[_0xcce8('0x31')]);_0x567fa3[_0xcce8('0x3c')]=_[_0xcce8('0x33')](_0x567fa3[_0xcce8('0x30')],_0x567fa3[_0xcce8('0x31')]);_0x3d6d0c[_0xcce8('0x34')]=_[_0xcce8('0x33')](_0x567fa3[_0xcce8('0x30')],qs[_0xcce8('0x35')](_0x4e60c4['query']['fields']));_0x3d6d0c[_0xcce8('0x34')]=_0x3d6d0c['attributes']['length']?_0x3d6d0c[_0xcce8('0x34')]:_0x567fa3[_0xcce8('0x30')];if(_0x4e60c4['query'][_0xcce8('0x42')]){_0x3d6d0c[_0xcce8('0x43')]=[{'all':!![]}];}_0x3d6d0c=_[_0xcce8('0x3f')]({},_0x3d6d0c,_0x4e60c4[_0xcce8('0x41')]);return db[_0xcce8('0x2c')][_0xcce8('0x48')](_0x3d6d0c)['then'](handleEntityNotFound(_0x47cec8,null))[_0xcce8('0x26')](respondWithResult(_0x47cec8,null))['catch'](handleError(_0x47cec8,null));};exports[_0xcce8('0x49')]=function(_0x4a5279,_0x254557){return db[_0xcce8('0x2c')][_0xcce8('0x49')](_0x4a5279['body'],{})[_0xcce8('0x26')](respondWithResult(_0x254557,0xc9))['catch'](handleError(_0x254557,null));};exports[_0xcce8('0x25')]=function(_0x100553,_0x16d169){if(_0x100553['body']['id']){delete _0x100553['body']['id'];}return db[_0xcce8('0x2c')][_0xcce8('0x48')]({'where':{'id':_0x100553[_0xcce8('0x47')]['id']}})[_0xcce8('0x26')](handleEntityNotFound(_0x16d169,null))[_0xcce8('0x26')](saveUpdates(_0x100553[_0xcce8('0x4a')],null))[_0xcce8('0x26')](respondWithResult(_0x16d169,null))['catch'](handleError(_0x16d169,null));};exports[_0xcce8('0x27')]=function(_0x1c7197,_0x321929){return db[_0xcce8('0x2c')][_0xcce8('0x48')]({'where':{'id':_0x1c7197[_0xcce8('0x47')]['id']}})['then'](handleEntityNotFound(_0x321929,null))[_0xcce8('0x26')](removeEntity(_0x321929,null))[_0xcce8('0x45')](handleError(_0x321929,null));};exports[_0xcce8('0x4b')]=function(_0x1f3379,_0x1d63d0){return db[_0xcce8('0x2c')]['describe']()[_0xcce8('0x26')](respondWithResult(_0x1d63d0,null))['catch'](handleError(_0x1d63d0,null));};