// middlewares/trackActivity.middleware.js
const { PrismaClient } = require("@prisma/client");
const prisma = new PrismaClient();

async function trackActivity(req, res, next) {
  try {
    if (req.user?.id) {  // assuming authMiddleware sets req.user
      await prisma.user.update({
        where: { id: req.user.id },
        data: { lastActivity: new Date() },
      });
    }
  } catch (err) {
    console.error("Failed to track user activity", err);
  }
  next();
}

module.exports = { trackActivity };