Built motion from commit 538092ac.|2.6.10
[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 _0x10bf=['include','eml-format','rimraf','request-promise','moment','util','sox','ejs','fs-extra','squel','desk.js','to-csv','querystring','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','api','../../config/utils','../../config/environment','../../config/license/util','sendStatus','status','end','json','offset','undefined','limit','count','set','apply','reject','update','then','error','name','send','index','map','JscriptySessionReport','rawAttributes','fieldName','type','key','model','query','keys','intersection','fields','attributes','length','hasOwnProperty','nolimit','order','sort','filters','pick','filter','where','merge','VIRTUAL','options','includeAll','rows','show','params','find','catch','create','body','describe','getQuestions','findOne','JscriptyQuestionReport','SessionId'];(function(_0x4fbfd9,_0x3ab91a){var _0x31dc94=function(_0x11e53b){while(--_0x11e53b){_0x4fbfd9['push'](_0x4fbfd9['shift']());}};_0x31dc94(++_0x3ab91a);}(_0x10bf,0x135));var _0xf10b=function(_0x7564d,_0x40270f){_0x7564d=_0x7564d-0x0;var _0x1e520d=_0x10bf[_0x7564d];return _0x1e520d;};'use strict';var emlformat=require(_0xf10b('0x0'));var rimraf=require(_0xf10b('0x1'));var zipdir=require('zip-dir');var jsonpatch=require('fast-json-patch');var rp=require(_0xf10b('0x2'));var moment=require(_0xf10b('0x3'));var BPromise=require('bluebird');var Mustache=require('mustache');var util=require(_0xf10b('0x4'));var path=require('path');var sox=require(_0xf10b('0x5'));var csv=require('to-csv');var ejs=require(_0xf10b('0x6'));var fs=require('fs');var fs_extra=require(_0xf10b('0x7'));var _=require('lodash');var squel=require(_0xf10b('0x8'));var crypto=require('crypto');var jsforce=require('jsforce');var deskjs=require(_0xf10b('0x9'));var toCsv=require(_0xf10b('0xa'));var querystring=require(_0xf10b('0xb'));var Papa=require('papaparse');var Redis=require(_0xf10b('0xc'));var authService=require(_0xf10b('0xd'));var qs=require(_0xf10b('0xe'));var as=require(_0xf10b('0xf'));var hardwareService=require(_0xf10b('0x10'));var logger=require(_0xf10b('0x11'))(_0xf10b('0x12'));var utils=require(_0xf10b('0x13'));var config=require(_0xf10b('0x14'));var licenseUtil=require(_0xf10b('0x15'));var db=require('../../mysqldb')['db'];function respondWithStatusCode(_0x2828d0,_0x396c2a){_0x396c2a=_0x396c2a||0xcc;return function(_0x22269c){if(_0x22269c){return _0x2828d0[_0xf10b('0x16')](_0x396c2a);}return _0x2828d0[_0xf10b('0x17')](_0x396c2a)[_0xf10b('0x18')]();};}function respondWithResult(_0x58685a,_0x340bcd){_0x340bcd=_0x340bcd||0xc8;return function(_0x61aa88){if(_0x61aa88){return _0x58685a[_0xf10b('0x17')](_0x340bcd)[_0xf10b('0x19')](_0x61aa88);}};}function respondWithFilteredResult(_0x562026,_0x2fcc59){return function(_0x2774bb){if(_0x2774bb){var _0x51d102=typeof _0x2fcc59[_0xf10b('0x1a')]===_0xf10b('0x1b')&&typeof _0x2fcc59[_0xf10b('0x1c')]==='undefined';var _0x365bc8=_0x2774bb[_0xf10b('0x1d')];var _0x2281df=_0x51d102?0x0:_0x2fcc59[_0xf10b('0x1a')];var _0xd33290=_0x51d102?_0x2774bb[_0xf10b('0x1d')]:_0x2fcc59['offset']+_0x2fcc59[_0xf10b('0x1c')];var _0x25ebe3;if(_0xd33290>=_0x365bc8){_0xd33290=_0x365bc8;_0x25ebe3=0xc8;}else{_0x25ebe3=0xce;}_0x562026[_0xf10b('0x17')](_0x25ebe3);return _0x562026[_0xf10b('0x1e')]('Content-Range',_0x2281df+'-'+_0xd33290+'/'+_0x365bc8)[_0xf10b('0x19')](_0x2774bb);}return null;};}function patchUpdates(_0x56cd3b){return function(_0x51673f){try{jsonpatch[_0xf10b('0x1f')](_0x51673f,_0x56cd3b,!![]);}catch(_0xcd8a3){return BPromise[_0xf10b('0x20')](_0xcd8a3);}return _0x51673f['save']();};}function saveUpdates(_0x391b37,_0x29911e){return function(_0x85478c){if(_0x85478c){return _0x85478c[_0xf10b('0x21')](_0x391b37)[_0xf10b('0x22')](function(_0x56e8c6){return _0x56e8c6;});}return null;};}function removeEntity(_0x34f95a,_0x2768f8){return function(_0x19384d){if(_0x19384d){return _0x19384d['destroy']()[_0xf10b('0x22')](function(){_0x34f95a[_0xf10b('0x17')](0xcc)[_0xf10b('0x18')]();});}};}function handleEntityNotFound(_0x371856,_0x4a48d7){return function(_0x584ef8){if(!_0x584ef8){_0x371856[_0xf10b('0x16')](0x194);}return _0x584ef8;};}function handleError(_0x43c107,_0x4655bb){_0x4655bb=_0x4655bb||0x1f4;return function(_0x525395){logger[_0xf10b('0x23')](_0x525395['stack']);if(_0x525395[_0xf10b('0x24')]){delete _0x525395[_0xf10b('0x24')];}_0x43c107[_0xf10b('0x17')](_0x4655bb)[_0xf10b('0x25')](_0x525395);};}exports[_0xf10b('0x26')]=function(_0x35eda8,_0x441035){var _0x352900={},_0x4597d8={},_0x52ae6c={'count':0x0,'rows':[]};var _0x4f427d=_[_0xf10b('0x27')](db[_0xf10b('0x28')][_0xf10b('0x29')],function(_0x32f733){return{'name':_0x32f733[_0xf10b('0x2a')],'type':_0x32f733[_0xf10b('0x2b')][_0xf10b('0x2c')]};});_0x4597d8[_0xf10b('0x2d')]=_[_0xf10b('0x27')](_0x4f427d,_0xf10b('0x24'));_0x4597d8[_0xf10b('0x2e')]=_[_0xf10b('0x2f')](_0x35eda8[_0xf10b('0x2e')]);_0x4597d8['filters']=_[_0xf10b('0x30')](_0x4597d8['model'],_0x4597d8[_0xf10b('0x2e')]);_0x352900['attributes']=_[_0xf10b('0x30')](_0x4597d8[_0xf10b('0x2d')],qs[_0xf10b('0x31')](_0x35eda8['query'][_0xf10b('0x31')]));_0x352900[_0xf10b('0x32')]=_0x352900[_0xf10b('0x32')][_0xf10b('0x33')]?_0x352900['attributes']:_0x4597d8['model'];if(!_0x35eda8[_0xf10b('0x2e')][_0xf10b('0x34')](_0xf10b('0x35'))){_0x352900[_0xf10b('0x1c')]=qs[_0xf10b('0x1c')](_0x35eda8['query'][_0xf10b('0x1c')]);_0x352900[_0xf10b('0x1a')]=qs[_0xf10b('0x1a')](_0x35eda8[_0xf10b('0x2e')][_0xf10b('0x1a')]);}_0x352900[_0xf10b('0x36')]=qs[_0xf10b('0x37')](_0x35eda8[_0xf10b('0x2e')][_0xf10b('0x37')]);_0x352900['where']=qs[_0xf10b('0x38')](_[_0xf10b('0x39')](_0x35eda8[_0xf10b('0x2e')],_0x4597d8[_0xf10b('0x38')]),_0x4f427d);if(_0x35eda8['query'][_0xf10b('0x3a')]){_0x352900[_0xf10b('0x3b')]=_[_0xf10b('0x3c')](_0x352900[_0xf10b('0x3b')],{'$or':_[_0xf10b('0x27')](_0x4f427d,function(_0x38a79e){if(_0x38a79e[_0xf10b('0x2b')]!==_0xf10b('0x3d')){var _0x4c713c={};_0x4c713c[_0x38a79e['name']]={'$like':'%'+_0x35eda8[_0xf10b('0x2e')][_0xf10b('0x3a')]+'%'};return _0x4c713c;}})});}_0x352900=_[_0xf10b('0x3c')]({},_0x352900,_0x35eda8[_0xf10b('0x3e')]);var _0x2f995c={'where':_0x352900[_0xf10b('0x3b')]};return db['JscriptySessionReport'][_0xf10b('0x1d')](_0x2f995c)[_0xf10b('0x22')](function(_0xb6fda6){_0x52ae6c[_0xf10b('0x1d')]=_0xb6fda6;if(_0x35eda8[_0xf10b('0x2e')][_0xf10b('0x3f')]){_0x352900['include']=[{'all':!![]}];}return db[_0xf10b('0x28')]['findAll'](_0x352900);})['then'](function(_0x1aa414){_0x52ae6c[_0xf10b('0x40')]=_0x1aa414;return _0x52ae6c;})[_0xf10b('0x22')](respondWithFilteredResult(_0x441035,_0x352900))['catch'](handleError(_0x441035,null));};exports[_0xf10b('0x41')]=function(_0x11be4a,_0x486c57){var _0x21c418={'raw':!![],'where':{'id':_0x11be4a[_0xf10b('0x42')]['id']}},_0x195139={};_0x195139['model']=_[_0xf10b('0x2f')](db[_0xf10b('0x28')][_0xf10b('0x29')]);_0x195139[_0xf10b('0x2e')]=_[_0xf10b('0x2f')](_0x11be4a[_0xf10b('0x2e')]);_0x195139[_0xf10b('0x38')]=_[_0xf10b('0x30')](_0x195139['model'],_0x195139[_0xf10b('0x2e')]);_0x21c418[_0xf10b('0x32')]=_[_0xf10b('0x30')](_0x195139[_0xf10b('0x2d')],qs['fields'](_0x11be4a['query'][_0xf10b('0x31')]));_0x21c418[_0xf10b('0x32')]=_0x21c418['attributes'][_0xf10b('0x33')]?_0x21c418[_0xf10b('0x32')]:_0x195139[_0xf10b('0x2d')];if(_0x11be4a['query']['includeAll']){_0x21c418['include']=[{'all':!![]}];}_0x21c418=_[_0xf10b('0x3c')]({},_0x21c418,_0x11be4a['options']);return db[_0xf10b('0x28')][_0xf10b('0x43')](_0x21c418)['then'](handleEntityNotFound(_0x486c57,null))[_0xf10b('0x22')](respondWithResult(_0x486c57,null))[_0xf10b('0x44')](handleError(_0x486c57,null));};exports[_0xf10b('0x45')]=function(_0x25e484,_0x4d480a){return db[_0xf10b('0x28')][_0xf10b('0x45')](_0x25e484[_0xf10b('0x46')],{})[_0xf10b('0x22')](respondWithResult(_0x4d480a,0xc9))[_0xf10b('0x44')](handleError(_0x4d480a,null));};exports[_0xf10b('0x21')]=function(_0x4141e0,_0x4f183e){if(_0x4141e0['body']['id']){delete _0x4141e0[_0xf10b('0x46')]['id'];}return db[_0xf10b('0x28')][_0xf10b('0x43')]({'where':{'id':_0x4141e0[_0xf10b('0x42')]['id']}})['then'](handleEntityNotFound(_0x4f183e,null))['then'](saveUpdates(_0x4141e0[_0xf10b('0x46')],null))[_0xf10b('0x22')](respondWithResult(_0x4f183e,null))[_0xf10b('0x44')](handleError(_0x4f183e,null));};exports['destroy']=function(_0x3ac48e,_0x53de96){return db[_0xf10b('0x28')][_0xf10b('0x43')]({'where':{'id':_0x3ac48e[_0xf10b('0x42')]['id']}})[_0xf10b('0x22')](handleEntityNotFound(_0x53de96,null))['then'](removeEntity(_0x53de96,null))[_0xf10b('0x44')](handleError(_0x53de96,null));};exports[_0xf10b('0x47')]=function(_0x4fb802,_0x23fc86){return db[_0xf10b('0x28')]['describe']()[_0xf10b('0x22')](respondWithResult(_0x23fc86,null))['catch'](handleError(_0x23fc86,null));};exports[_0xf10b('0x48')]=function(_0x40d0d5,_0x3aeba5,_0x4fa19b){var _0x1fa5b0={'raw':!![],'where':{}};var _0x33d68b={};var _0x2ec056={'count':0x0,'rows':[]};return db[_0xf10b('0x28')][_0xf10b('0x49')]({'where':{'id':_0x40d0d5[_0xf10b('0x42')]['id']}})[_0xf10b('0x22')](handleEntityNotFound(_0x3aeba5,null))[_0xf10b('0x22')](function(_0x5bcd86){if(_0x5bcd86){_0x33d68b[_0xf10b('0x2d')]=_[_0xf10b('0x2f')](db[_0xf10b('0x4a')]['rawAttributes']);_0x33d68b[_0xf10b('0x2e')]=_[_0xf10b('0x2f')](_0x40d0d5[_0xf10b('0x2e')]);_0x33d68b[_0xf10b('0x38')]=_[_0xf10b('0x30')](_0x33d68b[_0xf10b('0x2d')],_0x33d68b[_0xf10b('0x2e')]);_0x1fa5b0[_0xf10b('0x32')]=_['intersection'](_0x33d68b[_0xf10b('0x2d')],qs[_0xf10b('0x31')](_0x40d0d5[_0xf10b('0x2e')][_0xf10b('0x31')]));_0x1fa5b0[_0xf10b('0x32')]=_0x1fa5b0[_0xf10b('0x32')][_0xf10b('0x33')]?_0x1fa5b0[_0xf10b('0x32')]:_0x33d68b['model'];if(!_0x40d0d5[_0xf10b('0x2e')]['hasOwnProperty']('nolimit')){_0x1fa5b0[_0xf10b('0x1c')]=qs['limit'](_0x40d0d5[_0xf10b('0x2e')][_0xf10b('0x1c')]);_0x1fa5b0[_0xf10b('0x1a')]=qs['offset'](_0x40d0d5[_0xf10b('0x2e')][_0xf10b('0x1a')]);}_0x1fa5b0[_0xf10b('0x36')]=qs[_0xf10b('0x37')](_0x40d0d5['query']['sort']);_0x1fa5b0[_0xf10b('0x3b')]=qs[_0xf10b('0x38')](_[_0xf10b('0x39')](_0x40d0d5[_0xf10b('0x2e')],_0x33d68b['filters']));_0x1fa5b0[_0xf10b('0x3b')][_0xf10b('0x4b')]=_0x5bcd86['id'];if(_0x40d0d5[_0xf10b('0x2e')][_0xf10b('0x3a')]){_0x1fa5b0[_0xf10b('0x3b')]=_['merge'](_0x1fa5b0['where'],{'$or':_['map'](_0x1fa5b0[_0xf10b('0x32')],function(_0x378d0d){var _0x4fc7c6={};_0x4fc7c6[_0x378d0d]={'$like':'%'+_0x40d0d5[_0xf10b('0x2e')]['filter']+'%'};return _0x4fc7c6;})});}_0x1fa5b0=_[_0xf10b('0x3c')]({},_0x1fa5b0,_0x40d0d5[_0xf10b('0x3e')]);return db[_0xf10b('0x4a')][_0xf10b('0x1d')]({'where':_0x1fa5b0[_0xf10b('0x3b')]})['then'](function(_0x22de02){_0x2ec056['count']=_0x22de02;if(_0x40d0d5[_0xf10b('0x2e')]['includeAll']){_0x1fa5b0[_0xf10b('0x4c')]=[{'all':!![]}];}return db[_0xf10b('0x4a')]['findAll'](_0x1fa5b0);})[_0xf10b('0x22')](function(_0x2cd261){_0x2ec056[_0xf10b('0x40')]=_0x2cd261;return _0x2ec056;});}})[_0xf10b('0x22')](respondWithFilteredResult(_0x3aeba5,_0x1fa5b0))[_0xf10b('0x44')](handleError(_0x3aeba5,null));};