Built motion from commit db94841.|2.5.3
[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 _0xf99b=['nolimit','order','where','pick','filter','merge','VIRTUAL','options','count','findAll','rows','catch','show','params','includeAll','include','find','create','body','Unable\x20to\x20retrieve\x20the\x20current\x20user','role','user','userProfileId','Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s','clone','omit','createdAt','updatedAt','UserProfileSection','getSessions','JscriptySessionReport','hasOwnProperty','limit','sort','getAnswers','findOne','JscriptyAnswerReport','ProjectId','number','fromCharCode','apply','toString','indexOf','replace','getSummary','startTime','parse','JscriptyQuestionReport','questionId','question','starttime','format','SessionId','answer','push','isEmpty','writeFileSync','Content-disposition','attachment;\x20filename=','setHeader','Content-type','download','/tmp/Jscripty_Project_%d_Summary_%s.csv','html-pdf','rimraf','zip-dir','fast-json-patch','request-promise','moment','bluebird','mustache','util','path','sox','to-csv','ejs','lodash','jsforce','desk.js','querystring','papaparse','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','api','../../config/utils','sendStatus','status','end','json','offset','set','Content-Range','save','update','then','get','Projects','UserProfileResource','destroy','error','stack','name','index','map','JscriptyProject','rawAttributes','fieldName','type','key','model','query','keys','filters','attributes','intersection','fields','length'];(function(_0x3c65a3,_0x366bd1){var _0x541417=function(_0x359e5c){while(--_0x359e5c){_0x3c65a3['push'](_0x3c65a3['shift']());}};_0x541417(++_0x366bd1);}(_0xf99b,0x1a4));var _0xbf99=function(_0x5db44b,_0x2d9f64){_0x5db44b=_0x5db44b-0x0;var _0x2376b1=_0xf99b[_0x5db44b];return _0x2376b1;};'use strict';var pdf=require(_0xbf99('0x0'));var emlformat=require('eml-format');var rimraf=require(_0xbf99('0x1'));var zipdir=require(_0xbf99('0x2'));var jsonpatch=require(_0xbf99('0x3'));var rp=require(_0xbf99('0x4'));var moment=require(_0xbf99('0x5'));var BPromise=require(_0xbf99('0x6'));var Mustache=require(_0xbf99('0x7'));var util=require(_0xbf99('0x8'));var path=require(_0xbf99('0x9'));var sox=require(_0xbf99('0xa'));var csv=require(_0xbf99('0xb'));var ejs=require(_0xbf99('0xc'));var fs=require('fs');var _=require(_0xbf99('0xd'));var squel=require('squel');var crypto=require('crypto');var jsforce=require(_0xbf99('0xe'));var deskjs=require(_0xbf99('0xf'));var toCsv=require(_0xbf99('0xb'));var querystring=require(_0xbf99('0x10'));var Papa=require(_0xbf99('0x11'));var Redis=require('ioredis');var authService=require('../../components/auth/service');var qs=require(_0xbf99('0x12'));var as=require(_0xbf99('0x13'));var hardwareService=require(_0xbf99('0x14'));var logger=require(_0xbf99('0x15'))(_0xbf99('0x16'));var utils=require(_0xbf99('0x17'));var config=require('../../config/environment');var db=require('../../mysqldb')['db'];function respondWithStatusCode(_0x4d7302,_0x786ab9){_0x786ab9=_0x786ab9||0xcc;return function(_0x49dc1f){if(_0x49dc1f){return _0x4d7302[_0xbf99('0x18')](_0x786ab9);}return _0x4d7302[_0xbf99('0x19')](_0x786ab9)[_0xbf99('0x1a')]();};}function respondWithResult(_0x204b52,_0xe1b0c3){_0xe1b0c3=_0xe1b0c3||0xc8;return function(_0x210134){if(_0x210134){return _0x204b52[_0xbf99('0x19')](_0xe1b0c3)[_0xbf99('0x1b')](_0x210134);}};}function respondWithFilteredResult(_0x5c4644,_0x300e98){return function(_0xf0dc63){if(_0xf0dc63){var _0x37310d=_0xf0dc63['count'],_0x167cc3=_0x300e98[_0xbf99('0x1c')],_0x2f93c8=_0x300e98[_0xbf99('0x1c')]+_0x300e98['limit'],_0x2c43c3;if(_0x2f93c8>=_0x37310d){_0x2f93c8=_0x37310d;_0x2c43c3=0xc8;}else{_0x2c43c3=0xce;}_0x5c4644['status'](_0x2c43c3);return _0x5c4644[_0xbf99('0x1d')](_0xbf99('0x1e'),_0x167cc3+'-'+_0x2f93c8+'/'+_0x37310d)[_0xbf99('0x1b')](_0xf0dc63);}return null;};}function patchUpdates(_0x6e10ab){return function(_0x2cf4e7){try{jsonpatch['apply'](_0x2cf4e7,_0x6e10ab,!![]);}catch(_0x53da1e){return BPromise['reject'](_0x53da1e);}return _0x2cf4e7[_0xbf99('0x1f')]();};}function saveUpdates(_0x2f1c17,_0x750771){return function(_0x106286){if(_0x106286){return _0x106286[_0xbf99('0x20')](_0x2f1c17)['then'](function(_0xf68ed5){return _0xf68ed5;});}return null;};}function removeEntity(_0x39019c,_0x40560d){return function(_0x11732c){if(_0x11732c){return _0x11732c['destroy']()[_0xbf99('0x21')](function(){var _0x197777=_0x11732c[_0xbf99('0x22')]({'plain':!![]});var _0x3abd9f=_0xbf99('0x23');return db[_0xbf99('0x24')][_0xbf99('0x25')]({'where':{'type':_0x3abd9f,'resourceId':_0x197777['id']}})[_0xbf99('0x21')](function(){return _0x11732c;});})[_0xbf99('0x21')](function(){_0x39019c[_0xbf99('0x19')](0xcc)['end']();});}};}function handleEntityNotFound(_0x497669,_0x24b979){return function(_0xdd7f57){if(!_0xdd7f57){_0x497669['sendStatus'](0x194);}return _0xdd7f57;};}function handleError(_0x1c8d30,_0x196d2d){_0x196d2d=_0x196d2d||0x1f4;return function(_0xe5cdc2){logger[_0xbf99('0x26')](_0xe5cdc2[_0xbf99('0x27')]);if(_0xe5cdc2['name']){delete _0xe5cdc2[_0xbf99('0x28')];}_0x1c8d30[_0xbf99('0x19')](_0x196d2d)['send'](_0xe5cdc2);};}exports[_0xbf99('0x29')]=function(_0x29c57c,_0x566806){var _0x156d25={},_0x5489d6={},_0x4c3154={'count':0x0,'rows':[]};var _0x1e7d0d=_[_0xbf99('0x2a')](db[_0xbf99('0x2b')][_0xbf99('0x2c')],function(_0x11b66d){return{'name':_0x11b66d[_0xbf99('0x2d')],'type':_0x11b66d[_0xbf99('0x2e')][_0xbf99('0x2f')]};});_0x5489d6[_0xbf99('0x30')]=_[_0xbf99('0x2a')](_0x1e7d0d,_0xbf99('0x28'));_0x5489d6[_0xbf99('0x31')]=_[_0xbf99('0x32')](_0x29c57c['query']);_0x5489d6[_0xbf99('0x33')]=_['intersection'](_0x5489d6['model'],_0x5489d6['query']);_0x156d25[_0xbf99('0x34')]=_[_0xbf99('0x35')](_0x5489d6['model'],qs[_0xbf99('0x36')](_0x29c57c['query']['fields']));_0x156d25[_0xbf99('0x34')]=_0x156d25[_0xbf99('0x34')][_0xbf99('0x37')]?_0x156d25['attributes']:_0x5489d6[_0xbf99('0x30')];if(!_0x29c57c[_0xbf99('0x31')]['hasOwnProperty'](_0xbf99('0x38'))){_0x156d25['limit']=qs['limit'](_0x29c57c[_0xbf99('0x31')]['limit']);_0x156d25[_0xbf99('0x1c')]=qs[_0xbf99('0x1c')](_0x29c57c[_0xbf99('0x31')][_0xbf99('0x1c')]);}_0x156d25[_0xbf99('0x39')]=qs['sort'](_0x29c57c[_0xbf99('0x31')]['sort']);_0x156d25[_0xbf99('0x3a')]=qs[_0xbf99('0x33')](_[_0xbf99('0x3b')](_0x29c57c[_0xbf99('0x31')],_0x5489d6[_0xbf99('0x33')]),_0x1e7d0d);if(_0x29c57c[_0xbf99('0x31')][_0xbf99('0x3c')]){_0x156d25[_0xbf99('0x3a')]=_[_0xbf99('0x3d')](_0x156d25[_0xbf99('0x3a')],{'$or':_['map'](_0x1e7d0d,function(_0x265e48){if(_0x265e48['type']!==_0xbf99('0x3e')){var _0xf6fa1b={};_0xf6fa1b[_0x265e48[_0xbf99('0x28')]]={'$like':'%'+_0x29c57c[_0xbf99('0x31')][_0xbf99('0x3c')]+'%'};return _0xf6fa1b;}})});}_0x156d25=_[_0xbf99('0x3d')]({},_0x156d25,_0x29c57c[_0xbf99('0x3f')]);var _0x4e259d={'where':_0x156d25[_0xbf99('0x3a')]};return db['JscriptyProject']['count'](_0x4e259d)['then'](function(_0x3656bc){_0x4c3154[_0xbf99('0x40')]=_0x3656bc;if(_0x29c57c[_0xbf99('0x31')]['includeAll']){_0x156d25['include']=[{'all':!![]}];}return db[_0xbf99('0x2b')][_0xbf99('0x41')](_0x156d25);})['then'](function(_0x4681f9){_0x4c3154[_0xbf99('0x42')]=_0x4681f9;return _0x4c3154;})[_0xbf99('0x21')](respondWithFilteredResult(_0x566806,_0x156d25))[_0xbf99('0x43')](handleError(_0x566806,null));};exports[_0xbf99('0x44')]=function(_0x3c2025,_0x108b6d){var _0x39e852={'raw':![],'where':{'id':_0x3c2025[_0xbf99('0x45')]['id']}},_0x592ed9={};_0x592ed9[_0xbf99('0x30')]=_['keys'](db['JscriptyProject'][_0xbf99('0x2c')]);_0x592ed9[_0xbf99('0x31')]=_[_0xbf99('0x32')](_0x3c2025[_0xbf99('0x31')]);_0x592ed9[_0xbf99('0x33')]=_[_0xbf99('0x35')](_0x592ed9['model'],_0x592ed9[_0xbf99('0x31')]);_0x39e852[_0xbf99('0x34')]=_['intersection'](_0x592ed9[_0xbf99('0x30')],qs[_0xbf99('0x36')](_0x3c2025[_0xbf99('0x31')][_0xbf99('0x36')]));_0x39e852['attributes']=_0x39e852[_0xbf99('0x34')][_0xbf99('0x37')]?_0x39e852['attributes']:_0x592ed9[_0xbf99('0x30')];if(_0x3c2025[_0xbf99('0x31')][_0xbf99('0x46')]){_0x39e852[_0xbf99('0x47')]=[{'all':!![]}];}_0x39e852=_[_0xbf99('0x3d')]({},_0x39e852,_0x3c2025['options']);return db[_0xbf99('0x2b')][_0xbf99('0x48')](_0x39e852)[_0xbf99('0x21')](handleEntityNotFound(_0x108b6d,null))[_0xbf99('0x21')](respondWithResult(_0x108b6d,null))[_0xbf99('0x43')](handleError(_0x108b6d,null));};exports[_0xbf99('0x49')]=function(_0x3faed6,_0x2a5f5a){return db[_0xbf99('0x2b')][_0xbf99('0x49')](_0x3faed6[_0xbf99('0x4a')],{})['then'](function(_0x197d5a){var _0x42b4ec=_0x3faed6['user'][_0xbf99('0x22')]({'plain':!![]});if(!_0x42b4ec)throw new Error(_0xbf99('0x4b'));if(_0x42b4ec[_0xbf99('0x4c')]===_0xbf99('0x4d')){var _0x5683db=_0x197d5a[_0xbf99('0x22')]({'plain':!![]});var _0x3865fc='Projects';return db['UserProfileSection'][_0xbf99('0x48')]({'where':{'name':_0x3865fc,'userProfileId':_0x42b4ec[_0xbf99('0x4e')]},'raw':!![]})[_0xbf99('0x21')](function(_0x517372){if(_0x517372&&_0x517372['autoAssociation']===0x0){return db['UserProfileResource'][_0xbf99('0x49')]({'name':_0x5683db[_0xbf99('0x28')],'resourceId':_0x5683db['id'],'type':_0x517372['name'],'sectionId':_0x517372['id']},{})[_0xbf99('0x21')](function(){return _0x197d5a;});}else{return _0x197d5a;}})[_0xbf99('0x43')](function(_0x4d3eb5){logger['error'](_0xbf99('0x4f'),_0x4d3eb5);throw _0x4d3eb5;});}return _0x197d5a;})[_0xbf99('0x21')](respondWithResult(_0x2a5f5a,0xc9))[_0xbf99('0x43')](handleError(_0x2a5f5a,null));};exports[_0xbf99('0x50')]=function(_0x282a8e,_0x58f0ff){var _0x2f74fc={'where':{'id':_0x282a8e[_0xbf99('0x45')]['id']}},_0x32ea32={};_0x32ea32[_0xbf99('0x30')]=_[_0xbf99('0x32')](db[_0xbf99('0x2b')]['rawAttributes']);_0x2f74fc[_0xbf99('0x34')]=_['intersection'](_0x32ea32[_0xbf99('0x30')],qs['fields'](_0x282a8e[_0xbf99('0x31')]['fields']));_0x2f74fc['attributes']=_0x2f74fc[_0xbf99('0x34')][_0xbf99('0x37')]?_0x2f74fc[_0xbf99('0x34')]:_0x32ea32['model'];if(_0x282a8e[_0xbf99('0x31')][_0xbf99('0x46')]){_0x2f74fc['include']=[{'all':!![]}];}_0x2f74fc=_[_0xbf99('0x3d')]({},_0x2f74fc,_0x282a8e['options']);return db['JscriptyProject'][_0xbf99('0x48')](_0x2f74fc)[_0xbf99('0x21')](handleEntityNotFound(_0x58f0ff,null))['then'](function(_0x5c935b){if(_0x5c935b){var _0x3b6f48=_0x5c935b[_0xbf99('0x22')]({'plain':!![]});_0x3b6f48=qs[_0xbf99('0x51')](_0x3b6f48,['id',_0xbf99('0x52'),_0xbf99('0x53')]);_0x282a8e['body']=_['omit'](_0x282a8e[_0xbf99('0x4a')],['id',_0xbf99('0x52'),_0xbf99('0x53')]);return db['JscriptyProject'][_0xbf99('0x49')](_[_0xbf99('0x3d')](_0x3b6f48,_0x282a8e[_0xbf99('0x4a')]),{'include':_0x282a8e[_0xbf99('0x31')][_0xbf99('0x46')]?[{'all':!![]}]:undefined})['then'](function(_0x157f7e){var _0x2ef3af=_0x282a8e[_0xbf99('0x4d')]['get']({'plain':!![]});if(!_0x2ef3af)throw new Error('Unable\x20to\x20retrieve\x20the\x20current\x20user');if(_0x2ef3af[_0xbf99('0x4c')]===_0xbf99('0x4d')){var _0x35f987=_0x157f7e['get']({'plain':!![]});var _0x2d367b=_0xbf99('0x23');return db[_0xbf99('0x54')][_0xbf99('0x48')]({'where':{'name':_0x2d367b,'userProfileId':_0x2ef3af[_0xbf99('0x4e')]},'raw':!![]})[_0xbf99('0x21')](function(_0x506b36){if(_0x506b36&&_0x506b36['autoAssociation']===0x0){return db['UserProfileResource'][_0xbf99('0x49')]({'name':_0x35f987[_0xbf99('0x28')],'resourceId':_0x35f987['id'],'type':_0x506b36[_0xbf99('0x28')],'sectionId':_0x506b36['id']},{})[_0xbf99('0x21')](function(){return _0x157f7e;});}else{return _0x157f7e;}})[_0xbf99('0x43')](function(_0x361f37){logger[_0xbf99('0x26')](_0xbf99('0x4f'),_0x361f37);throw _0x361f37;});}return _0x157f7e;});}})[_0xbf99('0x21')](respondWithResult(_0x58f0ff,0xc9))['catch'](handleError(_0x58f0ff,null));};exports[_0xbf99('0x20')]=function(_0x4eb097,_0x15e43f){if(_0x4eb097[_0xbf99('0x4a')]['id']){delete _0x4eb097['body']['id'];}return db[_0xbf99('0x2b')]['find']({'where':{'id':_0x4eb097['params']['id']}})['then'](handleEntityNotFound(_0x15e43f,null))[_0xbf99('0x21')](saveUpdates(_0x4eb097[_0xbf99('0x4a')],null))[_0xbf99('0x21')](respondWithResult(_0x15e43f,null))[_0xbf99('0x43')](handleError(_0x15e43f,null));};exports[_0xbf99('0x25')]=function(_0x286dd7,_0x70c15b){return db[_0xbf99('0x2b')]['find']({'where':{'id':_0x286dd7[_0xbf99('0x45')]['id']}})[_0xbf99('0x21')](handleEntityNotFound(_0x70c15b,null))['then'](removeEntity(_0x70c15b,null))['catch'](handleError(_0x70c15b,null));};exports[_0xbf99('0x55')]=function(_0x189be2,_0x56001b,_0x2e0033){var _0x544568={'raw':!![],'where':{}};var _0x22b9fa={};var _0x2471de={'count':0x0,'rows':[]};return db[_0xbf99('0x2b')]['findOne']({'where':{'id':_0x189be2[_0xbf99('0x45')]['id']}})[_0xbf99('0x21')](handleEntityNotFound(_0x56001b,null))[_0xbf99('0x21')](function(_0x1c564e){if(_0x1c564e){_0x22b9fa['model']=_[_0xbf99('0x32')](db[_0xbf99('0x56')][_0xbf99('0x2c')]);_0x22b9fa['query']=_[_0xbf99('0x32')](_0x189be2[_0xbf99('0x31')]);_0x22b9fa[_0xbf99('0x33')]=_[_0xbf99('0x35')](_0x22b9fa[_0xbf99('0x30')],_0x22b9fa[_0xbf99('0x31')]);_0x544568[_0xbf99('0x34')]=_[_0xbf99('0x35')](_0x22b9fa[_0xbf99('0x30')],qs[_0xbf99('0x36')](_0x189be2['query'][_0xbf99('0x36')]));_0x544568[_0xbf99('0x34')]=_0x544568[_0xbf99('0x34')][_0xbf99('0x37')]?_0x544568['attributes']:_0x22b9fa[_0xbf99('0x30')];if(!_0x189be2[_0xbf99('0x31')][_0xbf99('0x57')](_0xbf99('0x38'))){_0x544568[_0xbf99('0x58')]=qs[_0xbf99('0x58')](_0x189be2[_0xbf99('0x31')][_0xbf99('0x58')]);_0x544568[_0xbf99('0x1c')]=qs[_0xbf99('0x1c')](_0x189be2[_0xbf99('0x31')][_0xbf99('0x1c')]);}_0x544568[_0xbf99('0x39')]=qs[_0xbf99('0x59')](_0x189be2[_0xbf99('0x31')][_0xbf99('0x59')]);_0x544568[_0xbf99('0x3a')]=qs['filters'](_[_0xbf99('0x3b')](_0x189be2['query'],_0x22b9fa[_0xbf99('0x33')]));_0x544568[_0xbf99('0x3a')]['ProjectId']=_0x1c564e['id'];if(_0x189be2[_0xbf99('0x31')]['filter']){_0x544568['where']=_[_0xbf99('0x3d')](_0x544568[_0xbf99('0x3a')],{'$or':_['map'](_0x544568['attributes'],function(_0xdd3377){var _0x2371e9={};_0x2371e9[_0xdd3377]={'$like':'%'+_0x189be2[_0xbf99('0x31')][_0xbf99('0x3c')]+'%'};return _0x2371e9;})});}_0x544568=_['merge']({},_0x544568,_0x189be2[_0xbf99('0x3f')]);return db[_0xbf99('0x56')]['count']({'where':_0x544568[_0xbf99('0x3a')]})[_0xbf99('0x21')](function(_0x385282){_0x2471de[_0xbf99('0x40')]=_0x385282;if(_0x189be2[_0xbf99('0x31')][_0xbf99('0x46')]){_0x544568[_0xbf99('0x47')]=[{'all':!![]}];}return db[_0xbf99('0x56')][_0xbf99('0x41')](_0x544568);})[_0xbf99('0x21')](function(_0xfaca0e){_0x2471de[_0xbf99('0x42')]=_0xfaca0e;return _0x2471de;});}})[_0xbf99('0x21')](respondWithFilteredResult(_0x56001b,_0x544568))[_0xbf99('0x43')](handleError(_0x56001b,null));};exports[_0xbf99('0x5a')]=function(_0x4b2ca7,_0x3e7c71,_0x2783e9){var _0x16ba42={'raw':!![],'where':{}};var _0x39cf0f={};var _0x1cdde1={'count':0x0,'rows':[]};return db[_0xbf99('0x2b')][_0xbf99('0x5b')]({'where':{'id':_0x4b2ca7[_0xbf99('0x45')]['id']}})[_0xbf99('0x21')](handleEntityNotFound(_0x3e7c71,null))[_0xbf99('0x21')](function(_0x573fa9){if(_0x573fa9){_0x39cf0f[_0xbf99('0x30')]=_[_0xbf99('0x32')](db[_0xbf99('0x5c')]['rawAttributes']);_0x39cf0f[_0xbf99('0x31')]=_[_0xbf99('0x32')](_0x4b2ca7['query']);_0x39cf0f[_0xbf99('0x33')]=_[_0xbf99('0x35')](_0x39cf0f[_0xbf99('0x30')],_0x39cf0f[_0xbf99('0x31')]);_0x16ba42[_0xbf99('0x34')]=_[_0xbf99('0x35')](_0x39cf0f[_0xbf99('0x30')],qs[_0xbf99('0x36')](_0x4b2ca7[_0xbf99('0x31')][_0xbf99('0x36')]));_0x16ba42['attributes']=_0x16ba42['attributes'][_0xbf99('0x37')]?_0x16ba42[_0xbf99('0x34')]:_0x39cf0f['model'];if(!_0x4b2ca7[_0xbf99('0x31')][_0xbf99('0x57')](_0xbf99('0x38'))){_0x16ba42[_0xbf99('0x58')]=qs[_0xbf99('0x58')](_0x4b2ca7[_0xbf99('0x31')][_0xbf99('0x58')]);_0x16ba42[_0xbf99('0x1c')]=qs['offset'](_0x4b2ca7[_0xbf99('0x31')][_0xbf99('0x1c')]);}_0x16ba42[_0xbf99('0x39')]=qs['sort'](_0x4b2ca7[_0xbf99('0x31')]['sort']);_0x16ba42[_0xbf99('0x3a')]=qs['filters'](_[_0xbf99('0x3b')](_0x4b2ca7[_0xbf99('0x31')],_0x39cf0f[_0xbf99('0x33')]));_0x16ba42[_0xbf99('0x3a')][_0xbf99('0x5d')]=_0x573fa9['id'];if(_0x4b2ca7[_0xbf99('0x31')][_0xbf99('0x3c')]){_0x16ba42[_0xbf99('0x3a')]=_['merge'](_0x16ba42['where'],{'$or':_['map'](_0x16ba42['attributes'],function(_0x5bbba6){var _0x332535={};_0x332535[_0x5bbba6]={'$like':'%'+_0x4b2ca7['query'][_0xbf99('0x3c')]+'%'};return _0x332535;})});}_0x16ba42=_[_0xbf99('0x3d')]({},_0x16ba42,_0x4b2ca7[_0xbf99('0x3f')]);return db[_0xbf99('0x5c')][_0xbf99('0x40')]({'where':_0x16ba42[_0xbf99('0x3a')]})[_0xbf99('0x21')](function(_0x2b7512){_0x1cdde1['count']=_0x2b7512;if(_0x4b2ca7[_0xbf99('0x31')][_0xbf99('0x46')]){_0x16ba42[_0xbf99('0x47')]=[{'all':!![]}];}return db[_0xbf99('0x5c')][_0xbf99('0x41')](_0x16ba42);})[_0xbf99('0x21')](function(_0x59abb3){_0x1cdde1[_0xbf99('0x42')]=_0x59abb3;return _0x1cdde1;});}})[_0xbf99('0x21')](respondWithFilteredResult(_0x3e7c71,_0x16ba42))[_0xbf99('0x43')](handleError(_0x3e7c71,null));};function char(_0xf9516e){return _0xbf99('0x5e')===typeof _0xf9516e?String[_0xbf99('0x5f')][_0xbf99('0x60')](null,arguments):_0xf9516e;}function needsEncapsulation(_0x4501e3){return!!_0x4501e3&&(_0x4501e3[_0xbf99('0x61')]()['indexOf'](char(0xd))>=0x0||_0x4501e3['toString']()[_0xbf99('0x62')](char(0xa))>=0x0||_0x4501e3[_0xbf99('0x61')]()['indexOf'](char(0x2c))>=0x0||_0x4501e3[_0xbf99('0x61')]()[_0xbf99('0x62')](char(0x22))>=0x0);}function encapsulate(_0x41c28e){var _0x313383=char(0x22),_0x23d024='\x5c'+char(0x22),_0x1e6073=_0x41c28e[_0xbf99('0x61')]()[_0xbf99('0x63')](new RegExp(_0x313383,'g'),_0x23d024);return _0x313383+_0x1e6073+_0x313383;}exports[_0xbf99('0x64')]=function(_0x1f4497,_0x2044b2,_0x56ff64){var _0x30f342,_0x59ddaa;var _0x2e37d4={'where':{'ProjectId':_0x1f4497['params']['id']}};if(_0x1f4497[_0xbf99('0x31')][_0xbf99('0x65')]){_0x2e37d4['where']['starttime']=JSON[_0xbf99('0x66')](_0x1f4497[_0xbf99('0x31')][_0xbf99('0x65')]);}return db[_0xbf99('0x56')][_0xbf99('0x41')](_0x2e37d4)[_0xbf99('0x21')](handleEntityNotFound(_0x2044b2,null))[_0xbf99('0x21')](function(_0x2d881f){if(_0x2d881f){_0x30f342=_0x2d881f;return db[_0xbf99('0x67')][_0xbf99('0x41')]({'where':{'SessionId':{'$in':_[_0xbf99('0x2a')](_0x30f342,'id')},'ProjectId':_0x1f4497['params']['id']},'order':'-createdAt'});}})[_0xbf99('0x21')](handleEntityNotFound(_0x2044b2,null))[_0xbf99('0x21')](function(_0x2910a5){if(_0x2910a5){_0x59ddaa=_0x2910a5;var _0x3dffff={};for(var _0x11b608=0x0,_0x4744ab=_0x59ddaa[_0xbf99('0x37')];_0x11b608<_0x4744ab;_0x11b608++){if(!_0x3dffff[_0xbf99('0x57')](_0x59ddaa[_0x11b608][_0xbf99('0x68')])){_0x3dffff[_0x59ddaa[_0x11b608][_0xbf99('0x68')]]=needsEncapsulation(_0x59ddaa[_0x11b608][_0xbf99('0x69')])?encapsulate(_0x59ddaa[_0x11b608][_0xbf99('0x69')]):_0x59ddaa[_0x11b608]['question'];}}var _0x46d977=[],_0x43aa8e={};for(var _0x7d82b0=0x0,_0x3e37e7=_0x30f342[_0xbf99('0x37')];_0x7d82b0<_0x3e37e7;_0x7d82b0++){_0x43aa8e={'ProjectId':_0x1f4497['params']['id'],'SessionId':_0x30f342[_0x7d82b0]['id'],'StartTime':moment(_0x30f342[_0x7d82b0][_0xbf99('0x6a')])[_0xbf99('0x6b')]('YYYY-MM-DD\x20HH:mm:ss')};for(var _0x30ee55=0x0,_0x1ea602=_0x59ddaa[_0xbf99('0x37')];_0x30ee55<_0x1ea602;_0x30ee55++){if(_0x59ddaa[_0x30ee55][_0xbf99('0x6c')]==_0x30f342[_0x7d82b0]['id']&&_0x3dffff[_0xbf99('0x57')](_0x59ddaa[_0x30ee55][_0xbf99('0x68')])){_0x43aa8e[_0x3dffff[_0x59ddaa[_0x30ee55][_0xbf99('0x68')]]]=_0x59ddaa[_0x30ee55][_0xbf99('0x6d')];}}for(var _0x39df3f in _0x3dffff){if(!_0x43aa8e[_0xbf99('0x57')](_0x3dffff[_0x39df3f])){_0x43aa8e[_0x3dffff[_0x39df3f]]=null;}}_0x46d977[_0xbf99('0x6e')](_0x43aa8e);}return _0x46d977;}})[_0xbf99('0x21')](function(_0x57db5b){if(!_[_0xbf99('0x6f')](_0x57db5b)){var _0x27e7c3=toCsv(_0x57db5b);var _0x257c4e=Date['now']();fs[_0xbf99('0x70')](util['format']('/tmp/Jscripty_Project_%d_Summary_%s.csv',_0x1f4497['params']['id'],_0x257c4e),_0x27e7c3);_0x2044b2['setHeader'](_0xbf99('0x71'),_0xbf99('0x72')+util[_0xbf99('0x6b')]('Jscripty_Project_%d_Summary_%s.csv',_0x1f4497[_0xbf99('0x45')]['id'],_0x257c4e));_0x2044b2[_0xbf99('0x73')](_0xbf99('0x74'),'text/csv');return _0x2044b2[_0xbf99('0x75')](util[_0xbf99('0x6b')](_0xbf99('0x76'),_0x1f4497[_0xbf99('0x45')]['id'],_0x257c4e));}else{return _0x2044b2[_0xbf99('0x18')](0xcc);}})[_0xbf99('0x43')](handleError(_0x2044b2,null));};