Built motion from commit (unavailable).|2.5.3
[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 _0xf664=['length','hasOwnProperty','nolimit','sort','where','pick','filter','merge','VIRTUAL','options','includeAll','include','catch','show','params','create','body','destroy','find','describe','getQuestions','findOne','JscriptyQuestionReport','findAll','rows','html-pdf','eml-format','rimraf','zip-dir','fast-json-patch','request-promise','moment','bluebird','path','sox','lodash','squel','crypto','jsforce','desk.js','to-csv','querystring','papaparse','../../components/auth/service','../../components/parsers/qs','../../config/license/hardware','../../config/logger','../../config/utils','../../mysqldb','sendStatus','status','end','json','count','offset','limit','Content-Range','apply','reject','save','update','then','error','name','send','index','map','JscriptySessionReport','rawAttributes','fieldName','type','key','model','query','keys','filters','intersection','attributes','fields'];(function(_0x4e625f,_0x3781df){var _0xc986a3=function(_0xb49874){while(--_0xb49874){_0x4e625f['push'](_0x4e625f['shift']());}};_0xc986a3(++_0x3781df);}(_0xf664,0x68));var _0x4f66=function(_0x2f45ea,_0x15c656){_0x2f45ea=_0x2f45ea-0x0;var _0x485a84=_0xf664[_0x2f45ea];return _0x485a84;};'use strict';var pdf=require(_0x4f66('0x0'));var emlformat=require(_0x4f66('0x1'));var rimraf=require(_0x4f66('0x2'));var zipdir=require(_0x4f66('0x3'));var jsonpatch=require(_0x4f66('0x4'));var rp=require(_0x4f66('0x5'));var moment=require(_0x4f66('0x6'));var BPromise=require(_0x4f66('0x7'));var Mustache=require('mustache');var util=require('util');var path=require(_0x4f66('0x8'));var sox=require(_0x4f66('0x9'));var csv=require('to-csv');var ejs=require('ejs');var fs=require('fs');var _=require(_0x4f66('0xa'));var squel=require(_0x4f66('0xb'));var crypto=require(_0x4f66('0xc'));var jsforce=require(_0x4f66('0xd'));var deskjs=require(_0x4f66('0xe'));var toCsv=require(_0x4f66('0xf'));var querystring=require(_0x4f66('0x10'));var Papa=require(_0x4f66('0x11'));var Redis=require('ioredis');var authService=require(_0x4f66('0x12'));var qs=require(_0x4f66('0x13'));var as=require('../../components/parsers/advancedSearch');var hardwareService=require(_0x4f66('0x14'));var logger=require(_0x4f66('0x15'))('api');var utils=require(_0x4f66('0x16'));var config=require('../../config/environment');var db=require(_0x4f66('0x17'))['db'];function respondWithStatusCode(_0x3d67a9,_0x1d3e24){_0x1d3e24=_0x1d3e24||0xcc;return function(_0x53c576){if(_0x53c576){return _0x3d67a9[_0x4f66('0x18')](_0x1d3e24);}return _0x3d67a9[_0x4f66('0x19')](_0x1d3e24)[_0x4f66('0x1a')]();};}function respondWithResult(_0x506de1,_0x1793c9){_0x1793c9=_0x1793c9||0xc8;return function(_0x56a331){if(_0x56a331){return _0x506de1[_0x4f66('0x19')](_0x1793c9)[_0x4f66('0x1b')](_0x56a331);}};}function respondWithFilteredResult(_0x6bb40c,_0x195bf0){return function(_0xa84fa3){if(_0xa84fa3){var _0x2754ec=_0xa84fa3[_0x4f66('0x1c')],_0x7cf064=_0x195bf0[_0x4f66('0x1d')],_0x2663ff=_0x195bf0[_0x4f66('0x1d')]+_0x195bf0[_0x4f66('0x1e')],_0x27a7bd;if(_0x2663ff>=_0x2754ec){_0x2663ff=_0x2754ec;_0x27a7bd=0xc8;}else{_0x27a7bd=0xce;}_0x6bb40c[_0x4f66('0x19')](_0x27a7bd);return _0x6bb40c['set'](_0x4f66('0x1f'),_0x7cf064+'-'+_0x2663ff+'/'+_0x2754ec)[_0x4f66('0x1b')](_0xa84fa3);}return null;};}function patchUpdates(_0x2e7713){return function(_0x239f47){try{jsonpatch[_0x4f66('0x20')](_0x239f47,_0x2e7713,!![]);}catch(_0x50ad26){return BPromise[_0x4f66('0x21')](_0x50ad26);}return _0x239f47[_0x4f66('0x22')]();};}function saveUpdates(_0x59dc7a,_0x5bdaca){return function(_0x21286e){if(_0x21286e){return _0x21286e[_0x4f66('0x23')](_0x59dc7a)[_0x4f66('0x24')](function(_0x1eba82){return _0x1eba82;});}return null;};}function removeEntity(_0x5e2bea,_0x458b9d){return function(_0x19c876){if(_0x19c876){return _0x19c876['destroy']()[_0x4f66('0x24')](function(){_0x5e2bea[_0x4f66('0x19')](0xcc)[_0x4f66('0x1a')]();});}};}function handleEntityNotFound(_0x5b3952,_0x2ba4aa){return function(_0x13e7e8){if(!_0x13e7e8){_0x5b3952[_0x4f66('0x18')](0x194);}return _0x13e7e8;};}function handleError(_0x207f41,_0x254196){_0x254196=_0x254196||0x1f4;return function(_0x50ad5f){logger[_0x4f66('0x25')](_0x50ad5f['stack']);if(_0x50ad5f[_0x4f66('0x26')]){delete _0x50ad5f[_0x4f66('0x26')];}_0x207f41[_0x4f66('0x19')](_0x254196)[_0x4f66('0x27')](_0x50ad5f);};}exports[_0x4f66('0x28')]=function(_0xb0b5bf,_0x48e494){var _0x24cb60={},_0x342dc0={},_0x313a24={'count':0x0,'rows':[]};var _0x2179e=_[_0x4f66('0x29')](db[_0x4f66('0x2a')][_0x4f66('0x2b')],function(_0x3315c8){return{'name':_0x3315c8[_0x4f66('0x2c')],'type':_0x3315c8[_0x4f66('0x2d')][_0x4f66('0x2e')]};});_0x342dc0[_0x4f66('0x2f')]=_[_0x4f66('0x29')](_0x2179e,_0x4f66('0x26'));_0x342dc0[_0x4f66('0x30')]=_[_0x4f66('0x31')](_0xb0b5bf['query']);_0x342dc0[_0x4f66('0x32')]=_[_0x4f66('0x33')](_0x342dc0['model'],_0x342dc0[_0x4f66('0x30')]);_0x24cb60[_0x4f66('0x34')]=_['intersection'](_0x342dc0[_0x4f66('0x2f')],qs[_0x4f66('0x35')](_0xb0b5bf[_0x4f66('0x30')]['fields']));_0x24cb60[_0x4f66('0x34')]=_0x24cb60[_0x4f66('0x34')][_0x4f66('0x36')]?_0x24cb60[_0x4f66('0x34')]:_0x342dc0[_0x4f66('0x2f')];if(!_0xb0b5bf[_0x4f66('0x30')][_0x4f66('0x37')](_0x4f66('0x38'))){_0x24cb60[_0x4f66('0x1e')]=qs[_0x4f66('0x1e')](_0xb0b5bf[_0x4f66('0x30')][_0x4f66('0x1e')]);_0x24cb60['offset']=qs[_0x4f66('0x1d')](_0xb0b5bf[_0x4f66('0x30')]['offset']);}_0x24cb60['order']=qs[_0x4f66('0x39')](_0xb0b5bf['query'][_0x4f66('0x39')]);_0x24cb60[_0x4f66('0x3a')]=qs[_0x4f66('0x32')](_[_0x4f66('0x3b')](_0xb0b5bf[_0x4f66('0x30')],_0x342dc0['filters']),_0x2179e);if(_0xb0b5bf[_0x4f66('0x30')][_0x4f66('0x3c')]){_0x24cb60[_0x4f66('0x3a')]=_[_0x4f66('0x3d')](_0x24cb60['where'],{'$or':_[_0x4f66('0x29')](_0x2179e,function(_0x58fa2e){if(_0x58fa2e['type']!==_0x4f66('0x3e')){var _0x46ccb3={};_0x46ccb3[_0x58fa2e['name']]={'$like':'%'+_0xb0b5bf[_0x4f66('0x30')]['filter']+'%'};return _0x46ccb3;}})});}_0x24cb60=_[_0x4f66('0x3d')]({},_0x24cb60,_0xb0b5bf[_0x4f66('0x3f')]);var _0x106f99={'where':_0x24cb60['where']};return db[_0x4f66('0x2a')]['count'](_0x106f99)[_0x4f66('0x24')](function(_0x547b06){_0x313a24[_0x4f66('0x1c')]=_0x547b06;if(_0xb0b5bf[_0x4f66('0x30')][_0x4f66('0x40')]){_0x24cb60[_0x4f66('0x41')]=[{'all':!![]}];}return db[_0x4f66('0x2a')]['findAll'](_0x24cb60);})[_0x4f66('0x24')](function(_0x228776){_0x313a24['rows']=_0x228776;return _0x313a24;})['then'](respondWithFilteredResult(_0x48e494,_0x24cb60))[_0x4f66('0x42')](handleError(_0x48e494,null));};exports[_0x4f66('0x43')]=function(_0x2d26d8,_0x3cbbe8){var _0x43cf6a={'raw':!![],'where':{'id':_0x2d26d8[_0x4f66('0x44')]['id']}},_0x50828f={};_0x50828f[_0x4f66('0x2f')]=_[_0x4f66('0x31')](db[_0x4f66('0x2a')][_0x4f66('0x2b')]);_0x50828f[_0x4f66('0x30')]=_[_0x4f66('0x31')](_0x2d26d8[_0x4f66('0x30')]);_0x50828f[_0x4f66('0x32')]=_[_0x4f66('0x33')](_0x50828f['model'],_0x50828f[_0x4f66('0x30')]);_0x43cf6a[_0x4f66('0x34')]=_[_0x4f66('0x33')](_0x50828f[_0x4f66('0x2f')],qs['fields'](_0x2d26d8[_0x4f66('0x30')]['fields']));_0x43cf6a['attributes']=_0x43cf6a[_0x4f66('0x34')]['length']?_0x43cf6a[_0x4f66('0x34')]:_0x50828f[_0x4f66('0x2f')];if(_0x2d26d8['query']['includeAll']){_0x43cf6a[_0x4f66('0x41')]=[{'all':!![]}];}_0x43cf6a=_[_0x4f66('0x3d')]({},_0x43cf6a,_0x2d26d8[_0x4f66('0x3f')]);return db[_0x4f66('0x2a')]['find'](_0x43cf6a)[_0x4f66('0x24')](handleEntityNotFound(_0x3cbbe8,null))[_0x4f66('0x24')](respondWithResult(_0x3cbbe8,null))[_0x4f66('0x42')](handleError(_0x3cbbe8,null));};exports[_0x4f66('0x45')]=function(_0x31ef4d,_0x2f7b90){return db['JscriptySessionReport'][_0x4f66('0x45')](_0x31ef4d[_0x4f66('0x46')],{})[_0x4f66('0x24')](respondWithResult(_0x2f7b90,0xc9))['catch'](handleError(_0x2f7b90,null));};exports[_0x4f66('0x23')]=function(_0x1f8a9e,_0x2c271a){if(_0x1f8a9e['body']['id']){delete _0x1f8a9e[_0x4f66('0x46')]['id'];}return db[_0x4f66('0x2a')]['find']({'where':{'id':_0x1f8a9e[_0x4f66('0x44')]['id']}})[_0x4f66('0x24')](handleEntityNotFound(_0x2c271a,null))[_0x4f66('0x24')](saveUpdates(_0x1f8a9e[_0x4f66('0x46')],null))[_0x4f66('0x24')](respondWithResult(_0x2c271a,null))[_0x4f66('0x42')](handleError(_0x2c271a,null));};exports[_0x4f66('0x47')]=function(_0x5b5f1a,_0x192809){return db['JscriptySessionReport'][_0x4f66('0x48')]({'where':{'id':_0x5b5f1a[_0x4f66('0x44')]['id']}})[_0x4f66('0x24')](handleEntityNotFound(_0x192809,null))[_0x4f66('0x24')](removeEntity(_0x192809,null))[_0x4f66('0x42')](handleError(_0x192809,null));};exports[_0x4f66('0x49')]=function(_0x442646,_0x3dcbba){return db['JscriptySessionReport'][_0x4f66('0x49')]()[_0x4f66('0x24')](respondWithResult(_0x3dcbba,null))[_0x4f66('0x42')](handleError(_0x3dcbba,null));};exports[_0x4f66('0x4a')]=function(_0x2e8f6f,_0x30c88a,_0x523f57){var _0x176e66={'raw':!![],'where':{}};var _0x36bbf7={};var _0x432722={'count':0x0,'rows':[]};return db[_0x4f66('0x2a')][_0x4f66('0x4b')]({'where':{'id':_0x2e8f6f[_0x4f66('0x44')]['id']}})[_0x4f66('0x24')](handleEntityNotFound(_0x30c88a,null))['then'](function(_0x18efe8){if(_0x18efe8){_0x36bbf7[_0x4f66('0x2f')]=_[_0x4f66('0x31')](db[_0x4f66('0x4c')][_0x4f66('0x2b')]);_0x36bbf7[_0x4f66('0x30')]=_['keys'](_0x2e8f6f['query']);_0x36bbf7[_0x4f66('0x32')]=_[_0x4f66('0x33')](_0x36bbf7[_0x4f66('0x2f')],_0x36bbf7[_0x4f66('0x30')]);_0x176e66[_0x4f66('0x34')]=_[_0x4f66('0x33')](_0x36bbf7[_0x4f66('0x2f')],qs[_0x4f66('0x35')](_0x2e8f6f[_0x4f66('0x30')][_0x4f66('0x35')]));_0x176e66[_0x4f66('0x34')]=_0x176e66[_0x4f66('0x34')][_0x4f66('0x36')]?_0x176e66[_0x4f66('0x34')]:_0x36bbf7['model'];if(!_0x2e8f6f['query'][_0x4f66('0x37')](_0x4f66('0x38'))){_0x176e66['limit']=qs[_0x4f66('0x1e')](_0x2e8f6f['query']['limit']);_0x176e66[_0x4f66('0x1d')]=qs[_0x4f66('0x1d')](_0x2e8f6f['query'][_0x4f66('0x1d')]);}_0x176e66['order']=qs[_0x4f66('0x39')](_0x2e8f6f[_0x4f66('0x30')][_0x4f66('0x39')]);_0x176e66[_0x4f66('0x3a')]=qs[_0x4f66('0x32')](_[_0x4f66('0x3b')](_0x2e8f6f[_0x4f66('0x30')],_0x36bbf7[_0x4f66('0x32')]));_0x176e66[_0x4f66('0x3a')]['SessionId']=_0x18efe8['id'];if(_0x2e8f6f['query'][_0x4f66('0x3c')]){_0x176e66[_0x4f66('0x3a')]=_[_0x4f66('0x3d')](_0x176e66[_0x4f66('0x3a')],{'$or':_[_0x4f66('0x29')](_0x176e66[_0x4f66('0x34')],function(_0x38e838){var _0x2ce21e={};_0x2ce21e[_0x38e838]={'$like':'%'+_0x2e8f6f[_0x4f66('0x30')][_0x4f66('0x3c')]+'%'};return _0x2ce21e;})});}_0x176e66=_['merge']({},_0x176e66,_0x2e8f6f[_0x4f66('0x3f')]);return db[_0x4f66('0x4c')]['count']({'where':_0x176e66[_0x4f66('0x3a')]})[_0x4f66('0x24')](function(_0x132ff8){_0x432722['count']=_0x132ff8;if(_0x2e8f6f[_0x4f66('0x30')][_0x4f66('0x40')]){_0x176e66['include']=[{'all':!![]}];}return db[_0x4f66('0x4c')][_0x4f66('0x4d')](_0x176e66);})[_0x4f66('0x24')](function(_0x27c083){_0x432722[_0x4f66('0x4e')]=_0x27c083;return _0x432722;});}})[_0x4f66('0x24')](respondWithFilteredResult(_0x30c88a,_0x176e66))['catch'](handleError(_0x30c88a,null));};