feat: remove inactive users (scheduler)

This commit is contained in:
Sonny
2024-09-18 16:58:51 +02:00
parent b0e3bfa0f6
commit 05f067a430
13 changed files with 779 additions and 830 deletions

View File

@@ -4,6 +4,8 @@ import logger from '@adonisjs/core/services/logger';
import db from '@adonisjs/lucid/services/db';
import { RouteName } from '@izzyjs/route/types';
const INACTIVE_USER_THRESHOLD = 7;
export default class UsersController {
private redirectTo: RouteName = 'auth.login';
@@ -75,4 +77,18 @@ export default class UsersController {
.withCount('collections', (q) => q.as('totalCollections'))
.withCount('links', (q) => q.as('totalLinks'));
}
async getAllInactiveUsers() {
const users = await this.getAllUsersWithTotalRelations();
const inactiveUsers = users.filter((user) => {
const totalLinks = Number(user.$extras.totalLinks);
const totalCollections = Number(user.$extras.totalCollections);
const isOlderThan7Days =
Math.abs(user.updatedAt.diffNow('days').days) > INACTIVE_USER_THRESHOLD;
return (totalLinks === 0 || totalCollections === 0) && isOlderThan7Days;
});
return inactiveUsers ?? [];
}
}