Built motion from commit 0900f080.|2.5.45
[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 _0xfe91=['fast-json-patch','moment','bluebird','mustache','util','path','sox','to-csv','fs-extra','lodash','squel','desk.js','papaparse','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','api','../../config/environment','../../config/license/util','sendStatus','status','offset','undefined','limit','count','set','Content-Range','json','update','then','error','stack','name','send','index','map','ChatQueueReport','rawAttributes','fieldName','type','model','query','keys','filters','intersection','attributes','fields','length','nolimit','sort','where','pick','filter','merge','VIRTUAL','options','include','rows','catch','show','params','includeAll','create','body','find','destroy','describe','eml-format'];(function(_0x31f647,_0x4dd253){var _0x127e94=function(_0x5b2f53){while(--_0x5b2f53){_0x31f647['push'](_0x31f647['shift']());}};_0x127e94(++_0x4dd253);}(_0xfe91,0xd4));var _0x1fe9=function(_0x3899d1,_0x4aa04c){_0x3899d1=_0x3899d1-0x0;var _0xeb4a7d=_0xfe91[_0x3899d1];return _0xeb4a7d;};'use strict';var emlformat=require(_0x1fe9('0x0'));var rimraf=require('rimraf');var zipdir=require('zip-dir');var jsonpatch=require(_0x1fe9('0x1'));var rp=require('request-promise');var moment=require(_0x1fe9('0x2'));var BPromise=require(_0x1fe9('0x3'));var Mustache=require(_0x1fe9('0x4'));var util=require(_0x1fe9('0x5'));var path=require(_0x1fe9('0x6'));var sox=require(_0x1fe9('0x7'));var csv=require(_0x1fe9('0x8'));var ejs=require('ejs');var fs=require('fs');var fs_extra=require(_0x1fe9('0x9'));var _=require(_0x1fe9('0xa'));var squel=require(_0x1fe9('0xb'));var crypto=require('crypto');var jsforce=require('jsforce');var deskjs=require(_0x1fe9('0xc'));var toCsv=require(_0x1fe9('0x8'));var querystring=require('querystring');var Papa=require(_0x1fe9('0xd'));var Redis=require(_0x1fe9('0xe'));var authService=require(_0x1fe9('0xf'));var qs=require(_0x1fe9('0x10'));var as=require(_0x1fe9('0x11'));var hardwareService=require(_0x1fe9('0x12'));var logger=require(_0x1fe9('0x13'))(_0x1fe9('0x14'));var utils=require('../../config/utils');var config=require(_0x1fe9('0x15'));var licenseUtil=require(_0x1fe9('0x16'));var db=require('../../mysqldb')['db'];function respondWithStatusCode(_0x1d747e,_0x2deeaf){_0x2deeaf=_0x2deeaf||0xcc;return function(_0x4299dd){if(_0x4299dd){return _0x1d747e[_0x1fe9('0x17')](_0x2deeaf);}return _0x1d747e[_0x1fe9('0x18')](_0x2deeaf)['end']();};}function respondWithResult(_0x1c10ef,_0x1f6026){_0x1f6026=_0x1f6026||0xc8;return function(_0x4c5e41){if(_0x4c5e41){return _0x1c10ef[_0x1fe9('0x18')](_0x1f6026)['json'](_0x4c5e41);}};}function respondWithFilteredResult(_0x30d5c8,_0x3b6988){return function(_0x2f62a8){if(_0x2f62a8){var _0x5da3c1=typeof _0x3b6988[_0x1fe9('0x19')]===_0x1fe9('0x1a')&&typeof _0x3b6988[_0x1fe9('0x1b')]==='undefined';var _0x440e0a=_0x2f62a8[_0x1fe9('0x1c')];var _0x2085ac=_0x5da3c1?0x0:_0x3b6988['offset'];var _0x2070a3=_0x5da3c1?_0x2f62a8['count']:_0x3b6988[_0x1fe9('0x19')]+_0x3b6988[_0x1fe9('0x1b')];var _0x491bcb;if(_0x2070a3>=_0x440e0a){_0x2070a3=_0x440e0a;_0x491bcb=0xc8;}else{_0x491bcb=0xce;}_0x30d5c8[_0x1fe9('0x18')](_0x491bcb);return _0x30d5c8[_0x1fe9('0x1d')](_0x1fe9('0x1e'),_0x2085ac+'-'+_0x2070a3+'/'+_0x440e0a)[_0x1fe9('0x1f')](_0x2f62a8);}return null;};}function patchUpdates(_0x442ae7){return function(_0x125775){try{jsonpatch['apply'](_0x125775,_0x442ae7,!![]);}catch(_0x38ec4e){return BPromise['reject'](_0x38ec4e);}return _0x125775['save']();};}function saveUpdates(_0x15b582,_0xe32090){return function(_0x1859ee){if(_0x1859ee){return _0x1859ee[_0x1fe9('0x20')](_0x15b582)[_0x1fe9('0x21')](function(_0xa79582){return _0xa79582;});}return null;};}function removeEntity(_0x56d3bf,_0x18afe2){return function(_0xa92d55){if(_0xa92d55){return _0xa92d55['destroy']()[_0x1fe9('0x21')](function(){_0x56d3bf[_0x1fe9('0x18')](0xcc)['end']();});}};}function handleEntityNotFound(_0x2e492f,_0x462537){return function(_0x5f135d){if(!_0x5f135d){_0x2e492f[_0x1fe9('0x17')](0x194);}return _0x5f135d;};}function handleError(_0x44ae36,_0x5206a0){_0x5206a0=_0x5206a0||0x1f4;return function(_0x297c4b){logger[_0x1fe9('0x22')](_0x297c4b[_0x1fe9('0x23')]);if(_0x297c4b[_0x1fe9('0x24')]){delete _0x297c4b[_0x1fe9('0x24')];}_0x44ae36[_0x1fe9('0x18')](_0x5206a0)[_0x1fe9('0x25')](_0x297c4b);};}exports[_0x1fe9('0x26')]=function(_0xed426c,_0x1828ca){var _0x2aea20={},_0x11f374={},_0x3551e4={'count':0x0,'rows':[]};var _0x538d33=_[_0x1fe9('0x27')](db[_0x1fe9('0x28')][_0x1fe9('0x29')],function(_0x5319d2){return{'name':_0x5319d2[_0x1fe9('0x2a')],'type':_0x5319d2[_0x1fe9('0x2b')]['key']};});_0x11f374[_0x1fe9('0x2c')]=_['map'](_0x538d33,_0x1fe9('0x24'));_0x11f374[_0x1fe9('0x2d')]=_[_0x1fe9('0x2e')](_0xed426c[_0x1fe9('0x2d')]);_0x11f374[_0x1fe9('0x2f')]=_[_0x1fe9('0x30')](_0x11f374[_0x1fe9('0x2c')],_0x11f374[_0x1fe9('0x2d')]);_0x2aea20[_0x1fe9('0x31')]=_['intersection'](_0x11f374[_0x1fe9('0x2c')],qs[_0x1fe9('0x32')](_0xed426c['query'][_0x1fe9('0x32')]));_0x2aea20[_0x1fe9('0x31')]=_0x2aea20[_0x1fe9('0x31')][_0x1fe9('0x33')]?_0x2aea20[_0x1fe9('0x31')]:_0x11f374[_0x1fe9('0x2c')];if(!_0xed426c['query']['hasOwnProperty'](_0x1fe9('0x34'))){_0x2aea20['limit']=qs['limit'](_0xed426c[_0x1fe9('0x2d')][_0x1fe9('0x1b')]);_0x2aea20[_0x1fe9('0x19')]=qs[_0x1fe9('0x19')](_0xed426c['query'][_0x1fe9('0x19')]);}_0x2aea20['order']=qs[_0x1fe9('0x35')](_0xed426c[_0x1fe9('0x2d')]['sort']);_0x2aea20[_0x1fe9('0x36')]=qs['filters'](_[_0x1fe9('0x37')](_0xed426c[_0x1fe9('0x2d')],_0x11f374[_0x1fe9('0x2f')]),_0x538d33);if(_0xed426c['query'][_0x1fe9('0x38')]){_0x2aea20[_0x1fe9('0x36')]=_[_0x1fe9('0x39')](_0x2aea20['where'],{'$or':_[_0x1fe9('0x27')](_0x538d33,function(_0x1bf2df){if(_0x1bf2df['type']!==_0x1fe9('0x3a')){var _0x36ef35={};_0x36ef35[_0x1bf2df[_0x1fe9('0x24')]]={'$like':'%'+_0xed426c[_0x1fe9('0x2d')][_0x1fe9('0x38')]+'%'};return _0x36ef35;}})});}_0x2aea20=_['merge']({},_0x2aea20,_0xed426c[_0x1fe9('0x3b')]);var _0xcb61ae={'where':_0x2aea20[_0x1fe9('0x36')]};return db[_0x1fe9('0x28')][_0x1fe9('0x1c')](_0xcb61ae)[_0x1fe9('0x21')](function(_0x110530){_0x3551e4['count']=_0x110530;if(_0xed426c['query']['includeAll']){_0x2aea20[_0x1fe9('0x3c')]=[{'all':!![]}];}return db['ChatQueueReport']['findAll'](_0x2aea20);})[_0x1fe9('0x21')](function(_0x427db5){_0x3551e4[_0x1fe9('0x3d')]=_0x427db5;return _0x3551e4;})[_0x1fe9('0x21')](respondWithFilteredResult(_0x1828ca,_0x2aea20))[_0x1fe9('0x3e')](handleError(_0x1828ca,null));};exports[_0x1fe9('0x3f')]=function(_0x38f045,_0x2a9bf7){var _0x2b3f92={'raw':!![],'where':{'id':_0x38f045[_0x1fe9('0x40')]['id']}},_0xd4d387={};_0xd4d387[_0x1fe9('0x2c')]=_['keys'](db[_0x1fe9('0x28')]['rawAttributes']);_0xd4d387['query']=_[_0x1fe9('0x2e')](_0x38f045[_0x1fe9('0x2d')]);_0xd4d387[_0x1fe9('0x2f')]=_['intersection'](_0xd4d387['model'],_0xd4d387[_0x1fe9('0x2d')]);_0x2b3f92[_0x1fe9('0x31')]=_[_0x1fe9('0x30')](_0xd4d387['model'],qs[_0x1fe9('0x32')](_0x38f045[_0x1fe9('0x2d')][_0x1fe9('0x32')]));_0x2b3f92[_0x1fe9('0x31')]=_0x2b3f92[_0x1fe9('0x31')][_0x1fe9('0x33')]?_0x2b3f92[_0x1fe9('0x31')]:_0xd4d387[_0x1fe9('0x2c')];if(_0x38f045[_0x1fe9('0x2d')][_0x1fe9('0x41')]){_0x2b3f92[_0x1fe9('0x3c')]=[{'all':!![]}];}_0x2b3f92=_[_0x1fe9('0x39')]({},_0x2b3f92,_0x38f045[_0x1fe9('0x3b')]);return db[_0x1fe9('0x28')]['find'](_0x2b3f92)['then'](handleEntityNotFound(_0x2a9bf7,null))['then'](respondWithResult(_0x2a9bf7,null))[_0x1fe9('0x3e')](handleError(_0x2a9bf7,null));};exports[_0x1fe9('0x42')]=function(_0x2d490f,_0x3c9a4e){return db[_0x1fe9('0x28')][_0x1fe9('0x42')](_0x2d490f[_0x1fe9('0x43')],{})[_0x1fe9('0x21')](respondWithResult(_0x3c9a4e,0xc9))[_0x1fe9('0x3e')](handleError(_0x3c9a4e,null));};exports[_0x1fe9('0x20')]=function(_0x3f9a18,_0x2ccf57){if(_0x3f9a18[_0x1fe9('0x43')]['id']){delete _0x3f9a18[_0x1fe9('0x43')]['id'];}return db[_0x1fe9('0x28')][_0x1fe9('0x44')]({'where':{'id':_0x3f9a18['params']['id']}})[_0x1fe9('0x21')](handleEntityNotFound(_0x2ccf57,null))[_0x1fe9('0x21')](saveUpdates(_0x3f9a18['body'],null))[_0x1fe9('0x21')](respondWithResult(_0x2ccf57,null))[_0x1fe9('0x3e')](handleError(_0x2ccf57,null));};exports[_0x1fe9('0x45')]=function(_0x85d38e,_0x4eea2d){return db[_0x1fe9('0x28')][_0x1fe9('0x44')]({'where':{'id':_0x85d38e[_0x1fe9('0x40')]['id']}})[_0x1fe9('0x21')](handleEntityNotFound(_0x4eea2d,null))[_0x1fe9('0x21')](removeEntity(_0x4eea2d,null))[_0x1fe9('0x3e')](handleError(_0x4eea2d,null));};exports[_0x1fe9('0x46')]=function(_0x5c4123,_0x3081f8){return db[_0x1fe9('0x28')]['describe']()[_0x1fe9('0x21')](respondWithResult(_0x3081f8,null))[_0x1fe9('0x3e')](handleError(_0x3081f8,null));};