6e30a82eb6315f31e99f88fddc1c7d5890aab1e3
[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 _0x1cdb=['params','describe','getQuestions','findOne','JscriptyQuestionReport','rawAttributes','nolimit','SessionId','eml-format','rimraf','fast-json-patch','request-promise','moment','mustache','util','path','sox','to-csv','ejs','fs-extra','squel','crypto','desk.js','querystring','papaparse','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','api','../../config/utils','../../config/license/util','../../mysqldb','sendStatus','status','end','json','offset','undefined','limit','count','Content-Range','apply','reject','update','then','destroy','stack','name','send','index','map','JscriptySessionReport','fieldName','type','key','model','query','filters','intersection','attributes','length','hasOwnProperty','order','sort','where','pick','filter','merge','includeAll','include','findAll','rows','catch','keys','fields','options','find','create','body'];(function(_0x3c1df5,_0x1bc574){var _0x15b848=function(_0xcdaf10){while(--_0xcdaf10){_0x3c1df5['push'](_0x3c1df5['shift']());}};_0x15b848(++_0x1bc574);}(_0x1cdb,0x198));var _0xb1cd=function(_0x4e48c4,_0x57aeb4){_0x4e48c4=_0x4e48c4-0x0;var _0x53e44b=_0x1cdb[_0x4e48c4];return _0x53e44b;};'use strict';var emlformat=require(_0xb1cd('0x0'));var rimraf=require(_0xb1cd('0x1'));var zipdir=require('zip-dir');var jsonpatch=require(_0xb1cd('0x2'));var rp=require(_0xb1cd('0x3'));var moment=require(_0xb1cd('0x4'));var BPromise=require('bluebird');var Mustache=require(_0xb1cd('0x5'));var util=require(_0xb1cd('0x6'));var path=require(_0xb1cd('0x7'));var sox=require(_0xb1cd('0x8'));var csv=require(_0xb1cd('0x9'));var ejs=require(_0xb1cd('0xa'));var fs=require('fs');var fs_extra=require(_0xb1cd('0xb'));var _=require('lodash');var squel=require(_0xb1cd('0xc'));var crypto=require(_0xb1cd('0xd'));var jsforce=require('jsforce');var deskjs=require(_0xb1cd('0xe'));var toCsv=require(_0xb1cd('0x9'));var querystring=require(_0xb1cd('0xf'));var Papa=require(_0xb1cd('0x10'));var Redis=require('ioredis');var authService=require(_0xb1cd('0x11'));var qs=require(_0xb1cd('0x12'));var as=require(_0xb1cd('0x13'));var hardwareService=require(_0xb1cd('0x14'));var logger=require('../../config/logger')(_0xb1cd('0x15'));var utils=require(_0xb1cd('0x16'));var config=require('../../config/environment');var licenseUtil=require(_0xb1cd('0x17'));var db=require(_0xb1cd('0x18'))['db'];function respondWithStatusCode(_0x59f501,_0x101c7c){_0x101c7c=_0x101c7c||0xcc;return function(_0x3c0960){if(_0x3c0960){return _0x59f501[_0xb1cd('0x19')](_0x101c7c);}return _0x59f501[_0xb1cd('0x1a')](_0x101c7c)[_0xb1cd('0x1b')]();};}function respondWithResult(_0xb91eac,_0x1379d3){_0x1379d3=_0x1379d3||0xc8;return function(_0x3af7d2){if(_0x3af7d2){return _0xb91eac[_0xb1cd('0x1a')](_0x1379d3)[_0xb1cd('0x1c')](_0x3af7d2);}};}function respondWithFilteredResult(_0x4dd15e,_0x56092d){return function(_0x2736de){if(_0x2736de){var _0x2d2989=typeof _0x56092d[_0xb1cd('0x1d')]===_0xb1cd('0x1e')&&typeof _0x56092d[_0xb1cd('0x1f')]==='undefined';var _0xdd7b7e=_0x2736de['count'];var _0x1834df=_0x2d2989?0x0:_0x56092d[_0xb1cd('0x1d')];var _0x105d8b=_0x2d2989?_0x2736de[_0xb1cd('0x20')]:_0x56092d[_0xb1cd('0x1d')]+_0x56092d['limit'];var _0x828565;if(_0x105d8b>=_0xdd7b7e){_0x105d8b=_0xdd7b7e;_0x828565=0xc8;}else{_0x828565=0xce;}_0x4dd15e['status'](_0x828565);return _0x4dd15e['set'](_0xb1cd('0x21'),_0x1834df+'-'+_0x105d8b+'/'+_0xdd7b7e)[_0xb1cd('0x1c')](_0x2736de);}return null;};}function patchUpdates(_0x3ad7c5){return function(_0x3a8f28){try{jsonpatch[_0xb1cd('0x22')](_0x3a8f28,_0x3ad7c5,!![]);}catch(_0x4e859a){return BPromise[_0xb1cd('0x23')](_0x4e859a);}return _0x3a8f28['save']();};}function saveUpdates(_0x2543a4,_0xf4aa36){return function(_0x1b2102){if(_0x1b2102){return _0x1b2102[_0xb1cd('0x24')](_0x2543a4)[_0xb1cd('0x25')](function(_0x408d22){return _0x408d22;});}return null;};}function removeEntity(_0x29c399,_0x6f5208){return function(_0x5e554f){if(_0x5e554f){return _0x5e554f[_0xb1cd('0x26')]()['then'](function(){_0x29c399[_0xb1cd('0x1a')](0xcc)['end']();});}};}function handleEntityNotFound(_0x146a9a,_0xfbcc15){return function(_0x286464){if(!_0x286464){_0x146a9a['sendStatus'](0x194);}return _0x286464;};}function handleError(_0xbdaa73,_0x5e383f){_0x5e383f=_0x5e383f||0x1f4;return function(_0x4e27bc){logger['error'](_0x4e27bc[_0xb1cd('0x27')]);if(_0x4e27bc[_0xb1cd('0x28')]){delete _0x4e27bc[_0xb1cd('0x28')];}_0xbdaa73[_0xb1cd('0x1a')](_0x5e383f)[_0xb1cd('0x29')](_0x4e27bc);};}exports[_0xb1cd('0x2a')]=function(_0xa5b7a,_0x6d5a26){var _0x2c80eb={},_0x176d38={},_0x37988c={'count':0x0,'rows':[]};var _0x1f6d38=_[_0xb1cd('0x2b')](db[_0xb1cd('0x2c')]['rawAttributes'],function(_0x5ac095){return{'name':_0x5ac095[_0xb1cd('0x2d')],'type':_0x5ac095[_0xb1cd('0x2e')][_0xb1cd('0x2f')]};});_0x176d38[_0xb1cd('0x30')]=_[_0xb1cd('0x2b')](_0x1f6d38,_0xb1cd('0x28'));_0x176d38[_0xb1cd('0x31')]=_['keys'](_0xa5b7a[_0xb1cd('0x31')]);_0x176d38[_0xb1cd('0x32')]=_[_0xb1cd('0x33')](_0x176d38[_0xb1cd('0x30')],_0x176d38[_0xb1cd('0x31')]);_0x2c80eb['attributes']=_[_0xb1cd('0x33')](_0x176d38[_0xb1cd('0x30')],qs['fields'](_0xa5b7a[_0xb1cd('0x31')]['fields']));_0x2c80eb[_0xb1cd('0x34')]=_0x2c80eb[_0xb1cd('0x34')][_0xb1cd('0x35')]?_0x2c80eb[_0xb1cd('0x34')]:_0x176d38[_0xb1cd('0x30')];if(!_0xa5b7a['query'][_0xb1cd('0x36')]('nolimit')){_0x2c80eb['limit']=qs[_0xb1cd('0x1f')](_0xa5b7a[_0xb1cd('0x31')][_0xb1cd('0x1f')]);_0x2c80eb[_0xb1cd('0x1d')]=qs[_0xb1cd('0x1d')](_0xa5b7a[_0xb1cd('0x31')]['offset']);}_0x2c80eb[_0xb1cd('0x37')]=qs[_0xb1cd('0x38')](_0xa5b7a[_0xb1cd('0x31')][_0xb1cd('0x38')]);_0x2c80eb[_0xb1cd('0x39')]=qs[_0xb1cd('0x32')](_[_0xb1cd('0x3a')](_0xa5b7a[_0xb1cd('0x31')],_0x176d38['filters']),_0x1f6d38);if(_0xa5b7a['query'][_0xb1cd('0x3b')]){_0x2c80eb[_0xb1cd('0x39')]=_[_0xb1cd('0x3c')](_0x2c80eb[_0xb1cd('0x39')],{'$or':_[_0xb1cd('0x2b')](_0x1f6d38,function(_0x5ed43c){if(_0x5ed43c[_0xb1cd('0x2e')]!=='VIRTUAL'){var _0x302d65={};_0x302d65[_0x5ed43c[_0xb1cd('0x28')]]={'$like':'%'+_0xa5b7a[_0xb1cd('0x31')][_0xb1cd('0x3b')]+'%'};return _0x302d65;}})});}_0x2c80eb=_[_0xb1cd('0x3c')]({},_0x2c80eb,_0xa5b7a['options']);var _0x332ffe={'where':_0x2c80eb[_0xb1cd('0x39')]};return db[_0xb1cd('0x2c')][_0xb1cd('0x20')](_0x332ffe)['then'](function(_0x35c2ba){_0x37988c[_0xb1cd('0x20')]=_0x35c2ba;if(_0xa5b7a['query'][_0xb1cd('0x3d')]){_0x2c80eb[_0xb1cd('0x3e')]=[{'all':!![]}];}return db[_0xb1cd('0x2c')][_0xb1cd('0x3f')](_0x2c80eb);})[_0xb1cd('0x25')](function(_0x5bcdbe){_0x37988c[_0xb1cd('0x40')]=_0x5bcdbe;return _0x37988c;})[_0xb1cd('0x25')](respondWithFilteredResult(_0x6d5a26,_0x2c80eb))[_0xb1cd('0x41')](handleError(_0x6d5a26,null));};exports['show']=function(_0x34e8cf,_0x3d2f0f){var _0x4aa07e={'raw':!![],'where':{'id':_0x34e8cf['params']['id']}},_0x324e97={};_0x324e97[_0xb1cd('0x30')]=_[_0xb1cd('0x42')](db['JscriptySessionReport']['rawAttributes']);_0x324e97[_0xb1cd('0x31')]=_[_0xb1cd('0x42')](_0x34e8cf[_0xb1cd('0x31')]);_0x324e97[_0xb1cd('0x32')]=_[_0xb1cd('0x33')](_0x324e97['model'],_0x324e97[_0xb1cd('0x31')]);_0x4aa07e[_0xb1cd('0x34')]=_[_0xb1cd('0x33')](_0x324e97[_0xb1cd('0x30')],qs[_0xb1cd('0x43')](_0x34e8cf[_0xb1cd('0x31')][_0xb1cd('0x43')]));_0x4aa07e['attributes']=_0x4aa07e['attributes'][_0xb1cd('0x35')]?_0x4aa07e[_0xb1cd('0x34')]:_0x324e97[_0xb1cd('0x30')];if(_0x34e8cf[_0xb1cd('0x31')][_0xb1cd('0x3d')]){_0x4aa07e[_0xb1cd('0x3e')]=[{'all':!![]}];}_0x4aa07e=_[_0xb1cd('0x3c')]({},_0x4aa07e,_0x34e8cf[_0xb1cd('0x44')]);return db[_0xb1cd('0x2c')][_0xb1cd('0x45')](_0x4aa07e)['then'](handleEntityNotFound(_0x3d2f0f,null))[_0xb1cd('0x25')](respondWithResult(_0x3d2f0f,null))[_0xb1cd('0x41')](handleError(_0x3d2f0f,null));};exports[_0xb1cd('0x46')]=function(_0x218a8c,_0x207738){return db['JscriptySessionReport']['create'](_0x218a8c[_0xb1cd('0x47')],{})[_0xb1cd('0x25')](respondWithResult(_0x207738,0xc9))[_0xb1cd('0x41')](handleError(_0x207738,null));};exports['update']=function(_0x10c73c,_0x52fe0a){if(_0x10c73c[_0xb1cd('0x47')]['id']){delete _0x10c73c['body']['id'];}return db[_0xb1cd('0x2c')]['find']({'where':{'id':_0x10c73c['params']['id']}})['then'](handleEntityNotFound(_0x52fe0a,null))['then'](saveUpdates(_0x10c73c[_0xb1cd('0x47')],null))['then'](respondWithResult(_0x52fe0a,null))[_0xb1cd('0x41')](handleError(_0x52fe0a,null));};exports[_0xb1cd('0x26')]=function(_0x53b401,_0x13550e){return db[_0xb1cd('0x2c')][_0xb1cd('0x45')]({'where':{'id':_0x53b401[_0xb1cd('0x48')]['id']}})[_0xb1cd('0x25')](handleEntityNotFound(_0x13550e,null))['then'](removeEntity(_0x13550e,null))['catch'](handleError(_0x13550e,null));};exports[_0xb1cd('0x49')]=function(_0x52adee,_0x1490f5){return db[_0xb1cd('0x2c')][_0xb1cd('0x49')]()['then'](respondWithResult(_0x1490f5,null))[_0xb1cd('0x41')](handleError(_0x1490f5,null));};exports[_0xb1cd('0x4a')]=function(_0x8589da,_0x1fe175,_0x118a87){var _0x1de93a={'raw':!![],'where':{}};var _0xb7df89={};var _0xdf6db9={'count':0x0,'rows':[]};return db['JscriptySessionReport'][_0xb1cd('0x4b')]({'where':{'id':_0x8589da[_0xb1cd('0x48')]['id']}})[_0xb1cd('0x25')](handleEntityNotFound(_0x1fe175,null))['then'](function(_0x3bf545){if(_0x3bf545){_0xb7df89[_0xb1cd('0x30')]=_[_0xb1cd('0x42')](db[_0xb1cd('0x4c')][_0xb1cd('0x4d')]);_0xb7df89[_0xb1cd('0x31')]=_['keys'](_0x8589da[_0xb1cd('0x31')]);_0xb7df89['filters']=_[_0xb1cd('0x33')](_0xb7df89[_0xb1cd('0x30')],_0xb7df89[_0xb1cd('0x31')]);_0x1de93a['attributes']=_[_0xb1cd('0x33')](_0xb7df89[_0xb1cd('0x30')],qs['fields'](_0x8589da[_0xb1cd('0x31')][_0xb1cd('0x43')]));_0x1de93a['attributes']=_0x1de93a[_0xb1cd('0x34')][_0xb1cd('0x35')]?_0x1de93a[_0xb1cd('0x34')]:_0xb7df89[_0xb1cd('0x30')];if(!_0x8589da[_0xb1cd('0x31')][_0xb1cd('0x36')](_0xb1cd('0x4e'))){_0x1de93a[_0xb1cd('0x1f')]=qs[_0xb1cd('0x1f')](_0x8589da['query']['limit']);_0x1de93a[_0xb1cd('0x1d')]=qs[_0xb1cd('0x1d')](_0x8589da[_0xb1cd('0x31')][_0xb1cd('0x1d')]);}_0x1de93a[_0xb1cd('0x37')]=qs[_0xb1cd('0x38')](_0x8589da[_0xb1cd('0x31')]['sort']);_0x1de93a[_0xb1cd('0x39')]=qs[_0xb1cd('0x32')](_[_0xb1cd('0x3a')](_0x8589da[_0xb1cd('0x31')],_0xb7df89[_0xb1cd('0x32')]));_0x1de93a[_0xb1cd('0x39')][_0xb1cd('0x4f')]=_0x3bf545['id'];if(_0x8589da[_0xb1cd('0x31')][_0xb1cd('0x3b')]){_0x1de93a[_0xb1cd('0x39')]=_[_0xb1cd('0x3c')](_0x1de93a[_0xb1cd('0x39')],{'$or':_[_0xb1cd('0x2b')](_0x1de93a[_0xb1cd('0x34')],function(_0x58a900){var _0x36e47b={};_0x36e47b[_0x58a900]={'$like':'%'+_0x8589da[_0xb1cd('0x31')][_0xb1cd('0x3b')]+'%'};return _0x36e47b;})});}_0x1de93a=_['merge']({},_0x1de93a,_0x8589da['options']);return db[_0xb1cd('0x4c')][_0xb1cd('0x20')]({'where':_0x1de93a[_0xb1cd('0x39')]})[_0xb1cd('0x25')](function(_0x3a3f98){_0xdf6db9[_0xb1cd('0x20')]=_0x3a3f98;if(_0x8589da['query'][_0xb1cd('0x3d')]){_0x1de93a[_0xb1cd('0x3e')]=[{'all':!![]}];}return db[_0xb1cd('0x4c')]['findAll'](_0x1de93a);})[_0xb1cd('0x25')](function(_0x4915b1){_0xdf6db9[_0xb1cd('0x40')]=_0x4915b1;return _0xdf6db9;});}})[_0xb1cd('0x25')](respondWithFilteredResult(_0x1fe175,_0x1de93a))[_0xb1cd('0x41')](handleError(_0x1fe175,null));};