Built motion from commit ce97982f.|2.6.29
[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 _0x68f4=['sendStatus','status','end','json','offset','undefined','limit','count','set','Content-Range','apply','update','then','destroy','error','stack','name','send','index','JscriptySessionReport','rawAttributes','type','key','map','query','keys','filters','intersection','model','attributes','fields','hasOwnProperty','nolimit','order','sort','where','pick','VIRTUAL','merge','options','includeAll','include','rows','catch','show','params','length','create','body','find','describe','getQuestions','filter','JscriptyQuestionReport','findAll','eml-format','rimraf','fast-json-patch','request-promise','mustache','util','path','sox','to-csv','ejs','fs-extra','lodash','squel','crypto','querystring','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','api','../../config/utils','../../config/environment','../../config/license/util','../../mysqldb'];(function(_0x597fc6,_0x32f069){var _0x121bba=function(_0x8da8e2){while(--_0x8da8e2){_0x597fc6['push'](_0x597fc6['shift']());}};_0x121bba(++_0x32f069);}(_0x68f4,0x87));var _0x468f=function(_0x5951e8,_0x42b9a7){_0x5951e8=_0x5951e8-0x0;var _0x20a1f5=_0x68f4[_0x5951e8];return _0x20a1f5;};'use strict';var emlformat=require(_0x468f('0x0'));var rimraf=require(_0x468f('0x1'));var zipdir=require('zip-dir');var jsonpatch=require(_0x468f('0x2'));var rp=require(_0x468f('0x3'));var moment=require('moment');var BPromise=require('bluebird');var Mustache=require(_0x468f('0x4'));var util=require(_0x468f('0x5'));var path=require(_0x468f('0x6'));var sox=require(_0x468f('0x7'));var csv=require(_0x468f('0x8'));var ejs=require(_0x468f('0x9'));var fs=require('fs');var fs_extra=require(_0x468f('0xa'));var _=require(_0x468f('0xb'));var squel=require(_0x468f('0xc'));var crypto=require(_0x468f('0xd'));var jsforce=require('jsforce');var deskjs=require('desk.js');var toCsv=require(_0x468f('0x8'));var querystring=require(_0x468f('0xe'));var Papa=require('papaparse');var Redis=require(_0x468f('0xf'));var authService=require(_0x468f('0x10'));var qs=require(_0x468f('0x11'));var as=require(_0x468f('0x12'));var hardwareService=require(_0x468f('0x13'));var logger=require('../../config/logger')(_0x468f('0x14'));var utils=require(_0x468f('0x15'));var config=require(_0x468f('0x16'));var licenseUtil=require(_0x468f('0x17'));var db=require(_0x468f('0x18'))['db'];function respondWithStatusCode(_0x295b64,_0x99afe7){_0x99afe7=_0x99afe7||0xcc;return function(_0x52acea){if(_0x52acea){return _0x295b64[_0x468f('0x19')](_0x99afe7);}return _0x295b64[_0x468f('0x1a')](_0x99afe7)[_0x468f('0x1b')]();};}function respondWithResult(_0xe5e9bf,_0x3ceedd){_0x3ceedd=_0x3ceedd||0xc8;return function(_0x104dbf){if(_0x104dbf){return _0xe5e9bf[_0x468f('0x1a')](_0x3ceedd)[_0x468f('0x1c')](_0x104dbf);}};}function respondWithFilteredResult(_0x3e0557,_0x85b846){return function(_0x3d5d90){if(_0x3d5d90){var _0x38b354=typeof _0x85b846[_0x468f('0x1d')]===_0x468f('0x1e')&&typeof _0x85b846[_0x468f('0x1f')]===_0x468f('0x1e');var _0x112589=_0x3d5d90[_0x468f('0x20')];var _0x43d6ff=_0x38b354?0x0:_0x85b846[_0x468f('0x1d')];var _0x5693bc=_0x38b354?_0x3d5d90[_0x468f('0x20')]:_0x85b846[_0x468f('0x1d')]+_0x85b846[_0x468f('0x1f')];var _0x17cf00;if(_0x5693bc>=_0x112589){_0x5693bc=_0x112589;_0x17cf00=0xc8;}else{_0x17cf00=0xce;}_0x3e0557[_0x468f('0x1a')](_0x17cf00);return _0x3e0557[_0x468f('0x21')](_0x468f('0x22'),_0x43d6ff+'-'+_0x5693bc+'/'+_0x112589)[_0x468f('0x1c')](_0x3d5d90);}return null;};}function patchUpdates(_0x9fbc23){return function(_0x3a8e72){try{jsonpatch[_0x468f('0x23')](_0x3a8e72,_0x9fbc23,!![]);}catch(_0x2112e4){return BPromise['reject'](_0x2112e4);}return _0x3a8e72['save']();};}function saveUpdates(_0x96f3e9,_0x5d3c22){return function(_0x4ac7c0){if(_0x4ac7c0){return _0x4ac7c0[_0x468f('0x24')](_0x96f3e9)[_0x468f('0x25')](function(_0x1d8f35){return _0x1d8f35;});}return null;};}function removeEntity(_0x4f6795,_0x300d23){return function(_0x451751){if(_0x451751){return _0x451751[_0x468f('0x26')]()[_0x468f('0x25')](function(){_0x4f6795[_0x468f('0x1a')](0xcc)[_0x468f('0x1b')]();});}};}function handleEntityNotFound(_0x5c02b9,_0x39d90a){return function(_0x22ccd4){if(!_0x22ccd4){_0x5c02b9['sendStatus'](0x194);}return _0x22ccd4;};}function handleError(_0x26db10,_0x5b50f3){_0x5b50f3=_0x5b50f3||0x1f4;return function(_0x149c9d){logger[_0x468f('0x27')](_0x149c9d[_0x468f('0x28')]);if(_0x149c9d[_0x468f('0x29')]){delete _0x149c9d['name'];}_0x26db10[_0x468f('0x1a')](_0x5b50f3)[_0x468f('0x2a')](_0x149c9d);};}exports[_0x468f('0x2b')]=function(_0x1b0955,_0x1d4213){var _0xc67b28={},_0x4a76d4={},_0x40260e={'count':0x0,'rows':[]};var _0x19f3c9=_['map'](db[_0x468f('0x2c')][_0x468f('0x2d')],function(_0x42295b){return{'name':_0x42295b['fieldName'],'type':_0x42295b[_0x468f('0x2e')][_0x468f('0x2f')]};});_0x4a76d4['model']=_[_0x468f('0x30')](_0x19f3c9,_0x468f('0x29'));_0x4a76d4[_0x468f('0x31')]=_[_0x468f('0x32')](_0x1b0955[_0x468f('0x31')]);_0x4a76d4[_0x468f('0x33')]=_[_0x468f('0x34')](_0x4a76d4[_0x468f('0x35')],_0x4a76d4[_0x468f('0x31')]);_0xc67b28[_0x468f('0x36')]=_['intersection'](_0x4a76d4[_0x468f('0x35')],qs[_0x468f('0x37')](_0x1b0955[_0x468f('0x31')][_0x468f('0x37')]));_0xc67b28['attributes']=_0xc67b28[_0x468f('0x36')]['length']?_0xc67b28['attributes']:_0x4a76d4['model'];if(!_0x1b0955[_0x468f('0x31')][_0x468f('0x38')](_0x468f('0x39'))){_0xc67b28['limit']=qs[_0x468f('0x1f')](_0x1b0955[_0x468f('0x31')][_0x468f('0x1f')]);_0xc67b28['offset']=qs[_0x468f('0x1d')](_0x1b0955[_0x468f('0x31')]['offset']);}_0xc67b28[_0x468f('0x3a')]=qs['sort'](_0x1b0955[_0x468f('0x31')][_0x468f('0x3b')]);_0xc67b28[_0x468f('0x3c')]=qs['filters'](_[_0x468f('0x3d')](_0x1b0955[_0x468f('0x31')],_0x4a76d4[_0x468f('0x33')]),_0x19f3c9);if(_0x1b0955[_0x468f('0x31')]['filter']){_0xc67b28['where']=_['merge'](_0xc67b28['where'],{'$or':_[_0x468f('0x30')](_0x19f3c9,function(_0x43ba0d){if(_0x43ba0d[_0x468f('0x2e')]!==_0x468f('0x3e')){var _0x11787={};_0x11787[_0x43ba0d[_0x468f('0x29')]]={'$like':'%'+_0x1b0955['query']['filter']+'%'};return _0x11787;}})});}_0xc67b28=_[_0x468f('0x3f')]({},_0xc67b28,_0x1b0955[_0x468f('0x40')]);var _0x1e876b={'where':_0xc67b28[_0x468f('0x3c')]};return db[_0x468f('0x2c')][_0x468f('0x20')](_0x1e876b)['then'](function(_0x369b4c){_0x40260e[_0x468f('0x20')]=_0x369b4c;if(_0x1b0955[_0x468f('0x31')][_0x468f('0x41')]){_0xc67b28[_0x468f('0x42')]=[{'all':!![]}];}return db[_0x468f('0x2c')]['findAll'](_0xc67b28);})['then'](function(_0x1f6acb){_0x40260e[_0x468f('0x43')]=_0x1f6acb;return _0x40260e;})['then'](respondWithFilteredResult(_0x1d4213,_0xc67b28))[_0x468f('0x44')](handleError(_0x1d4213,null));};exports[_0x468f('0x45')]=function(_0x1ec15f,_0x34f10c){var _0x391fd9={'raw':!![],'where':{'id':_0x1ec15f[_0x468f('0x46')]['id']}},_0x5a3b24={};_0x5a3b24[_0x468f('0x35')]=_[_0x468f('0x32')](db[_0x468f('0x2c')][_0x468f('0x2d')]);_0x5a3b24['query']=_['keys'](_0x1ec15f[_0x468f('0x31')]);_0x5a3b24[_0x468f('0x33')]=_['intersection'](_0x5a3b24[_0x468f('0x35')],_0x5a3b24['query']);_0x391fd9[_0x468f('0x36')]=_['intersection'](_0x5a3b24['model'],qs[_0x468f('0x37')](_0x1ec15f[_0x468f('0x31')][_0x468f('0x37')]));_0x391fd9[_0x468f('0x36')]=_0x391fd9[_0x468f('0x36')][_0x468f('0x47')]?_0x391fd9[_0x468f('0x36')]:_0x5a3b24[_0x468f('0x35')];if(_0x1ec15f['query'][_0x468f('0x41')]){_0x391fd9['include']=[{'all':!![]}];}_0x391fd9=_['merge']({},_0x391fd9,_0x1ec15f['options']);return db[_0x468f('0x2c')]['find'](_0x391fd9)['then'](handleEntityNotFound(_0x34f10c,null))[_0x468f('0x25')](respondWithResult(_0x34f10c,null))['catch'](handleError(_0x34f10c,null));};exports[_0x468f('0x48')]=function(_0x5aa8d9,_0x14bcd8){return db[_0x468f('0x2c')]['create'](_0x5aa8d9[_0x468f('0x49')],{})[_0x468f('0x25')](respondWithResult(_0x14bcd8,0xc9))[_0x468f('0x44')](handleError(_0x14bcd8,null));};exports[_0x468f('0x24')]=function(_0x2922e2,_0x57f4c8){if(_0x2922e2['body']['id']){delete _0x2922e2[_0x468f('0x49')]['id'];}return db['JscriptySessionReport']['find']({'where':{'id':_0x2922e2[_0x468f('0x46')]['id']}})[_0x468f('0x25')](handleEntityNotFound(_0x57f4c8,null))['then'](saveUpdates(_0x2922e2[_0x468f('0x49')],null))['then'](respondWithResult(_0x57f4c8,null))[_0x468f('0x44')](handleError(_0x57f4c8,null));};exports[_0x468f('0x26')]=function(_0x51e5a4,_0x3308e5){return db[_0x468f('0x2c')][_0x468f('0x4a')]({'where':{'id':_0x51e5a4[_0x468f('0x46')]['id']}})[_0x468f('0x25')](handleEntityNotFound(_0x3308e5,null))['then'](removeEntity(_0x3308e5,null))[_0x468f('0x44')](handleError(_0x3308e5,null));};exports[_0x468f('0x4b')]=function(_0x213a2e,_0x819669){return db['JscriptySessionReport'][_0x468f('0x4b')]()['then'](respondWithResult(_0x819669,null))[_0x468f('0x44')](handleError(_0x819669,null));};exports[_0x468f('0x4c')]=function(_0x1b45e9,_0x60e4ec,_0x394f6d){var _0x27b485={'raw':!![],'where':{}};var _0xa655c2={};var _0x53dc96={'count':0x0,'rows':[]};return db[_0x468f('0x2c')]['findOne']({'where':{'id':_0x1b45e9[_0x468f('0x46')]['id']}})[_0x468f('0x25')](handleEntityNotFound(_0x60e4ec,null))[_0x468f('0x25')](function(_0x1d08af){if(_0x1d08af){_0xa655c2[_0x468f('0x35')]=_[_0x468f('0x32')](db['JscriptyQuestionReport']['rawAttributes']);_0xa655c2[_0x468f('0x31')]=_[_0x468f('0x32')](_0x1b45e9['query']);_0xa655c2['filters']=_[_0x468f('0x34')](_0xa655c2[_0x468f('0x35')],_0xa655c2[_0x468f('0x31')]);_0x27b485[_0x468f('0x36')]=_[_0x468f('0x34')](_0xa655c2['model'],qs['fields'](_0x1b45e9['query'][_0x468f('0x37')]));_0x27b485[_0x468f('0x36')]=_0x27b485[_0x468f('0x36')][_0x468f('0x47')]?_0x27b485[_0x468f('0x36')]:_0xa655c2[_0x468f('0x35')];if(!_0x1b45e9[_0x468f('0x31')][_0x468f('0x38')]('nolimit')){_0x27b485[_0x468f('0x1f')]=qs[_0x468f('0x1f')](_0x1b45e9[_0x468f('0x31')]['limit']);_0x27b485[_0x468f('0x1d')]=qs['offset'](_0x1b45e9[_0x468f('0x31')][_0x468f('0x1d')]);}_0x27b485['order']=qs[_0x468f('0x3b')](_0x1b45e9[_0x468f('0x31')][_0x468f('0x3b')]);_0x27b485[_0x468f('0x3c')]=qs['filters'](_['pick'](_0x1b45e9['query'],_0xa655c2['filters']));_0x27b485['where']['SessionId']=_0x1d08af['id'];if(_0x1b45e9['query'][_0x468f('0x4d')]){_0x27b485[_0x468f('0x3c')]=_['merge'](_0x27b485[_0x468f('0x3c')],{'$or':_['map'](_0x27b485[_0x468f('0x36')],function(_0x31b370){var _0x311558={};_0x311558[_0x31b370]={'$like':'%'+_0x1b45e9[_0x468f('0x31')][_0x468f('0x4d')]+'%'};return _0x311558;})});}_0x27b485=_[_0x468f('0x3f')]({},_0x27b485,_0x1b45e9['options']);return db['JscriptyQuestionReport'][_0x468f('0x20')]({'where':_0x27b485['where']})[_0x468f('0x25')](function(_0x8bc37d){_0x53dc96[_0x468f('0x20')]=_0x8bc37d;if(_0x1b45e9[_0x468f('0x31')]['includeAll']){_0x27b485[_0x468f('0x42')]=[{'all':!![]}];}return db[_0x468f('0x4e')][_0x468f('0x4f')](_0x27b485);})[_0x468f('0x25')](function(_0x155890){_0x53dc96['rows']=_0x155890;return _0x53dc96;});}})[_0x468f('0x25')](respondWithFilteredResult(_0x60e4ec,_0x27b485))['catch'](handleError(_0x60e4ec,null));};