6bd69f41b576225d1281b1038c701b4a61e0b102
[motion2.git] / server / api / jscriptyProject / jscriptyProject.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 _0x21f5=['pick','filter','merge','VIRTUAL','options','JscriptyProject','includeAll','include','findAll','rows','catch','params','find','create','user','get','Unable\x20to\x20retrieve\x20the\x20current\x20user','role','UserProfileSection','autoAssociation','Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s','clone','length','omit','updatedAt','body','createdAt','userProfileId','getSessions','findOne','JscriptySessionReport','ProjectId','getAnswers','JscriptyAnswerReport','number','toString','indexOf','replace','getSummary','startTime','starttime','parse','JscriptyQuestionReport','-createdAt','questionId','question','format','YYYY-MM-DD\x20HH:mm:ss','SessionId','/tmp/Jscripty_Project_%d_Summary_%s.csv','setHeader','attachment;\x20filename=','text/csv','rimraf','fast-json-patch','request-promise','moment','bluebird','mustache','util','sox','ejs','lodash','squel','jsforce','querystring','ioredis','../../components/parsers/advancedSearch','../../config/utils','../../config/environment','../../config/license/util','../../mysqldb','sendStatus','status','json','offset','undefined','count','limit','Content-Range','apply','reject','update','then','destroy','Projects','UserProfileResource','error','stack','name','send','index','map','rawAttributes','type','key','model','keys','intersection','query','attributes','fields','hasOwnProperty','nolimit','order','sort','where','filters'];(function(_0x271060,_0x3f86b1){var _0x40540b=function(_0x1735a7){while(--_0x1735a7){_0x271060['push'](_0x271060['shift']());}};_0x40540b(++_0x3f86b1);}(_0x21f5,0x1e5));var _0x521f=function(_0x29a80f,_0xcf7573){_0x29a80f=_0x29a80f-0x0;var _0x18d6ce=_0x21f5[_0x29a80f];return _0x18d6ce;};'use strict';var emlformat=require('eml-format');var rimraf=require(_0x521f('0x0'));var zipdir=require('zip-dir');var jsonpatch=require(_0x521f('0x1'));var rp=require(_0x521f('0x2'));var moment=require(_0x521f('0x3'));var BPromise=require(_0x521f('0x4'));var Mustache=require(_0x521f('0x5'));var util=require(_0x521f('0x6'));var path=require('path');var sox=require(_0x521f('0x7'));var csv=require('to-csv');var ejs=require(_0x521f('0x8'));var fs=require('fs');var fs_extra=require('fs-extra');var _=require(_0x521f('0x9'));var squel=require(_0x521f('0xa'));var crypto=require('crypto');var jsforce=require(_0x521f('0xb'));var deskjs=require('desk.js');var toCsv=require('to-csv');var querystring=require(_0x521f('0xc'));var Papa=require('papaparse');var Redis=require(_0x521f('0xd'));var authService=require('../../components/auth/service');var qs=require('../../components/parsers/qs');var as=require(_0x521f('0xe'));var hardwareService=require('../../config/license/hardware');var logger=require('../../config/logger')('api');var utils=require(_0x521f('0xf'));var config=require(_0x521f('0x10'));var licenseUtil=require(_0x521f('0x11'));var db=require(_0x521f('0x12'))['db'];function respondWithStatusCode(_0x140fbd,_0x53c1e5){_0x53c1e5=_0x53c1e5||0xcc;return function(_0x50297a){if(_0x50297a){return _0x140fbd[_0x521f('0x13')](_0x53c1e5);}return _0x140fbd['status'](_0x53c1e5)['end']();};}function respondWithResult(_0x8ff9c3,_0x5897a8){_0x5897a8=_0x5897a8||0xc8;return function(_0x50cbb5){if(_0x50cbb5){return _0x8ff9c3[_0x521f('0x14')](_0x5897a8)[_0x521f('0x15')](_0x50cbb5);}};}function respondWithFilteredResult(_0x33bf35,_0x44f222){return function(_0x93c983){if(_0x93c983){var _0x2fdd05=typeof _0x44f222[_0x521f('0x16')]===_0x521f('0x17')&&typeof _0x44f222['limit']===_0x521f('0x17');var _0xdfa8ba=_0x93c983[_0x521f('0x18')];var _0x7fdbd0=_0x2fdd05?0x0:_0x44f222[_0x521f('0x16')];var _0x597bc0=_0x2fdd05?_0x93c983[_0x521f('0x18')]:_0x44f222[_0x521f('0x16')]+_0x44f222[_0x521f('0x19')];var _0x1f3357;if(_0x597bc0>=_0xdfa8ba){_0x597bc0=_0xdfa8ba;_0x1f3357=0xc8;}else{_0x1f3357=0xce;}_0x33bf35[_0x521f('0x14')](_0x1f3357);return _0x33bf35['set'](_0x521f('0x1a'),_0x7fdbd0+'-'+_0x597bc0+'/'+_0xdfa8ba)[_0x521f('0x15')](_0x93c983);}return null;};}function patchUpdates(_0x181fa1){return function(_0xef91b){try{jsonpatch[_0x521f('0x1b')](_0xef91b,_0x181fa1,!![]);}catch(_0x51ddbd){return BPromise[_0x521f('0x1c')](_0x51ddbd);}return _0xef91b['save']();};}function saveUpdates(_0xfb8650,_0x517da0){return function(_0x202a85){if(_0x202a85){return _0x202a85[_0x521f('0x1d')](_0xfb8650)[_0x521f('0x1e')](function(_0x1185ef){return _0x1185ef;});}return null;};}function removeEntity(_0x375e94,_0x3c2f4f){return function(_0x2112c2){if(_0x2112c2){return _0x2112c2[_0x521f('0x1f')]()[_0x521f('0x1e')](function(){var _0x295e14=_0x2112c2['get']({'plain':!![]});var _0x3e9fe2=_0x521f('0x20');return db[_0x521f('0x21')]['destroy']({'where':{'type':_0x3e9fe2,'resourceId':_0x295e14['id']}})[_0x521f('0x1e')](function(){return _0x2112c2;});})[_0x521f('0x1e')](function(){_0x375e94[_0x521f('0x14')](0xcc)['end']();});}};}function handleEntityNotFound(_0x39e3a7,_0x3c0267){return function(_0x46a1fb){if(!_0x46a1fb){_0x39e3a7[_0x521f('0x13')](0x194);}return _0x46a1fb;};}function handleError(_0x3673ad,_0x3814d9){_0x3814d9=_0x3814d9||0x1f4;return function(_0xdd89b6){logger[_0x521f('0x22')](_0xdd89b6[_0x521f('0x23')]);if(_0xdd89b6[_0x521f('0x24')]){delete _0xdd89b6[_0x521f('0x24')];}_0x3673ad['status'](_0x3814d9)[_0x521f('0x25')](_0xdd89b6);};}exports[_0x521f('0x26')]=function(_0x6bc709,_0x2974da){var _0x554707={},_0x438deb={},_0x5e021b={'count':0x0,'rows':[]};var _0x209f9f=_[_0x521f('0x27')](db['JscriptyProject'][_0x521f('0x28')],function(_0x263aa2){return{'name':_0x263aa2['fieldName'],'type':_0x263aa2[_0x521f('0x29')][_0x521f('0x2a')]};});_0x438deb[_0x521f('0x2b')]=_[_0x521f('0x27')](_0x209f9f,_0x521f('0x24'));_0x438deb['query']=_[_0x521f('0x2c')](_0x6bc709['query']);_0x438deb['filters']=_[_0x521f('0x2d')](_0x438deb[_0x521f('0x2b')],_0x438deb[_0x521f('0x2e')]);_0x554707[_0x521f('0x2f')]=_[_0x521f('0x2d')](_0x438deb[_0x521f('0x2b')],qs['fields'](_0x6bc709[_0x521f('0x2e')][_0x521f('0x30')]));_0x554707['attributes']=_0x554707[_0x521f('0x2f')]['length']?_0x554707[_0x521f('0x2f')]:_0x438deb['model'];if(!_0x6bc709[_0x521f('0x2e')][_0x521f('0x31')](_0x521f('0x32'))){_0x554707['limit']=qs[_0x521f('0x19')](_0x6bc709[_0x521f('0x2e')][_0x521f('0x19')]);_0x554707[_0x521f('0x16')]=qs['offset'](_0x6bc709['query'][_0x521f('0x16')]);}_0x554707[_0x521f('0x33')]=qs['sort'](_0x6bc709['query'][_0x521f('0x34')]);_0x554707[_0x521f('0x35')]=qs[_0x521f('0x36')](_[_0x521f('0x37')](_0x6bc709[_0x521f('0x2e')],_0x438deb[_0x521f('0x36')]),_0x209f9f);if(_0x6bc709['query'][_0x521f('0x38')]){_0x554707['where']=_[_0x521f('0x39')](_0x554707['where'],{'$or':_['map'](_0x209f9f,function(_0x2006cf){if(_0x2006cf['type']!==_0x521f('0x3a')){var _0x3703eb={};_0x3703eb[_0x2006cf[_0x521f('0x24')]]={'$like':'%'+_0x6bc709[_0x521f('0x2e')][_0x521f('0x38')]+'%'};return _0x3703eb;}})});}_0x554707=_[_0x521f('0x39')]({},_0x554707,_0x6bc709[_0x521f('0x3b')]);var _0x585017={'where':_0x554707['where']};return db[_0x521f('0x3c')][_0x521f('0x18')](_0x585017)[_0x521f('0x1e')](function(_0x3a1a07){_0x5e021b[_0x521f('0x18')]=_0x3a1a07;if(_0x6bc709[_0x521f('0x2e')][_0x521f('0x3d')]){_0x554707[_0x521f('0x3e')]=[{'all':!![]}];}return db[_0x521f('0x3c')][_0x521f('0x3f')](_0x554707);})['then'](function(_0x1337cd){_0x5e021b[_0x521f('0x40')]=_0x1337cd;return _0x5e021b;})[_0x521f('0x1e')](respondWithFilteredResult(_0x2974da,_0x554707))[_0x521f('0x41')](handleError(_0x2974da,null));};exports['show']=function(_0x58086d,_0x2067cb){var _0x468cfa={'raw':![],'where':{'id':_0x58086d[_0x521f('0x42')]['id']}},_0x5f1473={};_0x5f1473[_0x521f('0x2b')]=_[_0x521f('0x2c')](db['JscriptyProject'][_0x521f('0x28')]);_0x5f1473[_0x521f('0x2e')]=_[_0x521f('0x2c')](_0x58086d[_0x521f('0x2e')]);_0x5f1473[_0x521f('0x36')]=_[_0x521f('0x2d')](_0x5f1473[_0x521f('0x2b')],_0x5f1473[_0x521f('0x2e')]);_0x468cfa[_0x521f('0x2f')]=_[_0x521f('0x2d')](_0x5f1473[_0x521f('0x2b')],qs[_0x521f('0x30')](_0x58086d[_0x521f('0x2e')][_0x521f('0x30')]));_0x468cfa[_0x521f('0x2f')]=_0x468cfa['attributes']['length']?_0x468cfa['attributes']:_0x5f1473['model'];if(_0x58086d[_0x521f('0x2e')][_0x521f('0x3d')]){_0x468cfa['include']=[{'all':!![]}];}_0x468cfa=_[_0x521f('0x39')]({},_0x468cfa,_0x58086d['options']);return db[_0x521f('0x3c')][_0x521f('0x43')](_0x468cfa)[_0x521f('0x1e')](handleEntityNotFound(_0x2067cb,null))['then'](respondWithResult(_0x2067cb,null))['catch'](handleError(_0x2067cb,null));};exports[_0x521f('0x44')]=function(_0x2241ae,_0x1d90d9){return db[_0x521f('0x3c')][_0x521f('0x44')](_0x2241ae['body'],{})['then'](function(_0x5d322a){var _0x16b217=_0x2241ae[_0x521f('0x45')][_0x521f('0x46')]({'plain':!![]});if(!_0x16b217)throw new Error(_0x521f('0x47'));if(_0x16b217[_0x521f('0x48')]==='user'){var _0x348b4b=_0x5d322a[_0x521f('0x46')]({'plain':!![]});var _0x3cddc0=_0x521f('0x20');return db[_0x521f('0x49')]['find']({'where':{'name':_0x3cddc0,'userProfileId':_0x16b217['userProfileId']},'raw':!![]})['then'](function(_0xfb14e8){if(_0xfb14e8&&_0xfb14e8[_0x521f('0x4a')]===0x0){return db['UserProfileResource'][_0x521f('0x44')]({'name':_0x348b4b[_0x521f('0x24')],'resourceId':_0x348b4b['id'],'type':_0xfb14e8['name'],'sectionId':_0xfb14e8['id']},{})[_0x521f('0x1e')](function(){return _0x5d322a;});}else{return _0x5d322a;}})['catch'](function(_0x225eb5){logger[_0x521f('0x22')](_0x521f('0x4b'),_0x225eb5);throw _0x225eb5;});}return _0x5d322a;})[_0x521f('0x1e')](respondWithResult(_0x1d90d9,0xc9))[_0x521f('0x41')](handleError(_0x1d90d9,null));};exports[_0x521f('0x4c')]=function(_0x18b5d5,_0x24c09c){var _0x5a1264={'where':{'id':_0x18b5d5['params']['id']}},_0x2112d1={};_0x2112d1['model']=_[_0x521f('0x2c')](db[_0x521f('0x3c')][_0x521f('0x28')]);_0x5a1264[_0x521f('0x2f')]=_[_0x521f('0x2d')](_0x2112d1[_0x521f('0x2b')],qs[_0x521f('0x30')](_0x18b5d5[_0x521f('0x2e')][_0x521f('0x30')]));_0x5a1264['attributes']=_0x5a1264[_0x521f('0x2f')][_0x521f('0x4d')]?_0x5a1264['attributes']:_0x2112d1[_0x521f('0x2b')];if(_0x18b5d5[_0x521f('0x2e')][_0x521f('0x3d')]){_0x5a1264[_0x521f('0x3e')]=[{'all':!![]}];}_0x5a1264=_[_0x521f('0x39')]({},_0x5a1264,_0x18b5d5[_0x521f('0x3b')]);return db[_0x521f('0x3c')][_0x521f('0x43')](_0x5a1264)[_0x521f('0x1e')](handleEntityNotFound(_0x24c09c,null))['then'](function(_0x4ef215){if(_0x4ef215){var _0x57dc73=_0x4ef215['get']({'plain':!![]});_0x57dc73=qs[_0x521f('0x4e')](_0x57dc73,['id','createdAt',_0x521f('0x4f')]);_0x18b5d5[_0x521f('0x50')]=_[_0x521f('0x4e')](_0x18b5d5[_0x521f('0x50')],['id',_0x521f('0x51'),_0x521f('0x4f')]);return db[_0x521f('0x3c')][_0x521f('0x44')](_[_0x521f('0x39')](_0x57dc73,_0x18b5d5[_0x521f('0x50')]),{'include':_0x18b5d5[_0x521f('0x2e')][_0x521f('0x3d')]?[{'all':!![]}]:undefined})[_0x521f('0x1e')](function(_0x377e65){var _0x6b47da=_0x18b5d5[_0x521f('0x45')][_0x521f('0x46')]({'plain':!![]});if(!_0x6b47da)throw new Error('Unable\x20to\x20retrieve\x20the\x20current\x20user');if(_0x6b47da['role']===_0x521f('0x45')){var _0x401f5b=_0x377e65[_0x521f('0x46')]({'plain':!![]});var _0x12a104=_0x521f('0x20');return db[_0x521f('0x49')][_0x521f('0x43')]({'where':{'name':_0x12a104,'userProfileId':_0x6b47da[_0x521f('0x52')]},'raw':!![]})[_0x521f('0x1e')](function(_0x2138d1){if(_0x2138d1&&_0x2138d1['autoAssociation']===0x0){return db['UserProfileResource'][_0x521f('0x44')]({'name':_0x401f5b[_0x521f('0x24')],'resourceId':_0x401f5b['id'],'type':_0x2138d1[_0x521f('0x24')],'sectionId':_0x2138d1['id']},{})[_0x521f('0x1e')](function(){return _0x377e65;});}else{return _0x377e65;}})[_0x521f('0x41')](function(_0x30ad13){logger[_0x521f('0x22')](_0x521f('0x4b'),_0x30ad13);throw _0x30ad13;});}return _0x377e65;});}})[_0x521f('0x1e')](respondWithResult(_0x24c09c,0xc9))[_0x521f('0x41')](handleError(_0x24c09c,null));};exports['update']=function(_0x1fb35c,_0x4fe006){if(_0x1fb35c[_0x521f('0x50')]['id']){delete _0x1fb35c[_0x521f('0x50')]['id'];}return db[_0x521f('0x3c')][_0x521f('0x43')]({'where':{'id':_0x1fb35c[_0x521f('0x42')]['id']}})[_0x521f('0x1e')](handleEntityNotFound(_0x4fe006,null))[_0x521f('0x1e')](saveUpdates(_0x1fb35c['body'],null))['then'](respondWithResult(_0x4fe006,null))[_0x521f('0x41')](handleError(_0x4fe006,null));};exports['destroy']=function(_0x177bc8,_0x49eb5e){return db[_0x521f('0x3c')][_0x521f('0x43')]({'where':{'id':_0x177bc8[_0x521f('0x42')]['id']}})['then'](handleEntityNotFound(_0x49eb5e,null))[_0x521f('0x1e')](removeEntity(_0x49eb5e,null))[_0x521f('0x41')](handleError(_0x49eb5e,null));};exports[_0x521f('0x53')]=function(_0x408bf3,_0xd9aaa9,_0x1ce27f){var _0x3c578a={'raw':!![],'where':{}};var _0x19139a={};var _0x29ab89={'count':0x0,'rows':[]};return db[_0x521f('0x3c')][_0x521f('0x54')]({'where':{'id':_0x408bf3[_0x521f('0x42')]['id']}})[_0x521f('0x1e')](handleEntityNotFound(_0xd9aaa9,null))[_0x521f('0x1e')](function(_0x205361){if(_0x205361){_0x19139a[_0x521f('0x2b')]=_[_0x521f('0x2c')](db[_0x521f('0x55')][_0x521f('0x28')]);_0x19139a[_0x521f('0x2e')]=_[_0x521f('0x2c')](_0x408bf3[_0x521f('0x2e')]);_0x19139a['filters']=_[_0x521f('0x2d')](_0x19139a[_0x521f('0x2b')],_0x19139a['query']);_0x3c578a[_0x521f('0x2f')]=_[_0x521f('0x2d')](_0x19139a[_0x521f('0x2b')],qs[_0x521f('0x30')](_0x408bf3[_0x521f('0x2e')]['fields']));_0x3c578a[_0x521f('0x2f')]=_0x3c578a[_0x521f('0x2f')][_0x521f('0x4d')]?_0x3c578a[_0x521f('0x2f')]:_0x19139a[_0x521f('0x2b')];if(!_0x408bf3[_0x521f('0x2e')][_0x521f('0x31')](_0x521f('0x32'))){_0x3c578a[_0x521f('0x19')]=qs[_0x521f('0x19')](_0x408bf3[_0x521f('0x2e')][_0x521f('0x19')]);_0x3c578a[_0x521f('0x16')]=qs[_0x521f('0x16')](_0x408bf3['query'][_0x521f('0x16')]);}_0x3c578a[_0x521f('0x33')]=qs[_0x521f('0x34')](_0x408bf3['query']['sort']);_0x3c578a[_0x521f('0x35')]=qs[_0x521f('0x36')](_[_0x521f('0x37')](_0x408bf3[_0x521f('0x2e')],_0x19139a['filters']));_0x3c578a[_0x521f('0x35')][_0x521f('0x56')]=_0x205361['id'];if(_0x408bf3[_0x521f('0x2e')][_0x521f('0x38')]){_0x3c578a['where']=_[_0x521f('0x39')](_0x3c578a[_0x521f('0x35')],{'$or':_[_0x521f('0x27')](_0x3c578a[_0x521f('0x2f')],function(_0x8534ac){var _0x13d7b4={};_0x13d7b4[_0x8534ac]={'$like':'%'+_0x408bf3['query']['filter']+'%'};return _0x13d7b4;})});}_0x3c578a=_[_0x521f('0x39')]({},_0x3c578a,_0x408bf3['options']);return db[_0x521f('0x55')][_0x521f('0x18')]({'where':_0x3c578a[_0x521f('0x35')]})['then'](function(_0x63b38b){_0x29ab89[_0x521f('0x18')]=_0x63b38b;if(_0x408bf3[_0x521f('0x2e')][_0x521f('0x3d')]){_0x3c578a[_0x521f('0x3e')]=[{'all':!![]}];}return db[_0x521f('0x55')][_0x521f('0x3f')](_0x3c578a);})[_0x521f('0x1e')](function(_0x575a84){_0x29ab89['rows']=_0x575a84;return _0x29ab89;});}})[_0x521f('0x1e')](respondWithFilteredResult(_0xd9aaa9,_0x3c578a))[_0x521f('0x41')](handleError(_0xd9aaa9,null));};exports[_0x521f('0x57')]=function(_0x431c1a,_0x54fbc2,_0x134395){var _0x937935={'raw':!![],'where':{}};var _0x28d1c7={};var _0xb2ef96={'count':0x0,'rows':[]};return db[_0x521f('0x3c')][_0x521f('0x54')]({'where':{'id':_0x431c1a[_0x521f('0x42')]['id']}})[_0x521f('0x1e')](handleEntityNotFound(_0x54fbc2,null))['then'](function(_0x484bcb){if(_0x484bcb){_0x28d1c7[_0x521f('0x2b')]=_[_0x521f('0x2c')](db[_0x521f('0x58')][_0x521f('0x28')]);_0x28d1c7['query']=_['keys'](_0x431c1a[_0x521f('0x2e')]);_0x28d1c7[_0x521f('0x36')]=_[_0x521f('0x2d')](_0x28d1c7[_0x521f('0x2b')],_0x28d1c7[_0x521f('0x2e')]);_0x937935['attributes']=_[_0x521f('0x2d')](_0x28d1c7[_0x521f('0x2b')],qs[_0x521f('0x30')](_0x431c1a[_0x521f('0x2e')][_0x521f('0x30')]));_0x937935[_0x521f('0x2f')]=_0x937935[_0x521f('0x2f')][_0x521f('0x4d')]?_0x937935[_0x521f('0x2f')]:_0x28d1c7[_0x521f('0x2b')];if(!_0x431c1a['query'][_0x521f('0x31')](_0x521f('0x32'))){_0x937935[_0x521f('0x19')]=qs['limit'](_0x431c1a[_0x521f('0x2e')]['limit']);_0x937935['offset']=qs[_0x521f('0x16')](_0x431c1a['query'][_0x521f('0x16')]);}_0x937935[_0x521f('0x33')]=qs[_0x521f('0x34')](_0x431c1a[_0x521f('0x2e')]['sort']);_0x937935[_0x521f('0x35')]=qs[_0x521f('0x36')](_['pick'](_0x431c1a['query'],_0x28d1c7[_0x521f('0x36')]));_0x937935['where']['ProjectId']=_0x484bcb['id'];if(_0x431c1a[_0x521f('0x2e')][_0x521f('0x38')]){_0x937935[_0x521f('0x35')]=_[_0x521f('0x39')](_0x937935[_0x521f('0x35')],{'$or':_[_0x521f('0x27')](_0x937935[_0x521f('0x2f')],function(_0x179733){var _0x5cf2ba={};_0x5cf2ba[_0x179733]={'$like':'%'+_0x431c1a[_0x521f('0x2e')][_0x521f('0x38')]+'%'};return _0x5cf2ba;})});}_0x937935=_['merge']({},_0x937935,_0x431c1a[_0x521f('0x3b')]);return db[_0x521f('0x58')][_0x521f('0x18')]({'where':_0x937935['where']})[_0x521f('0x1e')](function(_0x150749){_0xb2ef96[_0x521f('0x18')]=_0x150749;if(_0x431c1a[_0x521f('0x2e')][_0x521f('0x3d')]){_0x937935[_0x521f('0x3e')]=[{'all':!![]}];}return db[_0x521f('0x58')][_0x521f('0x3f')](_0x937935);})['then'](function(_0x4d050f){_0xb2ef96[_0x521f('0x40')]=_0x4d050f;return _0xb2ef96;});}})[_0x521f('0x1e')](respondWithFilteredResult(_0x54fbc2,_0x937935))['catch'](handleError(_0x54fbc2,null));};function char(_0x39a1f2){return _0x521f('0x59')===typeof _0x39a1f2?String['fromCharCode'][_0x521f('0x1b')](null,arguments):_0x39a1f2;}function needsEncapsulation(_0x2682a1){return!!_0x2682a1&&(_0x2682a1[_0x521f('0x5a')]()[_0x521f('0x5b')](char(0xd))>=0x0||_0x2682a1[_0x521f('0x5a')]()[_0x521f('0x5b')](char(0xa))>=0x0||_0x2682a1[_0x521f('0x5a')]()[_0x521f('0x5b')](char(0x2c))>=0x0||_0x2682a1[_0x521f('0x5a')]()[_0x521f('0x5b')](char(0x22))>=0x0);}function encapsulate(_0x1749ed){var _0x3440ca=char(0x22),_0x18c6e5='\x5c'+char(0x22),_0x1a6f50=_0x1749ed['toString']()[_0x521f('0x5c')](new RegExp(_0x3440ca,'g'),_0x18c6e5);return _0x3440ca+_0x1a6f50+_0x3440ca;}exports[_0x521f('0x5d')]=function(_0x4216d6,_0x158559,_0x3bc642){var _0x212625,_0x3571fb;var _0x10e2c1={'where':{'ProjectId':_0x4216d6[_0x521f('0x42')]['id']}};if(_0x4216d6['query'][_0x521f('0x5e')]){_0x10e2c1[_0x521f('0x35')][_0x521f('0x5f')]=JSON[_0x521f('0x60')](_0x4216d6[_0x521f('0x2e')]['startTime']);}return db['JscriptySessionReport']['findAll'](_0x10e2c1)[_0x521f('0x1e')](handleEntityNotFound(_0x158559,null))[_0x521f('0x1e')](function(_0x17e90f){if(_0x17e90f){_0x212625=_0x17e90f;return db[_0x521f('0x61')][_0x521f('0x3f')]({'where':{'SessionId':{'$in':_[_0x521f('0x27')](_0x212625,'id')},'ProjectId':_0x4216d6['params']['id']},'order':_0x521f('0x62')});}})[_0x521f('0x1e')](handleEntityNotFound(_0x158559,null))['then'](function(_0x445d4e){if(_0x445d4e){_0x3571fb=_0x445d4e;var _0x48e6fb={};for(var _0x105ece=0x0,_0x566a1f=_0x3571fb[_0x521f('0x4d')];_0x105ece<_0x566a1f;_0x105ece++){if(!_0x48e6fb[_0x521f('0x31')](_0x3571fb[_0x105ece][_0x521f('0x63')])){_0x48e6fb[_0x3571fb[_0x105ece][_0x521f('0x63')]]=needsEncapsulation(_0x3571fb[_0x105ece]['question'])?encapsulate(_0x3571fb[_0x105ece][_0x521f('0x64')]):_0x3571fb[_0x105ece][_0x521f('0x64')];}}var _0x37149f=[],_0xa798f8={};for(var _0x184684=0x0,_0x3fa00a=_0x212625['length'];_0x184684<_0x3fa00a;_0x184684++){_0xa798f8={'ProjectId':_0x4216d6['params']['id'],'SessionId':_0x212625[_0x184684]['id'],'StartTime':moment(_0x212625[_0x184684][_0x521f('0x5f')])[_0x521f('0x65')](_0x521f('0x66'))};for(var _0x3f7f84=0x0,_0x4205ec=_0x3571fb[_0x521f('0x4d')];_0x3f7f84<_0x4205ec;_0x3f7f84++){if(_0x3571fb[_0x3f7f84][_0x521f('0x67')]==_0x212625[_0x184684]['id']&&_0x48e6fb[_0x521f('0x31')](_0x3571fb[_0x3f7f84]['questionId'])){_0xa798f8[_0x48e6fb[_0x3571fb[_0x3f7f84][_0x521f('0x63')]]]=_0x3571fb[_0x3f7f84]['answer'];}}for(var _0x5a6e93 in _0x48e6fb){if(!_0xa798f8[_0x521f('0x31')](_0x48e6fb[_0x5a6e93])){_0xa798f8[_0x48e6fb[_0x5a6e93]]=null;}}_0x37149f['push'](_0xa798f8);}return _0x37149f;}})[_0x521f('0x1e')](function(_0x57da6){if(!_['isEmpty'](_0x57da6)){var _0x51d203=toCsv(_0x57da6);var _0x14f519=Date['now']();fs['writeFileSync'](util[_0x521f('0x65')](_0x521f('0x68'),_0x4216d6[_0x521f('0x42')]['id'],_0x14f519),_0x51d203);_0x158559[_0x521f('0x69')]('Content-disposition',_0x521f('0x6a')+util[_0x521f('0x65')]('Jscripty_Project_%d_Summary_%s.csv',_0x4216d6[_0x521f('0x42')]['id'],_0x14f519));_0x158559[_0x521f('0x69')]('Content-type',_0x521f('0x6b'));return _0x158559['download'](util[_0x521f('0x65')](_0x521f('0x68'),_0x4216d6[_0x521f('0x42')]['id'],_0x14f519));}else{return _0x158559[_0x521f('0x13')](0xcc);}})[_0x521f('0x41')](handleError(_0x158559,null));};