a931c63344aafc56454a0a6a34fc1d8fb5ce7c37
[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 _0x544f=['../../config/license/hardware','../../config/logger','../../config/utils','../../config/environment','sendStatus','end','json','count','offset','limit','status','set','Content-Range','apply','reject','save','update','error','stack','name','send','index','JscriptySessionReport','rawAttributes','key','map','query','intersection','model','attributes','fields','hasOwnProperty','nolimit','order','sort','where','filters','pick','filter','type','VIRTUAL','merge','options','include','findAll','rows','catch','show','params','keys','find','then','create','body','destroy','JscriptyQuestionReport','length','eml-format','rimraf','zip-dir','fast-json-patch','moment','bluebird','mustache','path','to-csv','ejs','lodash','crypto','jsforce','desk.js','querystring','papaparse','ioredis','../../components/auth/service','../../components/parsers/advancedSearch'];(function(_0x54dd2f,_0x267728){var _0x257429=function(_0x9ef824){while(--_0x9ef824){_0x54dd2f['push'](_0x54dd2f['shift']());}};_0x257429(++_0x267728);}(_0x544f,0x85));var _0xf544=function(_0x4c445a,_0x4ee80f){_0x4c445a=_0x4c445a-0x0;var _0x2f611c=_0x544f[_0x4c445a];return _0x2f611c;};'use strict';var emlformat=require(_0xf544('0x0'));var rimraf=require(_0xf544('0x1'));var zipdir=require(_0xf544('0x2'));var jsonpatch=require(_0xf544('0x3'));var rp=require('request-promise');var moment=require(_0xf544('0x4'));var BPromise=require(_0xf544('0x5'));var Mustache=require(_0xf544('0x6'));var util=require('util');var path=require(_0xf544('0x7'));var sox=require('sox');var csv=require(_0xf544('0x8'));var ejs=require(_0xf544('0x9'));var fs=require('fs');var fs_extra=require('fs-extra');var _=require(_0xf544('0xa'));var squel=require('squel');var crypto=require(_0xf544('0xb'));var jsforce=require(_0xf544('0xc'));var deskjs=require(_0xf544('0xd'));var toCsv=require(_0xf544('0x8'));var querystring=require(_0xf544('0xe'));var Papa=require(_0xf544('0xf'));var Redis=require(_0xf544('0x10'));var authService=require(_0xf544('0x11'));var qs=require('../../components/parsers/qs');var as=require(_0xf544('0x12'));var hardwareService=require(_0xf544('0x13'));var logger=require(_0xf544('0x14'))('api');var utils=require(_0xf544('0x15'));var config=require(_0xf544('0x16'));var licenseUtil=require('../../config/license/util');var db=require('../../mysqldb')['db'];function respondWithStatusCode(_0x20cec7,_0x2e5793){_0x2e5793=_0x2e5793||0xcc;return function(_0x23001d){if(_0x23001d){return _0x20cec7[_0xf544('0x17')](_0x2e5793);}return _0x20cec7['status'](_0x2e5793)[_0xf544('0x18')]();};}function respondWithResult(_0x302033,_0x469fef){_0x469fef=_0x469fef||0xc8;return function(_0x321ed7){if(_0x321ed7){return _0x302033['status'](_0x469fef)[_0xf544('0x19')](_0x321ed7);}};}function respondWithFilteredResult(_0x58fa73,_0x43fafd){return function(_0x5e1742){if(_0x5e1742){var _0x1dd0f8=_0x5e1742[_0xf544('0x1a')],_0x31370e=_0x43fafd[_0xf544('0x1b')],_0x5860d0=_0x43fafd[_0xf544('0x1b')]+_0x43fafd[_0xf544('0x1c')],_0x32b9ab;if(_0x5860d0>=_0x1dd0f8){_0x5860d0=_0x1dd0f8;_0x32b9ab=0xc8;}else{_0x32b9ab=0xce;}_0x58fa73[_0xf544('0x1d')](_0x32b9ab);return _0x58fa73[_0xf544('0x1e')](_0xf544('0x1f'),_0x31370e+'-'+_0x5860d0+'/'+_0x1dd0f8)[_0xf544('0x19')](_0x5e1742);}return null;};}function patchUpdates(_0x105730){return function(_0x539cd2){try{jsonpatch[_0xf544('0x20')](_0x539cd2,_0x105730,!![]);}catch(_0x37153){return BPromise[_0xf544('0x21')](_0x37153);}return _0x539cd2[_0xf544('0x22')]();};}function saveUpdates(_0x53672e,_0x1b0004){return function(_0x3e6224){if(_0x3e6224){return _0x3e6224[_0xf544('0x23')](_0x53672e)['then'](function(_0x4c1bdb){return _0x4c1bdb;});}return null;};}function removeEntity(_0xb01533,_0x479acb){return function(_0x1b8fd6){if(_0x1b8fd6){return _0x1b8fd6['destroy']()['then'](function(){_0xb01533[_0xf544('0x1d')](0xcc)[_0xf544('0x18')]();});}};}function handleEntityNotFound(_0x4f3d13,_0x4737ec){return function(_0x5c75e9){if(!_0x5c75e9){_0x4f3d13[_0xf544('0x17')](0x194);}return _0x5c75e9;};}function handleError(_0x250514,_0x78fe44){_0x78fe44=_0x78fe44||0x1f4;return function(_0x52bf0a){logger[_0xf544('0x24')](_0x52bf0a[_0xf544('0x25')]);if(_0x52bf0a[_0xf544('0x26')]){delete _0x52bf0a[_0xf544('0x26')];}_0x250514[_0xf544('0x1d')](_0x78fe44)[_0xf544('0x27')](_0x52bf0a);};}exports[_0xf544('0x28')]=function(_0x4c332c,_0x43c95e){var _0x40cc51={},_0x79f9bb={},_0x5a8002={'count':0x0,'rows':[]};var _0x8d167e=_['map'](db[_0xf544('0x29')][_0xf544('0x2a')],function(_0xf710a6){return{'name':_0xf710a6['fieldName'],'type':_0xf710a6['type'][_0xf544('0x2b')]};});_0x79f9bb['model']=_[_0xf544('0x2c')](_0x8d167e,_0xf544('0x26'));_0x79f9bb[_0xf544('0x2d')]=_['keys'](_0x4c332c[_0xf544('0x2d')]);_0x79f9bb['filters']=_[_0xf544('0x2e')](_0x79f9bb[_0xf544('0x2f')],_0x79f9bb[_0xf544('0x2d')]);_0x40cc51[_0xf544('0x30')]=_[_0xf544('0x2e')](_0x79f9bb[_0xf544('0x2f')],qs[_0xf544('0x31')](_0x4c332c[_0xf544('0x2d')][_0xf544('0x31')]));_0x40cc51[_0xf544('0x30')]=_0x40cc51[_0xf544('0x30')]['length']?_0x40cc51[_0xf544('0x30')]:_0x79f9bb[_0xf544('0x2f')];if(!_0x4c332c[_0xf544('0x2d')][_0xf544('0x32')](_0xf544('0x33'))){_0x40cc51[_0xf544('0x1c')]=qs[_0xf544('0x1c')](_0x4c332c['query'][_0xf544('0x1c')]);_0x40cc51[_0xf544('0x1b')]=qs[_0xf544('0x1b')](_0x4c332c['query'][_0xf544('0x1b')]);}_0x40cc51[_0xf544('0x34')]=qs[_0xf544('0x35')](_0x4c332c[_0xf544('0x2d')][_0xf544('0x35')]);_0x40cc51[_0xf544('0x36')]=qs[_0xf544('0x37')](_[_0xf544('0x38')](_0x4c332c[_0xf544('0x2d')],_0x79f9bb['filters']),_0x8d167e);if(_0x4c332c[_0xf544('0x2d')][_0xf544('0x39')]){_0x40cc51['where']=_['merge'](_0x40cc51['where'],{'$or':_['map'](_0x8d167e,function(_0x2c84f2){if(_0x2c84f2[_0xf544('0x3a')]!==_0xf544('0x3b')){var _0x4160a0={};_0x4160a0[_0x2c84f2['name']]={'$like':'%'+_0x4c332c[_0xf544('0x2d')]['filter']+'%'};return _0x4160a0;}})});}_0x40cc51=_[_0xf544('0x3c')]({},_0x40cc51,_0x4c332c[_0xf544('0x3d')]);var _0x43734a={'where':_0x40cc51[_0xf544('0x36')]};return db[_0xf544('0x29')]['count'](_0x43734a)['then'](function(_0x18f8aa){_0x5a8002[_0xf544('0x1a')]=_0x18f8aa;if(_0x4c332c[_0xf544('0x2d')]['includeAll']){_0x40cc51[_0xf544('0x3e')]=[{'all':!![]}];}return db[_0xf544('0x29')][_0xf544('0x3f')](_0x40cc51);})['then'](function(_0x35ae27){_0x5a8002[_0xf544('0x40')]=_0x35ae27;return _0x5a8002;})['then'](respondWithFilteredResult(_0x43c95e,_0x40cc51))[_0xf544('0x41')](handleError(_0x43c95e,null));};exports[_0xf544('0x42')]=function(_0x43b426,_0x5ef391){var _0x58173d={'raw':!![],'where':{'id':_0x43b426[_0xf544('0x43')]['id']}},_0x144ffc={};_0x144ffc[_0xf544('0x2f')]=_[_0xf544('0x44')](db['JscriptySessionReport'][_0xf544('0x2a')]);_0x144ffc['query']=_[_0xf544('0x44')](_0x43b426[_0xf544('0x2d')]);_0x144ffc[_0xf544('0x37')]=_[_0xf544('0x2e')](_0x144ffc['model'],_0x144ffc['query']);_0x58173d[_0xf544('0x30')]=_[_0xf544('0x2e')](_0x144ffc['model'],qs['fields'](_0x43b426[_0xf544('0x2d')][_0xf544('0x31')]));_0x58173d[_0xf544('0x30')]=_0x58173d[_0xf544('0x30')]['length']?_0x58173d[_0xf544('0x30')]:_0x144ffc[_0xf544('0x2f')];if(_0x43b426['query']['includeAll']){_0x58173d[_0xf544('0x3e')]=[{'all':!![]}];}_0x58173d=_['merge']({},_0x58173d,_0x43b426['options']);return db[_0xf544('0x29')][_0xf544('0x45')](_0x58173d)[_0xf544('0x46')](handleEntityNotFound(_0x5ef391,null))['then'](respondWithResult(_0x5ef391,null))[_0xf544('0x41')](handleError(_0x5ef391,null));};exports[_0xf544('0x47')]=function(_0x275c2c,_0x1bd570){return db[_0xf544('0x29')][_0xf544('0x47')](_0x275c2c[_0xf544('0x48')],{})[_0xf544('0x46')](respondWithResult(_0x1bd570,0xc9))[_0xf544('0x41')](handleError(_0x1bd570,null));};exports[_0xf544('0x23')]=function(_0xfee669,_0x280af1){if(_0xfee669[_0xf544('0x48')]['id']){delete _0xfee669[_0xf544('0x48')]['id'];}return db[_0xf544('0x29')][_0xf544('0x45')]({'where':{'id':_0xfee669[_0xf544('0x43')]['id']}})[_0xf544('0x46')](handleEntityNotFound(_0x280af1,null))['then'](saveUpdates(_0xfee669['body'],null))[_0xf544('0x46')](respondWithResult(_0x280af1,null))[_0xf544('0x41')](handleError(_0x280af1,null));};exports[_0xf544('0x49')]=function(_0x4e1ed5,_0x5ae4d1){return db[_0xf544('0x29')][_0xf544('0x45')]({'where':{'id':_0x4e1ed5['params']['id']}})[_0xf544('0x46')](handleEntityNotFound(_0x5ae4d1,null))['then'](removeEntity(_0x5ae4d1,null))[_0xf544('0x41')](handleError(_0x5ae4d1,null));};exports['describe']=function(_0x3f4f5f,_0x32b8a4){return db[_0xf544('0x29')]['describe']()[_0xf544('0x46')](respondWithResult(_0x32b8a4,null))[_0xf544('0x41')](handleError(_0x32b8a4,null));};exports['getQuestions']=function(_0x13c1d6,_0x159bd4,_0xba0b34){var _0x5bf847={'raw':!![],'where':{}};var _0x55ec34={};var _0x32e8cb={'count':0x0,'rows':[]};return db[_0xf544('0x29')]['findOne']({'where':{'id':_0x13c1d6[_0xf544('0x43')]['id']}})[_0xf544('0x46')](handleEntityNotFound(_0x159bd4,null))['then'](function(_0x46e3f3){if(_0x46e3f3){_0x55ec34['model']=_[_0xf544('0x44')](db[_0xf544('0x4a')][_0xf544('0x2a')]);_0x55ec34[_0xf544('0x2d')]=_[_0xf544('0x44')](_0x13c1d6['query']);_0x55ec34[_0xf544('0x37')]=_[_0xf544('0x2e')](_0x55ec34[_0xf544('0x2f')],_0x55ec34[_0xf544('0x2d')]);_0x5bf847['attributes']=_[_0xf544('0x2e')](_0x55ec34[_0xf544('0x2f')],qs[_0xf544('0x31')](_0x13c1d6[_0xf544('0x2d')][_0xf544('0x31')]));_0x5bf847[_0xf544('0x30')]=_0x5bf847[_0xf544('0x30')][_0xf544('0x4b')]?_0x5bf847[_0xf544('0x30')]:_0x55ec34['model'];if(!_0x13c1d6['query'][_0xf544('0x32')](_0xf544('0x33'))){_0x5bf847[_0xf544('0x1c')]=qs['limit'](_0x13c1d6[_0xf544('0x2d')][_0xf544('0x1c')]);_0x5bf847[_0xf544('0x1b')]=qs[_0xf544('0x1b')](_0x13c1d6[_0xf544('0x2d')][_0xf544('0x1b')]);}_0x5bf847[_0xf544('0x34')]=qs['sort'](_0x13c1d6[_0xf544('0x2d')][_0xf544('0x35')]);_0x5bf847[_0xf544('0x36')]=qs[_0xf544('0x37')](_[_0xf544('0x38')](_0x13c1d6[_0xf544('0x2d')],_0x55ec34[_0xf544('0x37')]));_0x5bf847['where']['SessionId']=_0x46e3f3['id'];if(_0x13c1d6[_0xf544('0x2d')][_0xf544('0x39')]){_0x5bf847[_0xf544('0x36')]=_[_0xf544('0x3c')](_0x5bf847[_0xf544('0x36')],{'$or':_['map'](_0x5bf847[_0xf544('0x30')],function(_0x2fb2a8){var _0x17e767={};_0x17e767[_0x2fb2a8]={'$like':'%'+_0x13c1d6['query'][_0xf544('0x39')]+'%'};return _0x17e767;})});}_0x5bf847=_['merge']({},_0x5bf847,_0x13c1d6[_0xf544('0x3d')]);return db[_0xf544('0x4a')][_0xf544('0x1a')]({'where':_0x5bf847[_0xf544('0x36')]})['then'](function(_0xd9d272){_0x32e8cb[_0xf544('0x1a')]=_0xd9d272;if(_0x13c1d6['query']['includeAll']){_0x5bf847[_0xf544('0x3e')]=[{'all':!![]}];}return db[_0xf544('0x4a')][_0xf544('0x3f')](_0x5bf847);})[_0xf544('0x46')](function(_0x110ce7){_0x32e8cb['rows']=_0x110ce7;return _0x32e8cb;});}})[_0xf544('0x46')](respondWithFilteredResult(_0x159bd4,_0x5bf847))['catch'](handleError(_0x159bd4,null));};