transcreation-backend / models /AccessSession.js
Tristan Yu
feat(sessions): persist visitor/student/admin heartbeats and add login summary API
195c966
raw
history blame contribute delete
641 Bytes
const mongoose = require('mongoose');
const accessSessionSchema = new mongoose.Schema({
email: { type: String, index: true },
role: { type: String, enum: ['student', 'instructor', 'admin', 'visitor'], index: true },
startAt: { type: Date, default: Date.now, index: true },
lastSeen: { type: Date, default: Date.now, index: true },
userAgent: { type: String },
ip: { type: String },
path: { type: String }
}, { timestamps: true });
// Compound index for querying active sessions by email + startAt
accessSessionSchema.index({ email: 1, startAt: -1 });
module.exports = mongoose.model('AccessSession', accessSessionSchema);