Built motion from commit (unavailable).|2.5.21
[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 _0xb2c6=['status','end','json','count','offset','set','Content-Range','apply','reject','save','destroy','name','send','index','map','JscriptySessionReport','rawAttributes','fieldName','type','key','model','query','filters','intersection','fields','attributes','length','nolimit','limit','sort','where','pick','merge','VIRTUAL','options','then','includeAll','show','params','keys','include','find','catch','create','body','describe','getQuestions','findOne','hasOwnProperty','order','filter','html-pdf','eml-format','zip-dir','request-promise','moment','mustache','util','to-csv','ejs','squel','crypto','jsforce','desk.js','querystring','papaparse','../../components/auth/service','../../config/license/hardware','../../config/logger','api','../../config/utils','../../config/license/util','../../mysqldb','sendStatus'];(function(_0x3d1187,_0x2a8e79){var _0x3ceb4d=function(_0x54aa9b){while(--_0x54aa9b){_0x3d1187['push'](_0x3d1187['shift']());}};_0x3ceb4d(++_0x2a8e79);}(_0xb2c6,0x1a5));var _0x6b2c=function(_0x480fa6,_0xbe1ffc){_0x480fa6=_0x480fa6-0x0;var _0x3c61a1=_0xb2c6[_0x480fa6];return _0x3c61a1;};'use strict';var pdf=require(_0x6b2c('0x0'));var emlformat=require(_0x6b2c('0x1'));var rimraf=require('rimraf');var zipdir=require(_0x6b2c('0x2'));var jsonpatch=require('fast-json-patch');var rp=require(_0x6b2c('0x3'));var moment=require(_0x6b2c('0x4'));var BPromise=require('bluebird');var Mustache=require(_0x6b2c('0x5'));var util=require(_0x6b2c('0x6'));var path=require('path');var sox=require('sox');var csv=require(_0x6b2c('0x7'));var ejs=require(_0x6b2c('0x8'));var fs=require('fs');var _=require('lodash');var squel=require(_0x6b2c('0x9'));var crypto=require(_0x6b2c('0xa'));var jsforce=require(_0x6b2c('0xb'));var deskjs=require(_0x6b2c('0xc'));var toCsv=require(_0x6b2c('0x7'));var querystring=require(_0x6b2c('0xd'));var Papa=require(_0x6b2c('0xe'));var Redis=require('ioredis');var authService=require(_0x6b2c('0xf'));var qs=require('../../components/parsers/qs');var as=require('../../components/parsers/advancedSearch');var hardwareService=require(_0x6b2c('0x10'));var logger=require(_0x6b2c('0x11'))(_0x6b2c('0x12'));var utils=require(_0x6b2c('0x13'));var config=require('../../config/environment');var licenseUtil=require(_0x6b2c('0x14'));var db=require(_0x6b2c('0x15'))['db'];function respondWithStatusCode(_0x41f178,_0x3aa3c2){_0x3aa3c2=_0x3aa3c2||0xcc;return function(_0x2c0f5a){if(_0x2c0f5a){return _0x41f178[_0x6b2c('0x16')](_0x3aa3c2);}return _0x41f178[_0x6b2c('0x17')](_0x3aa3c2)[_0x6b2c('0x18')]();};}function respondWithResult(_0x2c29db,_0x36981b){_0x36981b=_0x36981b||0xc8;return function(_0xd2b71){if(_0xd2b71){return _0x2c29db[_0x6b2c('0x17')](_0x36981b)[_0x6b2c('0x19')](_0xd2b71);}};}function respondWithFilteredResult(_0x57bdd3,_0x417090){return function(_0x143e4e){if(_0x143e4e){var _0x10b863=_0x143e4e[_0x6b2c('0x1a')],_0x3510bc=_0x417090['offset'],_0x495172=_0x417090[_0x6b2c('0x1b')]+_0x417090['limit'],_0x108477;if(_0x495172>=_0x10b863){_0x495172=_0x10b863;_0x108477=0xc8;}else{_0x108477=0xce;}_0x57bdd3[_0x6b2c('0x17')](_0x108477);return _0x57bdd3[_0x6b2c('0x1c')](_0x6b2c('0x1d'),_0x3510bc+'-'+_0x495172+'/'+_0x10b863)['json'](_0x143e4e);}return null;};}function patchUpdates(_0x57ffd9){return function(_0x5b2362){try{jsonpatch[_0x6b2c('0x1e')](_0x5b2362,_0x57ffd9,!![]);}catch(_0x2e0f75){return BPromise[_0x6b2c('0x1f')](_0x2e0f75);}return _0x5b2362[_0x6b2c('0x20')]();};}function saveUpdates(_0x2680e4,_0x3b1a5d){return function(_0x40c909){if(_0x40c909){return _0x40c909['update'](_0x2680e4)['then'](function(_0x1765e6){return _0x1765e6;});}return null;};}function removeEntity(_0xbf20a,_0x8f2747){return function(_0x15b622){if(_0x15b622){return _0x15b622[_0x6b2c('0x21')]()['then'](function(){_0xbf20a['status'](0xcc)[_0x6b2c('0x18')]();});}};}function handleEntityNotFound(_0x13d1f1,_0x32a18e){return function(_0x151500){if(!_0x151500){_0x13d1f1['sendStatus'](0x194);}return _0x151500;};}function handleError(_0x4594ec,_0x164136){_0x164136=_0x164136||0x1f4;return function(_0xfe7a0d){logger['error'](_0xfe7a0d['stack']);if(_0xfe7a0d[_0x6b2c('0x22')]){delete _0xfe7a0d['name'];}_0x4594ec[_0x6b2c('0x17')](_0x164136)[_0x6b2c('0x23')](_0xfe7a0d);};}exports[_0x6b2c('0x24')]=function(_0x2a40a9,_0x5e981f){var _0x32f3b6={},_0x2a9747={},_0x2c10ac={'count':0x0,'rows':[]};var _0x41895e=_[_0x6b2c('0x25')](db[_0x6b2c('0x26')][_0x6b2c('0x27')],function(_0x43c4f0){return{'name':_0x43c4f0[_0x6b2c('0x28')],'type':_0x43c4f0[_0x6b2c('0x29')][_0x6b2c('0x2a')]};});_0x2a9747[_0x6b2c('0x2b')]=_[_0x6b2c('0x25')](_0x41895e,_0x6b2c('0x22'));_0x2a9747[_0x6b2c('0x2c')]=_['keys'](_0x2a40a9[_0x6b2c('0x2c')]);_0x2a9747[_0x6b2c('0x2d')]=_[_0x6b2c('0x2e')](_0x2a9747[_0x6b2c('0x2b')],_0x2a9747['query']);_0x32f3b6['attributes']=_[_0x6b2c('0x2e')](_0x2a9747[_0x6b2c('0x2b')],qs['fields'](_0x2a40a9[_0x6b2c('0x2c')][_0x6b2c('0x2f')]));_0x32f3b6[_0x6b2c('0x30')]=_0x32f3b6['attributes'][_0x6b2c('0x31')]?_0x32f3b6[_0x6b2c('0x30')]:_0x2a9747[_0x6b2c('0x2b')];if(!_0x2a40a9[_0x6b2c('0x2c')]['hasOwnProperty'](_0x6b2c('0x32'))){_0x32f3b6[_0x6b2c('0x33')]=qs[_0x6b2c('0x33')](_0x2a40a9[_0x6b2c('0x2c')][_0x6b2c('0x33')]);_0x32f3b6[_0x6b2c('0x1b')]=qs[_0x6b2c('0x1b')](_0x2a40a9[_0x6b2c('0x2c')]['offset']);}_0x32f3b6['order']=qs[_0x6b2c('0x34')](_0x2a40a9[_0x6b2c('0x2c')][_0x6b2c('0x34')]);_0x32f3b6[_0x6b2c('0x35')]=qs[_0x6b2c('0x2d')](_[_0x6b2c('0x36')](_0x2a40a9[_0x6b2c('0x2c')],_0x2a9747[_0x6b2c('0x2d')]),_0x41895e);if(_0x2a40a9[_0x6b2c('0x2c')]['filter']){_0x32f3b6[_0x6b2c('0x35')]=_[_0x6b2c('0x37')](_0x32f3b6[_0x6b2c('0x35')],{'$or':_[_0x6b2c('0x25')](_0x41895e,function(_0xfe5bd4){if(_0xfe5bd4[_0x6b2c('0x29')]!==_0x6b2c('0x38')){var _0x533f81={};_0x533f81[_0xfe5bd4[_0x6b2c('0x22')]]={'$like':'%'+_0x2a40a9['query']['filter']+'%'};return _0x533f81;}})});}_0x32f3b6=_[_0x6b2c('0x37')]({},_0x32f3b6,_0x2a40a9[_0x6b2c('0x39')]);var _0x2e073d={'where':_0x32f3b6[_0x6b2c('0x35')]};return db[_0x6b2c('0x26')]['count'](_0x2e073d)[_0x6b2c('0x3a')](function(_0x292967){_0x2c10ac[_0x6b2c('0x1a')]=_0x292967;if(_0x2a40a9[_0x6b2c('0x2c')][_0x6b2c('0x3b')]){_0x32f3b6['include']=[{'all':!![]}];}return db[_0x6b2c('0x26')]['findAll'](_0x32f3b6);})[_0x6b2c('0x3a')](function(_0x55d564){_0x2c10ac['rows']=_0x55d564;return _0x2c10ac;})['then'](respondWithFilteredResult(_0x5e981f,_0x32f3b6))['catch'](handleError(_0x5e981f,null));};exports[_0x6b2c('0x3c')]=function(_0x2bd619,_0x22cff1){var _0x34bc06={'raw':!![],'where':{'id':_0x2bd619[_0x6b2c('0x3d')]['id']}},_0x3edeb8={};_0x3edeb8[_0x6b2c('0x2b')]=_[_0x6b2c('0x3e')](db['JscriptySessionReport'][_0x6b2c('0x27')]);_0x3edeb8[_0x6b2c('0x2c')]=_['keys'](_0x2bd619[_0x6b2c('0x2c')]);_0x3edeb8['filters']=_[_0x6b2c('0x2e')](_0x3edeb8[_0x6b2c('0x2b')],_0x3edeb8[_0x6b2c('0x2c')]);_0x34bc06[_0x6b2c('0x30')]=_[_0x6b2c('0x2e')](_0x3edeb8[_0x6b2c('0x2b')],qs[_0x6b2c('0x2f')](_0x2bd619[_0x6b2c('0x2c')][_0x6b2c('0x2f')]));_0x34bc06[_0x6b2c('0x30')]=_0x34bc06['attributes']['length']?_0x34bc06[_0x6b2c('0x30')]:_0x3edeb8[_0x6b2c('0x2b')];if(_0x2bd619[_0x6b2c('0x2c')]['includeAll']){_0x34bc06[_0x6b2c('0x3f')]=[{'all':!![]}];}_0x34bc06=_['merge']({},_0x34bc06,_0x2bd619[_0x6b2c('0x39')]);return db['JscriptySessionReport'][_0x6b2c('0x40')](_0x34bc06)[_0x6b2c('0x3a')](handleEntityNotFound(_0x22cff1,null))[_0x6b2c('0x3a')](respondWithResult(_0x22cff1,null))[_0x6b2c('0x41')](handleError(_0x22cff1,null));};exports[_0x6b2c('0x42')]=function(_0x45ecdb,_0x5ccd50){return db[_0x6b2c('0x26')]['create'](_0x45ecdb[_0x6b2c('0x43')],{})['then'](respondWithResult(_0x5ccd50,0xc9))[_0x6b2c('0x41')](handleError(_0x5ccd50,null));};exports['update']=function(_0x56c262,_0x3f0e60){if(_0x56c262[_0x6b2c('0x43')]['id']){delete _0x56c262[_0x6b2c('0x43')]['id'];}return db[_0x6b2c('0x26')]['find']({'where':{'id':_0x56c262[_0x6b2c('0x3d')]['id']}})[_0x6b2c('0x3a')](handleEntityNotFound(_0x3f0e60,null))['then'](saveUpdates(_0x56c262[_0x6b2c('0x43')],null))[_0x6b2c('0x3a')](respondWithResult(_0x3f0e60,null))[_0x6b2c('0x41')](handleError(_0x3f0e60,null));};exports['destroy']=function(_0x3c816b,_0x2d2f78){return db[_0x6b2c('0x26')][_0x6b2c('0x40')]({'where':{'id':_0x3c816b[_0x6b2c('0x3d')]['id']}})[_0x6b2c('0x3a')](handleEntityNotFound(_0x2d2f78,null))['then'](removeEntity(_0x2d2f78,null))[_0x6b2c('0x41')](handleError(_0x2d2f78,null));};exports[_0x6b2c('0x44')]=function(_0x186bb0,_0x31b21c){return db[_0x6b2c('0x26')][_0x6b2c('0x44')]()[_0x6b2c('0x3a')](respondWithResult(_0x31b21c,null))[_0x6b2c('0x41')](handleError(_0x31b21c,null));};exports[_0x6b2c('0x45')]=function(_0x5e567a,_0x29ee4c,_0x102f17){var _0x3df00c={'raw':!![],'where':{}};var _0x1af921={};var _0x43a949={'count':0x0,'rows':[]};return db[_0x6b2c('0x26')][_0x6b2c('0x46')]({'where':{'id':_0x5e567a[_0x6b2c('0x3d')]['id']}})[_0x6b2c('0x3a')](handleEntityNotFound(_0x29ee4c,null))['then'](function(_0x146ab2){if(_0x146ab2){_0x1af921[_0x6b2c('0x2b')]=_[_0x6b2c('0x3e')](db['JscriptyQuestionReport'][_0x6b2c('0x27')]);_0x1af921[_0x6b2c('0x2c')]=_[_0x6b2c('0x3e')](_0x5e567a[_0x6b2c('0x2c')]);_0x1af921['filters']=_[_0x6b2c('0x2e')](_0x1af921[_0x6b2c('0x2b')],_0x1af921[_0x6b2c('0x2c')]);_0x3df00c[_0x6b2c('0x30')]=_['intersection'](_0x1af921['model'],qs[_0x6b2c('0x2f')](_0x5e567a['query'][_0x6b2c('0x2f')]));_0x3df00c[_0x6b2c('0x30')]=_0x3df00c['attributes'][_0x6b2c('0x31')]?_0x3df00c[_0x6b2c('0x30')]:_0x1af921[_0x6b2c('0x2b')];if(!_0x5e567a[_0x6b2c('0x2c')][_0x6b2c('0x47')](_0x6b2c('0x32'))){_0x3df00c[_0x6b2c('0x33')]=qs[_0x6b2c('0x33')](_0x5e567a['query'][_0x6b2c('0x33')]);_0x3df00c[_0x6b2c('0x1b')]=qs[_0x6b2c('0x1b')](_0x5e567a['query'][_0x6b2c('0x1b')]);}_0x3df00c[_0x6b2c('0x48')]=qs[_0x6b2c('0x34')](_0x5e567a[_0x6b2c('0x2c')]['sort']);_0x3df00c['where']=qs[_0x6b2c('0x2d')](_[_0x6b2c('0x36')](_0x5e567a[_0x6b2c('0x2c')],_0x1af921[_0x6b2c('0x2d')]));_0x3df00c[_0x6b2c('0x35')]['SessionId']=_0x146ab2['id'];if(_0x5e567a[_0x6b2c('0x2c')][_0x6b2c('0x49')]){_0x3df00c['where']=_['merge'](_0x3df00c[_0x6b2c('0x35')],{'$or':_[_0x6b2c('0x25')](_0x3df00c['attributes'],function(_0x5a7cae){var _0x1fdab3={};_0x1fdab3[_0x5a7cae]={'$like':'%'+_0x5e567a[_0x6b2c('0x2c')][_0x6b2c('0x49')]+'%'};return _0x1fdab3;})});}_0x3df00c=_[_0x6b2c('0x37')]({},_0x3df00c,_0x5e567a[_0x6b2c('0x39')]);return db['JscriptyQuestionReport'][_0x6b2c('0x1a')]({'where':_0x3df00c[_0x6b2c('0x35')]})[_0x6b2c('0x3a')](function(_0xa4df7e){_0x43a949[_0x6b2c('0x1a')]=_0xa4df7e;if(_0x5e567a[_0x6b2c('0x2c')][_0x6b2c('0x3b')]){_0x3df00c[_0x6b2c('0x3f')]=[{'all':!![]}];}return db['JscriptyQuestionReport']['findAll'](_0x3df00c);})[_0x6b2c('0x3a')](function(_0x4cf5f2){_0x43a949['rows']=_0x4cf5f2;return _0x43a949;});}})[_0x6b2c('0x3a')](respondWithFilteredResult(_0x29ee4c,_0x3df00c))[_0x6b2c('0x41')](handleError(_0x29ee4c,null));};