da2812e505d1cc3e5527efdd585d1309790edb2b
[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 _0x9c5b=['moment','mustache','util','path','ejs','fs-extra','squel','crypto','desk.js','to-csv','querystring','papaparse','../../components/auth/service','../../components/parsers/advancedSearch','../../config/license/hardware','api','../../config/utils','../../config/environment','../../config/license/util','sendStatus','status','end','json','offset','limit','undefined','count','set','Content-Range','apply','reject','save','update','then','error','stack','name','send','JscriptySessionReport','rawAttributes','fieldName','type','model','map','query','keys','filters','intersection','attributes','fields','length','hasOwnProperty','nolimit','order','sort','where','pick','filter','merge','VIRTUAL','options','include','rows','catch','params','includeAll','find','create','body','destroy','describe','getQuestions','findOne','SessionId','JscriptyQuestionReport','findAll','eml-format','zip-dir','fast-json-patch'];(function(_0x1100c6,_0x401e64){var _0x51a87f=function(_0x4d2254){while(--_0x4d2254){_0x1100c6['push'](_0x1100c6['shift']());}};_0x51a87f(++_0x401e64);}(_0x9c5b,0x188));var _0xb9c5=function(_0x34ce72,_0x19ce31){_0x34ce72=_0x34ce72-0x0;var _0x4a3fe8=_0x9c5b[_0x34ce72];return _0x4a3fe8;};'use strict';var emlformat=require(_0xb9c5('0x0'));var rimraf=require('rimraf');var zipdir=require(_0xb9c5('0x1'));var jsonpatch=require(_0xb9c5('0x2'));var rp=require('request-promise');var moment=require(_0xb9c5('0x3'));var BPromise=require('bluebird');var Mustache=require(_0xb9c5('0x4'));var util=require(_0xb9c5('0x5'));var path=require(_0xb9c5('0x6'));var sox=require('sox');var csv=require('to-csv');var ejs=require(_0xb9c5('0x7'));var fs=require('fs');var fs_extra=require(_0xb9c5('0x8'));var _=require('lodash');var squel=require(_0xb9c5('0x9'));var crypto=require(_0xb9c5('0xa'));var jsforce=require('jsforce');var deskjs=require(_0xb9c5('0xb'));var toCsv=require(_0xb9c5('0xc'));var querystring=require(_0xb9c5('0xd'));var Papa=require(_0xb9c5('0xe'));var Redis=require('ioredis');var authService=require(_0xb9c5('0xf'));var qs=require('../../components/parsers/qs');var as=require(_0xb9c5('0x10'));var hardwareService=require(_0xb9c5('0x11'));var logger=require('../../config/logger')(_0xb9c5('0x12'));var utils=require(_0xb9c5('0x13'));var config=require(_0xb9c5('0x14'));var licenseUtil=require(_0xb9c5('0x15'));var db=require('../../mysqldb')['db'];function respondWithStatusCode(_0x7180ef,_0x14c74e){_0x14c74e=_0x14c74e||0xcc;return function(_0x4f1349){if(_0x4f1349){return _0x7180ef[_0xb9c5('0x16')](_0x14c74e);}return _0x7180ef[_0xb9c5('0x17')](_0x14c74e)[_0xb9c5('0x18')]();};}function respondWithResult(_0x44e762,_0x3328dd){_0x3328dd=_0x3328dd||0xc8;return function(_0x331232){if(_0x331232){return _0x44e762['status'](_0x3328dd)[_0xb9c5('0x19')](_0x331232);}};}function respondWithFilteredResult(_0x26b1c7,_0x4bb60e){return function(_0xbd5453){if(_0xbd5453){var _0x164fcb=typeof _0x4bb60e[_0xb9c5('0x1a')]==='undefined'&&typeof _0x4bb60e[_0xb9c5('0x1b')]===_0xb9c5('0x1c');var _0x1b6f10=_0xbd5453[_0xb9c5('0x1d')];var _0x4e18ba=_0x164fcb?0x0:_0x4bb60e[_0xb9c5('0x1a')];var _0x14c92f=_0x164fcb?_0xbd5453[_0xb9c5('0x1d')]:_0x4bb60e['offset']+_0x4bb60e[_0xb9c5('0x1b')];var _0x1814c6;if(_0x14c92f>=_0x1b6f10){_0x14c92f=_0x1b6f10;_0x1814c6=0xc8;}else{_0x1814c6=0xce;}_0x26b1c7[_0xb9c5('0x17')](_0x1814c6);return _0x26b1c7[_0xb9c5('0x1e')](_0xb9c5('0x1f'),_0x4e18ba+'-'+_0x14c92f+'/'+_0x1b6f10)[_0xb9c5('0x19')](_0xbd5453);}return null;};}function patchUpdates(_0x1096f6){return function(_0x2aa93f){try{jsonpatch[_0xb9c5('0x20')](_0x2aa93f,_0x1096f6,!![]);}catch(_0x49979b){return BPromise[_0xb9c5('0x21')](_0x49979b);}return _0x2aa93f[_0xb9c5('0x22')]();};}function saveUpdates(_0x31bee7,_0x321bb9){return function(_0x2228a7){if(_0x2228a7){return _0x2228a7[_0xb9c5('0x23')](_0x31bee7)[_0xb9c5('0x24')](function(_0x2f639d){return _0x2f639d;});}return null;};}function removeEntity(_0x3774d5,_0x11401c){return function(_0x52efbd){if(_0x52efbd){return _0x52efbd['destroy']()[_0xb9c5('0x24')](function(){_0x3774d5[_0xb9c5('0x17')](0xcc)[_0xb9c5('0x18')]();});}};}function handleEntityNotFound(_0x149135,_0x1da8f0){return function(_0x3a89e9){if(!_0x3a89e9){_0x149135[_0xb9c5('0x16')](0x194);}return _0x3a89e9;};}function handleError(_0x2564e9,_0x35f9b6){_0x35f9b6=_0x35f9b6||0x1f4;return function(_0x4b29e4){logger[_0xb9c5('0x25')](_0x4b29e4[_0xb9c5('0x26')]);if(_0x4b29e4[_0xb9c5('0x27')]){delete _0x4b29e4[_0xb9c5('0x27')];}_0x2564e9[_0xb9c5('0x17')](_0x35f9b6)[_0xb9c5('0x28')](_0x4b29e4);};}exports['index']=function(_0x56b86a,_0x1d5e71){var _0x524b5a={},_0x43673d={},_0x5b1708={'count':0x0,'rows':[]};var _0x45b0b0=_['map'](db[_0xb9c5('0x29')][_0xb9c5('0x2a')],function(_0x50de95){return{'name':_0x50de95[_0xb9c5('0x2b')],'type':_0x50de95[_0xb9c5('0x2c')]['key']};});_0x43673d[_0xb9c5('0x2d')]=_[_0xb9c5('0x2e')](_0x45b0b0,_0xb9c5('0x27'));_0x43673d[_0xb9c5('0x2f')]=_[_0xb9c5('0x30')](_0x56b86a[_0xb9c5('0x2f')]);_0x43673d[_0xb9c5('0x31')]=_[_0xb9c5('0x32')](_0x43673d[_0xb9c5('0x2d')],_0x43673d['query']);_0x524b5a[_0xb9c5('0x33')]=_[_0xb9c5('0x32')](_0x43673d[_0xb9c5('0x2d')],qs['fields'](_0x56b86a[_0xb9c5('0x2f')][_0xb9c5('0x34')]));_0x524b5a[_0xb9c5('0x33')]=_0x524b5a[_0xb9c5('0x33')][_0xb9c5('0x35')]?_0x524b5a['attributes']:_0x43673d[_0xb9c5('0x2d')];if(!_0x56b86a[_0xb9c5('0x2f')][_0xb9c5('0x36')](_0xb9c5('0x37'))){_0x524b5a[_0xb9c5('0x1b')]=qs[_0xb9c5('0x1b')](_0x56b86a[_0xb9c5('0x2f')][_0xb9c5('0x1b')]);_0x524b5a[_0xb9c5('0x1a')]=qs[_0xb9c5('0x1a')](_0x56b86a['query']['offset']);}_0x524b5a[_0xb9c5('0x38')]=qs[_0xb9c5('0x39')](_0x56b86a[_0xb9c5('0x2f')][_0xb9c5('0x39')]);_0x524b5a[_0xb9c5('0x3a')]=qs[_0xb9c5('0x31')](_[_0xb9c5('0x3b')](_0x56b86a['query'],_0x43673d[_0xb9c5('0x31')]),_0x45b0b0);if(_0x56b86a[_0xb9c5('0x2f')][_0xb9c5('0x3c')]){_0x524b5a['where']=_[_0xb9c5('0x3d')](_0x524b5a['where'],{'$or':_[_0xb9c5('0x2e')](_0x45b0b0,function(_0x14c06e){if(_0x14c06e[_0xb9c5('0x2c')]!==_0xb9c5('0x3e')){var _0x44923c={};_0x44923c[_0x14c06e[_0xb9c5('0x27')]]={'$like':'%'+_0x56b86a['query']['filter']+'%'};return _0x44923c;}})});}_0x524b5a=_[_0xb9c5('0x3d')]({},_0x524b5a,_0x56b86a[_0xb9c5('0x3f')]);var _0x1453cf={'where':_0x524b5a[_0xb9c5('0x3a')]};return db[_0xb9c5('0x29')][_0xb9c5('0x1d')](_0x1453cf)[_0xb9c5('0x24')](function(_0x2a9a4f){_0x5b1708[_0xb9c5('0x1d')]=_0x2a9a4f;if(_0x56b86a[_0xb9c5('0x2f')]['includeAll']){_0x524b5a[_0xb9c5('0x40')]=[{'all':!![]}];}return db[_0xb9c5('0x29')]['findAll'](_0x524b5a);})[_0xb9c5('0x24')](function(_0x1d30b7){_0x5b1708[_0xb9c5('0x41')]=_0x1d30b7;return _0x5b1708;})['then'](respondWithFilteredResult(_0x1d5e71,_0x524b5a))[_0xb9c5('0x42')](handleError(_0x1d5e71,null));};exports['show']=function(_0x4b402d,_0x16b9e1){var _0x1c34ff={'raw':!![],'where':{'id':_0x4b402d[_0xb9c5('0x43')]['id']}},_0x4d8fd6={};_0x4d8fd6['model']=_[_0xb9c5('0x30')](db[_0xb9c5('0x29')][_0xb9c5('0x2a')]);_0x4d8fd6[_0xb9c5('0x2f')]=_['keys'](_0x4b402d[_0xb9c5('0x2f')]);_0x4d8fd6[_0xb9c5('0x31')]=_[_0xb9c5('0x32')](_0x4d8fd6['model'],_0x4d8fd6[_0xb9c5('0x2f')]);_0x1c34ff[_0xb9c5('0x33')]=_[_0xb9c5('0x32')](_0x4d8fd6[_0xb9c5('0x2d')],qs[_0xb9c5('0x34')](_0x4b402d[_0xb9c5('0x2f')]['fields']));_0x1c34ff[_0xb9c5('0x33')]=_0x1c34ff[_0xb9c5('0x33')][_0xb9c5('0x35')]?_0x1c34ff['attributes']:_0x4d8fd6[_0xb9c5('0x2d')];if(_0x4b402d[_0xb9c5('0x2f')][_0xb9c5('0x44')]){_0x1c34ff['include']=[{'all':!![]}];}_0x1c34ff=_[_0xb9c5('0x3d')]({},_0x1c34ff,_0x4b402d[_0xb9c5('0x3f')]);return db[_0xb9c5('0x29')][_0xb9c5('0x45')](_0x1c34ff)[_0xb9c5('0x24')](handleEntityNotFound(_0x16b9e1,null))[_0xb9c5('0x24')](respondWithResult(_0x16b9e1,null))[_0xb9c5('0x42')](handleError(_0x16b9e1,null));};exports[_0xb9c5('0x46')]=function(_0x3c3f69,_0x3aee92){return db['JscriptySessionReport'][_0xb9c5('0x46')](_0x3c3f69['body'],{})[_0xb9c5('0x24')](respondWithResult(_0x3aee92,0xc9))[_0xb9c5('0x42')](handleError(_0x3aee92,null));};exports[_0xb9c5('0x23')]=function(_0x128822,_0x56c54f){if(_0x128822[_0xb9c5('0x47')]['id']){delete _0x128822[_0xb9c5('0x47')]['id'];}return db['JscriptySessionReport'][_0xb9c5('0x45')]({'where':{'id':_0x128822['params']['id']}})[_0xb9c5('0x24')](handleEntityNotFound(_0x56c54f,null))[_0xb9c5('0x24')](saveUpdates(_0x128822[_0xb9c5('0x47')],null))[_0xb9c5('0x24')](respondWithResult(_0x56c54f,null))['catch'](handleError(_0x56c54f,null));};exports[_0xb9c5('0x48')]=function(_0x1423a2,_0x10c6e5){return db[_0xb9c5('0x29')]['find']({'where':{'id':_0x1423a2['params']['id']}})['then'](handleEntityNotFound(_0x10c6e5,null))['then'](removeEntity(_0x10c6e5,null))[_0xb9c5('0x42')](handleError(_0x10c6e5,null));};exports[_0xb9c5('0x49')]=function(_0x3b2273,_0x30af15){return db[_0xb9c5('0x29')][_0xb9c5('0x49')]()[_0xb9c5('0x24')](respondWithResult(_0x30af15,null))[_0xb9c5('0x42')](handleError(_0x30af15,null));};exports[_0xb9c5('0x4a')]=function(_0x13a43c,_0x2e51d4,_0x3c3ed9){var _0x6fd606={'raw':!![],'where':{}};var _0x49541f={};var _0x98a290={'count':0x0,'rows':[]};return db['JscriptySessionReport'][_0xb9c5('0x4b')]({'where':{'id':_0x13a43c['params']['id']}})[_0xb9c5('0x24')](handleEntityNotFound(_0x2e51d4,null))[_0xb9c5('0x24')](function(_0x383729){if(_0x383729){_0x49541f[_0xb9c5('0x2d')]=_[_0xb9c5('0x30')](db['JscriptyQuestionReport'][_0xb9c5('0x2a')]);_0x49541f[_0xb9c5('0x2f')]=_[_0xb9c5('0x30')](_0x13a43c['query']);_0x49541f[_0xb9c5('0x31')]=_[_0xb9c5('0x32')](_0x49541f[_0xb9c5('0x2d')],_0x49541f[_0xb9c5('0x2f')]);_0x6fd606[_0xb9c5('0x33')]=_[_0xb9c5('0x32')](_0x49541f[_0xb9c5('0x2d')],qs[_0xb9c5('0x34')](_0x13a43c[_0xb9c5('0x2f')][_0xb9c5('0x34')]));_0x6fd606['attributes']=_0x6fd606[_0xb9c5('0x33')]['length']?_0x6fd606[_0xb9c5('0x33')]:_0x49541f[_0xb9c5('0x2d')];if(!_0x13a43c[_0xb9c5('0x2f')][_0xb9c5('0x36')](_0xb9c5('0x37'))){_0x6fd606[_0xb9c5('0x1b')]=qs['limit'](_0x13a43c[_0xb9c5('0x2f')]['limit']);_0x6fd606[_0xb9c5('0x1a')]=qs[_0xb9c5('0x1a')](_0x13a43c['query'][_0xb9c5('0x1a')]);}_0x6fd606['order']=qs[_0xb9c5('0x39')](_0x13a43c['query'][_0xb9c5('0x39')]);_0x6fd606['where']=qs['filters'](_[_0xb9c5('0x3b')](_0x13a43c[_0xb9c5('0x2f')],_0x49541f[_0xb9c5('0x31')]));_0x6fd606[_0xb9c5('0x3a')][_0xb9c5('0x4c')]=_0x383729['id'];if(_0x13a43c[_0xb9c5('0x2f')]['filter']){_0x6fd606[_0xb9c5('0x3a')]=_['merge'](_0x6fd606[_0xb9c5('0x3a')],{'$or':_[_0xb9c5('0x2e')](_0x6fd606[_0xb9c5('0x33')],function(_0x360161){var _0x45c550={};_0x45c550[_0x360161]={'$like':'%'+_0x13a43c[_0xb9c5('0x2f')][_0xb9c5('0x3c')]+'%'};return _0x45c550;})});}_0x6fd606=_[_0xb9c5('0x3d')]({},_0x6fd606,_0x13a43c[_0xb9c5('0x3f')]);return db[_0xb9c5('0x4d')]['count']({'where':_0x6fd606[_0xb9c5('0x3a')]})[_0xb9c5('0x24')](function(_0x2d0769){_0x98a290[_0xb9c5('0x1d')]=_0x2d0769;if(_0x13a43c[_0xb9c5('0x2f')][_0xb9c5('0x44')]){_0x6fd606[_0xb9c5('0x40')]=[{'all':!![]}];}return db[_0xb9c5('0x4d')][_0xb9c5('0x4e')](_0x6fd606);})[_0xb9c5('0x24')](function(_0x30f1ee){_0x98a290['rows']=_0x30f1ee;return _0x98a290;});}})['then'](respondWithFilteredResult(_0x2e51d4,_0x6fd606))[_0xb9c5('0x42')](handleError(_0x2e51d4,null));};