Built motion from commit (unavailable).|2.5.4
[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 _0x734f=['limit','set','Content-Range','apply','reject','save','update','then','destroy','UserProfileResource','end','sendStatus','error','stack','name','send','index','map','JscriptyProject','rawAttributes','fieldName','type','query','keys','filters','model','intersection','fields','length','attributes','order','sort','where','pick','filter','VIRTUAL','options','include','findAll','rows','catch','params','includeAll','merge','create','user','get','role','UserProfileSection','find','userProfileId','Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s','clone','omit','createdAt','updatedAt','body','Unable\x20to\x20retrieve\x20the\x20current\x20user','autoAssociation','getSessions','findOne','JscriptySessionReport','hasOwnProperty','nolimit','ProjectId','JscriptyAnswerReport','fromCharCode','toString','indexOf','replace','getSummary','startTime','parse','JscriptyQuestionReport','questionId','question','answer','push','now','format','Content-disposition','attachment;\x20filename=','setHeader','Content-type','text/csv','html-pdf','rimraf','zip-dir','fast-json-patch','request-promise','moment','bluebird','mustache','util','path','sox','ejs','lodash','squel','crypto','jsforce','desk.js','to-csv','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/logger','../../config/utils','../../config/environment','../../mysqldb','status','json','count','offset'];(function(_0x472e35,_0x32ee94){var _0x56b383=function(_0x1832f2){while(--_0x1832f2){_0x472e35['push'](_0x472e35['shift']());}};_0x56b383(++_0x32ee94);}(_0x734f,0xc7));var _0xf734=function(_0x543670,_0x4d26b5){_0x543670=_0x543670-0x0;var _0x1e1c2d=_0x734f[_0x543670];return _0x1e1c2d;};'use strict';var pdf=require(_0xf734('0x0'));var emlformat=require('eml-format');var rimraf=require(_0xf734('0x1'));var zipdir=require(_0xf734('0x2'));var jsonpatch=require(_0xf734('0x3'));var rp=require(_0xf734('0x4'));var moment=require(_0xf734('0x5'));var BPromise=require(_0xf734('0x6'));var Mustache=require(_0xf734('0x7'));var util=require(_0xf734('0x8'));var path=require(_0xf734('0x9'));var sox=require(_0xf734('0xa'));var csv=require('to-csv');var ejs=require(_0xf734('0xb'));var fs=require('fs');var _=require(_0xf734('0xc'));var squel=require(_0xf734('0xd'));var crypto=require(_0xf734('0xe'));var jsforce=require(_0xf734('0xf'));var deskjs=require(_0xf734('0x10'));var toCsv=require(_0xf734('0x11'));var querystring=require('querystring');var Papa=require('papaparse');var Redis=require('ioredis');var authService=require(_0xf734('0x12'));var qs=require(_0xf734('0x13'));var as=require(_0xf734('0x14'));var hardwareService=require('../../config/license/hardware');var logger=require(_0xf734('0x15'))('api');var utils=require(_0xf734('0x16'));var config=require(_0xf734('0x17'));var db=require(_0xf734('0x18'))['db'];function respondWithStatusCode(_0xdf0e3f,_0xcfc42b){_0xcfc42b=_0xcfc42b||0xcc;return function(_0xf66589){if(_0xf66589){return _0xdf0e3f['sendStatus'](_0xcfc42b);}return _0xdf0e3f['status'](_0xcfc42b)['end']();};}function respondWithResult(_0x5ebc42,_0x51db82){_0x51db82=_0x51db82||0xc8;return function(_0x2a4801){if(_0x2a4801){return _0x5ebc42[_0xf734('0x19')](_0x51db82)[_0xf734('0x1a')](_0x2a4801);}};}function respondWithFilteredResult(_0x277154,_0x22b3c8){return function(_0x4246bf){if(_0x4246bf){var _0x3415f5=_0x4246bf[_0xf734('0x1b')],_0xbfc177=_0x22b3c8[_0xf734('0x1c')],_0x58ec2a=_0x22b3c8['offset']+_0x22b3c8[_0xf734('0x1d')],_0x121859;if(_0x58ec2a>=_0x3415f5){_0x58ec2a=_0x3415f5;_0x121859=0xc8;}else{_0x121859=0xce;}_0x277154[_0xf734('0x19')](_0x121859);return _0x277154[_0xf734('0x1e')](_0xf734('0x1f'),_0xbfc177+'-'+_0x58ec2a+'/'+_0x3415f5)[_0xf734('0x1a')](_0x4246bf);}return null;};}function patchUpdates(_0x40b3fe){return function(_0x56cdea){try{jsonpatch[_0xf734('0x20')](_0x56cdea,_0x40b3fe,!![]);}catch(_0x47a89e){return BPromise[_0xf734('0x21')](_0x47a89e);}return _0x56cdea[_0xf734('0x22')]();};}function saveUpdates(_0xc01021,_0x14acb9){return function(_0x59d9fe){if(_0x59d9fe){return _0x59d9fe[_0xf734('0x23')](_0xc01021)[_0xf734('0x24')](function(_0x41db2b){return _0x41db2b;});}return null;};}function removeEntity(_0x25fbee,_0xf7a56e){return function(_0x6f0027){if(_0x6f0027){return _0x6f0027[_0xf734('0x25')]()[_0xf734('0x24')](function(){var _0x485952=_0x6f0027['get']({'plain':!![]});var _0xceabdd='Projects';return db[_0xf734('0x26')][_0xf734('0x25')]({'where':{'type':_0xceabdd,'resourceId':_0x485952['id']}})[_0xf734('0x24')](function(){return _0x6f0027;});})[_0xf734('0x24')](function(){_0x25fbee[_0xf734('0x19')](0xcc)[_0xf734('0x27')]();});}};}function handleEntityNotFound(_0x8097a8,_0x3e30d6){return function(_0x23ce31){if(!_0x23ce31){_0x8097a8[_0xf734('0x28')](0x194);}return _0x23ce31;};}function handleError(_0x386d31,_0x20ef7f){_0x20ef7f=_0x20ef7f||0x1f4;return function(_0x2fe37e){logger[_0xf734('0x29')](_0x2fe37e[_0xf734('0x2a')]);if(_0x2fe37e[_0xf734('0x2b')]){delete _0x2fe37e[_0xf734('0x2b')];}_0x386d31[_0xf734('0x19')](_0x20ef7f)[_0xf734('0x2c')](_0x2fe37e);};}exports[_0xf734('0x2d')]=function(_0x30e38a,_0x34a1f9){var _0x2c570a={},_0x2016b6={},_0x2200a0={'count':0x0,'rows':[]};var _0x335ac4=_[_0xf734('0x2e')](db[_0xf734('0x2f')][_0xf734('0x30')],function(_0x2d7b6f){return{'name':_0x2d7b6f[_0xf734('0x31')],'type':_0x2d7b6f[_0xf734('0x32')]['key']};});_0x2016b6['model']=_['map'](_0x335ac4,_0xf734('0x2b'));_0x2016b6[_0xf734('0x33')]=_[_0xf734('0x34')](_0x30e38a['query']);_0x2016b6[_0xf734('0x35')]=_['intersection'](_0x2016b6[_0xf734('0x36')],_0x2016b6[_0xf734('0x33')]);_0x2c570a['attributes']=_[_0xf734('0x37')](_0x2016b6[_0xf734('0x36')],qs['fields'](_0x30e38a[_0xf734('0x33')][_0xf734('0x38')]));_0x2c570a['attributes']=_0x2c570a['attributes'][_0xf734('0x39')]?_0x2c570a[_0xf734('0x3a')]:_0x2016b6[_0xf734('0x36')];if(!_0x30e38a['query']['hasOwnProperty']('nolimit')){_0x2c570a['limit']=qs[_0xf734('0x1d')](_0x30e38a[_0xf734('0x33')]['limit']);_0x2c570a[_0xf734('0x1c')]=qs['offset'](_0x30e38a['query']['offset']);}_0x2c570a[_0xf734('0x3b')]=qs[_0xf734('0x3c')](_0x30e38a[_0xf734('0x33')][_0xf734('0x3c')]);_0x2c570a[_0xf734('0x3d')]=qs[_0xf734('0x35')](_[_0xf734('0x3e')](_0x30e38a[_0xf734('0x33')],_0x2016b6[_0xf734('0x35')]),_0x335ac4);if(_0x30e38a[_0xf734('0x33')][_0xf734('0x3f')]){_0x2c570a['where']=_['merge'](_0x2c570a[_0xf734('0x3d')],{'$or':_[_0xf734('0x2e')](_0x335ac4,function(_0x23aae1){if(_0x23aae1[_0xf734('0x32')]!==_0xf734('0x40')){var _0x59f2d1={};_0x59f2d1[_0x23aae1['name']]={'$like':'%'+_0x30e38a[_0xf734('0x33')][_0xf734('0x3f')]+'%'};return _0x59f2d1;}})});}_0x2c570a=_['merge']({},_0x2c570a,_0x30e38a[_0xf734('0x41')]);var _0x325016={'where':_0x2c570a[_0xf734('0x3d')]};return db['JscriptyProject'][_0xf734('0x1b')](_0x325016)[_0xf734('0x24')](function(_0x1ad88d){_0x2200a0[_0xf734('0x1b')]=_0x1ad88d;if(_0x30e38a[_0xf734('0x33')]['includeAll']){_0x2c570a[_0xf734('0x42')]=[{'all':!![]}];}return db['JscriptyProject'][_0xf734('0x43')](_0x2c570a);})[_0xf734('0x24')](function(_0x295323){_0x2200a0[_0xf734('0x44')]=_0x295323;return _0x2200a0;})[_0xf734('0x24')](respondWithFilteredResult(_0x34a1f9,_0x2c570a))[_0xf734('0x45')](handleError(_0x34a1f9,null));};exports['show']=function(_0x2db22e,_0xbb210a){var _0x4b449a={'raw':![],'where':{'id':_0x2db22e[_0xf734('0x46')]['id']}},_0x3709a5={};_0x3709a5[_0xf734('0x36')]=_[_0xf734('0x34')](db['JscriptyProject'][_0xf734('0x30')]);_0x3709a5[_0xf734('0x33')]=_['keys'](_0x2db22e[_0xf734('0x33')]);_0x3709a5[_0xf734('0x35')]=_[_0xf734('0x37')](_0x3709a5[_0xf734('0x36')],_0x3709a5[_0xf734('0x33')]);_0x4b449a[_0xf734('0x3a')]=_['intersection'](_0x3709a5['model'],qs['fields'](_0x2db22e[_0xf734('0x33')][_0xf734('0x38')]));_0x4b449a[_0xf734('0x3a')]=_0x4b449a[_0xf734('0x3a')]['length']?_0x4b449a[_0xf734('0x3a')]:_0x3709a5['model'];if(_0x2db22e[_0xf734('0x33')][_0xf734('0x47')]){_0x4b449a['include']=[{'all':!![]}];}_0x4b449a=_[_0xf734('0x48')]({},_0x4b449a,_0x2db22e[_0xf734('0x41')]);return db['JscriptyProject']['find'](_0x4b449a)[_0xf734('0x24')](handleEntityNotFound(_0xbb210a,null))['then'](respondWithResult(_0xbb210a,null))[_0xf734('0x45')](handleError(_0xbb210a,null));};exports[_0xf734('0x49')]=function(_0x2bd271,_0x428930){return db[_0xf734('0x2f')][_0xf734('0x49')](_0x2bd271['body'],{})[_0xf734('0x24')](function(_0x3143b1){var _0x42ba3b=_0x2bd271[_0xf734('0x4a')][_0xf734('0x4b')]({'plain':!![]});if(!_0x42ba3b)throw new Error('Unable\x20to\x20retrieve\x20the\x20current\x20user');if(_0x42ba3b[_0xf734('0x4c')]===_0xf734('0x4a')){var _0xbbba5c=_0x3143b1['get']({'plain':!![]});var _0x43faf0='Projects';return db[_0xf734('0x4d')][_0xf734('0x4e')]({'where':{'name':_0x43faf0,'userProfileId':_0x42ba3b[_0xf734('0x4f')]},'raw':!![]})[_0xf734('0x24')](function(_0x2b1ab6){if(_0x2b1ab6&&_0x2b1ab6['autoAssociation']===0x0){return db['UserProfileResource'][_0xf734('0x49')]({'name':_0xbbba5c[_0xf734('0x2b')],'resourceId':_0xbbba5c['id'],'type':_0x2b1ab6['name'],'sectionId':_0x2b1ab6['id']},{})['then'](function(){return _0x3143b1;});}else{return _0x3143b1;}})[_0xf734('0x45')](function(_0xd1e629){logger['error'](_0xf734('0x50'),_0xd1e629);throw _0xd1e629;});}return _0x3143b1;})[_0xf734('0x24')](respondWithResult(_0x428930,0xc9))['catch'](handleError(_0x428930,null));};exports[_0xf734('0x51')]=function(_0x195704,_0x2765a8){var _0x370539={'where':{'id':_0x195704[_0xf734('0x46')]['id']}},_0xf93488={};_0xf93488['model']=_[_0xf734('0x34')](db[_0xf734('0x2f')][_0xf734('0x30')]);_0x370539[_0xf734('0x3a')]=_[_0xf734('0x37')](_0xf93488[_0xf734('0x36')],qs[_0xf734('0x38')](_0x195704[_0xf734('0x33')][_0xf734('0x38')]));_0x370539['attributes']=_0x370539[_0xf734('0x3a')]['length']?_0x370539[_0xf734('0x3a')]:_0xf93488[_0xf734('0x36')];if(_0x195704['query']['includeAll']){_0x370539['include']=[{'all':!![]}];}_0x370539=_['merge']({},_0x370539,_0x195704['options']);return db['JscriptyProject']['find'](_0x370539)[_0xf734('0x24')](handleEntityNotFound(_0x2765a8,null))[_0xf734('0x24')](function(_0x527d32){if(_0x527d32){var _0x40ba96=_0x527d32[_0xf734('0x4b')]({'plain':!![]});_0x40ba96=qs[_0xf734('0x52')](_0x40ba96,['id',_0xf734('0x53'),_0xf734('0x54')]);_0x195704['body']=_[_0xf734('0x52')](_0x195704[_0xf734('0x55')],['id',_0xf734('0x53'),'updatedAt']);return db[_0xf734('0x2f')][_0xf734('0x49')](_[_0xf734('0x48')](_0x40ba96,_0x195704['body']),{'include':_0x195704[_0xf734('0x33')]['includeAll']?[{'all':!![]}]:undefined})[_0xf734('0x24')](function(_0x5676a1){var _0xc107ee=_0x195704[_0xf734('0x4a')][_0xf734('0x4b')]({'plain':!![]});if(!_0xc107ee)throw new Error(_0xf734('0x56'));if(_0xc107ee['role']===_0xf734('0x4a')){var _0x339bfc=_0x5676a1[_0xf734('0x4b')]({'plain':!![]});var _0x31fce1='Projects';return db[_0xf734('0x4d')][_0xf734('0x4e')]({'where':{'name':_0x31fce1,'userProfileId':_0xc107ee[_0xf734('0x4f')]},'raw':!![]})[_0xf734('0x24')](function(_0x180f7d){if(_0x180f7d&&_0x180f7d[_0xf734('0x57')]===0x0){return db[_0xf734('0x26')]['create']({'name':_0x339bfc[_0xf734('0x2b')],'resourceId':_0x339bfc['id'],'type':_0x180f7d[_0xf734('0x2b')],'sectionId':_0x180f7d['id']},{})[_0xf734('0x24')](function(){return _0x5676a1;});}else{return _0x5676a1;}})['catch'](function(_0x16966e){logger[_0xf734('0x29')](_0xf734('0x50'),_0x16966e);throw _0x16966e;});}return _0x5676a1;});}})['then'](respondWithResult(_0x2765a8,0xc9))['catch'](handleError(_0x2765a8,null));};exports[_0xf734('0x23')]=function(_0x5a3b00,_0x574707){if(_0x5a3b00[_0xf734('0x55')]['id']){delete _0x5a3b00[_0xf734('0x55')]['id'];}return db[_0xf734('0x2f')][_0xf734('0x4e')]({'where':{'id':_0x5a3b00[_0xf734('0x46')]['id']}})[_0xf734('0x24')](handleEntityNotFound(_0x574707,null))[_0xf734('0x24')](saveUpdates(_0x5a3b00[_0xf734('0x55')],null))[_0xf734('0x24')](respondWithResult(_0x574707,null))[_0xf734('0x45')](handleError(_0x574707,null));};exports[_0xf734('0x25')]=function(_0x729f80,_0x4dee0c){return db['JscriptyProject'][_0xf734('0x4e')]({'where':{'id':_0x729f80[_0xf734('0x46')]['id']}})['then'](handleEntityNotFound(_0x4dee0c,null))[_0xf734('0x24')](removeEntity(_0x4dee0c,null))[_0xf734('0x45')](handleError(_0x4dee0c,null));};exports[_0xf734('0x58')]=function(_0x2d0b0d,_0x31fb8a,_0x43e4f7){var _0x2e75a4={'raw':!![],'where':{}};var _0x54131c={};var _0x1c4abe={'count':0x0,'rows':[]};return db[_0xf734('0x2f')][_0xf734('0x59')]({'where':{'id':_0x2d0b0d[_0xf734('0x46')]['id']}})[_0xf734('0x24')](handleEntityNotFound(_0x31fb8a,null))[_0xf734('0x24')](function(_0x4deeb6){if(_0x4deeb6){_0x54131c['model']=_['keys'](db[_0xf734('0x5a')]['rawAttributes']);_0x54131c[_0xf734('0x33')]=_[_0xf734('0x34')](_0x2d0b0d[_0xf734('0x33')]);_0x54131c[_0xf734('0x35')]=_[_0xf734('0x37')](_0x54131c[_0xf734('0x36')],_0x54131c[_0xf734('0x33')]);_0x2e75a4[_0xf734('0x3a')]=_[_0xf734('0x37')](_0x54131c[_0xf734('0x36')],qs[_0xf734('0x38')](_0x2d0b0d['query'][_0xf734('0x38')]));_0x2e75a4[_0xf734('0x3a')]=_0x2e75a4[_0xf734('0x3a')]['length']?_0x2e75a4['attributes']:_0x54131c[_0xf734('0x36')];if(!_0x2d0b0d['query'][_0xf734('0x5b')](_0xf734('0x5c'))){_0x2e75a4[_0xf734('0x1d')]=qs['limit'](_0x2d0b0d['query'][_0xf734('0x1d')]);_0x2e75a4[_0xf734('0x1c')]=qs[_0xf734('0x1c')](_0x2d0b0d['query'][_0xf734('0x1c')]);}_0x2e75a4[_0xf734('0x3b')]=qs[_0xf734('0x3c')](_0x2d0b0d[_0xf734('0x33')][_0xf734('0x3c')]);_0x2e75a4[_0xf734('0x3d')]=qs[_0xf734('0x35')](_[_0xf734('0x3e')](_0x2d0b0d[_0xf734('0x33')],_0x54131c[_0xf734('0x35')]));_0x2e75a4['where'][_0xf734('0x5d')]=_0x4deeb6['id'];if(_0x2d0b0d['query'][_0xf734('0x3f')]){_0x2e75a4['where']=_[_0xf734('0x48')](_0x2e75a4['where'],{'$or':_[_0xf734('0x2e')](_0x2e75a4[_0xf734('0x3a')],function(_0x322786){var _0x449cc8={};_0x449cc8[_0x322786]={'$like':'%'+_0x2d0b0d[_0xf734('0x33')][_0xf734('0x3f')]+'%'};return _0x449cc8;})});}_0x2e75a4=_[_0xf734('0x48')]({},_0x2e75a4,_0x2d0b0d['options']);return db[_0xf734('0x5a')][_0xf734('0x1b')]({'where':_0x2e75a4['where']})['then'](function(_0x4a0a06){_0x1c4abe['count']=_0x4a0a06;if(_0x2d0b0d[_0xf734('0x33')]['includeAll']){_0x2e75a4[_0xf734('0x42')]=[{'all':!![]}];}return db[_0xf734('0x5a')][_0xf734('0x43')](_0x2e75a4);})[_0xf734('0x24')](function(_0x422892){_0x1c4abe[_0xf734('0x44')]=_0x422892;return _0x1c4abe;});}})[_0xf734('0x24')](respondWithFilteredResult(_0x31fb8a,_0x2e75a4))[_0xf734('0x45')](handleError(_0x31fb8a,null));};exports['getAnswers']=function(_0x44978b,_0x174a77,_0x20db95){var _0x2a3c71={'raw':!![],'where':{}};var _0x2f02fe={};var _0x3208d9={'count':0x0,'rows':[]};return db[_0xf734('0x2f')][_0xf734('0x59')]({'where':{'id':_0x44978b['params']['id']}})[_0xf734('0x24')](handleEntityNotFound(_0x174a77,null))[_0xf734('0x24')](function(_0x456b25){if(_0x456b25){_0x2f02fe['model']=_['keys'](db[_0xf734('0x5e')]['rawAttributes']);_0x2f02fe['query']=_[_0xf734('0x34')](_0x44978b['query']);_0x2f02fe[_0xf734('0x35')]=_[_0xf734('0x37')](_0x2f02fe[_0xf734('0x36')],_0x2f02fe[_0xf734('0x33')]);_0x2a3c71[_0xf734('0x3a')]=_[_0xf734('0x37')](_0x2f02fe[_0xf734('0x36')],qs[_0xf734('0x38')](_0x44978b[_0xf734('0x33')]['fields']));_0x2a3c71[_0xf734('0x3a')]=_0x2a3c71['attributes'][_0xf734('0x39')]?_0x2a3c71['attributes']:_0x2f02fe[_0xf734('0x36')];if(!_0x44978b[_0xf734('0x33')][_0xf734('0x5b')](_0xf734('0x5c'))){_0x2a3c71[_0xf734('0x1d')]=qs['limit'](_0x44978b[_0xf734('0x33')][_0xf734('0x1d')]);_0x2a3c71['offset']=qs[_0xf734('0x1c')](_0x44978b[_0xf734('0x33')]['offset']);}_0x2a3c71[_0xf734('0x3b')]=qs['sort'](_0x44978b[_0xf734('0x33')]['sort']);_0x2a3c71[_0xf734('0x3d')]=qs[_0xf734('0x35')](_[_0xf734('0x3e')](_0x44978b[_0xf734('0x33')],_0x2f02fe['filters']));_0x2a3c71[_0xf734('0x3d')]['ProjectId']=_0x456b25['id'];if(_0x44978b[_0xf734('0x33')]['filter']){_0x2a3c71[_0xf734('0x3d')]=_[_0xf734('0x48')](_0x2a3c71[_0xf734('0x3d')],{'$or':_['map'](_0x2a3c71['attributes'],function(_0x3a7307){var _0x4e5cf6={};_0x4e5cf6[_0x3a7307]={'$like':'%'+_0x44978b[_0xf734('0x33')][_0xf734('0x3f')]+'%'};return _0x4e5cf6;})});}_0x2a3c71=_['merge']({},_0x2a3c71,_0x44978b[_0xf734('0x41')]);return db[_0xf734('0x5e')][_0xf734('0x1b')]({'where':_0x2a3c71[_0xf734('0x3d')]})[_0xf734('0x24')](function(_0x1732a3){_0x3208d9['count']=_0x1732a3;if(_0x44978b[_0xf734('0x33')][_0xf734('0x47')]){_0x2a3c71[_0xf734('0x42')]=[{'all':!![]}];}return db['JscriptyAnswerReport'][_0xf734('0x43')](_0x2a3c71);})[_0xf734('0x24')](function(_0x442ebc){_0x3208d9[_0xf734('0x44')]=_0x442ebc;return _0x3208d9;});}})[_0xf734('0x24')](respondWithFilteredResult(_0x174a77,_0x2a3c71))[_0xf734('0x45')](handleError(_0x174a77,null));};function char(_0x4b3f94){return'number'===typeof _0x4b3f94?String[_0xf734('0x5f')][_0xf734('0x20')](null,arguments):_0x4b3f94;}function needsEncapsulation(_0x7efe05){return!!_0x7efe05&&(_0x7efe05[_0xf734('0x60')]()['indexOf'](char(0xd))>=0x0||_0x7efe05[_0xf734('0x60')]()[_0xf734('0x61')](char(0xa))>=0x0||_0x7efe05[_0xf734('0x60')]()[_0xf734('0x61')](char(0x2c))>=0x0||_0x7efe05[_0xf734('0x60')]()[_0xf734('0x61')](char(0x22))>=0x0);}function encapsulate(_0x25a9d7){var _0xa6ca21=char(0x22),_0x25c615='\x5c'+char(0x22),_0x1fdf6b=_0x25a9d7['toString']()[_0xf734('0x62')](new RegExp(_0xa6ca21,'g'),_0x25c615);return _0xa6ca21+_0x1fdf6b+_0xa6ca21;}exports[_0xf734('0x63')]=function(_0x543e74,_0x47ed84,_0x28ae03){var _0x5b83dc,_0x1b1887;var _0x569c1f={'where':{'ProjectId':_0x543e74[_0xf734('0x46')]['id']}};if(_0x543e74[_0xf734('0x33')][_0xf734('0x64')]){_0x569c1f[_0xf734('0x3d')]['starttime']=JSON[_0xf734('0x65')](_0x543e74['query'][_0xf734('0x64')]);}return db[_0xf734('0x5a')][_0xf734('0x43')](_0x569c1f)[_0xf734('0x24')](handleEntityNotFound(_0x47ed84,null))[_0xf734('0x24')](function(_0x5e1f17){if(_0x5e1f17){_0x5b83dc=_0x5e1f17;return db[_0xf734('0x66')][_0xf734('0x43')]({'where':{'SessionId':{'$in':_['map'](_0x5b83dc,'id')},'ProjectId':_0x543e74[_0xf734('0x46')]['id']},'order':'-createdAt'});}})[_0xf734('0x24')](handleEntityNotFound(_0x47ed84,null))[_0xf734('0x24')](function(_0x304be3){if(_0x304be3){_0x1b1887=_0x304be3;var _0x29ec3d={};for(var _0x30979b=0x0,_0x5b72ea=_0x1b1887[_0xf734('0x39')];_0x30979b<_0x5b72ea;_0x30979b++){if(!_0x29ec3d['hasOwnProperty'](_0x1b1887[_0x30979b]['questionId'])){_0x29ec3d[_0x1b1887[_0x30979b][_0xf734('0x67')]]=needsEncapsulation(_0x1b1887[_0x30979b][_0xf734('0x68')])?encapsulate(_0x1b1887[_0x30979b][_0xf734('0x68')]):_0x1b1887[_0x30979b]['question'];}}var _0x3f1771=[],_0x1f83fd={};for(var _0x1f9db1=0x0,_0x5d0f78=_0x5b83dc[_0xf734('0x39')];_0x1f9db1<_0x5d0f78;_0x1f9db1++){_0x1f83fd={'ProjectId':_0x543e74[_0xf734('0x46')]['id'],'SessionId':_0x5b83dc[_0x1f9db1]['id'],'StartTime':moment(_0x5b83dc[_0x1f9db1]['starttime'])['format']('YYYY-MM-DD\x20HH:mm:ss')};for(var _0x133e46=0x0,_0x8cb795=_0x1b1887[_0xf734('0x39')];_0x133e46<_0x8cb795;_0x133e46++){if(_0x1b1887[_0x133e46]['SessionId']==_0x5b83dc[_0x1f9db1]['id']&&_0x29ec3d[_0xf734('0x5b')](_0x1b1887[_0x133e46][_0xf734('0x67')])){_0x1f83fd[_0x29ec3d[_0x1b1887[_0x133e46]['questionId']]]=_0x1b1887[_0x133e46][_0xf734('0x69')];}}for(var _0x573f06 in _0x29ec3d){if(!_0x1f83fd[_0xf734('0x5b')](_0x29ec3d[_0x573f06])){_0x1f83fd[_0x29ec3d[_0x573f06]]=null;}}_0x3f1771[_0xf734('0x6a')](_0x1f83fd);}return _0x3f1771;}})[_0xf734('0x24')](function(_0x113136){if(!_['isEmpty'](_0x113136)){var _0xad6ca9=toCsv(_0x113136);var _0x2b0d64=Date[_0xf734('0x6b')]();fs['writeFileSync'](util[_0xf734('0x6c')]('/tmp/Jscripty_Project_%d_Summary_%s.csv',_0x543e74[_0xf734('0x46')]['id'],_0x2b0d64),_0xad6ca9);_0x47ed84['setHeader'](_0xf734('0x6d'),_0xf734('0x6e')+util[_0xf734('0x6c')]('Jscripty_Project_%d_Summary_%s.csv',_0x543e74[_0xf734('0x46')]['id'],_0x2b0d64));_0x47ed84[_0xf734('0x6f')](_0xf734('0x70'),_0xf734('0x71'));return _0x47ed84['download'](util[_0xf734('0x6c')]('/tmp/Jscripty_Project_%d_Summary_%s.csv',_0x543e74[_0xf734('0x46')]['id'],_0x2b0d64));}else{return _0x47ed84[_0xf734('0x28')](0xcc);}})['catch'](handleError(_0x47ed84,null));};