8b29d6b2dddd436bb0b5d5ece83a31e2c30b70f9
[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 _0xfc6c=['moment','bluebird','mustache','util','path','sox','to-csv','ejs','fs-extra','lodash','jsforce','desk.js','querystring','papaparse','ioredis','../../components/auth/service','../../components/parsers/qs','../../config/license/hardware','../../config/logger','../../config/utils','../../config/environment','../../config/license/util','../../mysqldb','status','end','json','offset','undefined','limit','count','Content-Range','save','update','then','sendStatus','error','stack','name','send','map','JscriptySessionReport','rawAttributes','type','key','model','query','filters','intersection','fields','attributes','length','nolimit','order','sort','pick','filter','where','merge','VIRTUAL','options','includeAll','findAll','rows','catch','params','keys','find','create','body','destroy','describe','getQuestions','JscriptyQuestionReport','hasOwnProperty','SessionId','include','rimraf','fast-json-patch','request-promise'];(function(_0x3bc2c6,_0x984b45){var _0x4c4b8d=function(_0x1e00e9){while(--_0x1e00e9){_0x3bc2c6['push'](_0x3bc2c6['shift']());}};_0x4c4b8d(++_0x984b45);}(_0xfc6c,0xea));var _0xcfc6=function(_0x1678bd,_0x356447){_0x1678bd=_0x1678bd-0x0;var _0x52200c=_0xfc6c[_0x1678bd];return _0x52200c;};'use strict';var emlformat=require('eml-format');var rimraf=require(_0xcfc6('0x0'));var zipdir=require('zip-dir');var jsonpatch=require(_0xcfc6('0x1'));var rp=require(_0xcfc6('0x2'));var moment=require(_0xcfc6('0x3'));var BPromise=require(_0xcfc6('0x4'));var Mustache=require(_0xcfc6('0x5'));var util=require(_0xcfc6('0x6'));var path=require(_0xcfc6('0x7'));var sox=require(_0xcfc6('0x8'));var csv=require(_0xcfc6('0x9'));var ejs=require(_0xcfc6('0xa'));var fs=require('fs');var fs_extra=require(_0xcfc6('0xb'));var _=require(_0xcfc6('0xc'));var squel=require('squel');var crypto=require('crypto');var jsforce=require(_0xcfc6('0xd'));var deskjs=require(_0xcfc6('0xe'));var toCsv=require(_0xcfc6('0x9'));var querystring=require(_0xcfc6('0xf'));var Papa=require(_0xcfc6('0x10'));var Redis=require(_0xcfc6('0x11'));var authService=require(_0xcfc6('0x12'));var qs=require(_0xcfc6('0x13'));var as=require('../../components/parsers/advancedSearch');var hardwareService=require(_0xcfc6('0x14'));var logger=require(_0xcfc6('0x15'))('api');var utils=require(_0xcfc6('0x16'));var config=require(_0xcfc6('0x17'));var licenseUtil=require(_0xcfc6('0x18'));var db=require(_0xcfc6('0x19'))['db'];function respondWithStatusCode(_0x243d6f,_0x202477){_0x202477=_0x202477||0xcc;return function(_0x5cba6b){if(_0x5cba6b){return _0x243d6f['sendStatus'](_0x202477);}return _0x243d6f[_0xcfc6('0x1a')](_0x202477)[_0xcfc6('0x1b')]();};}function respondWithResult(_0xf307c,_0x68891d){_0x68891d=_0x68891d||0xc8;return function(_0x31773c){if(_0x31773c){return _0xf307c['status'](_0x68891d)[_0xcfc6('0x1c')](_0x31773c);}};}function respondWithFilteredResult(_0x346a33,_0x438102){return function(_0x1e67cf){if(_0x1e67cf){var _0x5768dd=typeof _0x438102[_0xcfc6('0x1d')]===_0xcfc6('0x1e')&&typeof _0x438102[_0xcfc6('0x1f')]===_0xcfc6('0x1e');var _0x227ccc=_0x1e67cf['count'];var _0x5abae5=_0x5768dd?0x0:_0x438102[_0xcfc6('0x1d')];var _0x5e4554=_0x5768dd?_0x1e67cf[_0xcfc6('0x20')]:_0x438102[_0xcfc6('0x1d')]+_0x438102[_0xcfc6('0x1f')];var _0x36cdf9;if(_0x5e4554>=_0x227ccc){_0x5e4554=_0x227ccc;_0x36cdf9=0xc8;}else{_0x36cdf9=0xce;}_0x346a33[_0xcfc6('0x1a')](_0x36cdf9);return _0x346a33['set'](_0xcfc6('0x21'),_0x5abae5+'-'+_0x5e4554+'/'+_0x227ccc)[_0xcfc6('0x1c')](_0x1e67cf);}return null;};}function patchUpdates(_0x39f93a){return function(_0x4f3867){try{jsonpatch['apply'](_0x4f3867,_0x39f93a,!![]);}catch(_0x460e72){return BPromise['reject'](_0x460e72);}return _0x4f3867[_0xcfc6('0x22')]();};}function saveUpdates(_0x79738f,_0x558029){return function(_0x242bbc){if(_0x242bbc){return _0x242bbc[_0xcfc6('0x23')](_0x79738f)[_0xcfc6('0x24')](function(_0x4b1218){return _0x4b1218;});}return null;};}function removeEntity(_0x4cfea3,_0x43ee23){return function(_0x4eaf90){if(_0x4eaf90){return _0x4eaf90['destroy']()[_0xcfc6('0x24')](function(){_0x4cfea3[_0xcfc6('0x1a')](0xcc)[_0xcfc6('0x1b')]();});}};}function handleEntityNotFound(_0x293880,_0x2589c8){return function(_0x32ea1d){if(!_0x32ea1d){_0x293880[_0xcfc6('0x25')](0x194);}return _0x32ea1d;};}function handleError(_0x5df2d6,_0x2ecdf4){_0x2ecdf4=_0x2ecdf4||0x1f4;return function(_0x2e90d7){logger[_0xcfc6('0x26')](_0x2e90d7[_0xcfc6('0x27')]);if(_0x2e90d7[_0xcfc6('0x28')]){delete _0x2e90d7[_0xcfc6('0x28')];}_0x5df2d6[_0xcfc6('0x1a')](_0x2ecdf4)[_0xcfc6('0x29')](_0x2e90d7);};}exports['index']=function(_0x3be77c,_0x146ccc){var _0xc2cf2b={},_0x1b4209={},_0x28b223={'count':0x0,'rows':[]};var _0x30f202=_[_0xcfc6('0x2a')](db[_0xcfc6('0x2b')][_0xcfc6('0x2c')],function(_0x72d06f){return{'name':_0x72d06f['fieldName'],'type':_0x72d06f[_0xcfc6('0x2d')][_0xcfc6('0x2e')]};});_0x1b4209[_0xcfc6('0x2f')]=_[_0xcfc6('0x2a')](_0x30f202,_0xcfc6('0x28'));_0x1b4209[_0xcfc6('0x30')]=_['keys'](_0x3be77c[_0xcfc6('0x30')]);_0x1b4209[_0xcfc6('0x31')]=_['intersection'](_0x1b4209[_0xcfc6('0x2f')],_0x1b4209['query']);_0xc2cf2b['attributes']=_[_0xcfc6('0x32')](_0x1b4209['model'],qs[_0xcfc6('0x33')](_0x3be77c['query'][_0xcfc6('0x33')]));_0xc2cf2b[_0xcfc6('0x34')]=_0xc2cf2b[_0xcfc6('0x34')][_0xcfc6('0x35')]?_0xc2cf2b[_0xcfc6('0x34')]:_0x1b4209[_0xcfc6('0x2f')];if(!_0x3be77c[_0xcfc6('0x30')]['hasOwnProperty'](_0xcfc6('0x36'))){_0xc2cf2b[_0xcfc6('0x1f')]=qs[_0xcfc6('0x1f')](_0x3be77c[_0xcfc6('0x30')][_0xcfc6('0x1f')]);_0xc2cf2b[_0xcfc6('0x1d')]=qs[_0xcfc6('0x1d')](_0x3be77c[_0xcfc6('0x30')]['offset']);}_0xc2cf2b[_0xcfc6('0x37')]=qs[_0xcfc6('0x38')](_0x3be77c[_0xcfc6('0x30')][_0xcfc6('0x38')]);_0xc2cf2b['where']=qs[_0xcfc6('0x31')](_[_0xcfc6('0x39')](_0x3be77c[_0xcfc6('0x30')],_0x1b4209[_0xcfc6('0x31')]),_0x30f202);if(_0x3be77c[_0xcfc6('0x30')][_0xcfc6('0x3a')]){_0xc2cf2b[_0xcfc6('0x3b')]=_[_0xcfc6('0x3c')](_0xc2cf2b['where'],{'$or':_[_0xcfc6('0x2a')](_0x30f202,function(_0x17be60){if(_0x17be60[_0xcfc6('0x2d')]!==_0xcfc6('0x3d')){var _0x123043={};_0x123043[_0x17be60['name']]={'$like':'%'+_0x3be77c[_0xcfc6('0x30')][_0xcfc6('0x3a')]+'%'};return _0x123043;}})});}_0xc2cf2b=_[_0xcfc6('0x3c')]({},_0xc2cf2b,_0x3be77c[_0xcfc6('0x3e')]);var _0x40d6d5={'where':_0xc2cf2b['where']};return db[_0xcfc6('0x2b')][_0xcfc6('0x20')](_0x40d6d5)[_0xcfc6('0x24')](function(_0x3872e8){_0x28b223[_0xcfc6('0x20')]=_0x3872e8;if(_0x3be77c[_0xcfc6('0x30')][_0xcfc6('0x3f')]){_0xc2cf2b['include']=[{'all':!![]}];}return db[_0xcfc6('0x2b')][_0xcfc6('0x40')](_0xc2cf2b);})[_0xcfc6('0x24')](function(_0x59463c){_0x28b223[_0xcfc6('0x41')]=_0x59463c;return _0x28b223;})[_0xcfc6('0x24')](respondWithFilteredResult(_0x146ccc,_0xc2cf2b))[_0xcfc6('0x42')](handleError(_0x146ccc,null));};exports['show']=function(_0xb00247,_0x45bfe6){var _0x18b817={'raw':!![],'where':{'id':_0xb00247[_0xcfc6('0x43')]['id']}},_0x3f6d61={};_0x3f6d61[_0xcfc6('0x2f')]=_[_0xcfc6('0x44')](db[_0xcfc6('0x2b')][_0xcfc6('0x2c')]);_0x3f6d61[_0xcfc6('0x30')]=_[_0xcfc6('0x44')](_0xb00247[_0xcfc6('0x30')]);_0x3f6d61['filters']=_[_0xcfc6('0x32')](_0x3f6d61['model'],_0x3f6d61[_0xcfc6('0x30')]);_0x18b817[_0xcfc6('0x34')]=_[_0xcfc6('0x32')](_0x3f6d61[_0xcfc6('0x2f')],qs[_0xcfc6('0x33')](_0xb00247[_0xcfc6('0x30')][_0xcfc6('0x33')]));_0x18b817[_0xcfc6('0x34')]=_0x18b817[_0xcfc6('0x34')]['length']?_0x18b817[_0xcfc6('0x34')]:_0x3f6d61[_0xcfc6('0x2f')];if(_0xb00247[_0xcfc6('0x30')][_0xcfc6('0x3f')]){_0x18b817['include']=[{'all':!![]}];}_0x18b817=_[_0xcfc6('0x3c')]({},_0x18b817,_0xb00247[_0xcfc6('0x3e')]);return db[_0xcfc6('0x2b')][_0xcfc6('0x45')](_0x18b817)[_0xcfc6('0x24')](handleEntityNotFound(_0x45bfe6,null))['then'](respondWithResult(_0x45bfe6,null))[_0xcfc6('0x42')](handleError(_0x45bfe6,null));};exports[_0xcfc6('0x46')]=function(_0x379a3e,_0x3e42b3){return db[_0xcfc6('0x2b')]['create'](_0x379a3e[_0xcfc6('0x47')],{})['then'](respondWithResult(_0x3e42b3,0xc9))[_0xcfc6('0x42')](handleError(_0x3e42b3,null));};exports['update']=function(_0x2a6e05,_0x274b20){if(_0x2a6e05['body']['id']){delete _0x2a6e05[_0xcfc6('0x47')]['id'];}return db['JscriptySessionReport']['find']({'where':{'id':_0x2a6e05['params']['id']}})[_0xcfc6('0x24')](handleEntityNotFound(_0x274b20,null))['then'](saveUpdates(_0x2a6e05[_0xcfc6('0x47')],null))[_0xcfc6('0x24')](respondWithResult(_0x274b20,null))[_0xcfc6('0x42')](handleError(_0x274b20,null));};exports[_0xcfc6('0x48')]=function(_0x2dd4f8,_0x67ec56){return db[_0xcfc6('0x2b')][_0xcfc6('0x45')]({'where':{'id':_0x2dd4f8[_0xcfc6('0x43')]['id']}})[_0xcfc6('0x24')](handleEntityNotFound(_0x67ec56,null))['then'](removeEntity(_0x67ec56,null))[_0xcfc6('0x42')](handleError(_0x67ec56,null));};exports[_0xcfc6('0x49')]=function(_0x3fceea,_0x532e49){return db[_0xcfc6('0x2b')][_0xcfc6('0x49')]()[_0xcfc6('0x24')](respondWithResult(_0x532e49,null))[_0xcfc6('0x42')](handleError(_0x532e49,null));};exports[_0xcfc6('0x4a')]=function(_0x11963f,_0x3ab339,_0x4571f7){var _0x566c4a={'raw':!![],'where':{}};var _0x4d5b04={};var _0x266b50={'count':0x0,'rows':[]};return db[_0xcfc6('0x2b')]['findOne']({'where':{'id':_0x11963f['params']['id']}})[_0xcfc6('0x24')](handleEntityNotFound(_0x3ab339,null))[_0xcfc6('0x24')](function(_0xbaa4a0){if(_0xbaa4a0){_0x4d5b04[_0xcfc6('0x2f')]=_[_0xcfc6('0x44')](db[_0xcfc6('0x4b')][_0xcfc6('0x2c')]);_0x4d5b04[_0xcfc6('0x30')]=_[_0xcfc6('0x44')](_0x11963f[_0xcfc6('0x30')]);_0x4d5b04[_0xcfc6('0x31')]=_[_0xcfc6('0x32')](_0x4d5b04[_0xcfc6('0x2f')],_0x4d5b04[_0xcfc6('0x30')]);_0x566c4a['attributes']=_[_0xcfc6('0x32')](_0x4d5b04['model'],qs[_0xcfc6('0x33')](_0x11963f[_0xcfc6('0x30')]['fields']));_0x566c4a[_0xcfc6('0x34')]=_0x566c4a[_0xcfc6('0x34')][_0xcfc6('0x35')]?_0x566c4a[_0xcfc6('0x34')]:_0x4d5b04[_0xcfc6('0x2f')];if(!_0x11963f[_0xcfc6('0x30')][_0xcfc6('0x4c')](_0xcfc6('0x36'))){_0x566c4a[_0xcfc6('0x1f')]=qs[_0xcfc6('0x1f')](_0x11963f[_0xcfc6('0x30')]['limit']);_0x566c4a[_0xcfc6('0x1d')]=qs['offset'](_0x11963f['query'][_0xcfc6('0x1d')]);}_0x566c4a[_0xcfc6('0x37')]=qs['sort'](_0x11963f[_0xcfc6('0x30')][_0xcfc6('0x38')]);_0x566c4a[_0xcfc6('0x3b')]=qs[_0xcfc6('0x31')](_['pick'](_0x11963f['query'],_0x4d5b04['filters']));_0x566c4a[_0xcfc6('0x3b')][_0xcfc6('0x4d')]=_0xbaa4a0['id'];if(_0x11963f[_0xcfc6('0x30')][_0xcfc6('0x3a')]){_0x566c4a['where']=_[_0xcfc6('0x3c')](_0x566c4a[_0xcfc6('0x3b')],{'$or':_['map'](_0x566c4a[_0xcfc6('0x34')],function(_0x28660c){var _0x389e8a={};_0x389e8a[_0x28660c]={'$like':'%'+_0x11963f[_0xcfc6('0x30')]['filter']+'%'};return _0x389e8a;})});}_0x566c4a=_[_0xcfc6('0x3c')]({},_0x566c4a,_0x11963f['options']);return db[_0xcfc6('0x4b')][_0xcfc6('0x20')]({'where':_0x566c4a[_0xcfc6('0x3b')]})[_0xcfc6('0x24')](function(_0x5eb5d5){_0x266b50[_0xcfc6('0x20')]=_0x5eb5d5;if(_0x11963f['query']['includeAll']){_0x566c4a[_0xcfc6('0x4e')]=[{'all':!![]}];}return db[_0xcfc6('0x4b')]['findAll'](_0x566c4a);})['then'](function(_0x4fefdd){_0x266b50['rows']=_0x4fefdd;return _0x266b50;});}})[_0xcfc6('0x24')](respondWithFilteredResult(_0x3ab339,_0x566c4a))['catch'](handleError(_0x3ab339,null));};