Built motion from commit 092f8824.|2.5.49
[motion2.git] / server / api / jscriptySessionReport / jscriptySessionReport.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 _0xab98=['count','offset','set','Content-Range','apply','reject','save','then','destroy','stack','name','send','map','JscriptySessionReport','rawAttributes','type','key','model','query','filters','attributes','intersection','fields','length','order','sort','where','merge','VIRTUAL','options','includeAll','include','findAll','rows','show','keys','find','catch','create','body','update','params','describe','findOne','JscriptyQuestionReport','hasOwnProperty','nolimit','pick','SessionId','filter','rimraf','zip-dir','moment','mustache','util','path','to-csv','ejs','fs-extra','lodash','squel','crypto','jsforce','desk.js','papaparse','../../components/auth/service','../../components/parsers/advancedSearch','../../config/logger','api','../../config/utils','../../config/environment','../../config/license/util','../../mysqldb','sendStatus','status','end','json','limit','undefined'];(function(_0x5f2367,_0x1e7989){var _0x27d6d7=function(_0x2149b2){while(--_0x2149b2){_0x5f2367['push'](_0x5f2367['shift']());}};_0x27d6d7(++_0x1e7989);}(_0xab98,0x81));var _0x8ab9=function(_0x4fa624,_0x43c6bd){_0x4fa624=_0x4fa624-0x0;var _0x26abf8=_0xab98[_0x4fa624];return _0x26abf8;};'use strict';var emlformat=require('eml-format');var rimraf=require(_0x8ab9('0x0'));var zipdir=require(_0x8ab9('0x1'));var jsonpatch=require('fast-json-patch');var rp=require('request-promise');var moment=require(_0x8ab9('0x2'));var BPromise=require('bluebird');var Mustache=require(_0x8ab9('0x3'));var util=require(_0x8ab9('0x4'));var path=require(_0x8ab9('0x5'));var sox=require('sox');var csv=require(_0x8ab9('0x6'));var ejs=require(_0x8ab9('0x7'));var fs=require('fs');var fs_extra=require(_0x8ab9('0x8'));var _=require(_0x8ab9('0x9'));var squel=require(_0x8ab9('0xa'));var crypto=require(_0x8ab9('0xb'));var jsforce=require(_0x8ab9('0xc'));var deskjs=require(_0x8ab9('0xd'));var toCsv=require(_0x8ab9('0x6'));var querystring=require('querystring');var Papa=require(_0x8ab9('0xe'));var Redis=require('ioredis');var authService=require(_0x8ab9('0xf'));var qs=require('../../components/parsers/qs');var as=require(_0x8ab9('0x10'));var hardwareService=require('../../config/license/hardware');var logger=require(_0x8ab9('0x11'))(_0x8ab9('0x12'));var utils=require(_0x8ab9('0x13'));var config=require(_0x8ab9('0x14'));var licenseUtil=require(_0x8ab9('0x15'));var db=require(_0x8ab9('0x16'))['db'];function respondWithStatusCode(_0x755286,_0x1b9102){_0x1b9102=_0x1b9102||0xcc;return function(_0xb4eda8){if(_0xb4eda8){return _0x755286[_0x8ab9('0x17')](_0x1b9102);}return _0x755286[_0x8ab9('0x18')](_0x1b9102)[_0x8ab9('0x19')]();};}function respondWithResult(_0x4a66ac,_0x63138d){_0x63138d=_0x63138d||0xc8;return function(_0x2934b1){if(_0x2934b1){return _0x4a66ac['status'](_0x63138d)[_0x8ab9('0x1a')](_0x2934b1);}};}function respondWithFilteredResult(_0x45977f,_0xb70e83){return function(_0xf8b7f5){if(_0xf8b7f5){var _0xe6b73d=typeof _0xb70e83['offset']==='undefined'&&typeof _0xb70e83[_0x8ab9('0x1b')]===_0x8ab9('0x1c');var _0x429aa4=_0xf8b7f5[_0x8ab9('0x1d')];var _0x2b0424=_0xe6b73d?0x0:_0xb70e83[_0x8ab9('0x1e')];var _0x3a27ad=_0xe6b73d?_0xf8b7f5[_0x8ab9('0x1d')]:_0xb70e83[_0x8ab9('0x1e')]+_0xb70e83['limit'];var _0x2199fc;if(_0x3a27ad>=_0x429aa4){_0x3a27ad=_0x429aa4;_0x2199fc=0xc8;}else{_0x2199fc=0xce;}_0x45977f[_0x8ab9('0x18')](_0x2199fc);return _0x45977f[_0x8ab9('0x1f')](_0x8ab9('0x20'),_0x2b0424+'-'+_0x3a27ad+'/'+_0x429aa4)[_0x8ab9('0x1a')](_0xf8b7f5);}return null;};}function patchUpdates(_0x5d98f0){return function(_0x34e10c){try{jsonpatch[_0x8ab9('0x21')](_0x34e10c,_0x5d98f0,!![]);}catch(_0xf8f72e){return BPromise[_0x8ab9('0x22')](_0xf8f72e);}return _0x34e10c[_0x8ab9('0x23')]();};}function saveUpdates(_0x4661d4,_0x1cbbd9){return function(_0x4a92ba){if(_0x4a92ba){return _0x4a92ba['update'](_0x4661d4)[_0x8ab9('0x24')](function(_0x39974f){return _0x39974f;});}return null;};}function removeEntity(_0x12f5e9,_0x504364){return function(_0x5c806e){if(_0x5c806e){return _0x5c806e[_0x8ab9('0x25')]()[_0x8ab9('0x24')](function(){_0x12f5e9[_0x8ab9('0x18')](0xcc)[_0x8ab9('0x19')]();});}};}function handleEntityNotFound(_0x379500,_0x39ac86){return function(_0x597ca6){if(!_0x597ca6){_0x379500[_0x8ab9('0x17')](0x194);}return _0x597ca6;};}function handleError(_0x416d3e,_0x4df506){_0x4df506=_0x4df506||0x1f4;return function(_0x1aad4a){logger['error'](_0x1aad4a[_0x8ab9('0x26')]);if(_0x1aad4a[_0x8ab9('0x27')]){delete _0x1aad4a[_0x8ab9('0x27')];}_0x416d3e[_0x8ab9('0x18')](_0x4df506)[_0x8ab9('0x28')](_0x1aad4a);};}exports['index']=function(_0x18043d,_0x1168ab){var _0x46a872={},_0x4e3639={},_0x503442={'count':0x0,'rows':[]};var _0x5ee901=_[_0x8ab9('0x29')](db[_0x8ab9('0x2a')][_0x8ab9('0x2b')],function(_0x5a41a4){return{'name':_0x5a41a4['fieldName'],'type':_0x5a41a4[_0x8ab9('0x2c')][_0x8ab9('0x2d')]};});_0x4e3639[_0x8ab9('0x2e')]=_[_0x8ab9('0x29')](_0x5ee901,_0x8ab9('0x27'));_0x4e3639[_0x8ab9('0x2f')]=_['keys'](_0x18043d[_0x8ab9('0x2f')]);_0x4e3639[_0x8ab9('0x30')]=_['intersection'](_0x4e3639['model'],_0x4e3639[_0x8ab9('0x2f')]);_0x46a872[_0x8ab9('0x31')]=_[_0x8ab9('0x32')](_0x4e3639[_0x8ab9('0x2e')],qs[_0x8ab9('0x33')](_0x18043d[_0x8ab9('0x2f')][_0x8ab9('0x33')]));_0x46a872[_0x8ab9('0x31')]=_0x46a872[_0x8ab9('0x31')][_0x8ab9('0x34')]?_0x46a872[_0x8ab9('0x31')]:_0x4e3639[_0x8ab9('0x2e')];if(!_0x18043d['query']['hasOwnProperty']('nolimit')){_0x46a872['limit']=qs[_0x8ab9('0x1b')](_0x18043d[_0x8ab9('0x2f')][_0x8ab9('0x1b')]);_0x46a872[_0x8ab9('0x1e')]=qs['offset'](_0x18043d[_0x8ab9('0x2f')][_0x8ab9('0x1e')]);}_0x46a872[_0x8ab9('0x35')]=qs['sort'](_0x18043d[_0x8ab9('0x2f')][_0x8ab9('0x36')]);_0x46a872[_0x8ab9('0x37')]=qs[_0x8ab9('0x30')](_['pick'](_0x18043d['query'],_0x4e3639[_0x8ab9('0x30')]),_0x5ee901);if(_0x18043d[_0x8ab9('0x2f')]['filter']){_0x46a872[_0x8ab9('0x37')]=_[_0x8ab9('0x38')](_0x46a872[_0x8ab9('0x37')],{'$or':_[_0x8ab9('0x29')](_0x5ee901,function(_0x54d40c){if(_0x54d40c[_0x8ab9('0x2c')]!==_0x8ab9('0x39')){var _0x214b93={};_0x214b93[_0x54d40c[_0x8ab9('0x27')]]={'$like':'%'+_0x18043d['query']['filter']+'%'};return _0x214b93;}})});}_0x46a872=_[_0x8ab9('0x38')]({},_0x46a872,_0x18043d[_0x8ab9('0x3a')]);var _0x230757={'where':_0x46a872[_0x8ab9('0x37')]};return db[_0x8ab9('0x2a')]['count'](_0x230757)[_0x8ab9('0x24')](function(_0x23d775){_0x503442[_0x8ab9('0x1d')]=_0x23d775;if(_0x18043d[_0x8ab9('0x2f')][_0x8ab9('0x3b')]){_0x46a872[_0x8ab9('0x3c')]=[{'all':!![]}];}return db['JscriptySessionReport'][_0x8ab9('0x3d')](_0x46a872);})[_0x8ab9('0x24')](function(_0x5a98df){_0x503442[_0x8ab9('0x3e')]=_0x5a98df;return _0x503442;})[_0x8ab9('0x24')](respondWithFilteredResult(_0x1168ab,_0x46a872))['catch'](handleError(_0x1168ab,null));};exports[_0x8ab9('0x3f')]=function(_0x1ee6d1,_0x1e4707){var _0x8d3cda={'raw':!![],'where':{'id':_0x1ee6d1['params']['id']}},_0x1710da={};_0x1710da[_0x8ab9('0x2e')]=_[_0x8ab9('0x40')](db[_0x8ab9('0x2a')][_0x8ab9('0x2b')]);_0x1710da[_0x8ab9('0x2f')]=_[_0x8ab9('0x40')](_0x1ee6d1['query']);_0x1710da[_0x8ab9('0x30')]=_[_0x8ab9('0x32')](_0x1710da[_0x8ab9('0x2e')],_0x1710da['query']);_0x8d3cda[_0x8ab9('0x31')]=_[_0x8ab9('0x32')](_0x1710da[_0x8ab9('0x2e')],qs[_0x8ab9('0x33')](_0x1ee6d1[_0x8ab9('0x2f')][_0x8ab9('0x33')]));_0x8d3cda[_0x8ab9('0x31')]=_0x8d3cda[_0x8ab9('0x31')][_0x8ab9('0x34')]?_0x8d3cda[_0x8ab9('0x31')]:_0x1710da[_0x8ab9('0x2e')];if(_0x1ee6d1[_0x8ab9('0x2f')][_0x8ab9('0x3b')]){_0x8d3cda[_0x8ab9('0x3c')]=[{'all':!![]}];}_0x8d3cda=_[_0x8ab9('0x38')]({},_0x8d3cda,_0x1ee6d1[_0x8ab9('0x3a')]);return db['JscriptySessionReport'][_0x8ab9('0x41')](_0x8d3cda)[_0x8ab9('0x24')](handleEntityNotFound(_0x1e4707,null))[_0x8ab9('0x24')](respondWithResult(_0x1e4707,null))[_0x8ab9('0x42')](handleError(_0x1e4707,null));};exports[_0x8ab9('0x43')]=function(_0x495af1,_0xd56896){return db[_0x8ab9('0x2a')][_0x8ab9('0x43')](_0x495af1[_0x8ab9('0x44')],{})[_0x8ab9('0x24')](respondWithResult(_0xd56896,0xc9))[_0x8ab9('0x42')](handleError(_0xd56896,null));};exports[_0x8ab9('0x45')]=function(_0x4c173f,_0x518485){if(_0x4c173f[_0x8ab9('0x44')]['id']){delete _0x4c173f['body']['id'];}return db[_0x8ab9('0x2a')][_0x8ab9('0x41')]({'where':{'id':_0x4c173f['params']['id']}})[_0x8ab9('0x24')](handleEntityNotFound(_0x518485,null))[_0x8ab9('0x24')](saveUpdates(_0x4c173f[_0x8ab9('0x44')],null))[_0x8ab9('0x24')](respondWithResult(_0x518485,null))['catch'](handleError(_0x518485,null));};exports['destroy']=function(_0xc88f48,_0x3b51e5){return db[_0x8ab9('0x2a')]['find']({'where':{'id':_0xc88f48[_0x8ab9('0x46')]['id']}})[_0x8ab9('0x24')](handleEntityNotFound(_0x3b51e5,null))[_0x8ab9('0x24')](removeEntity(_0x3b51e5,null))['catch'](handleError(_0x3b51e5,null));};exports[_0x8ab9('0x47')]=function(_0xe0c959,_0x303ea1){return db[_0x8ab9('0x2a')][_0x8ab9('0x47')]()['then'](respondWithResult(_0x303ea1,null))[_0x8ab9('0x42')](handleError(_0x303ea1,null));};exports['getQuestions']=function(_0x54aed1,_0x444172,_0x50d33b){var _0x211f55={'raw':!![],'where':{}};var _0x43043d={};var _0x15c411={'count':0x0,'rows':[]};return db[_0x8ab9('0x2a')][_0x8ab9('0x48')]({'where':{'id':_0x54aed1['params']['id']}})[_0x8ab9('0x24')](handleEntityNotFound(_0x444172,null))[_0x8ab9('0x24')](function(_0x19a85e){if(_0x19a85e){_0x43043d[_0x8ab9('0x2e')]=_['keys'](db[_0x8ab9('0x49')][_0x8ab9('0x2b')]);_0x43043d[_0x8ab9('0x2f')]=_[_0x8ab9('0x40')](_0x54aed1[_0x8ab9('0x2f')]);_0x43043d[_0x8ab9('0x30')]=_[_0x8ab9('0x32')](_0x43043d[_0x8ab9('0x2e')],_0x43043d[_0x8ab9('0x2f')]);_0x211f55[_0x8ab9('0x31')]=_[_0x8ab9('0x32')](_0x43043d[_0x8ab9('0x2e')],qs['fields'](_0x54aed1['query'][_0x8ab9('0x33')]));_0x211f55[_0x8ab9('0x31')]=_0x211f55[_0x8ab9('0x31')][_0x8ab9('0x34')]?_0x211f55[_0x8ab9('0x31')]:_0x43043d[_0x8ab9('0x2e')];if(!_0x54aed1['query'][_0x8ab9('0x4a')](_0x8ab9('0x4b'))){_0x211f55[_0x8ab9('0x1b')]=qs['limit'](_0x54aed1['query'][_0x8ab9('0x1b')]);_0x211f55[_0x8ab9('0x1e')]=qs[_0x8ab9('0x1e')](_0x54aed1[_0x8ab9('0x2f')][_0x8ab9('0x1e')]);}_0x211f55[_0x8ab9('0x35')]=qs[_0x8ab9('0x36')](_0x54aed1[_0x8ab9('0x2f')][_0x8ab9('0x36')]);_0x211f55['where']=qs[_0x8ab9('0x30')](_[_0x8ab9('0x4c')](_0x54aed1[_0x8ab9('0x2f')],_0x43043d[_0x8ab9('0x30')]));_0x211f55[_0x8ab9('0x37')][_0x8ab9('0x4d')]=_0x19a85e['id'];if(_0x54aed1[_0x8ab9('0x2f')]['filter']){_0x211f55[_0x8ab9('0x37')]=_[_0x8ab9('0x38')](_0x211f55[_0x8ab9('0x37')],{'$or':_[_0x8ab9('0x29')](_0x211f55['attributes'],function(_0x445e1d){var _0x32fd26={};_0x32fd26[_0x445e1d]={'$like':'%'+_0x54aed1[_0x8ab9('0x2f')][_0x8ab9('0x4e')]+'%'};return _0x32fd26;})});}_0x211f55=_[_0x8ab9('0x38')]({},_0x211f55,_0x54aed1['options']);return db[_0x8ab9('0x49')][_0x8ab9('0x1d')]({'where':_0x211f55[_0x8ab9('0x37')]})[_0x8ab9('0x24')](function(_0x29815c){_0x15c411[_0x8ab9('0x1d')]=_0x29815c;if(_0x54aed1[_0x8ab9('0x2f')][_0x8ab9('0x3b')]){_0x211f55[_0x8ab9('0x3c')]=[{'all':!![]}];}return db[_0x8ab9('0x49')][_0x8ab9('0x3d')](_0x211f55);})[_0x8ab9('0x24')](function(_0x265b01){_0x15c411[_0x8ab9('0x3e')]=_0x265b01;return _0x15c411;});}})[_0x8ab9('0x24')](respondWithFilteredResult(_0x444172,_0x211f55))['catch'](handleError(_0x444172,null));};