mirror of
				https://github.com/HabitRPG/habitica.git
				synced 2025-10-30 20:52:29 +01:00 
			
		
		
		
	* chore(scripts): BTS Challenge archive and username email jobbing * refactor(migration): use batching and sendTxn * fix(script): introduce delay for batching * fix(migration): correct import, fix delay promise, slower batching * fix(migration): add daterange * WIP(script): deletion helper for GDPR * fix(script): address code comments * refactor(script): use for loop * fix(script-runner): bad catch syntax * fix(script-runner): oops I did it again * fix(lint): name functions
		
			
				
	
	
		
			49 lines
		
	
	
		
			1.2 KiB
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
			
		
		
	
	
			49 lines
		
	
	
		
			1.2 KiB
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
| import monk from 'monk';
 | |
| import nconf from 'nconf';
 | |
| 
 | |
| /*
 | |
|  * Output data on users who completed all the To-Do tasks in the 2018 Back-to-School Challenge.
 | |
|  * User ID,Profile Name
 | |
|  */
 | |
| const CONNECTION_STRING = nconf.get('MIGRATION_CONNECT_STRING');
 | |
| const CHALLENGE_ID = '0acb1d56-1660-41a4-af80-9259f080b62b';
 | |
| 
 | |
| let dbUsers = monk(CONNECTION_STRING).get('users', { castIds: false });
 | |
| let dbTasks = monk(CONNECTION_STRING).get('tasks', { castIds: false });
 | |
| 
 | |
| function usersReport() {
 | |
|   console.info('User ID,Profile Name');
 | |
|   let userCount = 0;
 | |
| 
 | |
|   dbUsers.find(
 | |
|     {challenges: CHALLENGE_ID},
 | |
|     {fields:
 | |
|       {_id: 1, 'profile.name': 1}
 | |
|     },
 | |
|   ).each((user, {close, pause, resume}) => {
 | |
|     pause();
 | |
|     userCount++;
 | |
|     let completedTodos = 0;
 | |
|     return dbTasks.find(
 | |
|       {
 | |
|         userId: user._id,
 | |
|         'challenge.id': CHALLENGE_ID,
 | |
|         type: 'todo',
 | |
|       },
 | |
|       {fields: {completed: 1}}
 | |
|     ).each((task) => {
 | |
|       if (task.completed) completedTodos++;
 | |
|     }).then(() => {
 | |
|       if (completedTodos >= 7) {
 | |
|         console.info(`${user._id},${user.profile.name}`);
 | |
|       }
 | |
|       resume();
 | |
|     });
 | |
|   }).then(() => {
 | |
|     console.info(`${userCount} users reviewed`);
 | |
|     return process.exit(0);
 | |
|   });
 | |
| }
 | |
| 
 | |
| module.exports = usersReport;
 |