Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions auth/schemas/authUsers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ export const AuthUsersSchema = new mongoose.Schema({
documento: String,
password: String,
foto: String,
lastLogin: Date,
authMethod: {
type: String,
required: false
Expand Down
3 changes: 2 additions & 1 deletion auth/schemas/permisos-organizaciones.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ export const PermisosOrganizacionesSchema = new Schema({
perfiles: [{
_id: Types.ObjectId,
nombre: String
}]
}],
lastLogin: Date
});
PermisosOrganizacionesSchema.plugin(AuditPlugin);

10 changes: 5 additions & 5 deletions core/tm/controller/authUser.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
/**
* Función que verifica la última vez que se actualizó/logueó un usuario.
* Si es mayor o igual a 1 mes se desactiva,
* Si es mayor o igual a 3 meses se desactiva,
* cambiando la variable activo que se encuentra en cada organización a false.
*/
import * as moment from 'moment';
import { AuthUsers } from '../../../auth/schemas/authUsers';

export async function verificarUltimoLogueo(done) {
const usuarios: any = AuthUsers.find({ 'organizaciones.activo': true }).cursor({ batchSize: 100 });
const fLimite = moment().subtract(1, 'months').toDate();
const fSinLogin = moment().subtract(2, 'months').toDate();
const usuarios = AuthUsers.find({ 'organizaciones.activo': true }).cursor({ batchSize: 100 });
const fLimite = moment().subtract(3, 'months').toDate();
const fSinLogin = moment().subtract(4, 'months').toDate();
const esMenor = (fecha) => (fecha && fecha < fLimite);
for await (const user of usuarios) {
for (const org of user.organizaciones) {
const lastUpdate = user.updatedAt || user.createdAt;
const lastUpdate = org.updatedAt || org.createdAt || user.updatedAt || user.createdAt;
if (esMenor(lastUpdate) && esMenor(org.lastLogin)) {
org.activo = false;
}
Expand Down