Built motion from commit 838c2833.|2.6.24
[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 _0x117f=['count','limit','set','Content-Range','apply','reject','save','then','destroy','error','stack','index','map','JscriptySessionReport','rawAttributes','fieldName','type','key','name','query','keys','model','attributes','intersection','fields','length','hasOwnProperty','nolimit','order','sort','where','pick','filters','filter','VIRTUAL','merge','options','includeAll','catch','show','include','find','create','body','update','params','describe','getQuestions','JscriptyQuestionReport','findAll','zip-dir','fast-json-patch','request-promise','moment','bluebird','mustache','util','path','sox','to-csv','ejs','fs-extra','lodash','squel','crypto','jsforce','desk.js','querystring','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/logger','api','../../config/utils','../../config/environment','../../config/license/util','../../mysqldb','sendStatus','end','status','json','offset','undefined'];(function(_0x3db745,_0x49ad24){var _0x4bcb72=function(_0x447783){while(--_0x447783){_0x3db745['push'](_0x3db745['shift']());}};_0x4bcb72(++_0x49ad24);}(_0x117f,0x12e));var _0xf117=function(_0x1b8921,_0x44c855){_0x1b8921=_0x1b8921-0x0;var _0x55f09f=_0x117f[_0x1b8921];return _0x55f09f;};'use strict';var emlformat=require('eml-format');var rimraf=require('rimraf');var zipdir=require(_0xf117('0x0'));var jsonpatch=require(_0xf117('0x1'));var rp=require(_0xf117('0x2'));var moment=require(_0xf117('0x3'));var BPromise=require(_0xf117('0x4'));var Mustache=require(_0xf117('0x5'));var util=require(_0xf117('0x6'));var path=require(_0xf117('0x7'));var sox=require(_0xf117('0x8'));var csv=require(_0xf117('0x9'));var ejs=require(_0xf117('0xa'));var fs=require('fs');var fs_extra=require(_0xf117('0xb'));var _=require(_0xf117('0xc'));var squel=require(_0xf117('0xd'));var crypto=require(_0xf117('0xe'));var jsforce=require(_0xf117('0xf'));var deskjs=require(_0xf117('0x10'));var toCsv=require(_0xf117('0x9'));var querystring=require(_0xf117('0x11'));var Papa=require('papaparse');var Redis=require(_0xf117('0x12'));var authService=require(_0xf117('0x13'));var qs=require(_0xf117('0x14'));var as=require(_0xf117('0x15'));var hardwareService=require('../../config/license/hardware');var logger=require(_0xf117('0x16'))(_0xf117('0x17'));var utils=require(_0xf117('0x18'));var config=require(_0xf117('0x19'));var licenseUtil=require(_0xf117('0x1a'));var db=require(_0xf117('0x1b'))['db'];function respondWithStatusCode(_0x5107aa,_0x11742b){_0x11742b=_0x11742b||0xcc;return function(_0x4d8bfd){if(_0x4d8bfd){return _0x5107aa[_0xf117('0x1c')](_0x11742b);}return _0x5107aa['status'](_0x11742b)[_0xf117('0x1d')]();};}function respondWithResult(_0x549513,_0x37ee28){_0x37ee28=_0x37ee28||0xc8;return function(_0x57aac7){if(_0x57aac7){return _0x549513[_0xf117('0x1e')](_0x37ee28)[_0xf117('0x1f')](_0x57aac7);}};}function respondWithFilteredResult(_0x1f717e,_0x512e41){return function(_0x51af7a){if(_0x51af7a){var _0x351d1b=typeof _0x512e41[_0xf117('0x20')]===_0xf117('0x21')&&typeof _0x512e41['limit']===_0xf117('0x21');var _0x519296=_0x51af7a[_0xf117('0x22')];var _0x50ccd0=_0x351d1b?0x0:_0x512e41[_0xf117('0x20')];var _0x5bd813=_0x351d1b?_0x51af7a[_0xf117('0x22')]:_0x512e41['offset']+_0x512e41[_0xf117('0x23')];var _0x978c51;if(_0x5bd813>=_0x519296){_0x5bd813=_0x519296;_0x978c51=0xc8;}else{_0x978c51=0xce;}_0x1f717e[_0xf117('0x1e')](_0x978c51);return _0x1f717e[_0xf117('0x24')](_0xf117('0x25'),_0x50ccd0+'-'+_0x5bd813+'/'+_0x519296)[_0xf117('0x1f')](_0x51af7a);}return null;};}function patchUpdates(_0x149300){return function(_0x40cb3a){try{jsonpatch[_0xf117('0x26')](_0x40cb3a,_0x149300,!![]);}catch(_0x46039a){return BPromise[_0xf117('0x27')](_0x46039a);}return _0x40cb3a[_0xf117('0x28')]();};}function saveUpdates(_0x41a9e7,_0x377d22){return function(_0x33caf4){if(_0x33caf4){return _0x33caf4['update'](_0x41a9e7)[_0xf117('0x29')](function(_0xefdd96){return _0xefdd96;});}return null;};}function removeEntity(_0x431172,_0x46f31d){return function(_0x491cf0){if(_0x491cf0){return _0x491cf0[_0xf117('0x2a')]()[_0xf117('0x29')](function(){_0x431172[_0xf117('0x1e')](0xcc)[_0xf117('0x1d')]();});}};}function handleEntityNotFound(_0x2dab87,_0x560467){return function(_0x17657c){if(!_0x17657c){_0x2dab87[_0xf117('0x1c')](0x194);}return _0x17657c;};}function handleError(_0x3f74e8,_0x1ba132){_0x1ba132=_0x1ba132||0x1f4;return function(_0x25d81e){logger[_0xf117('0x2b')](_0x25d81e[_0xf117('0x2c')]);if(_0x25d81e['name']){delete _0x25d81e['name'];}_0x3f74e8['status'](_0x1ba132)['send'](_0x25d81e);};}exports[_0xf117('0x2d')]=function(_0x192e31,_0x4a295d){var _0x34c1b6={},_0x3b1b3e={},_0x19fa03={'count':0x0,'rows':[]};var _0x28bf47=_[_0xf117('0x2e')](db[_0xf117('0x2f')][_0xf117('0x30')],function(_0x35f34e){return{'name':_0x35f34e[_0xf117('0x31')],'type':_0x35f34e[_0xf117('0x32')][_0xf117('0x33')]};});_0x3b1b3e['model']=_[_0xf117('0x2e')](_0x28bf47,_0xf117('0x34'));_0x3b1b3e[_0xf117('0x35')]=_[_0xf117('0x36')](_0x192e31[_0xf117('0x35')]);_0x3b1b3e['filters']=_['intersection'](_0x3b1b3e[_0xf117('0x37')],_0x3b1b3e[_0xf117('0x35')]);_0x34c1b6[_0xf117('0x38')]=_[_0xf117('0x39')](_0x3b1b3e[_0xf117('0x37')],qs['fields'](_0x192e31[_0xf117('0x35')][_0xf117('0x3a')]));_0x34c1b6[_0xf117('0x38')]=_0x34c1b6[_0xf117('0x38')][_0xf117('0x3b')]?_0x34c1b6[_0xf117('0x38')]:_0x3b1b3e[_0xf117('0x37')];if(!_0x192e31[_0xf117('0x35')][_0xf117('0x3c')](_0xf117('0x3d'))){_0x34c1b6[_0xf117('0x23')]=qs['limit'](_0x192e31[_0xf117('0x35')][_0xf117('0x23')]);_0x34c1b6[_0xf117('0x20')]=qs[_0xf117('0x20')](_0x192e31['query'][_0xf117('0x20')]);}_0x34c1b6[_0xf117('0x3e')]=qs[_0xf117('0x3f')](_0x192e31[_0xf117('0x35')][_0xf117('0x3f')]);_0x34c1b6[_0xf117('0x40')]=qs['filters'](_[_0xf117('0x41')](_0x192e31['query'],_0x3b1b3e[_0xf117('0x42')]),_0x28bf47);if(_0x192e31[_0xf117('0x35')][_0xf117('0x43')]){_0x34c1b6[_0xf117('0x40')]=_['merge'](_0x34c1b6[_0xf117('0x40')],{'$or':_[_0xf117('0x2e')](_0x28bf47,function(_0x52aca2){if(_0x52aca2[_0xf117('0x32')]!==_0xf117('0x44')){var _0x62dca={};_0x62dca[_0x52aca2[_0xf117('0x34')]]={'$like':'%'+_0x192e31[_0xf117('0x35')][_0xf117('0x43')]+'%'};return _0x62dca;}})});}_0x34c1b6=_[_0xf117('0x45')]({},_0x34c1b6,_0x192e31[_0xf117('0x46')]);var _0x110539={'where':_0x34c1b6[_0xf117('0x40')]};return db[_0xf117('0x2f')][_0xf117('0x22')](_0x110539)[_0xf117('0x29')](function(_0xfc516){_0x19fa03[_0xf117('0x22')]=_0xfc516;if(_0x192e31[_0xf117('0x35')][_0xf117('0x47')]){_0x34c1b6['include']=[{'all':!![]}];}return db[_0xf117('0x2f')]['findAll'](_0x34c1b6);})[_0xf117('0x29')](function(_0x19cc7b){_0x19fa03['rows']=_0x19cc7b;return _0x19fa03;})[_0xf117('0x29')](respondWithFilteredResult(_0x4a295d,_0x34c1b6))[_0xf117('0x48')](handleError(_0x4a295d,null));};exports[_0xf117('0x49')]=function(_0x50750c,_0x595628){var _0x280745={'raw':!![],'where':{'id':_0x50750c['params']['id']}},_0x272eba={};_0x272eba[_0xf117('0x37')]=_[_0xf117('0x36')](db['JscriptySessionReport'][_0xf117('0x30')]);_0x272eba[_0xf117('0x35')]=_[_0xf117('0x36')](_0x50750c[_0xf117('0x35')]);_0x272eba[_0xf117('0x42')]=_[_0xf117('0x39')](_0x272eba[_0xf117('0x37')],_0x272eba[_0xf117('0x35')]);_0x280745['attributes']=_['intersection'](_0x272eba[_0xf117('0x37')],qs[_0xf117('0x3a')](_0x50750c[_0xf117('0x35')][_0xf117('0x3a')]));_0x280745[_0xf117('0x38')]=_0x280745[_0xf117('0x38')][_0xf117('0x3b')]?_0x280745[_0xf117('0x38')]:_0x272eba[_0xf117('0x37')];if(_0x50750c[_0xf117('0x35')][_0xf117('0x47')]){_0x280745[_0xf117('0x4a')]=[{'all':!![]}];}_0x280745=_[_0xf117('0x45')]({},_0x280745,_0x50750c[_0xf117('0x46')]);return db[_0xf117('0x2f')][_0xf117('0x4b')](_0x280745)[_0xf117('0x29')](handleEntityNotFound(_0x595628,null))[_0xf117('0x29')](respondWithResult(_0x595628,null))['catch'](handleError(_0x595628,null));};exports[_0xf117('0x4c')]=function(_0x577894,_0x112fd3){return db[_0xf117('0x2f')][_0xf117('0x4c')](_0x577894[_0xf117('0x4d')],{})['then'](respondWithResult(_0x112fd3,0xc9))[_0xf117('0x48')](handleError(_0x112fd3,null));};exports[_0xf117('0x4e')]=function(_0x4ce05c,_0x113670){if(_0x4ce05c[_0xf117('0x4d')]['id']){delete _0x4ce05c['body']['id'];}return db[_0xf117('0x2f')][_0xf117('0x4b')]({'where':{'id':_0x4ce05c[_0xf117('0x4f')]['id']}})[_0xf117('0x29')](handleEntityNotFound(_0x113670,null))[_0xf117('0x29')](saveUpdates(_0x4ce05c[_0xf117('0x4d')],null))['then'](respondWithResult(_0x113670,null))[_0xf117('0x48')](handleError(_0x113670,null));};exports[_0xf117('0x2a')]=function(_0x4c04a1,_0x509060){return db[_0xf117('0x2f')][_0xf117('0x4b')]({'where':{'id':_0x4c04a1[_0xf117('0x4f')]['id']}})['then'](handleEntityNotFound(_0x509060,null))[_0xf117('0x29')](removeEntity(_0x509060,null))['catch'](handleError(_0x509060,null));};exports[_0xf117('0x50')]=function(_0x3089bd,_0x1fb5c4){return db['JscriptySessionReport'][_0xf117('0x50')]()['then'](respondWithResult(_0x1fb5c4,null))[_0xf117('0x48')](handleError(_0x1fb5c4,null));};exports[_0xf117('0x51')]=function(_0x49053e,_0x323528,_0x6df7ce){var _0xac2f24={'raw':!![],'where':{}};var _0x2e2d73={};var _0x206b8c={'count':0x0,'rows':[]};return db['JscriptySessionReport']['findOne']({'where':{'id':_0x49053e[_0xf117('0x4f')]['id']}})[_0xf117('0x29')](handleEntityNotFound(_0x323528,null))[_0xf117('0x29')](function(_0xcae52b){if(_0xcae52b){_0x2e2d73[_0xf117('0x37')]=_['keys'](db[_0xf117('0x52')][_0xf117('0x30')]);_0x2e2d73['query']=_[_0xf117('0x36')](_0x49053e['query']);_0x2e2d73[_0xf117('0x42')]=_[_0xf117('0x39')](_0x2e2d73['model'],_0x2e2d73[_0xf117('0x35')]);_0xac2f24[_0xf117('0x38')]=_['intersection'](_0x2e2d73[_0xf117('0x37')],qs[_0xf117('0x3a')](_0x49053e['query']['fields']));_0xac2f24['attributes']=_0xac2f24[_0xf117('0x38')][_0xf117('0x3b')]?_0xac2f24['attributes']:_0x2e2d73[_0xf117('0x37')];if(!_0x49053e[_0xf117('0x35')][_0xf117('0x3c')](_0xf117('0x3d'))){_0xac2f24[_0xf117('0x23')]=qs['limit'](_0x49053e[_0xf117('0x35')]['limit']);_0xac2f24['offset']=qs['offset'](_0x49053e[_0xf117('0x35')][_0xf117('0x20')]);}_0xac2f24[_0xf117('0x3e')]=qs['sort'](_0x49053e[_0xf117('0x35')][_0xf117('0x3f')]);_0xac2f24[_0xf117('0x40')]=qs[_0xf117('0x42')](_[_0xf117('0x41')](_0x49053e[_0xf117('0x35')],_0x2e2d73[_0xf117('0x42')]));_0xac2f24[_0xf117('0x40')]['SessionId']=_0xcae52b['id'];if(_0x49053e[_0xf117('0x35')][_0xf117('0x43')]){_0xac2f24[_0xf117('0x40')]=_[_0xf117('0x45')](_0xac2f24[_0xf117('0x40')],{'$or':_[_0xf117('0x2e')](_0xac2f24[_0xf117('0x38')],function(_0xa73fa3){var _0x2dacbe={};_0x2dacbe[_0xa73fa3]={'$like':'%'+_0x49053e[_0xf117('0x35')][_0xf117('0x43')]+'%'};return _0x2dacbe;})});}_0xac2f24=_['merge']({},_0xac2f24,_0x49053e[_0xf117('0x46')]);return db['JscriptyQuestionReport'][_0xf117('0x22')]({'where':_0xac2f24['where']})[_0xf117('0x29')](function(_0xd8fb6e){_0x206b8c[_0xf117('0x22')]=_0xd8fb6e;if(_0x49053e['query'][_0xf117('0x47')]){_0xac2f24['include']=[{'all':!![]}];}return db[_0xf117('0x52')][_0xf117('0x53')](_0xac2f24);})['then'](function(_0x364f9b){_0x206b8c['rows']=_0x364f9b;return _0x206b8c;});}})[_0xf117('0x29')](respondWithFilteredResult(_0x323528,_0xac2f24))[_0xf117('0x48')](handleError(_0x323528,null));};