feat:添加登录功能

This commit is contained in:
2025-11-10 13:58:06 +08:00
parent 49f9b28091
commit 2e2caeaab5
36 changed files with 1076 additions and 458 deletions

View File

@@ -1,7 +1,6 @@
import type { Request, Response } from 'express';
import { env } from '../../config/env.js';
import { TransactionModel } from '../../models/transaction.model.js';
import { getDefaultUserId } from '../../services/user-context.js';
const maskSecret = (secret?: string | null) => {
if (!secret) return null;
@@ -10,8 +9,10 @@ const maskSecret = (secret?: string | null) => {
};
export const getNotificationStatus = async (req: Request, res: Response) => {
const userId = await getDefaultUserId();
const filter = { userId, source: 'notification' as const };
if (!req.user) {
return res.status(401).json({ message: 'Authentication required' });
}
const filter = { userId: req.user.id, source: 'notification' as const };
const count = await TransactionModel.countDocuments(filter);
const latest = (await TransactionModel.findOne(filter).sort({ createdAt: -1 }).lean()) as
| { createdAt?: Date }

View File

@@ -1,8 +1,11 @@
import { Router } from 'express';
import { authenticate } from '../../middlewares/authenticate.js';
import { getNotificationStatus } from './notifications.controller.js';
const router = Router();
router.use(authenticate);
router.get('/status', getNotificationStatus);
export default router;