Built motion from commit 1fa89557.|2.6.10
[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 _0x4d68=['save','update','destroy','then','error','name','send','map','ChatQueueReport','rawAttributes','fieldName','type','model','query','keys','filters','intersection','fields','attributes','length','nolimit','order','sort','where','pick','filter','merge','includeAll','findAll','rows','catch','params','include','options','find','body','describe','eml-format','rimraf','zip-dir','fast-json-patch','request-promise','moment','mustache','path','to-csv','ejs','fs-extra','crypto','jsforce','desk.js','papaparse','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','api','../../config/environment','../../config/license/util','../../mysqldb','sendStatus','end','status','json','offset','undefined','limit','count','Content-Range','apply'];(function(_0x22d92a,_0x3d2a9b){var _0x308d0f=function(_0x1042e6){while(--_0x1042e6){_0x22d92a['push'](_0x22d92a['shift']());}};_0x308d0f(++_0x3d2a9b);}(_0x4d68,0x1c3));var _0x84d6=function(_0x28be72,_0x2b83af){_0x28be72=_0x28be72-0x0;var _0x46c5da=_0x4d68[_0x28be72];return _0x46c5da;};'use strict';var emlformat=require(_0x84d6('0x0'));var rimraf=require(_0x84d6('0x1'));var zipdir=require(_0x84d6('0x2'));var jsonpatch=require(_0x84d6('0x3'));var rp=require(_0x84d6('0x4'));var moment=require(_0x84d6('0x5'));var BPromise=require('bluebird');var Mustache=require(_0x84d6('0x6'));var util=require('util');var path=require(_0x84d6('0x7'));var sox=require('sox');var csv=require(_0x84d6('0x8'));var ejs=require(_0x84d6('0x9'));var fs=require('fs');var fs_extra=require(_0x84d6('0xa'));var _=require('lodash');var squel=require('squel');var crypto=require(_0x84d6('0xb'));var jsforce=require(_0x84d6('0xc'));var deskjs=require(_0x84d6('0xd'));var toCsv=require(_0x84d6('0x8'));var querystring=require('querystring');var Papa=require(_0x84d6('0xe'));var Redis=require('ioredis');var authService=require(_0x84d6('0xf'));var qs=require(_0x84d6('0x10'));var as=require(_0x84d6('0x11'));var hardwareService=require('../../config/license/hardware');var logger=require('../../config/logger')(_0x84d6('0x12'));var utils=require('../../config/utils');var config=require(_0x84d6('0x13'));var licenseUtil=require(_0x84d6('0x14'));var db=require(_0x84d6('0x15'))['db'];function respondWithStatusCode(_0x19e7a9,_0x203c54){_0x203c54=_0x203c54||0xcc;return function(_0x506edc){if(_0x506edc){return _0x19e7a9[_0x84d6('0x16')](_0x203c54);}return _0x19e7a9['status'](_0x203c54)[_0x84d6('0x17')]();};}function respondWithResult(_0x2e6340,_0x1a5d62){_0x1a5d62=_0x1a5d62||0xc8;return function(_0x44b065){if(_0x44b065){return _0x2e6340[_0x84d6('0x18')](_0x1a5d62)[_0x84d6('0x19')](_0x44b065);}};}function respondWithFilteredResult(_0x957ae6,_0x4f39f0){return function(_0x10646e){if(_0x10646e){var _0x41e128=typeof _0x4f39f0[_0x84d6('0x1a')]===_0x84d6('0x1b')&&typeof _0x4f39f0[_0x84d6('0x1c')]==='undefined';var _0x1dd975=_0x10646e[_0x84d6('0x1d')];var _0x579aa8=_0x41e128?0x0:_0x4f39f0[_0x84d6('0x1a')];var _0x47a884=_0x41e128?_0x10646e[_0x84d6('0x1d')]:_0x4f39f0[_0x84d6('0x1a')]+_0x4f39f0[_0x84d6('0x1c')];var _0x2cbfb5;if(_0x47a884>=_0x1dd975){_0x47a884=_0x1dd975;_0x2cbfb5=0xc8;}else{_0x2cbfb5=0xce;}_0x957ae6[_0x84d6('0x18')](_0x2cbfb5);return _0x957ae6['set'](_0x84d6('0x1e'),_0x579aa8+'-'+_0x47a884+'/'+_0x1dd975)[_0x84d6('0x19')](_0x10646e);}return null;};}function patchUpdates(_0x50ec59){return function(_0x4e4634){try{jsonpatch[_0x84d6('0x1f')](_0x4e4634,_0x50ec59,!![]);}catch(_0x5ebfcb){return BPromise['reject'](_0x5ebfcb);}return _0x4e4634[_0x84d6('0x20')]();};}function saveUpdates(_0x256787,_0x24c8fb){return function(_0x576510){if(_0x576510){return _0x576510[_0x84d6('0x21')](_0x256787)['then'](function(_0x5deb1f){return _0x5deb1f;});}return null;};}function removeEntity(_0x26e753,_0x1b86f2){return function(_0x596b7d){if(_0x596b7d){return _0x596b7d[_0x84d6('0x22')]()[_0x84d6('0x23')](function(){_0x26e753[_0x84d6('0x18')](0xcc)[_0x84d6('0x17')]();});}};}function handleEntityNotFound(_0x5deaa5,_0x282fbb){return function(_0x5d9284){if(!_0x5d9284){_0x5deaa5[_0x84d6('0x16')](0x194);}return _0x5d9284;};}function handleError(_0x19b6aa,_0x548ba5){_0x548ba5=_0x548ba5||0x1f4;return function(_0x500a81){logger[_0x84d6('0x24')](_0x500a81['stack']);if(_0x500a81['name']){delete _0x500a81[_0x84d6('0x25')];}_0x19b6aa['status'](_0x548ba5)[_0x84d6('0x26')](_0x500a81);};}exports['index']=function(_0x773fd0,_0x2c76e2){var _0x329926={},_0x37adf9={},_0x7c0074={'count':0x0,'rows':[]};var _0x125a2a=_[_0x84d6('0x27')](db[_0x84d6('0x28')][_0x84d6('0x29')],function(_0x1ebff2){return{'name':_0x1ebff2[_0x84d6('0x2a')],'type':_0x1ebff2[_0x84d6('0x2b')]['key']};});_0x37adf9[_0x84d6('0x2c')]=_[_0x84d6('0x27')](_0x125a2a,_0x84d6('0x25'));_0x37adf9[_0x84d6('0x2d')]=_[_0x84d6('0x2e')](_0x773fd0[_0x84d6('0x2d')]);_0x37adf9[_0x84d6('0x2f')]=_[_0x84d6('0x30')](_0x37adf9['model'],_0x37adf9[_0x84d6('0x2d')]);_0x329926['attributes']=_[_0x84d6('0x30')](_0x37adf9[_0x84d6('0x2c')],qs['fields'](_0x773fd0[_0x84d6('0x2d')][_0x84d6('0x31')]));_0x329926['attributes']=_0x329926[_0x84d6('0x32')][_0x84d6('0x33')]?_0x329926[_0x84d6('0x32')]:_0x37adf9[_0x84d6('0x2c')];if(!_0x773fd0[_0x84d6('0x2d')]['hasOwnProperty'](_0x84d6('0x34'))){_0x329926[_0x84d6('0x1c')]=qs[_0x84d6('0x1c')](_0x773fd0['query'][_0x84d6('0x1c')]);_0x329926['offset']=qs[_0x84d6('0x1a')](_0x773fd0['query']['offset']);}_0x329926[_0x84d6('0x35')]=qs[_0x84d6('0x36')](_0x773fd0[_0x84d6('0x2d')]['sort']);_0x329926[_0x84d6('0x37')]=qs[_0x84d6('0x2f')](_[_0x84d6('0x38')](_0x773fd0['query'],_0x37adf9['filters']),_0x125a2a);if(_0x773fd0['query'][_0x84d6('0x39')]){_0x329926[_0x84d6('0x37')]=_[_0x84d6('0x3a')](_0x329926[_0x84d6('0x37')],{'$or':_[_0x84d6('0x27')](_0x125a2a,function(_0x3b1dd2){if(_0x3b1dd2['type']!=='VIRTUAL'){var _0x30836a={};_0x30836a[_0x3b1dd2[_0x84d6('0x25')]]={'$like':'%'+_0x773fd0[_0x84d6('0x2d')][_0x84d6('0x39')]+'%'};return _0x30836a;}})});}_0x329926=_[_0x84d6('0x3a')]({},_0x329926,_0x773fd0['options']);var _0x59ea9b={'where':_0x329926['where']};return db[_0x84d6('0x28')]['count'](_0x59ea9b)[_0x84d6('0x23')](function(_0x25dccd){_0x7c0074['count']=_0x25dccd;if(_0x773fd0[_0x84d6('0x2d')][_0x84d6('0x3b')]){_0x329926['include']=[{'all':!![]}];}return db[_0x84d6('0x28')][_0x84d6('0x3c')](_0x329926);})[_0x84d6('0x23')](function(_0x4596c6){_0x7c0074[_0x84d6('0x3d')]=_0x4596c6;return _0x7c0074;})['then'](respondWithFilteredResult(_0x2c76e2,_0x329926))[_0x84d6('0x3e')](handleError(_0x2c76e2,null));};exports['show']=function(_0x1165f9,_0x1930af){var _0x95c924={'raw':!![],'where':{'id':_0x1165f9[_0x84d6('0x3f')]['id']}},_0x56ff93={};_0x56ff93[_0x84d6('0x2c')]=_[_0x84d6('0x2e')](db[_0x84d6('0x28')][_0x84d6('0x29')]);_0x56ff93[_0x84d6('0x2d')]=_['keys'](_0x1165f9[_0x84d6('0x2d')]);_0x56ff93['filters']=_['intersection'](_0x56ff93['model'],_0x56ff93[_0x84d6('0x2d')]);_0x95c924['attributes']=_['intersection'](_0x56ff93[_0x84d6('0x2c')],qs[_0x84d6('0x31')](_0x1165f9['query'][_0x84d6('0x31')]));_0x95c924[_0x84d6('0x32')]=_0x95c924[_0x84d6('0x32')][_0x84d6('0x33')]?_0x95c924[_0x84d6('0x32')]:_0x56ff93[_0x84d6('0x2c')];if(_0x1165f9['query']['includeAll']){_0x95c924[_0x84d6('0x40')]=[{'all':!![]}];}_0x95c924=_[_0x84d6('0x3a')]({},_0x95c924,_0x1165f9[_0x84d6('0x41')]);return db[_0x84d6('0x28')][_0x84d6('0x42')](_0x95c924)[_0x84d6('0x23')](handleEntityNotFound(_0x1930af,null))[_0x84d6('0x23')](respondWithResult(_0x1930af,null))['catch'](handleError(_0x1930af,null));};exports['create']=function(_0x1adbdc,_0x5a42fb){return db[_0x84d6('0x28')]['create'](_0x1adbdc[_0x84d6('0x43')],{})[_0x84d6('0x23')](respondWithResult(_0x5a42fb,0xc9))[_0x84d6('0x3e')](handleError(_0x5a42fb,null));};exports[_0x84d6('0x21')]=function(_0x4e4d67,_0x1aae95){if(_0x4e4d67['body']['id']){delete _0x4e4d67[_0x84d6('0x43')]['id'];}return db[_0x84d6('0x28')][_0x84d6('0x42')]({'where':{'id':_0x4e4d67['params']['id']}})['then'](handleEntityNotFound(_0x1aae95,null))[_0x84d6('0x23')](saveUpdates(_0x4e4d67['body'],null))['then'](respondWithResult(_0x1aae95,null))['catch'](handleError(_0x1aae95,null));};exports['destroy']=function(_0x5704cb,_0x12ea8b){return db['ChatQueueReport'][_0x84d6('0x42')]({'where':{'id':_0x5704cb[_0x84d6('0x3f')]['id']}})[_0x84d6('0x23')](handleEntityNotFound(_0x12ea8b,null))[_0x84d6('0x23')](removeEntity(_0x12ea8b,null))[_0x84d6('0x3e')](handleError(_0x12ea8b,null));};exports[_0x84d6('0x44')]=function(_0x2ec57c,_0x3acb28){return db[_0x84d6('0x28')]['describe']()['then'](respondWithResult(_0x3acb28,null))[_0x84d6('0x3e')](handleError(_0x3acb28,null));};