9b9aa1095fcc4927ee6d2c66b64d1fb450aeb86f
[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 _0xcd4d=['../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','../../config/utils','../../config/environment','../../config/license/util','../../mysqldb','sendStatus','end','status','json','offset','undefined','limit','count','set','Content-Range','apply','reject','update','then','destroy','get','Projects','UserProfileResource','name','send','map','JscriptyProject','rawAttributes','fieldName','key','model','query','filters','intersection','attributes','fields','length','nolimit','where','pick','filter','type','VIRTUAL','merge','options','includeAll','include','catch','show','params','keys','find','create','body','Unable\x20to\x20retrieve\x20the\x20current\x20user','UserProfileSection','userProfileId','autoAssociation','error','Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s','clone','omit','createdAt','updatedAt','user','getSessions','findOne','JscriptySessionReport','hasOwnProperty','order','sort','findAll','rows','getAnswers','ProjectId','JscriptyAnswerReport','number','fromCharCode','toString','indexOf','getSummary','startTime','starttime','parse','-createdAt','questionId','question','SessionId','answer','push','isEmpty','now','writeFileSync','/tmp/Jscripty_Project_%d_Summary_%s.csv','setHeader','Content-disposition','attachment;\x20filename=','format','Content-type','text/csv','eml-format','rimraf','fast-json-patch','request-promise','moment','bluebird','mustache','util','path','sox','to-csv','ejs','fs-extra','lodash','squel','crypto','jsforce','desk.js','querystring','papaparse'];(function(_0x189166,_0x3d84a9){var _0x166a69=function(_0xf7a045){while(--_0xf7a045){_0x189166['push'](_0x189166['shift']());}};_0x166a69(++_0x3d84a9);}(_0xcd4d,0xe4));var _0xdcd4=function(_0x276eb0,_0x2a4953){_0x276eb0=_0x276eb0-0x0;var _0x5d9833=_0xcd4d[_0x276eb0];return _0x5d9833;};'use strict';var emlformat=require(_0xdcd4('0x0'));var rimraf=require(_0xdcd4('0x1'));var zipdir=require('zip-dir');var jsonpatch=require(_0xdcd4('0x2'));var rp=require(_0xdcd4('0x3'));var moment=require(_0xdcd4('0x4'));var BPromise=require(_0xdcd4('0x5'));var Mustache=require(_0xdcd4('0x6'));var util=require(_0xdcd4('0x7'));var path=require(_0xdcd4('0x8'));var sox=require(_0xdcd4('0x9'));var csv=require(_0xdcd4('0xa'));var ejs=require(_0xdcd4('0xb'));var fs=require('fs');var fs_extra=require(_0xdcd4('0xc'));var _=require(_0xdcd4('0xd'));var squel=require(_0xdcd4('0xe'));var crypto=require(_0xdcd4('0xf'));var jsforce=require(_0xdcd4('0x10'));var deskjs=require(_0xdcd4('0x11'));var toCsv=require('to-csv');var querystring=require(_0xdcd4('0x12'));var Papa=require(_0xdcd4('0x13'));var Redis=require('ioredis');var authService=require(_0xdcd4('0x14'));var qs=require(_0xdcd4('0x15'));var as=require(_0xdcd4('0x16'));var hardwareService=require(_0xdcd4('0x17'));var logger=require(_0xdcd4('0x18'))('api');var utils=require(_0xdcd4('0x19'));var config=require(_0xdcd4('0x1a'));var licenseUtil=require(_0xdcd4('0x1b'));var db=require(_0xdcd4('0x1c'))['db'];function respondWithStatusCode(_0x2bf080,_0x553279){_0x553279=_0x553279||0xcc;return function(_0x12af2b){if(_0x12af2b){return _0x2bf080[_0xdcd4('0x1d')](_0x553279);}return _0x2bf080['status'](_0x553279)[_0xdcd4('0x1e')]();};}function respondWithResult(_0x16f7e5,_0x4aa877){_0x4aa877=_0x4aa877||0xc8;return function(_0x49f85e){if(_0x49f85e){return _0x16f7e5[_0xdcd4('0x1f')](_0x4aa877)[_0xdcd4('0x20')](_0x49f85e);}};}function respondWithFilteredResult(_0x282a21,_0x26b226){return function(_0x280598){if(_0x280598){var _0x3a1d3a=typeof _0x26b226[_0xdcd4('0x21')]===_0xdcd4('0x22')&&typeof _0x26b226[_0xdcd4('0x23')]===_0xdcd4('0x22');var _0xdb8b41=_0x280598['count'];var _0x579125=_0x3a1d3a?0x0:_0x26b226[_0xdcd4('0x21')];var _0x7682f8=_0x3a1d3a?_0x280598[_0xdcd4('0x24')]:_0x26b226[_0xdcd4('0x21')]+_0x26b226[_0xdcd4('0x23')];var _0x2433f0;if(_0x7682f8>=_0xdb8b41){_0x7682f8=_0xdb8b41;_0x2433f0=0xc8;}else{_0x2433f0=0xce;}_0x282a21[_0xdcd4('0x1f')](_0x2433f0);return _0x282a21[_0xdcd4('0x25')](_0xdcd4('0x26'),_0x579125+'-'+_0x7682f8+'/'+_0xdb8b41)[_0xdcd4('0x20')](_0x280598);}return null;};}function patchUpdates(_0x28bec2){return function(_0x2864c9){try{jsonpatch[_0xdcd4('0x27')](_0x2864c9,_0x28bec2,!![]);}catch(_0x196619){return BPromise[_0xdcd4('0x28')](_0x196619);}return _0x2864c9['save']();};}function saveUpdates(_0x21a330,_0xb4414e){return function(_0x520bb7){if(_0x520bb7){return _0x520bb7[_0xdcd4('0x29')](_0x21a330)[_0xdcd4('0x2a')](function(_0x17faa9){return _0x17faa9;});}return null;};}function removeEntity(_0x4d1e32,_0x46768f){return function(_0x427c92){if(_0x427c92){return _0x427c92[_0xdcd4('0x2b')]()['then'](function(){var _0x44dc04=_0x427c92[_0xdcd4('0x2c')]({'plain':!![]});var _0x48b046=_0xdcd4('0x2d');return db[_0xdcd4('0x2e')][_0xdcd4('0x2b')]({'where':{'type':_0x48b046,'resourceId':_0x44dc04['id']}})[_0xdcd4('0x2a')](function(){return _0x427c92;});})[_0xdcd4('0x2a')](function(){_0x4d1e32[_0xdcd4('0x1f')](0xcc)[_0xdcd4('0x1e')]();});}};}function handleEntityNotFound(_0xc9e4d4,_0x48dec1){return function(_0x134c00){if(!_0x134c00){_0xc9e4d4['sendStatus'](0x194);}return _0x134c00;};}function handleError(_0x114e94,_0x3d29d7){_0x3d29d7=_0x3d29d7||0x1f4;return function(_0x5b9f9d){logger['error'](_0x5b9f9d['stack']);if(_0x5b9f9d['name']){delete _0x5b9f9d[_0xdcd4('0x2f')];}_0x114e94[_0xdcd4('0x1f')](_0x3d29d7)[_0xdcd4('0x30')](_0x5b9f9d);};}exports['index']=function(_0x239479,_0x1d0937){var _0x565e9e={},_0x35d1e3={},_0x2e11d6={'count':0x0,'rows':[]};var _0x21aaaf=_[_0xdcd4('0x31')](db[_0xdcd4('0x32')][_0xdcd4('0x33')],function(_0x4a6a1f){return{'name':_0x4a6a1f[_0xdcd4('0x34')],'type':_0x4a6a1f['type'][_0xdcd4('0x35')]};});_0x35d1e3[_0xdcd4('0x36')]=_[_0xdcd4('0x31')](_0x21aaaf,_0xdcd4('0x2f'));_0x35d1e3[_0xdcd4('0x37')]=_['keys'](_0x239479['query']);_0x35d1e3[_0xdcd4('0x38')]=_[_0xdcd4('0x39')](_0x35d1e3[_0xdcd4('0x36')],_0x35d1e3['query']);_0x565e9e[_0xdcd4('0x3a')]=_[_0xdcd4('0x39')](_0x35d1e3['model'],qs['fields'](_0x239479[_0xdcd4('0x37')][_0xdcd4('0x3b')]));_0x565e9e[_0xdcd4('0x3a')]=_0x565e9e[_0xdcd4('0x3a')][_0xdcd4('0x3c')]?_0x565e9e[_0xdcd4('0x3a')]:_0x35d1e3['model'];if(!_0x239479[_0xdcd4('0x37')]['hasOwnProperty'](_0xdcd4('0x3d'))){_0x565e9e[_0xdcd4('0x23')]=qs[_0xdcd4('0x23')](_0x239479['query'][_0xdcd4('0x23')]);_0x565e9e[_0xdcd4('0x21')]=qs[_0xdcd4('0x21')](_0x239479[_0xdcd4('0x37')]['offset']);}_0x565e9e['order']=qs['sort'](_0x239479[_0xdcd4('0x37')]['sort']);_0x565e9e[_0xdcd4('0x3e')]=qs[_0xdcd4('0x38')](_[_0xdcd4('0x3f')](_0x239479[_0xdcd4('0x37')],_0x35d1e3[_0xdcd4('0x38')]),_0x21aaaf);if(_0x239479[_0xdcd4('0x37')][_0xdcd4('0x40')]){_0x565e9e[_0xdcd4('0x3e')]=_['merge'](_0x565e9e[_0xdcd4('0x3e')],{'$or':_['map'](_0x21aaaf,function(_0xf0b2c8){if(_0xf0b2c8[_0xdcd4('0x41')]!==_0xdcd4('0x42')){var _0x595e61={};_0x595e61[_0xf0b2c8[_0xdcd4('0x2f')]]={'$like':'%'+_0x239479[_0xdcd4('0x37')][_0xdcd4('0x40')]+'%'};return _0x595e61;}})});}_0x565e9e=_[_0xdcd4('0x43')]({},_0x565e9e,_0x239479[_0xdcd4('0x44')]);var _0x47717d={'where':_0x565e9e['where']};return db[_0xdcd4('0x32')][_0xdcd4('0x24')](_0x47717d)['then'](function(_0x82cd5e){_0x2e11d6['count']=_0x82cd5e;if(_0x239479[_0xdcd4('0x37')][_0xdcd4('0x45')]){_0x565e9e[_0xdcd4('0x46')]=[{'all':!![]}];}return db[_0xdcd4('0x32')]['findAll'](_0x565e9e);})[_0xdcd4('0x2a')](function(_0x30a725){_0x2e11d6['rows']=_0x30a725;return _0x2e11d6;})[_0xdcd4('0x2a')](respondWithFilteredResult(_0x1d0937,_0x565e9e))[_0xdcd4('0x47')](handleError(_0x1d0937,null));};exports[_0xdcd4('0x48')]=function(_0x392bc3,_0x1e53ec){var _0x35a808={'raw':![],'where':{'id':_0x392bc3[_0xdcd4('0x49')]['id']}},_0x193501={};_0x193501[_0xdcd4('0x36')]=_[_0xdcd4('0x4a')](db[_0xdcd4('0x32')]['rawAttributes']);_0x193501[_0xdcd4('0x37')]=_[_0xdcd4('0x4a')](_0x392bc3[_0xdcd4('0x37')]);_0x193501[_0xdcd4('0x38')]=_[_0xdcd4('0x39')](_0x193501[_0xdcd4('0x36')],_0x193501[_0xdcd4('0x37')]);_0x35a808['attributes']=_['intersection'](_0x193501[_0xdcd4('0x36')],qs['fields'](_0x392bc3['query']['fields']));_0x35a808['attributes']=_0x35a808[_0xdcd4('0x3a')][_0xdcd4('0x3c')]?_0x35a808['attributes']:_0x193501[_0xdcd4('0x36')];if(_0x392bc3[_0xdcd4('0x37')][_0xdcd4('0x45')]){_0x35a808['include']=[{'all':!![]}];}_0x35a808=_[_0xdcd4('0x43')]({},_0x35a808,_0x392bc3[_0xdcd4('0x44')]);return db[_0xdcd4('0x32')][_0xdcd4('0x4b')](_0x35a808)[_0xdcd4('0x2a')](handleEntityNotFound(_0x1e53ec,null))[_0xdcd4('0x2a')](respondWithResult(_0x1e53ec,null))[_0xdcd4('0x47')](handleError(_0x1e53ec,null));};exports[_0xdcd4('0x4c')]=function(_0x942d98,_0xa91417){return db['JscriptyProject'][_0xdcd4('0x4c')](_0x942d98[_0xdcd4('0x4d')],{})[_0xdcd4('0x2a')](function(_0x472827){var _0x535de8=_0x942d98['user'][_0xdcd4('0x2c')]({'plain':!![]});if(!_0x535de8)throw new Error(_0xdcd4('0x4e'));if(_0x535de8['role']==='user'){var _0x5a1695=_0x472827[_0xdcd4('0x2c')]({'plain':!![]});var _0x4b7457=_0xdcd4('0x2d');return db[_0xdcd4('0x4f')][_0xdcd4('0x4b')]({'where':{'name':_0x4b7457,'userProfileId':_0x535de8[_0xdcd4('0x50')]},'raw':!![]})['then'](function(_0x1bc801){if(_0x1bc801&&_0x1bc801[_0xdcd4('0x51')]===0x0){return db['UserProfileResource'][_0xdcd4('0x4c')]({'name':_0x5a1695[_0xdcd4('0x2f')],'resourceId':_0x5a1695['id'],'type':_0x1bc801[_0xdcd4('0x2f')],'sectionId':_0x1bc801['id']},{})[_0xdcd4('0x2a')](function(){return _0x472827;});}else{return _0x472827;}})['catch'](function(_0x4ce6bc){logger[_0xdcd4('0x52')](_0xdcd4('0x53'),_0x4ce6bc);throw _0x4ce6bc;});}return _0x472827;})[_0xdcd4('0x2a')](respondWithResult(_0xa91417,0xc9))[_0xdcd4('0x47')](handleError(_0xa91417,null));};exports[_0xdcd4('0x54')]=function(_0x5ecd77,_0xa1e423){var _0x4a8f5b={'where':{'id':_0x5ecd77[_0xdcd4('0x49')]['id']}},_0x3b133b={};_0x3b133b[_0xdcd4('0x36')]=_[_0xdcd4('0x4a')](db[_0xdcd4('0x32')]['rawAttributes']);_0x4a8f5b['attributes']=_['intersection'](_0x3b133b[_0xdcd4('0x36')],qs[_0xdcd4('0x3b')](_0x5ecd77[_0xdcd4('0x37')][_0xdcd4('0x3b')]));_0x4a8f5b[_0xdcd4('0x3a')]=_0x4a8f5b[_0xdcd4('0x3a')]['length']?_0x4a8f5b[_0xdcd4('0x3a')]:_0x3b133b[_0xdcd4('0x36')];if(_0x5ecd77[_0xdcd4('0x37')][_0xdcd4('0x45')]){_0x4a8f5b[_0xdcd4('0x46')]=[{'all':!![]}];}_0x4a8f5b=_[_0xdcd4('0x43')]({},_0x4a8f5b,_0x5ecd77[_0xdcd4('0x44')]);return db[_0xdcd4('0x32')][_0xdcd4('0x4b')](_0x4a8f5b)[_0xdcd4('0x2a')](handleEntityNotFound(_0xa1e423,null))[_0xdcd4('0x2a')](function(_0x1293f4){if(_0x1293f4){var _0x40ad2a=_0x1293f4['get']({'plain':!![]});_0x40ad2a=qs[_0xdcd4('0x55')](_0x40ad2a,['id',_0xdcd4('0x56'),'updatedAt']);_0x5ecd77[_0xdcd4('0x4d')]=_[_0xdcd4('0x55')](_0x5ecd77['body'],['id',_0xdcd4('0x56'),_0xdcd4('0x57')]);return db[_0xdcd4('0x32')][_0xdcd4('0x4c')](_[_0xdcd4('0x43')](_0x40ad2a,_0x5ecd77[_0xdcd4('0x4d')]),{'include':_0x5ecd77['query'][_0xdcd4('0x45')]?[{'all':!![]}]:undefined})['then'](function(_0x3bef7c){var _0xf41e7b=_0x5ecd77[_0xdcd4('0x58')]['get']({'plain':!![]});if(!_0xf41e7b)throw new Error(_0xdcd4('0x4e'));if(_0xf41e7b['role']==='user'){var _0x37d222=_0x3bef7c['get']({'plain':!![]});var _0x5a3402=_0xdcd4('0x2d');return db[_0xdcd4('0x4f')][_0xdcd4('0x4b')]({'where':{'name':_0x5a3402,'userProfileId':_0xf41e7b[_0xdcd4('0x50')]},'raw':!![]})[_0xdcd4('0x2a')](function(_0xb0bf48){if(_0xb0bf48&&_0xb0bf48[_0xdcd4('0x51')]===0x0){return db[_0xdcd4('0x2e')][_0xdcd4('0x4c')]({'name':_0x37d222[_0xdcd4('0x2f')],'resourceId':_0x37d222['id'],'type':_0xb0bf48[_0xdcd4('0x2f')],'sectionId':_0xb0bf48['id']},{})['then'](function(){return _0x3bef7c;});}else{return _0x3bef7c;}})['catch'](function(_0x3fa3de){logger[_0xdcd4('0x52')](_0xdcd4('0x53'),_0x3fa3de);throw _0x3fa3de;});}return _0x3bef7c;});}})[_0xdcd4('0x2a')](respondWithResult(_0xa1e423,0xc9))[_0xdcd4('0x47')](handleError(_0xa1e423,null));};exports['update']=function(_0x22e94a,_0x4048c9){if(_0x22e94a[_0xdcd4('0x4d')]['id']){delete _0x22e94a['body']['id'];}return db[_0xdcd4('0x32')]['find']({'where':{'id':_0x22e94a[_0xdcd4('0x49')]['id']}})[_0xdcd4('0x2a')](handleEntityNotFound(_0x4048c9,null))[_0xdcd4('0x2a')](saveUpdates(_0x22e94a[_0xdcd4('0x4d')],null))['then'](respondWithResult(_0x4048c9,null))[_0xdcd4('0x47')](handleError(_0x4048c9,null));};exports[_0xdcd4('0x2b')]=function(_0x1c117f,_0x580fca){return db['JscriptyProject'][_0xdcd4('0x4b')]({'where':{'id':_0x1c117f[_0xdcd4('0x49')]['id']}})[_0xdcd4('0x2a')](handleEntityNotFound(_0x580fca,null))[_0xdcd4('0x2a')](removeEntity(_0x580fca,null))['catch'](handleError(_0x580fca,null));};exports[_0xdcd4('0x59')]=function(_0x1ebdc7,_0x1ebcc1,_0x18aaa1){var _0x466a49={'raw':!![],'where':{}};var _0x2c29b2={};var _0x107b2f={'count':0x0,'rows':[]};return db[_0xdcd4('0x32')][_0xdcd4('0x5a')]({'where':{'id':_0x1ebdc7['params']['id']}})['then'](handleEntityNotFound(_0x1ebcc1,null))['then'](function(_0xda61ca){if(_0xda61ca){_0x2c29b2['model']=_[_0xdcd4('0x4a')](db[_0xdcd4('0x5b')][_0xdcd4('0x33')]);_0x2c29b2[_0xdcd4('0x37')]=_[_0xdcd4('0x4a')](_0x1ebdc7['query']);_0x2c29b2[_0xdcd4('0x38')]=_[_0xdcd4('0x39')](_0x2c29b2['model'],_0x2c29b2[_0xdcd4('0x37')]);_0x466a49['attributes']=_[_0xdcd4('0x39')](_0x2c29b2[_0xdcd4('0x36')],qs['fields'](_0x1ebdc7[_0xdcd4('0x37')][_0xdcd4('0x3b')]));_0x466a49[_0xdcd4('0x3a')]=_0x466a49['attributes']['length']?_0x466a49[_0xdcd4('0x3a')]:_0x2c29b2[_0xdcd4('0x36')];if(!_0x1ebdc7['query'][_0xdcd4('0x5c')]('nolimit')){_0x466a49[_0xdcd4('0x23')]=qs[_0xdcd4('0x23')](_0x1ebdc7['query']['limit']);_0x466a49[_0xdcd4('0x21')]=qs[_0xdcd4('0x21')](_0x1ebdc7[_0xdcd4('0x37')][_0xdcd4('0x21')]);}_0x466a49[_0xdcd4('0x5d')]=qs[_0xdcd4('0x5e')](_0x1ebdc7[_0xdcd4('0x37')][_0xdcd4('0x5e')]);_0x466a49['where']=qs[_0xdcd4('0x38')](_[_0xdcd4('0x3f')](_0x1ebdc7['query'],_0x2c29b2['filters']));_0x466a49['where']['ProjectId']=_0xda61ca['id'];if(_0x1ebdc7[_0xdcd4('0x37')][_0xdcd4('0x40')]){_0x466a49['where']=_['merge'](_0x466a49[_0xdcd4('0x3e')],{'$or':_[_0xdcd4('0x31')](_0x466a49[_0xdcd4('0x3a')],function(_0x18a215){var _0x3e8390={};_0x3e8390[_0x18a215]={'$like':'%'+_0x1ebdc7['query']['filter']+'%'};return _0x3e8390;})});}_0x466a49=_[_0xdcd4('0x43')]({},_0x466a49,_0x1ebdc7[_0xdcd4('0x44')]);return db[_0xdcd4('0x5b')][_0xdcd4('0x24')]({'where':_0x466a49[_0xdcd4('0x3e')]})[_0xdcd4('0x2a')](function(_0xf623ed){_0x107b2f[_0xdcd4('0x24')]=_0xf623ed;if(_0x1ebdc7[_0xdcd4('0x37')][_0xdcd4('0x45')]){_0x466a49['include']=[{'all':!![]}];}return db[_0xdcd4('0x5b')][_0xdcd4('0x5f')](_0x466a49);})['then'](function(_0x55d517){_0x107b2f[_0xdcd4('0x60')]=_0x55d517;return _0x107b2f;});}})[_0xdcd4('0x2a')](respondWithFilteredResult(_0x1ebcc1,_0x466a49))[_0xdcd4('0x47')](handleError(_0x1ebcc1,null));};exports[_0xdcd4('0x61')]=function(_0x5a60cb,_0x3e4f01,_0x5d1853){var _0x36eb6d={'raw':!![],'where':{}};var _0x361725={};var _0x11f15d={'count':0x0,'rows':[]};return db[_0xdcd4('0x32')]['findOne']({'where':{'id':_0x5a60cb[_0xdcd4('0x49')]['id']}})['then'](handleEntityNotFound(_0x3e4f01,null))[_0xdcd4('0x2a')](function(_0x22435c){if(_0x22435c){_0x361725[_0xdcd4('0x36')]=_['keys'](db['JscriptyAnswerReport'][_0xdcd4('0x33')]);_0x361725[_0xdcd4('0x37')]=_[_0xdcd4('0x4a')](_0x5a60cb['query']);_0x361725[_0xdcd4('0x38')]=_[_0xdcd4('0x39')](_0x361725['model'],_0x361725[_0xdcd4('0x37')]);_0x36eb6d[_0xdcd4('0x3a')]=_[_0xdcd4('0x39')](_0x361725[_0xdcd4('0x36')],qs[_0xdcd4('0x3b')](_0x5a60cb[_0xdcd4('0x37')]['fields']));_0x36eb6d[_0xdcd4('0x3a')]=_0x36eb6d[_0xdcd4('0x3a')][_0xdcd4('0x3c')]?_0x36eb6d[_0xdcd4('0x3a')]:_0x361725[_0xdcd4('0x36')];if(!_0x5a60cb['query'][_0xdcd4('0x5c')]('nolimit')){_0x36eb6d[_0xdcd4('0x23')]=qs['limit'](_0x5a60cb[_0xdcd4('0x37')][_0xdcd4('0x23')]);_0x36eb6d[_0xdcd4('0x21')]=qs[_0xdcd4('0x21')](_0x5a60cb[_0xdcd4('0x37')]['offset']);}_0x36eb6d[_0xdcd4('0x5d')]=qs['sort'](_0x5a60cb[_0xdcd4('0x37')][_0xdcd4('0x5e')]);_0x36eb6d[_0xdcd4('0x3e')]=qs[_0xdcd4('0x38')](_[_0xdcd4('0x3f')](_0x5a60cb['query'],_0x361725[_0xdcd4('0x38')]));_0x36eb6d[_0xdcd4('0x3e')][_0xdcd4('0x62')]=_0x22435c['id'];if(_0x5a60cb['query'][_0xdcd4('0x40')]){_0x36eb6d[_0xdcd4('0x3e')]=_['merge'](_0x36eb6d['where'],{'$or':_['map'](_0x36eb6d[_0xdcd4('0x3a')],function(_0x5e2085){var _0x5dc68d={};_0x5dc68d[_0x5e2085]={'$like':'%'+_0x5a60cb[_0xdcd4('0x37')]['filter']+'%'};return _0x5dc68d;})});}_0x36eb6d=_[_0xdcd4('0x43')]({},_0x36eb6d,_0x5a60cb['options']);return db['JscriptyAnswerReport'][_0xdcd4('0x24')]({'where':_0x36eb6d[_0xdcd4('0x3e')]})[_0xdcd4('0x2a')](function(_0x4d2b28){_0x11f15d['count']=_0x4d2b28;if(_0x5a60cb[_0xdcd4('0x37')][_0xdcd4('0x45')]){_0x36eb6d[_0xdcd4('0x46')]=[{'all':!![]}];}return db[_0xdcd4('0x63')]['findAll'](_0x36eb6d);})[_0xdcd4('0x2a')](function(_0x4ddc72){_0x11f15d[_0xdcd4('0x60')]=_0x4ddc72;return _0x11f15d;});}})['then'](respondWithFilteredResult(_0x3e4f01,_0x36eb6d))[_0xdcd4('0x47')](handleError(_0x3e4f01,null));};function char(_0x256c6a){return _0xdcd4('0x64')===typeof _0x256c6a?String[_0xdcd4('0x65')][_0xdcd4('0x27')](null,arguments):_0x256c6a;}function needsEncapsulation(_0x4b8209){return!!_0x4b8209&&(_0x4b8209[_0xdcd4('0x66')]()['indexOf'](char(0xd))>=0x0||_0x4b8209[_0xdcd4('0x66')]()['indexOf'](char(0xa))>=0x0||_0x4b8209[_0xdcd4('0x66')]()[_0xdcd4('0x67')](char(0x2c))>=0x0||_0x4b8209['toString']()[_0xdcd4('0x67')](char(0x22))>=0x0);}function encapsulate(_0x34b90b){var _0x5c9db3=char(0x22),_0x143cdc='\x5c'+char(0x22),_0x2d0f2a=_0x34b90b[_0xdcd4('0x66')]()['replace'](new RegExp(_0x5c9db3,'g'),_0x143cdc);return _0x5c9db3+_0x2d0f2a+_0x5c9db3;}exports[_0xdcd4('0x68')]=function(_0x4d152c,_0x4776ff,_0x39503a){var _0x595da1,_0x174ced;var _0x265fb0={'where':{'ProjectId':_0x4d152c[_0xdcd4('0x49')]['id']}};if(_0x4d152c[_0xdcd4('0x37')][_0xdcd4('0x69')]){_0x265fb0[_0xdcd4('0x3e')][_0xdcd4('0x6a')]=JSON[_0xdcd4('0x6b')](_0x4d152c[_0xdcd4('0x37')][_0xdcd4('0x69')]);}return db[_0xdcd4('0x5b')][_0xdcd4('0x5f')](_0x265fb0)[_0xdcd4('0x2a')](handleEntityNotFound(_0x4776ff,null))['then'](function(_0x3aed9c){if(_0x3aed9c){_0x595da1=_0x3aed9c;return db['JscriptyQuestionReport'][_0xdcd4('0x5f')]({'where':{'SessionId':{'$in':_[_0xdcd4('0x31')](_0x595da1,'id')},'ProjectId':_0x4d152c[_0xdcd4('0x49')]['id']},'order':_0xdcd4('0x6c')});}})['then'](handleEntityNotFound(_0x4776ff,null))[_0xdcd4('0x2a')](function(_0x2d332f){if(_0x2d332f){_0x174ced=_0x2d332f;var _0x389718={};for(var _0xbefcff=0x0,_0x3316b5=_0x174ced[_0xdcd4('0x3c')];_0xbefcff<_0x3316b5;_0xbefcff++){if(!_0x389718[_0xdcd4('0x5c')](_0x174ced[_0xbefcff][_0xdcd4('0x6d')])){_0x389718[_0x174ced[_0xbefcff][_0xdcd4('0x6d')]]=needsEncapsulation(_0x174ced[_0xbefcff][_0xdcd4('0x6e')])?encapsulate(_0x174ced[_0xbefcff][_0xdcd4('0x6e')]):_0x174ced[_0xbefcff][_0xdcd4('0x6e')];}}var _0x3d65cc=[],_0x35a64a={};for(var _0x1f5b59=0x0,_0x412bea=_0x595da1['length'];_0x1f5b59<_0x412bea;_0x1f5b59++){_0x35a64a={'ProjectId':_0x4d152c[_0xdcd4('0x49')]['id'],'SessionId':_0x595da1[_0x1f5b59]['id'],'StartTime':moment(_0x595da1[_0x1f5b59][_0xdcd4('0x6a')])['format']('YYYY-MM-DD\x20HH:mm:ss')};for(var _0x5b09ff=0x0,_0x492808=_0x174ced[_0xdcd4('0x3c')];_0x5b09ff<_0x492808;_0x5b09ff++){if(_0x174ced[_0x5b09ff][_0xdcd4('0x6f')]==_0x595da1[_0x1f5b59]['id']&&_0x389718['hasOwnProperty'](_0x174ced[_0x5b09ff][_0xdcd4('0x6d')])){_0x35a64a[_0x389718[_0x174ced[_0x5b09ff]['questionId']]]=_0x174ced[_0x5b09ff][_0xdcd4('0x70')];}}for(var _0x2f2c6a in _0x389718){if(!_0x35a64a[_0xdcd4('0x5c')](_0x389718[_0x2f2c6a])){_0x35a64a[_0x389718[_0x2f2c6a]]=null;}}_0x3d65cc[_0xdcd4('0x71')](_0x35a64a);}return _0x3d65cc;}})[_0xdcd4('0x2a')](function(_0x401529){if(!_[_0xdcd4('0x72')](_0x401529)){var _0x452a9c=toCsv(_0x401529);var _0xb56a81=Date[_0xdcd4('0x73')]();fs[_0xdcd4('0x74')](util['format'](_0xdcd4('0x75'),_0x4d152c[_0xdcd4('0x49')]['id'],_0xb56a81),_0x452a9c);_0x4776ff[_0xdcd4('0x76')](_0xdcd4('0x77'),_0xdcd4('0x78')+util[_0xdcd4('0x79')]('Jscripty_Project_%d_Summary_%s.csv',_0x4d152c[_0xdcd4('0x49')]['id'],_0xb56a81));_0x4776ff[_0xdcd4('0x76')](_0xdcd4('0x7a'),_0xdcd4('0x7b'));return _0x4776ff['download'](util[_0xdcd4('0x79')]('/tmp/Jscripty_Project_%d_Summary_%s.csv',_0x4d152c['params']['id'],_0xb56a81));}else{return _0x4776ff['sendStatus'](0xcc);}})[_0xdcd4('0x47')](handleError(_0x4776ff,null));};