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 _0x07bb=['where','merge','VIRTUAL','options','JscriptyProject','count','includeAll','include','rows','params','find','create','body','user','Unable\x20to\x20retrieve\x20the\x20current\x20user','autoAssociation','catch','error','Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s','omit','createdAt','updatedAt','UserProfileSection','userProfileId','getSessions','findOne','JscriptySessionReport','getAnswers','JscriptyAnswerReport','order','number','toString','indexOf','startTime','starttime','findAll','JscriptyQuestionReport','questionId','question','format','YYYY-MM-DD\x20HH:mm:ss','SessionId','answer','push','isEmpty','writeFileSync','/tmp/Jscripty_Project_%d_Summary_%s.csv','setHeader','Content-disposition','attachment;\x20filename=','Jscripty_Project_%d_Summary_%s.csv','Content-type','text/csv','html-pdf','eml-format','rimraf','zip-dir','fast-json-patch','moment','bluebird','util','path','sox','lodash','crypto','jsforce','papaparse','ioredis','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/logger','api','../../config/environment','../../mysqldb','end','status','json','offset','limit','set','Content-Range','apply','reject','update','then','destroy','get','Projects','UserProfileResource','sendStatus','stack','name','index','map','rawAttributes','fieldName','type','key','model','query','keys','filters','intersection','attributes','fields','length','hasOwnProperty','nolimit','sort','pick','filter'];(function(_0x2283dc,_0x2fcfc5){var _0x16db90=function(_0x376c35){while(--_0x376c35){_0x2283dc['push'](_0x2283dc['shift']());}};_0x16db90(++_0x2fcfc5);}(_0x07bb,0x182));var _0xb07b=function(_0x2c3e9e,_0xa87662){_0x2c3e9e=_0x2c3e9e-0x0;var _0x13058a=_0x07bb[_0x2c3e9e];return _0x13058a;};'use strict';var pdf=require(_0xb07b('0x0'));var emlformat=require(_0xb07b('0x1'));var rimraf=require(_0xb07b('0x2'));var zipdir=require(_0xb07b('0x3'));var jsonpatch=require(_0xb07b('0x4'));var rp=require('request-promise');var moment=require(_0xb07b('0x5'));var BPromise=require(_0xb07b('0x6'));var Mustache=require('mustache');var util=require(_0xb07b('0x7'));var path=require(_0xb07b('0x8'));var sox=require(_0xb07b('0x9'));var csv=require('to-csv');var ejs=require('ejs');var fs=require('fs');var _=require(_0xb07b('0xa'));var squel=require('squel');var crypto=require(_0xb07b('0xb'));var jsforce=require(_0xb07b('0xc'));var deskjs=require('desk.js');var toCsv=require('to-csv');var querystring=require('querystring');var Papa=require(_0xb07b('0xd'));var Redis=require(_0xb07b('0xe'));var authService=require('../../components/auth/service');var qs=require(_0xb07b('0xf'));var as=require(_0xb07b('0x10'));var hardwareService=require('../../config/license/hardware');var logger=require(_0xb07b('0x11'))(_0xb07b('0x12'));var utils=require('../../config/utils');var config=require(_0xb07b('0x13'));var db=require(_0xb07b('0x14'))['db'];function respondWithStatusCode(_0x322519,_0x543c78){_0x543c78=_0x543c78||0xcc;return function(_0xc8db7){if(_0xc8db7){return _0x322519['sendStatus'](_0x543c78);}return _0x322519['status'](_0x543c78)[_0xb07b('0x15')]();};}function respondWithResult(_0x1ec26b,_0x41ef02){_0x41ef02=_0x41ef02||0xc8;return function(_0x21fabd){if(_0x21fabd){return _0x1ec26b[_0xb07b('0x16')](_0x41ef02)[_0xb07b('0x17')](_0x21fabd);}};}function respondWithFilteredResult(_0x323610,_0x16440d){return function(_0x1b1716){if(_0x1b1716){var _0x3cfaa3=_0x1b1716['count'],_0x4f5698=_0x16440d[_0xb07b('0x18')],_0x3448df=_0x16440d[_0xb07b('0x18')]+_0x16440d[_0xb07b('0x19')],_0x1048c9;if(_0x3448df>=_0x3cfaa3){_0x3448df=_0x3cfaa3;_0x1048c9=0xc8;}else{_0x1048c9=0xce;}_0x323610['status'](_0x1048c9);return _0x323610[_0xb07b('0x1a')](_0xb07b('0x1b'),_0x4f5698+'-'+_0x3448df+'/'+_0x3cfaa3)['json'](_0x1b1716);}return null;};}function patchUpdates(_0x439903){return function(_0x718c25){try{jsonpatch[_0xb07b('0x1c')](_0x718c25,_0x439903,!![]);}catch(_0x1c10a3){return BPromise[_0xb07b('0x1d')](_0x1c10a3);}return _0x718c25['save']();};}function saveUpdates(_0x1b4b20,_0x5d52db){return function(_0x1e6020){if(_0x1e6020){return _0x1e6020[_0xb07b('0x1e')](_0x1b4b20)[_0xb07b('0x1f')](function(_0x823c54){return _0x823c54;});}return null;};}function removeEntity(_0x581393,_0x469ac){return function(_0x432435){if(_0x432435){return _0x432435[_0xb07b('0x20')]()[_0xb07b('0x1f')](function(){var _0x489c96=_0x432435[_0xb07b('0x21')]({'plain':!![]});var _0x24e84f=_0xb07b('0x22');return db[_0xb07b('0x23')][_0xb07b('0x20')]({'where':{'type':_0x24e84f,'resourceId':_0x489c96['id']}})[_0xb07b('0x1f')](function(){return _0x432435;});})[_0xb07b('0x1f')](function(){_0x581393['status'](0xcc)['end']();});}};}function handleEntityNotFound(_0x14e5ff,_0x4a6638){return function(_0x192641){if(!_0x192641){_0x14e5ff[_0xb07b('0x24')](0x194);}return _0x192641;};}function handleError(_0x56ff28,_0x212ce1){_0x212ce1=_0x212ce1||0x1f4;return function(_0x4d7606){logger['error'](_0x4d7606[_0xb07b('0x25')]);if(_0x4d7606[_0xb07b('0x26')]){delete _0x4d7606[_0xb07b('0x26')];}_0x56ff28['status'](_0x212ce1)['send'](_0x4d7606);};}exports[_0xb07b('0x27')]=function(_0x2c4d60,_0x1c59e5){var _0x264b48={},_0x58ac03={},_0x349903={'count':0x0,'rows':[]};var _0x5856a0=_[_0xb07b('0x28')](db['JscriptyProject'][_0xb07b('0x29')],function(_0xa0a963){return{'name':_0xa0a963[_0xb07b('0x2a')],'type':_0xa0a963[_0xb07b('0x2b')][_0xb07b('0x2c')]};});_0x58ac03[_0xb07b('0x2d')]=_[_0xb07b('0x28')](_0x5856a0,_0xb07b('0x26'));_0x58ac03[_0xb07b('0x2e')]=_[_0xb07b('0x2f')](_0x2c4d60['query']);_0x58ac03[_0xb07b('0x30')]=_[_0xb07b('0x31')](_0x58ac03[_0xb07b('0x2d')],_0x58ac03['query']);_0x264b48[_0xb07b('0x32')]=_[_0xb07b('0x31')](_0x58ac03['model'],qs[_0xb07b('0x33')](_0x2c4d60['query'][_0xb07b('0x33')]));_0x264b48[_0xb07b('0x32')]=_0x264b48[_0xb07b('0x32')][_0xb07b('0x34')]?_0x264b48[_0xb07b('0x32')]:_0x58ac03[_0xb07b('0x2d')];if(!_0x2c4d60['query'][_0xb07b('0x35')](_0xb07b('0x36'))){_0x264b48[_0xb07b('0x19')]=qs['limit'](_0x2c4d60[_0xb07b('0x2e')][_0xb07b('0x19')]);_0x264b48[_0xb07b('0x18')]=qs[_0xb07b('0x18')](_0x2c4d60[_0xb07b('0x2e')]['offset']);}_0x264b48['order']=qs['sort'](_0x2c4d60[_0xb07b('0x2e')][_0xb07b('0x37')]);_0x264b48['where']=qs[_0xb07b('0x30')](_[_0xb07b('0x38')](_0x2c4d60[_0xb07b('0x2e')],_0x58ac03[_0xb07b('0x30')]),_0x5856a0);if(_0x2c4d60['query'][_0xb07b('0x39')]){_0x264b48[_0xb07b('0x3a')]=_[_0xb07b('0x3b')](_0x264b48[_0xb07b('0x3a')],{'$or':_[_0xb07b('0x28')](_0x5856a0,function(_0x12b295){if(_0x12b295[_0xb07b('0x2b')]!==_0xb07b('0x3c')){var _0x193b0a={};_0x193b0a[_0x12b295[_0xb07b('0x26')]]={'$like':'%'+_0x2c4d60['query'][_0xb07b('0x39')]+'%'};return _0x193b0a;}})});}_0x264b48=_[_0xb07b('0x3b')]({},_0x264b48,_0x2c4d60[_0xb07b('0x3d')]);var _0x162dfc={'where':_0x264b48['where']};return db[_0xb07b('0x3e')][_0xb07b('0x3f')](_0x162dfc)[_0xb07b('0x1f')](function(_0x298e1a){_0x349903[_0xb07b('0x3f')]=_0x298e1a;if(_0x2c4d60[_0xb07b('0x2e')][_0xb07b('0x40')]){_0x264b48[_0xb07b('0x41')]=[{'all':!![]}];}return db[_0xb07b('0x3e')]['findAll'](_0x264b48);})[_0xb07b('0x1f')](function(_0x41638c){_0x349903[_0xb07b('0x42')]=_0x41638c;return _0x349903;})[_0xb07b('0x1f')](respondWithFilteredResult(_0x1c59e5,_0x264b48))['catch'](handleError(_0x1c59e5,null));};exports['show']=function(_0x1660c2,_0x18017f){var _0x57e85f={'raw':![],'where':{'id':_0x1660c2[_0xb07b('0x43')]['id']}},_0x393014={};_0x393014['model']=_['keys'](db['JscriptyProject']['rawAttributes']);_0x393014[_0xb07b('0x2e')]=_[_0xb07b('0x2f')](_0x1660c2['query']);_0x393014['filters']=_[_0xb07b('0x31')](_0x393014[_0xb07b('0x2d')],_0x393014[_0xb07b('0x2e')]);_0x57e85f[_0xb07b('0x32')]=_['intersection'](_0x393014[_0xb07b('0x2d')],qs[_0xb07b('0x33')](_0x1660c2['query']['fields']));_0x57e85f[_0xb07b('0x32')]=_0x57e85f[_0xb07b('0x32')][_0xb07b('0x34')]?_0x57e85f[_0xb07b('0x32')]:_0x393014['model'];if(_0x1660c2[_0xb07b('0x2e')]['includeAll']){_0x57e85f[_0xb07b('0x41')]=[{'all':!![]}];}_0x57e85f=_[_0xb07b('0x3b')]({},_0x57e85f,_0x1660c2[_0xb07b('0x3d')]);return db[_0xb07b('0x3e')][_0xb07b('0x44')](_0x57e85f)[_0xb07b('0x1f')](handleEntityNotFound(_0x18017f,null))[_0xb07b('0x1f')](respondWithResult(_0x18017f,null))['catch'](handleError(_0x18017f,null));};exports['create']=function(_0x21d638,_0x28d039){return db[_0xb07b('0x3e')][_0xb07b('0x45')](_0x21d638[_0xb07b('0x46')],{})['then'](function(_0x2d9357){var _0x3e6b4e=_0x21d638[_0xb07b('0x47')]['get']({'plain':!![]});if(!_0x3e6b4e)throw new Error(_0xb07b('0x48'));if(_0x3e6b4e['role']===_0xb07b('0x47')){var _0x1458c7=_0x2d9357[_0xb07b('0x21')]({'plain':!![]});var _0x16c941='Projects';return db['UserProfileSection'][_0xb07b('0x44')]({'where':{'name':_0x16c941,'userProfileId':_0x3e6b4e['userProfileId']},'raw':!![]})[_0xb07b('0x1f')](function(_0x3a6988){if(_0x3a6988&&_0x3a6988[_0xb07b('0x49')]===0x0){return db[_0xb07b('0x23')][_0xb07b('0x45')]({'name':_0x1458c7[_0xb07b('0x26')],'resourceId':_0x1458c7['id'],'type':_0x3a6988[_0xb07b('0x26')],'sectionId':_0x3a6988['id']},{})['then'](function(){return _0x2d9357;});}else{return _0x2d9357;}})[_0xb07b('0x4a')](function(_0xbf3869){logger[_0xb07b('0x4b')](_0xb07b('0x4c'),_0xbf3869);throw _0xbf3869;});}return _0x2d9357;})[_0xb07b('0x1f')](respondWithResult(_0x28d039,0xc9))[_0xb07b('0x4a')](handleError(_0x28d039,null));};exports['clone']=function(_0x41c5fa,_0x4c2e88){var _0x54f6b9={'where':{'id':_0x41c5fa['params']['id']}},_0x502c13={};_0x502c13[_0xb07b('0x2d')]=_['keys'](db[_0xb07b('0x3e')]['rawAttributes']);_0x54f6b9[_0xb07b('0x32')]=_[_0xb07b('0x31')](_0x502c13[_0xb07b('0x2d')],qs[_0xb07b('0x33')](_0x41c5fa[_0xb07b('0x2e')][_0xb07b('0x33')]));_0x54f6b9[_0xb07b('0x32')]=_0x54f6b9[_0xb07b('0x32')][_0xb07b('0x34')]?_0x54f6b9[_0xb07b('0x32')]:_0x502c13[_0xb07b('0x2d')];if(_0x41c5fa['query'][_0xb07b('0x40')]){_0x54f6b9[_0xb07b('0x41')]=[{'all':!![]}];}_0x54f6b9=_['merge']({},_0x54f6b9,_0x41c5fa['options']);return db[_0xb07b('0x3e')][_0xb07b('0x44')](_0x54f6b9)[_0xb07b('0x1f')](handleEntityNotFound(_0x4c2e88,null))[_0xb07b('0x1f')](function(_0x4254a7){if(_0x4254a7){var _0x5631d6=_0x4254a7[_0xb07b('0x21')]({'plain':!![]});_0x5631d6=qs[_0xb07b('0x4d')](_0x5631d6,['id',_0xb07b('0x4e'),'updatedAt']);_0x41c5fa['body']=_[_0xb07b('0x4d')](_0x41c5fa[_0xb07b('0x46')],['id','createdAt',_0xb07b('0x4f')]);return db['JscriptyProject'][_0xb07b('0x45')](_[_0xb07b('0x3b')](_0x5631d6,_0x41c5fa[_0xb07b('0x46')]),{'include':_0x41c5fa[_0xb07b('0x2e')][_0xb07b('0x40')]?[{'all':!![]}]:undefined})['then'](function(_0x563aa5){var _0x1d95ee=_0x41c5fa[_0xb07b('0x47')][_0xb07b('0x21')]({'plain':!![]});if(!_0x1d95ee)throw new Error(_0xb07b('0x48'));if(_0x1d95ee['role']===_0xb07b('0x47')){var _0x34ba5b=_0x563aa5['get']({'plain':!![]});var _0x48c674=_0xb07b('0x22');return db[_0xb07b('0x50')]['find']({'where':{'name':_0x48c674,'userProfileId':_0x1d95ee[_0xb07b('0x51')]},'raw':!![]})[_0xb07b('0x1f')](function(_0x2bf686){if(_0x2bf686&&_0x2bf686[_0xb07b('0x49')]===0x0){return db[_0xb07b('0x23')][_0xb07b('0x45')]({'name':_0x34ba5b[_0xb07b('0x26')],'resourceId':_0x34ba5b['id'],'type':_0x2bf686[_0xb07b('0x26')],'sectionId':_0x2bf686['id']},{})['then'](function(){return _0x563aa5;});}else{return _0x563aa5;}})['catch'](function(_0x567f3a){logger[_0xb07b('0x4b')](_0xb07b('0x4c'),_0x567f3a);throw _0x567f3a;});}return _0x563aa5;});}})['then'](respondWithResult(_0x4c2e88,0xc9))[_0xb07b('0x4a')](handleError(_0x4c2e88,null));};exports['update']=function(_0x418107,_0x5d152d){if(_0x418107['body']['id']){delete _0x418107['body']['id'];}return db[_0xb07b('0x3e')]['find']({'where':{'id':_0x418107[_0xb07b('0x43')]['id']}})[_0xb07b('0x1f')](handleEntityNotFound(_0x5d152d,null))[_0xb07b('0x1f')](saveUpdates(_0x418107[_0xb07b('0x46')],null))['then'](respondWithResult(_0x5d152d,null))[_0xb07b('0x4a')](handleError(_0x5d152d,null));};exports[_0xb07b('0x20')]=function(_0x3756f9,_0x2ce273){return db[_0xb07b('0x3e')][_0xb07b('0x44')]({'where':{'id':_0x3756f9['params']['id']}})['then'](handleEntityNotFound(_0x2ce273,null))[_0xb07b('0x1f')](removeEntity(_0x2ce273,null))['catch'](handleError(_0x2ce273,null));};exports[_0xb07b('0x52')]=function(_0x5ec5af,_0x1347a1,_0x178d02){var _0x5636ea={'raw':!![],'where':{}};var _0xff080f={};var _0xbb651a={'count':0x0,'rows':[]};return db[_0xb07b('0x3e')][_0xb07b('0x53')]({'where':{'id':_0x5ec5af[_0xb07b('0x43')]['id']}})['then'](handleEntityNotFound(_0x1347a1,null))[_0xb07b('0x1f')](function(_0x57c6a6){if(_0x57c6a6){_0xff080f['model']=_[_0xb07b('0x2f')](db[_0xb07b('0x54')][_0xb07b('0x29')]);_0xff080f[_0xb07b('0x2e')]=_[_0xb07b('0x2f')](_0x5ec5af['query']);_0xff080f[_0xb07b('0x30')]=_[_0xb07b('0x31')](_0xff080f[_0xb07b('0x2d')],_0xff080f[_0xb07b('0x2e')]);_0x5636ea[_0xb07b('0x32')]=_['intersection'](_0xff080f[_0xb07b('0x2d')],qs[_0xb07b('0x33')](_0x5ec5af[_0xb07b('0x2e')][_0xb07b('0x33')]));_0x5636ea[_0xb07b('0x32')]=_0x5636ea[_0xb07b('0x32')][_0xb07b('0x34')]?_0x5636ea[_0xb07b('0x32')]:_0xff080f[_0xb07b('0x2d')];if(!_0x5ec5af[_0xb07b('0x2e')][_0xb07b('0x35')](_0xb07b('0x36'))){_0x5636ea['limit']=qs[_0xb07b('0x19')](_0x5ec5af['query']['limit']);_0x5636ea['offset']=qs['offset'](_0x5ec5af[_0xb07b('0x2e')][_0xb07b('0x18')]);}_0x5636ea['order']=qs[_0xb07b('0x37')](_0x5ec5af[_0xb07b('0x2e')][_0xb07b('0x37')]);_0x5636ea[_0xb07b('0x3a')]=qs[_0xb07b('0x30')](_[_0xb07b('0x38')](_0x5ec5af['query'],_0xff080f[_0xb07b('0x30')]));_0x5636ea[_0xb07b('0x3a')]['ProjectId']=_0x57c6a6['id'];if(_0x5ec5af[_0xb07b('0x2e')][_0xb07b('0x39')]){_0x5636ea[_0xb07b('0x3a')]=_[_0xb07b('0x3b')](_0x5636ea['where'],{'$or':_[_0xb07b('0x28')](_0x5636ea[_0xb07b('0x32')],function(_0x2c179b){var _0x314b2d={};_0x314b2d[_0x2c179b]={'$like':'%'+_0x5ec5af[_0xb07b('0x2e')][_0xb07b('0x39')]+'%'};return _0x314b2d;})});}_0x5636ea=_[_0xb07b('0x3b')]({},_0x5636ea,_0x5ec5af[_0xb07b('0x3d')]);return db['JscriptySessionReport'][_0xb07b('0x3f')]({'where':_0x5636ea['where']})[_0xb07b('0x1f')](function(_0x61fa38){_0xbb651a[_0xb07b('0x3f')]=_0x61fa38;if(_0x5ec5af[_0xb07b('0x2e')][_0xb07b('0x40')]){_0x5636ea[_0xb07b('0x41')]=[{'all':!![]}];}return db['JscriptySessionReport']['findAll'](_0x5636ea);})[_0xb07b('0x1f')](function(_0x5bfd6c){_0xbb651a[_0xb07b('0x42')]=_0x5bfd6c;return _0xbb651a;});}})['then'](respondWithFilteredResult(_0x1347a1,_0x5636ea))[_0xb07b('0x4a')](handleError(_0x1347a1,null));};exports[_0xb07b('0x55')]=function(_0x73b40b,_0x7c4c3,_0x44e9d8){var _0x1d6984={'raw':!![],'where':{}};var _0x567675={};var _0x46e2bd={'count':0x0,'rows':[]};return db['JscriptyProject'][_0xb07b('0x53')]({'where':{'id':_0x73b40b[_0xb07b('0x43')]['id']}})['then'](handleEntityNotFound(_0x7c4c3,null))['then'](function(_0x13f5ce){if(_0x13f5ce){_0x567675[_0xb07b('0x2d')]=_[_0xb07b('0x2f')](db[_0xb07b('0x56')][_0xb07b('0x29')]);_0x567675[_0xb07b('0x2e')]=_[_0xb07b('0x2f')](_0x73b40b[_0xb07b('0x2e')]);_0x567675['filters']=_[_0xb07b('0x31')](_0x567675[_0xb07b('0x2d')],_0x567675['query']);_0x1d6984[_0xb07b('0x32')]=_[_0xb07b('0x31')](_0x567675[_0xb07b('0x2d')],qs[_0xb07b('0x33')](_0x73b40b['query'][_0xb07b('0x33')]));_0x1d6984[_0xb07b('0x32')]=_0x1d6984[_0xb07b('0x32')][_0xb07b('0x34')]?_0x1d6984[_0xb07b('0x32')]:_0x567675[_0xb07b('0x2d')];if(!_0x73b40b['query'][_0xb07b('0x35')](_0xb07b('0x36'))){_0x1d6984[_0xb07b('0x19')]=qs[_0xb07b('0x19')](_0x73b40b['query']['limit']);_0x1d6984[_0xb07b('0x18')]=qs[_0xb07b('0x18')](_0x73b40b[_0xb07b('0x2e')][_0xb07b('0x18')]);}_0x1d6984[_0xb07b('0x57')]=qs['sort'](_0x73b40b['query'][_0xb07b('0x37')]);_0x1d6984[_0xb07b('0x3a')]=qs[_0xb07b('0x30')](_['pick'](_0x73b40b['query'],_0x567675[_0xb07b('0x30')]));_0x1d6984[_0xb07b('0x3a')]['ProjectId']=_0x13f5ce['id'];if(_0x73b40b[_0xb07b('0x2e')][_0xb07b('0x39')]){_0x1d6984[_0xb07b('0x3a')]=_[_0xb07b('0x3b')](_0x1d6984['where'],{'$or':_[_0xb07b('0x28')](_0x1d6984[_0xb07b('0x32')],function(_0x346c4d){var _0x22c8a3={};_0x22c8a3[_0x346c4d]={'$like':'%'+_0x73b40b['query'][_0xb07b('0x39')]+'%'};return _0x22c8a3;})});}_0x1d6984=_[_0xb07b('0x3b')]({},_0x1d6984,_0x73b40b[_0xb07b('0x3d')]);return db['JscriptyAnswerReport'][_0xb07b('0x3f')]({'where':_0x1d6984['where']})[_0xb07b('0x1f')](function(_0x4abcff){_0x46e2bd[_0xb07b('0x3f')]=_0x4abcff;if(_0x73b40b[_0xb07b('0x2e')]['includeAll']){_0x1d6984['include']=[{'all':!![]}];}return db['JscriptyAnswerReport']['findAll'](_0x1d6984);})[_0xb07b('0x1f')](function(_0x29e63e){_0x46e2bd[_0xb07b('0x42')]=_0x29e63e;return _0x46e2bd;});}})[_0xb07b('0x1f')](respondWithFilteredResult(_0x7c4c3,_0x1d6984))[_0xb07b('0x4a')](handleError(_0x7c4c3,null));};function char(_0x15caa5){return _0xb07b('0x58')===typeof _0x15caa5?String['fromCharCode']['apply'](null,arguments):_0x15caa5;}function needsEncapsulation(_0x27fe74){return!!_0x27fe74&&(_0x27fe74[_0xb07b('0x59')]()['indexOf'](char(0xd))>=0x0||_0x27fe74[_0xb07b('0x59')]()[_0xb07b('0x5a')](char(0xa))>=0x0||_0x27fe74['toString']()[_0xb07b('0x5a')](char(0x2c))>=0x0||_0x27fe74[_0xb07b('0x59')]()['indexOf'](char(0x22))>=0x0);}function encapsulate(_0x47e0aa){var _0x53c8d0=char(0x22),_0x13a428='\x5c'+char(0x22),_0x5584af=_0x47e0aa[_0xb07b('0x59')]()['replace'](new RegExp(_0x53c8d0,'g'),_0x13a428);return _0x53c8d0+_0x5584af+_0x53c8d0;}exports['getSummary']=function(_0x3dc823,_0x4c9d72,_0x262b76){var _0x14adfc,_0x40ded0;var _0xf5898a={'where':{'ProjectId':_0x3dc823[_0xb07b('0x43')]['id']}};if(_0x3dc823['query'][_0xb07b('0x5b')]){_0xf5898a[_0xb07b('0x3a')][_0xb07b('0x5c')]=JSON['parse'](_0x3dc823[_0xb07b('0x2e')][_0xb07b('0x5b')]);}return db[_0xb07b('0x54')][_0xb07b('0x5d')](_0xf5898a)[_0xb07b('0x1f')](handleEntityNotFound(_0x4c9d72,null))[_0xb07b('0x1f')](function(_0x4201fd){if(_0x4201fd){_0x14adfc=_0x4201fd;return db[_0xb07b('0x5e')][_0xb07b('0x5d')]({'where':{'SessionId':{'$in':_['map'](_0x14adfc,'id')},'ProjectId':_0x3dc823[_0xb07b('0x43')]['id']},'order':'-createdAt'});}})[_0xb07b('0x1f')](handleEntityNotFound(_0x4c9d72,null))[_0xb07b('0x1f')](function(_0x5d7f94){if(_0x5d7f94){_0x40ded0=_0x5d7f94;var _0xb5296d={};for(var _0x2bc8d4=0x0,_0x443eca=_0x40ded0['length'];_0x2bc8d4<_0x443eca;_0x2bc8d4++){if(!_0xb5296d['hasOwnProperty'](_0x40ded0[_0x2bc8d4][_0xb07b('0x5f')])){_0xb5296d[_0x40ded0[_0x2bc8d4][_0xb07b('0x5f')]]=needsEncapsulation(_0x40ded0[_0x2bc8d4][_0xb07b('0x60')])?encapsulate(_0x40ded0[_0x2bc8d4][_0xb07b('0x60')]):_0x40ded0[_0x2bc8d4][_0xb07b('0x60')];}}var _0x407fbe=[],_0x375f38={};for(var _0x512457=0x0,_0x2e4e1c=_0x14adfc['length'];_0x512457<_0x2e4e1c;_0x512457++){_0x375f38={'ProjectId':_0x3dc823[_0xb07b('0x43')]['id'],'SessionId':_0x14adfc[_0x512457]['id'],'StartTime':moment(_0x14adfc[_0x512457][_0xb07b('0x5c')])[_0xb07b('0x61')](_0xb07b('0x62'))};for(var _0x33333f=0x0,_0x1c7bf2=_0x40ded0[_0xb07b('0x34')];_0x33333f<_0x1c7bf2;_0x33333f++){if(_0x40ded0[_0x33333f][_0xb07b('0x63')]==_0x14adfc[_0x512457]['id']&&_0xb5296d['hasOwnProperty'](_0x40ded0[_0x33333f][_0xb07b('0x5f')])){_0x375f38[_0xb5296d[_0x40ded0[_0x33333f][_0xb07b('0x5f')]]]=_0x40ded0[_0x33333f][_0xb07b('0x64')];}}for(var _0x14f704 in _0xb5296d){if(!_0x375f38['hasOwnProperty'](_0xb5296d[_0x14f704])){_0x375f38[_0xb5296d[_0x14f704]]=null;}}_0x407fbe[_0xb07b('0x65')](_0x375f38);}return _0x407fbe;}})['then'](function(_0x3282c9){if(!_[_0xb07b('0x66')](_0x3282c9)){var _0x21e4fe=toCsv(_0x3282c9);var _0x19bc15=Date['now']();fs[_0xb07b('0x67')](util[_0xb07b('0x61')](_0xb07b('0x68'),_0x3dc823[_0xb07b('0x43')]['id'],_0x19bc15),_0x21e4fe);_0x4c9d72[_0xb07b('0x69')](_0xb07b('0x6a'),_0xb07b('0x6b')+util[_0xb07b('0x61')](_0xb07b('0x6c'),_0x3dc823[_0xb07b('0x43')]['id'],_0x19bc15));_0x4c9d72[_0xb07b('0x69')](_0xb07b('0x6d'),_0xb07b('0x6e'));return _0x4c9d72['download'](util[_0xb07b('0x61')](_0xb07b('0x68'),_0x3dc823[_0xb07b('0x43')]['id'],_0x19bc15));}else{return _0x4c9d72[_0xb07b('0x24')](0xcc);}})['catch'](handleError(_0x4c9d72,null));};