8232e3c95d095a3ee9cb437b613a9d871ba5f74e
[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 _0xcbc2=['offset','undefined','count','limit','set','Content-Range','apply','then','destroy','end','sendStatus','error','stack','name','send','index','map','JscriptySessionReport','rawAttributes','type','key','query','intersection','model','fields','attributes','length','order','sort','where','filters','filter','merge','VIRTUAL','options','includeAll','include','rows','params','keys','catch','create','update','body','find','describe','getQuestions','JscriptyQuestionReport','hasOwnProperty','nolimit','pick','SessionId','eml-format','rimraf','fast-json-patch','request-promise','bluebird','mustache','path','sox','to-csv','ejs','fs-extra','crypto','jsforce','desk.js','querystring','papaparse','ioredis','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','api','../../config/environment','../../mysqldb','status','json'];(function(_0xf537d5,_0x4a84ca){var _0x3dc3f0=function(_0x32a289){while(--_0x32a289){_0xf537d5['push'](_0xf537d5['shift']());}};_0x3dc3f0(++_0x4a84ca);}(_0xcbc2,0x16c));var _0x2cbc=function(_0x3e49fe,_0x552dba){_0x3e49fe=_0x3e49fe-0x0;var _0x150873=_0xcbc2[_0x3e49fe];return _0x150873;};'use strict';var emlformat=require(_0x2cbc('0x0'));var rimraf=require(_0x2cbc('0x1'));var zipdir=require('zip-dir');var jsonpatch=require(_0x2cbc('0x2'));var rp=require(_0x2cbc('0x3'));var moment=require('moment');var BPromise=require(_0x2cbc('0x4'));var Mustache=require(_0x2cbc('0x5'));var util=require('util');var path=require(_0x2cbc('0x6'));var sox=require(_0x2cbc('0x7'));var csv=require(_0x2cbc('0x8'));var ejs=require(_0x2cbc('0x9'));var fs=require('fs');var fs_extra=require(_0x2cbc('0xa'));var _=require('lodash');var squel=require('squel');var crypto=require(_0x2cbc('0xb'));var jsforce=require(_0x2cbc('0xc'));var deskjs=require(_0x2cbc('0xd'));var toCsv=require(_0x2cbc('0x8'));var querystring=require(_0x2cbc('0xe'));var Papa=require(_0x2cbc('0xf'));var Redis=require(_0x2cbc('0x10'));var authService=require('../../components/auth/service');var qs=require(_0x2cbc('0x11'));var as=require(_0x2cbc('0x12'));var hardwareService=require(_0x2cbc('0x13'));var logger=require(_0x2cbc('0x14'))(_0x2cbc('0x15'));var utils=require('../../config/utils');var config=require(_0x2cbc('0x16'));var licenseUtil=require('../../config/license/util');var db=require(_0x2cbc('0x17'))['db'];function respondWithStatusCode(_0x1943fe,_0x3bdc07){_0x3bdc07=_0x3bdc07||0xcc;return function(_0x5321ac){if(_0x5321ac){return _0x1943fe['sendStatus'](_0x3bdc07);}return _0x1943fe['status'](_0x3bdc07)['end']();};}function respondWithResult(_0x376176,_0x312d95){_0x312d95=_0x312d95||0xc8;return function(_0x38b7a0){if(_0x38b7a0){return _0x376176[_0x2cbc('0x18')](_0x312d95)[_0x2cbc('0x19')](_0x38b7a0);}};}function respondWithFilteredResult(_0x33723d,_0x5310ba){return function(_0x2e7476){if(_0x2e7476){var _0x47950f=typeof _0x5310ba[_0x2cbc('0x1a')]===_0x2cbc('0x1b')&&typeof _0x5310ba['limit']===_0x2cbc('0x1b');var _0x21db06=_0x2e7476[_0x2cbc('0x1c')];var _0x1a637f=_0x47950f?0x0:_0x5310ba['offset'];var _0x403403=_0x47950f?_0x2e7476['count']:_0x5310ba['offset']+_0x5310ba[_0x2cbc('0x1d')];var _0x40be54;if(_0x403403>=_0x21db06){_0x403403=_0x21db06;_0x40be54=0xc8;}else{_0x40be54=0xce;}_0x33723d[_0x2cbc('0x18')](_0x40be54);return _0x33723d[_0x2cbc('0x1e')](_0x2cbc('0x1f'),_0x1a637f+'-'+_0x403403+'/'+_0x21db06)[_0x2cbc('0x19')](_0x2e7476);}return null;};}function patchUpdates(_0x3b30ad){return function(_0x91c00c){try{jsonpatch[_0x2cbc('0x20')](_0x91c00c,_0x3b30ad,!![]);}catch(_0x1d8944){return BPromise['reject'](_0x1d8944);}return _0x91c00c['save']();};}function saveUpdates(_0x4467d4,_0x1612c1){return function(_0x52b735){if(_0x52b735){return _0x52b735['update'](_0x4467d4)[_0x2cbc('0x21')](function(_0x1cba13){return _0x1cba13;});}return null;};}function removeEntity(_0x121d44,_0x1af8cf){return function(_0x5f5a09){if(_0x5f5a09){return _0x5f5a09[_0x2cbc('0x22')]()[_0x2cbc('0x21')](function(){_0x121d44['status'](0xcc)[_0x2cbc('0x23')]();});}};}function handleEntityNotFound(_0x324d0a,_0x1d9303){return function(_0xe67bbe){if(!_0xe67bbe){_0x324d0a[_0x2cbc('0x24')](0x194);}return _0xe67bbe;};}function handleError(_0x3b41a4,_0x15fa68){_0x15fa68=_0x15fa68||0x1f4;return function(_0x3b7d3c){logger[_0x2cbc('0x25')](_0x3b7d3c[_0x2cbc('0x26')]);if(_0x3b7d3c[_0x2cbc('0x27')]){delete _0x3b7d3c['name'];}_0x3b41a4[_0x2cbc('0x18')](_0x15fa68)[_0x2cbc('0x28')](_0x3b7d3c);};}exports[_0x2cbc('0x29')]=function(_0x3e5aaa,_0x4d556d){var _0x51055a={},_0x44f1e3={},_0x14bad5={'count':0x0,'rows':[]};var _0x42956c=_[_0x2cbc('0x2a')](db[_0x2cbc('0x2b')][_0x2cbc('0x2c')],function(_0x4bb948){return{'name':_0x4bb948['fieldName'],'type':_0x4bb948[_0x2cbc('0x2d')][_0x2cbc('0x2e')]};});_0x44f1e3['model']=_[_0x2cbc('0x2a')](_0x42956c,_0x2cbc('0x27'));_0x44f1e3[_0x2cbc('0x2f')]=_['keys'](_0x3e5aaa[_0x2cbc('0x2f')]);_0x44f1e3['filters']=_[_0x2cbc('0x30')](_0x44f1e3[_0x2cbc('0x31')],_0x44f1e3[_0x2cbc('0x2f')]);_0x51055a['attributes']=_[_0x2cbc('0x30')](_0x44f1e3[_0x2cbc('0x31')],qs[_0x2cbc('0x32')](_0x3e5aaa[_0x2cbc('0x2f')][_0x2cbc('0x32')]));_0x51055a[_0x2cbc('0x33')]=_0x51055a[_0x2cbc('0x33')][_0x2cbc('0x34')]?_0x51055a[_0x2cbc('0x33')]:_0x44f1e3['model'];if(!_0x3e5aaa[_0x2cbc('0x2f')]['hasOwnProperty']('nolimit')){_0x51055a[_0x2cbc('0x1d')]=qs[_0x2cbc('0x1d')](_0x3e5aaa[_0x2cbc('0x2f')]['limit']);_0x51055a[_0x2cbc('0x1a')]=qs['offset'](_0x3e5aaa[_0x2cbc('0x2f')][_0x2cbc('0x1a')]);}_0x51055a[_0x2cbc('0x35')]=qs[_0x2cbc('0x36')](_0x3e5aaa[_0x2cbc('0x2f')][_0x2cbc('0x36')]);_0x51055a[_0x2cbc('0x37')]=qs[_0x2cbc('0x38')](_['pick'](_0x3e5aaa[_0x2cbc('0x2f')],_0x44f1e3[_0x2cbc('0x38')]),_0x42956c);if(_0x3e5aaa[_0x2cbc('0x2f')][_0x2cbc('0x39')]){_0x51055a[_0x2cbc('0x37')]=_[_0x2cbc('0x3a')](_0x51055a[_0x2cbc('0x37')],{'$or':_[_0x2cbc('0x2a')](_0x42956c,function(_0x3e8e7c){if(_0x3e8e7c[_0x2cbc('0x2d')]!==_0x2cbc('0x3b')){var _0x1b7706={};_0x1b7706[_0x3e8e7c[_0x2cbc('0x27')]]={'$like':'%'+_0x3e5aaa['query'][_0x2cbc('0x39')]+'%'};return _0x1b7706;}})});}_0x51055a=_[_0x2cbc('0x3a')]({},_0x51055a,_0x3e5aaa[_0x2cbc('0x3c')]);var _0x2941e7={'where':_0x51055a[_0x2cbc('0x37')]};return db[_0x2cbc('0x2b')][_0x2cbc('0x1c')](_0x2941e7)[_0x2cbc('0x21')](function(_0x2f77ec){_0x14bad5[_0x2cbc('0x1c')]=_0x2f77ec;if(_0x3e5aaa['query'][_0x2cbc('0x3d')]){_0x51055a[_0x2cbc('0x3e')]=[{'all':!![]}];}return db['JscriptySessionReport']['findAll'](_0x51055a);})[_0x2cbc('0x21')](function(_0x3e1f74){_0x14bad5[_0x2cbc('0x3f')]=_0x3e1f74;return _0x14bad5;})[_0x2cbc('0x21')](respondWithFilteredResult(_0x4d556d,_0x51055a))['catch'](handleError(_0x4d556d,null));};exports['show']=function(_0x574806,_0x547562){var _0x4aab51={'raw':!![],'where':{'id':_0x574806[_0x2cbc('0x40')]['id']}},_0x33925c={};_0x33925c[_0x2cbc('0x31')]=_[_0x2cbc('0x41')](db[_0x2cbc('0x2b')][_0x2cbc('0x2c')]);_0x33925c['query']=_[_0x2cbc('0x41')](_0x574806[_0x2cbc('0x2f')]);_0x33925c[_0x2cbc('0x38')]=_[_0x2cbc('0x30')](_0x33925c[_0x2cbc('0x31')],_0x33925c[_0x2cbc('0x2f')]);_0x4aab51[_0x2cbc('0x33')]=_['intersection'](_0x33925c['model'],qs['fields'](_0x574806[_0x2cbc('0x2f')]['fields']));_0x4aab51['attributes']=_0x4aab51[_0x2cbc('0x33')][_0x2cbc('0x34')]?_0x4aab51[_0x2cbc('0x33')]:_0x33925c[_0x2cbc('0x31')];if(_0x574806[_0x2cbc('0x2f')][_0x2cbc('0x3d')]){_0x4aab51[_0x2cbc('0x3e')]=[{'all':!![]}];}_0x4aab51=_[_0x2cbc('0x3a')]({},_0x4aab51,_0x574806[_0x2cbc('0x3c')]);return db[_0x2cbc('0x2b')]['find'](_0x4aab51)['then'](handleEntityNotFound(_0x547562,null))[_0x2cbc('0x21')](respondWithResult(_0x547562,null))[_0x2cbc('0x42')](handleError(_0x547562,null));};exports[_0x2cbc('0x43')]=function(_0x1acd24,_0x13d30d){return db['JscriptySessionReport'][_0x2cbc('0x43')](_0x1acd24['body'],{})[_0x2cbc('0x21')](respondWithResult(_0x13d30d,0xc9))['catch'](handleError(_0x13d30d,null));};exports[_0x2cbc('0x44')]=function(_0x4e7fda,_0xd66222){if(_0x4e7fda[_0x2cbc('0x45')]['id']){delete _0x4e7fda['body']['id'];}return db[_0x2cbc('0x2b')]['find']({'where':{'id':_0x4e7fda[_0x2cbc('0x40')]['id']}})[_0x2cbc('0x21')](handleEntityNotFound(_0xd66222,null))['then'](saveUpdates(_0x4e7fda[_0x2cbc('0x45')],null))[_0x2cbc('0x21')](respondWithResult(_0xd66222,null))[_0x2cbc('0x42')](handleError(_0xd66222,null));};exports[_0x2cbc('0x22')]=function(_0x511ed5,_0x55f8cb){return db[_0x2cbc('0x2b')][_0x2cbc('0x46')]({'where':{'id':_0x511ed5[_0x2cbc('0x40')]['id']}})[_0x2cbc('0x21')](handleEntityNotFound(_0x55f8cb,null))[_0x2cbc('0x21')](removeEntity(_0x55f8cb,null))[_0x2cbc('0x42')](handleError(_0x55f8cb,null));};exports[_0x2cbc('0x47')]=function(_0xb7d865,_0x4642ce){return db['JscriptySessionReport']['describe']()[_0x2cbc('0x21')](respondWithResult(_0x4642ce,null))[_0x2cbc('0x42')](handleError(_0x4642ce,null));};exports[_0x2cbc('0x48')]=function(_0xb352a1,_0x222942,_0x27868c){var _0x4e8af9={'raw':!![],'where':{}};var _0x1c077f={};var _0x371d38={'count':0x0,'rows':[]};return db[_0x2cbc('0x2b')]['findOne']({'where':{'id':_0xb352a1[_0x2cbc('0x40')]['id']}})[_0x2cbc('0x21')](handleEntityNotFound(_0x222942,null))[_0x2cbc('0x21')](function(_0xba4e4c){if(_0xba4e4c){_0x1c077f[_0x2cbc('0x31')]=_[_0x2cbc('0x41')](db[_0x2cbc('0x49')][_0x2cbc('0x2c')]);_0x1c077f[_0x2cbc('0x2f')]=_[_0x2cbc('0x41')](_0xb352a1['query']);_0x1c077f['filters']=_[_0x2cbc('0x30')](_0x1c077f['model'],_0x1c077f[_0x2cbc('0x2f')]);_0x4e8af9[_0x2cbc('0x33')]=_[_0x2cbc('0x30')](_0x1c077f[_0x2cbc('0x31')],qs[_0x2cbc('0x32')](_0xb352a1[_0x2cbc('0x2f')][_0x2cbc('0x32')]));_0x4e8af9[_0x2cbc('0x33')]=_0x4e8af9[_0x2cbc('0x33')]['length']?_0x4e8af9['attributes']:_0x1c077f[_0x2cbc('0x31')];if(!_0xb352a1[_0x2cbc('0x2f')][_0x2cbc('0x4a')](_0x2cbc('0x4b'))){_0x4e8af9['limit']=qs[_0x2cbc('0x1d')](_0xb352a1[_0x2cbc('0x2f')]['limit']);_0x4e8af9[_0x2cbc('0x1a')]=qs[_0x2cbc('0x1a')](_0xb352a1[_0x2cbc('0x2f')]['offset']);}_0x4e8af9[_0x2cbc('0x35')]=qs[_0x2cbc('0x36')](_0xb352a1[_0x2cbc('0x2f')]['sort']);_0x4e8af9[_0x2cbc('0x37')]=qs[_0x2cbc('0x38')](_[_0x2cbc('0x4c')](_0xb352a1[_0x2cbc('0x2f')],_0x1c077f['filters']));_0x4e8af9[_0x2cbc('0x37')][_0x2cbc('0x4d')]=_0xba4e4c['id'];if(_0xb352a1[_0x2cbc('0x2f')]['filter']){_0x4e8af9['where']=_[_0x2cbc('0x3a')](_0x4e8af9[_0x2cbc('0x37')],{'$or':_[_0x2cbc('0x2a')](_0x4e8af9[_0x2cbc('0x33')],function(_0x2ac103){var _0x36f51c={};_0x36f51c[_0x2ac103]={'$like':'%'+_0xb352a1[_0x2cbc('0x2f')][_0x2cbc('0x39')]+'%'};return _0x36f51c;})});}_0x4e8af9=_['merge']({},_0x4e8af9,_0xb352a1['options']);return db[_0x2cbc('0x49')]['count']({'where':_0x4e8af9['where']})[_0x2cbc('0x21')](function(_0x1f105c){_0x371d38['count']=_0x1f105c;if(_0xb352a1[_0x2cbc('0x2f')][_0x2cbc('0x3d')]){_0x4e8af9[_0x2cbc('0x3e')]=[{'all':!![]}];}return db[_0x2cbc('0x49')]['findAll'](_0x4e8af9);})[_0x2cbc('0x21')](function(_0x203990){_0x371d38['rows']=_0x203990;return _0x371d38;});}})[_0x2cbc('0x21')](respondWithFilteredResult(_0x222942,_0x4e8af9))[_0x2cbc('0x42')](handleError(_0x222942,null));};