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 _0xf823=['lodash','squel','desk.js','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','api','../../config/utils','../../mysqldb','status','offset','set','Content-Range','json','apply','reject','save','update','then','destroy','get','Projects','UserProfileResource','end','sendStatus','error','name','send','map','JscriptyProject','rawAttributes','fieldName','type','key','query','intersection','attributes','model','fields','length','hasOwnProperty','nolimit','limit','order','sort','pick','filters','where','merge','VIRTUAL','filter','options','count','includeAll','include','findAll','params','keys','find','create','body','user','Unable\x20to\x20retrieve\x20the\x20current\x20user','role','UserProfileSection','autoAssociation','catch','Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s','omit','createdAt','updatedAt','userProfileId','getSessions','findOne','JscriptySessionReport','ProjectId','rows','JscriptyAnswerReport','number','fromCharCode','indexOf','toString','replace','getSummary','startTime','starttime','parse','JscriptyQuestionReport','-createdAt','questionId','question','answer','isEmpty','now','writeFileSync','format','Content-disposition','attachment;\x20filename=','Jscripty_Project_%d_Summary_%s.csv','Content-type','text/csv','download','/tmp/Jscripty_Project_%d_Summary_%s.csv','html-pdf','eml-format','rimraf','zip-dir','fast-json-patch','request-promise','moment','bluebird','mustache','util','path','sox','to-csv','ejs'];(function(_0x120283,_0x3fe3bf){var _0x37dfa3=function(_0x58ae25){while(--_0x58ae25){_0x120283['push'](_0x120283['shift']());}};_0x37dfa3(++_0x3fe3bf);}(_0xf823,0x1d2));var _0x3f82=function(_0x5c24e3,_0x995479){_0x5c24e3=_0x5c24e3-0x0;var _0x3322ee=_0xf823[_0x5c24e3];return _0x3322ee;};'use strict';var pdf=require(_0x3f82('0x0'));var emlformat=require(_0x3f82('0x1'));var rimraf=require(_0x3f82('0x2'));var zipdir=require(_0x3f82('0x3'));var jsonpatch=require(_0x3f82('0x4'));var rp=require(_0x3f82('0x5'));var moment=require(_0x3f82('0x6'));var BPromise=require(_0x3f82('0x7'));var Mustache=require(_0x3f82('0x8'));var util=require(_0x3f82('0x9'));var path=require(_0x3f82('0xa'));var sox=require(_0x3f82('0xb'));var csv=require(_0x3f82('0xc'));var ejs=require(_0x3f82('0xd'));var fs=require('fs');var _=require(_0x3f82('0xe'));var squel=require(_0x3f82('0xf'));var crypto=require('crypto');var jsforce=require('jsforce');var deskjs=require(_0x3f82('0x10'));var toCsv=require(_0x3f82('0xc'));var querystring=require('querystring');var Papa=require('papaparse');var Redis=require(_0x3f82('0x11'));var authService=require(_0x3f82('0x12'));var qs=require(_0x3f82('0x13'));var as=require(_0x3f82('0x14'));var hardwareService=require(_0x3f82('0x15'));var logger=require(_0x3f82('0x16'))(_0x3f82('0x17'));var utils=require(_0x3f82('0x18'));var config=require('../../config/environment');var db=require(_0x3f82('0x19'))['db'];function respondWithStatusCode(_0xf10c21,_0x1732c7){_0x1732c7=_0x1732c7||0xcc;return function(_0x53a886){if(_0x53a886){return _0xf10c21['sendStatus'](_0x1732c7);}return _0xf10c21['status'](_0x1732c7)['end']();};}function respondWithResult(_0x42d6d3,_0x56e59a){_0x56e59a=_0x56e59a||0xc8;return function(_0x3da05d){if(_0x3da05d){return _0x42d6d3[_0x3f82('0x1a')](_0x56e59a)['json'](_0x3da05d);}};}function respondWithFilteredResult(_0x3fda48,_0x111f3e){return function(_0x3f42a0){if(_0x3f42a0){var _0x40e974=_0x3f42a0['count'],_0x25f2f6=_0x111f3e[_0x3f82('0x1b')],_0x1d7a39=_0x111f3e[_0x3f82('0x1b')]+_0x111f3e['limit'],_0x2c752d;if(_0x1d7a39>=_0x40e974){_0x1d7a39=_0x40e974;_0x2c752d=0xc8;}else{_0x2c752d=0xce;}_0x3fda48['status'](_0x2c752d);return _0x3fda48[_0x3f82('0x1c')](_0x3f82('0x1d'),_0x25f2f6+'-'+_0x1d7a39+'/'+_0x40e974)[_0x3f82('0x1e')](_0x3f42a0);}return null;};}function patchUpdates(_0x55a3d5){return function(_0x7f6c02){try{jsonpatch[_0x3f82('0x1f')](_0x7f6c02,_0x55a3d5,!![]);}catch(_0x36a74a){return BPromise[_0x3f82('0x20')](_0x36a74a);}return _0x7f6c02[_0x3f82('0x21')]();};}function saveUpdates(_0x5677b4,_0x2ea29b){return function(_0x541328){if(_0x541328){return _0x541328[_0x3f82('0x22')](_0x5677b4)[_0x3f82('0x23')](function(_0x86cc7c){return _0x86cc7c;});}return null;};}function removeEntity(_0xc00057,_0x28bfef){return function(_0x259185){if(_0x259185){return _0x259185[_0x3f82('0x24')]()['then'](function(){var _0x52ef55=_0x259185[_0x3f82('0x25')]({'plain':!![]});var _0x192eed=_0x3f82('0x26');return db[_0x3f82('0x27')][_0x3f82('0x24')]({'where':{'type':_0x192eed,'resourceId':_0x52ef55['id']}})[_0x3f82('0x23')](function(){return _0x259185;});})['then'](function(){_0xc00057[_0x3f82('0x1a')](0xcc)[_0x3f82('0x28')]();});}};}function handleEntityNotFound(_0x46734e,_0xbff944){return function(_0x3e5a79){if(!_0x3e5a79){_0x46734e[_0x3f82('0x29')](0x194);}return _0x3e5a79;};}function handleError(_0x38baa6,_0x529861){_0x529861=_0x529861||0x1f4;return function(_0x504a7d){logger[_0x3f82('0x2a')](_0x504a7d['stack']);if(_0x504a7d[_0x3f82('0x2b')]){delete _0x504a7d[_0x3f82('0x2b')];}_0x38baa6[_0x3f82('0x1a')](_0x529861)[_0x3f82('0x2c')](_0x504a7d);};}exports['index']=function(_0x29ac84,_0x39401c){var _0x265160={},_0x53d204={},_0xdf43db={'count':0x0,'rows':[]};var _0x2ffe48=_[_0x3f82('0x2d')](db[_0x3f82('0x2e')][_0x3f82('0x2f')],function(_0x9bb142){return{'name':_0x9bb142[_0x3f82('0x30')],'type':_0x9bb142[_0x3f82('0x31')][_0x3f82('0x32')]};});_0x53d204['model']=_[_0x3f82('0x2d')](_0x2ffe48,_0x3f82('0x2b'));_0x53d204['query']=_['keys'](_0x29ac84[_0x3f82('0x33')]);_0x53d204['filters']=_[_0x3f82('0x34')](_0x53d204['model'],_0x53d204['query']);_0x265160[_0x3f82('0x35')]=_['intersection'](_0x53d204[_0x3f82('0x36')],qs['fields'](_0x29ac84[_0x3f82('0x33')][_0x3f82('0x37')]));_0x265160[_0x3f82('0x35')]=_0x265160['attributes'][_0x3f82('0x38')]?_0x265160[_0x3f82('0x35')]:_0x53d204[_0x3f82('0x36')];if(!_0x29ac84[_0x3f82('0x33')][_0x3f82('0x39')](_0x3f82('0x3a'))){_0x265160[_0x3f82('0x3b')]=qs[_0x3f82('0x3b')](_0x29ac84[_0x3f82('0x33')][_0x3f82('0x3b')]);_0x265160['offset']=qs[_0x3f82('0x1b')](_0x29ac84[_0x3f82('0x33')][_0x3f82('0x1b')]);}_0x265160[_0x3f82('0x3c')]=qs[_0x3f82('0x3d')](_0x29ac84[_0x3f82('0x33')][_0x3f82('0x3d')]);_0x265160['where']=qs['filters'](_[_0x3f82('0x3e')](_0x29ac84[_0x3f82('0x33')],_0x53d204[_0x3f82('0x3f')]),_0x2ffe48);if(_0x29ac84[_0x3f82('0x33')]['filter']){_0x265160[_0x3f82('0x40')]=_[_0x3f82('0x41')](_0x265160[_0x3f82('0x40')],{'$or':_['map'](_0x2ffe48,function(_0x542555){if(_0x542555[_0x3f82('0x31')]!==_0x3f82('0x42')){var _0xd0f7ed={};_0xd0f7ed[_0x542555['name']]={'$like':'%'+_0x29ac84['query'][_0x3f82('0x43')]+'%'};return _0xd0f7ed;}})});}_0x265160=_[_0x3f82('0x41')]({},_0x265160,_0x29ac84[_0x3f82('0x44')]);var _0x34ad5b={'where':_0x265160['where']};return db[_0x3f82('0x2e')][_0x3f82('0x45')](_0x34ad5b)[_0x3f82('0x23')](function(_0x7a9ccd){_0xdf43db[_0x3f82('0x45')]=_0x7a9ccd;if(_0x29ac84[_0x3f82('0x33')][_0x3f82('0x46')]){_0x265160[_0x3f82('0x47')]=[{'all':!![]}];}return db[_0x3f82('0x2e')][_0x3f82('0x48')](_0x265160);})[_0x3f82('0x23')](function(_0x4bb6cc){_0xdf43db['rows']=_0x4bb6cc;return _0xdf43db;})[_0x3f82('0x23')](respondWithFilteredResult(_0x39401c,_0x265160))['catch'](handleError(_0x39401c,null));};exports['show']=function(_0x170e47,_0x587de7){var _0x2732c7={'raw':![],'where':{'id':_0x170e47[_0x3f82('0x49')]['id']}},_0x354241={};_0x354241['model']=_[_0x3f82('0x4a')](db['JscriptyProject'][_0x3f82('0x2f')]);_0x354241['query']=_[_0x3f82('0x4a')](_0x170e47[_0x3f82('0x33')]);_0x354241['filters']=_[_0x3f82('0x34')](_0x354241['model'],_0x354241['query']);_0x2732c7[_0x3f82('0x35')]=_[_0x3f82('0x34')](_0x354241[_0x3f82('0x36')],qs[_0x3f82('0x37')](_0x170e47['query'][_0x3f82('0x37')]));_0x2732c7[_0x3f82('0x35')]=_0x2732c7[_0x3f82('0x35')]['length']?_0x2732c7[_0x3f82('0x35')]:_0x354241[_0x3f82('0x36')];if(_0x170e47[_0x3f82('0x33')]['includeAll']){_0x2732c7['include']=[{'all':!![]}];}_0x2732c7=_[_0x3f82('0x41')]({},_0x2732c7,_0x170e47[_0x3f82('0x44')]);return db['JscriptyProject'][_0x3f82('0x4b')](_0x2732c7)['then'](handleEntityNotFound(_0x587de7,null))['then'](respondWithResult(_0x587de7,null))['catch'](handleError(_0x587de7,null));};exports['create']=function(_0x2b22c2,_0x1e4de1){return db[_0x3f82('0x2e')][_0x3f82('0x4c')](_0x2b22c2[_0x3f82('0x4d')],{})[_0x3f82('0x23')](function(_0x4ea230){var _0x23933f=_0x2b22c2[_0x3f82('0x4e')][_0x3f82('0x25')]({'plain':!![]});if(!_0x23933f)throw new Error(_0x3f82('0x4f'));if(_0x23933f[_0x3f82('0x50')]===_0x3f82('0x4e')){var _0x15814e=_0x4ea230[_0x3f82('0x25')]({'plain':!![]});var _0x433cda='Projects';return db[_0x3f82('0x51')][_0x3f82('0x4b')]({'where':{'name':_0x433cda,'userProfileId':_0x23933f['userProfileId']},'raw':!![]})[_0x3f82('0x23')](function(_0x47a475){if(_0x47a475&&_0x47a475[_0x3f82('0x52')]===0x0){return db[_0x3f82('0x27')][_0x3f82('0x4c')]({'name':_0x15814e[_0x3f82('0x2b')],'resourceId':_0x15814e['id'],'type':_0x47a475['name'],'sectionId':_0x47a475['id']},{})[_0x3f82('0x23')](function(){return _0x4ea230;});}else{return _0x4ea230;}})[_0x3f82('0x53')](function(_0x470ce1){logger[_0x3f82('0x2a')](_0x3f82('0x54'),_0x470ce1);throw _0x470ce1;});}return _0x4ea230;})[_0x3f82('0x23')](respondWithResult(_0x1e4de1,0xc9))[_0x3f82('0x53')](handleError(_0x1e4de1,null));};exports['clone']=function(_0x50c0b3,_0x2003fa){var _0x2ed813={'where':{'id':_0x50c0b3[_0x3f82('0x49')]['id']}},_0x13f29e={};_0x13f29e[_0x3f82('0x36')]=_[_0x3f82('0x4a')](db['JscriptyProject'][_0x3f82('0x2f')]);_0x2ed813[_0x3f82('0x35')]=_['intersection'](_0x13f29e['model'],qs[_0x3f82('0x37')](_0x50c0b3['query'][_0x3f82('0x37')]));_0x2ed813['attributes']=_0x2ed813['attributes'][_0x3f82('0x38')]?_0x2ed813['attributes']:_0x13f29e[_0x3f82('0x36')];if(_0x50c0b3[_0x3f82('0x33')][_0x3f82('0x46')]){_0x2ed813[_0x3f82('0x47')]=[{'all':!![]}];}_0x2ed813=_['merge']({},_0x2ed813,_0x50c0b3[_0x3f82('0x44')]);return db['JscriptyProject'][_0x3f82('0x4b')](_0x2ed813)['then'](handleEntityNotFound(_0x2003fa,null))[_0x3f82('0x23')](function(_0x2da582){if(_0x2da582){var _0x219e24=_0x2da582[_0x3f82('0x25')]({'plain':!![]});_0x219e24=qs[_0x3f82('0x55')](_0x219e24,['id','createdAt','updatedAt']);_0x50c0b3['body']=_[_0x3f82('0x55')](_0x50c0b3[_0x3f82('0x4d')],['id',_0x3f82('0x56'),_0x3f82('0x57')]);return db['JscriptyProject'][_0x3f82('0x4c')](_[_0x3f82('0x41')](_0x219e24,_0x50c0b3[_0x3f82('0x4d')]),{'include':_0x50c0b3[_0x3f82('0x33')][_0x3f82('0x46')]?[{'all':!![]}]:undefined})['then'](function(_0x44424a){var _0x10abad=_0x50c0b3[_0x3f82('0x4e')][_0x3f82('0x25')]({'plain':!![]});if(!_0x10abad)throw new Error(_0x3f82('0x4f'));if(_0x10abad['role']==='user'){var _0x5cdda3=_0x44424a[_0x3f82('0x25')]({'plain':!![]});var _0x5bfb20=_0x3f82('0x26');return db[_0x3f82('0x51')][_0x3f82('0x4b')]({'where':{'name':_0x5bfb20,'userProfileId':_0x10abad[_0x3f82('0x58')]},'raw':!![]})[_0x3f82('0x23')](function(_0x3821cf){if(_0x3821cf&&_0x3821cf[_0x3f82('0x52')]===0x0){return db[_0x3f82('0x27')]['create']({'name':_0x5cdda3[_0x3f82('0x2b')],'resourceId':_0x5cdda3['id'],'type':_0x3821cf[_0x3f82('0x2b')],'sectionId':_0x3821cf['id']},{})[_0x3f82('0x23')](function(){return _0x44424a;});}else{return _0x44424a;}})[_0x3f82('0x53')](function(_0x38c91a){logger[_0x3f82('0x2a')]('Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s',_0x38c91a);throw _0x38c91a;});}return _0x44424a;});}})[_0x3f82('0x23')](respondWithResult(_0x2003fa,0xc9))[_0x3f82('0x53')](handleError(_0x2003fa,null));};exports[_0x3f82('0x22')]=function(_0x6cf6eb,_0x27ffe0){if(_0x6cf6eb['body']['id']){delete _0x6cf6eb['body']['id'];}return db[_0x3f82('0x2e')][_0x3f82('0x4b')]({'where':{'id':_0x6cf6eb[_0x3f82('0x49')]['id']}})['then'](handleEntityNotFound(_0x27ffe0,null))[_0x3f82('0x23')](saveUpdates(_0x6cf6eb[_0x3f82('0x4d')],null))['then'](respondWithResult(_0x27ffe0,null))['catch'](handleError(_0x27ffe0,null));};exports[_0x3f82('0x24')]=function(_0x31ee54,_0x453a82){return db['JscriptyProject']['find']({'where':{'id':_0x31ee54[_0x3f82('0x49')]['id']}})[_0x3f82('0x23')](handleEntityNotFound(_0x453a82,null))[_0x3f82('0x23')](removeEntity(_0x453a82,null))[_0x3f82('0x53')](handleError(_0x453a82,null));};exports[_0x3f82('0x59')]=function(_0x2387b3,_0x1e9074,_0x22550d){var _0x17db28={'raw':!![],'where':{}};var _0x5c6cc4={};var _0x269ed9={'count':0x0,'rows':[]};return db[_0x3f82('0x2e')][_0x3f82('0x5a')]({'where':{'id':_0x2387b3[_0x3f82('0x49')]['id']}})['then'](handleEntityNotFound(_0x1e9074,null))[_0x3f82('0x23')](function(_0x48c3c8){if(_0x48c3c8){_0x5c6cc4[_0x3f82('0x36')]=_[_0x3f82('0x4a')](db[_0x3f82('0x5b')][_0x3f82('0x2f')]);_0x5c6cc4[_0x3f82('0x33')]=_[_0x3f82('0x4a')](_0x2387b3[_0x3f82('0x33')]);_0x5c6cc4[_0x3f82('0x3f')]=_[_0x3f82('0x34')](_0x5c6cc4[_0x3f82('0x36')],_0x5c6cc4['query']);_0x17db28[_0x3f82('0x35')]=_[_0x3f82('0x34')](_0x5c6cc4[_0x3f82('0x36')],qs[_0x3f82('0x37')](_0x2387b3['query']['fields']));_0x17db28[_0x3f82('0x35')]=_0x17db28['attributes'][_0x3f82('0x38')]?_0x17db28[_0x3f82('0x35')]:_0x5c6cc4[_0x3f82('0x36')];if(!_0x2387b3[_0x3f82('0x33')][_0x3f82('0x39')](_0x3f82('0x3a'))){_0x17db28['limit']=qs['limit'](_0x2387b3[_0x3f82('0x33')][_0x3f82('0x3b')]);_0x17db28['offset']=qs[_0x3f82('0x1b')](_0x2387b3[_0x3f82('0x33')][_0x3f82('0x1b')]);}_0x17db28[_0x3f82('0x3c')]=qs[_0x3f82('0x3d')](_0x2387b3[_0x3f82('0x33')]['sort']);_0x17db28[_0x3f82('0x40')]=qs[_0x3f82('0x3f')](_['pick'](_0x2387b3[_0x3f82('0x33')],_0x5c6cc4[_0x3f82('0x3f')]));_0x17db28[_0x3f82('0x40')][_0x3f82('0x5c')]=_0x48c3c8['id'];if(_0x2387b3[_0x3f82('0x33')][_0x3f82('0x43')]){_0x17db28['where']=_[_0x3f82('0x41')](_0x17db28['where'],{'$or':_[_0x3f82('0x2d')](_0x17db28['attributes'],function(_0x10b16b){var _0x3d2fbf={};_0x3d2fbf[_0x10b16b]={'$like':'%'+_0x2387b3[_0x3f82('0x33')][_0x3f82('0x43')]+'%'};return _0x3d2fbf;})});}_0x17db28=_[_0x3f82('0x41')]({},_0x17db28,_0x2387b3[_0x3f82('0x44')]);return db[_0x3f82('0x5b')]['count']({'where':_0x17db28[_0x3f82('0x40')]})['then'](function(_0x3ccc61){_0x269ed9['count']=_0x3ccc61;if(_0x2387b3['query'][_0x3f82('0x46')]){_0x17db28[_0x3f82('0x47')]=[{'all':!![]}];}return db[_0x3f82('0x5b')][_0x3f82('0x48')](_0x17db28);})[_0x3f82('0x23')](function(_0x2f9fb4){_0x269ed9[_0x3f82('0x5d')]=_0x2f9fb4;return _0x269ed9;});}})['then'](respondWithFilteredResult(_0x1e9074,_0x17db28))[_0x3f82('0x53')](handleError(_0x1e9074,null));};exports['getAnswers']=function(_0x23dbd9,_0x3b9af5,_0x1b268a){var _0x23453b={'raw':!![],'where':{}};var _0x5c753b={};var _0x585db={'count':0x0,'rows':[]};return db[_0x3f82('0x2e')]['findOne']({'where':{'id':_0x23dbd9[_0x3f82('0x49')]['id']}})['then'](handleEntityNotFound(_0x3b9af5,null))['then'](function(_0x475cc9){if(_0x475cc9){_0x5c753b['model']=_['keys'](db[_0x3f82('0x5e')][_0x3f82('0x2f')]);_0x5c753b[_0x3f82('0x33')]=_[_0x3f82('0x4a')](_0x23dbd9[_0x3f82('0x33')]);_0x5c753b['filters']=_[_0x3f82('0x34')](_0x5c753b[_0x3f82('0x36')],_0x5c753b[_0x3f82('0x33')]);_0x23453b['attributes']=_[_0x3f82('0x34')](_0x5c753b[_0x3f82('0x36')],qs['fields'](_0x23dbd9[_0x3f82('0x33')][_0x3f82('0x37')]));_0x23453b[_0x3f82('0x35')]=_0x23453b['attributes']['length']?_0x23453b['attributes']:_0x5c753b[_0x3f82('0x36')];if(!_0x23dbd9[_0x3f82('0x33')]['hasOwnProperty'](_0x3f82('0x3a'))){_0x23453b['limit']=qs[_0x3f82('0x3b')](_0x23dbd9[_0x3f82('0x33')][_0x3f82('0x3b')]);_0x23453b[_0x3f82('0x1b')]=qs[_0x3f82('0x1b')](_0x23dbd9[_0x3f82('0x33')][_0x3f82('0x1b')]);}_0x23453b[_0x3f82('0x3c')]=qs[_0x3f82('0x3d')](_0x23dbd9[_0x3f82('0x33')][_0x3f82('0x3d')]);_0x23453b[_0x3f82('0x40')]=qs[_0x3f82('0x3f')](_['pick'](_0x23dbd9[_0x3f82('0x33')],_0x5c753b[_0x3f82('0x3f')]));_0x23453b[_0x3f82('0x40')][_0x3f82('0x5c')]=_0x475cc9['id'];if(_0x23dbd9[_0x3f82('0x33')]['filter']){_0x23453b[_0x3f82('0x40')]=_[_0x3f82('0x41')](_0x23453b['where'],{'$or':_[_0x3f82('0x2d')](_0x23453b['attributes'],function(_0x3e8241){var _0x591faf={};_0x591faf[_0x3e8241]={'$like':'%'+_0x23dbd9[_0x3f82('0x33')]['filter']+'%'};return _0x591faf;})});}_0x23453b=_[_0x3f82('0x41')]({},_0x23453b,_0x23dbd9[_0x3f82('0x44')]);return db['JscriptyAnswerReport'][_0x3f82('0x45')]({'where':_0x23453b['where']})['then'](function(_0x5413e8){_0x585db[_0x3f82('0x45')]=_0x5413e8;if(_0x23dbd9[_0x3f82('0x33')]['includeAll']){_0x23453b[_0x3f82('0x47')]=[{'all':!![]}];}return db['JscriptyAnswerReport'][_0x3f82('0x48')](_0x23453b);})['then'](function(_0x54a8de){_0x585db[_0x3f82('0x5d')]=_0x54a8de;return _0x585db;});}})[_0x3f82('0x23')](respondWithFilteredResult(_0x3b9af5,_0x23453b))['catch'](handleError(_0x3b9af5,null));};function char(_0x2a53b8){return _0x3f82('0x5f')===typeof _0x2a53b8?String[_0x3f82('0x60')][_0x3f82('0x1f')](null,arguments):_0x2a53b8;}function needsEncapsulation(_0x17c76d){return!!_0x17c76d&&(_0x17c76d['toString']()[_0x3f82('0x61')](char(0xd))>=0x0||_0x17c76d[_0x3f82('0x62')]()['indexOf'](char(0xa))>=0x0||_0x17c76d[_0x3f82('0x62')]()[_0x3f82('0x61')](char(0x2c))>=0x0||_0x17c76d['toString']()[_0x3f82('0x61')](char(0x22))>=0x0);}function encapsulate(_0xd57c4a){var _0x5c54e0=char(0x22),_0x41794d='\x5c'+char(0x22),_0x45a5dc=_0xd57c4a[_0x3f82('0x62')]()[_0x3f82('0x63')](new RegExp(_0x5c54e0,'g'),_0x41794d);return _0x5c54e0+_0x45a5dc+_0x5c54e0;}exports[_0x3f82('0x64')]=function(_0x34a9f2,_0x42a46d,_0x30c37a){var _0x1663de,_0x2d87d1;var _0x1ad01e={'where':{'ProjectId':_0x34a9f2[_0x3f82('0x49')]['id']}};if(_0x34a9f2[_0x3f82('0x33')][_0x3f82('0x65')]){_0x1ad01e['where'][_0x3f82('0x66')]=JSON[_0x3f82('0x67')](_0x34a9f2['query'][_0x3f82('0x65')]);}return db[_0x3f82('0x5b')][_0x3f82('0x48')](_0x1ad01e)[_0x3f82('0x23')](handleEntityNotFound(_0x42a46d,null))['then'](function(_0x83f5bf){if(_0x83f5bf){_0x1663de=_0x83f5bf;return db[_0x3f82('0x68')][_0x3f82('0x48')]({'where':{'SessionId':{'$in':_[_0x3f82('0x2d')](_0x1663de,'id')},'ProjectId':_0x34a9f2[_0x3f82('0x49')]['id']},'order':_0x3f82('0x69')});}})[_0x3f82('0x23')](handleEntityNotFound(_0x42a46d,null))['then'](function(_0x501419){if(_0x501419){_0x2d87d1=_0x501419;var _0x2f645b={};for(var _0x100c61=0x0,_0x39436a=_0x2d87d1[_0x3f82('0x38')];_0x100c61<_0x39436a;_0x100c61++){if(!_0x2f645b[_0x3f82('0x39')](_0x2d87d1[_0x100c61]['questionId'])){_0x2f645b[_0x2d87d1[_0x100c61][_0x3f82('0x6a')]]=needsEncapsulation(_0x2d87d1[_0x100c61][_0x3f82('0x6b')])?encapsulate(_0x2d87d1[_0x100c61][_0x3f82('0x6b')]):_0x2d87d1[_0x100c61]['question'];}}var _0x4200f8=[],_0x3916db={};for(var _0x43bea9=0x0,_0xb8ba27=_0x1663de[_0x3f82('0x38')];_0x43bea9<_0xb8ba27;_0x43bea9++){_0x3916db={'ProjectId':_0x34a9f2[_0x3f82('0x49')]['id'],'SessionId':_0x1663de[_0x43bea9]['id'],'StartTime':moment(_0x1663de[_0x43bea9][_0x3f82('0x66')])['format']('YYYY-MM-DD\x20HH:mm:ss')};for(var _0x32cd24=0x0,_0x2aaccc=_0x2d87d1[_0x3f82('0x38')];_0x32cd24<_0x2aaccc;_0x32cd24++){if(_0x2d87d1[_0x32cd24]['SessionId']==_0x1663de[_0x43bea9]['id']&&_0x2f645b[_0x3f82('0x39')](_0x2d87d1[_0x32cd24][_0x3f82('0x6a')])){_0x3916db[_0x2f645b[_0x2d87d1[_0x32cd24][_0x3f82('0x6a')]]]=_0x2d87d1[_0x32cd24][_0x3f82('0x6c')];}}for(var _0x1d928d in _0x2f645b){if(!_0x3916db[_0x3f82('0x39')](_0x2f645b[_0x1d928d])){_0x3916db[_0x2f645b[_0x1d928d]]=null;}}_0x4200f8['push'](_0x3916db);}return _0x4200f8;}})[_0x3f82('0x23')](function(_0x26dd46){if(!_[_0x3f82('0x6d')](_0x26dd46)){var _0x3f46e0=toCsv(_0x26dd46);var _0x435c79=Date[_0x3f82('0x6e')]();fs[_0x3f82('0x6f')](util[_0x3f82('0x70')]('/tmp/Jscripty_Project_%d_Summary_%s.csv',_0x34a9f2[_0x3f82('0x49')]['id'],_0x435c79),_0x3f46e0);_0x42a46d['setHeader'](_0x3f82('0x71'),_0x3f82('0x72')+util[_0x3f82('0x70')](_0x3f82('0x73'),_0x34a9f2[_0x3f82('0x49')]['id'],_0x435c79));_0x42a46d['setHeader'](_0x3f82('0x74'),_0x3f82('0x75'));return _0x42a46d[_0x3f82('0x76')](util[_0x3f82('0x70')](_0x3f82('0x77'),_0x34a9f2[_0x3f82('0x49')]['id'],_0x435c79));}else{return _0x42a46d['sendStatus'](0xcc);}})[_0x3f82('0x53')](handleError(_0x42a46d,null));};