feat: add Student-User association and activate all notification TODOs

This commit is contained in:
2026-07-05 23:42:22 +08:00
parent 9e6c136ef0
commit 9d9d4719b5
6 changed files with 116 additions and 10 deletions

View File

@@ -10,6 +10,9 @@ import {
UseGuards,
Request,
} from '@nestjs/common';
import { InjectRepository } from '@nestjs/typeorm';
import { Repository } from 'typeorm';
import { Student } from '../entities/student.entity';
import { DepositsService } from './deposits.service';
import { NotificationsService } from '../notifications/notifications.service';
import { NotificationType } from '../entities/notification.entity';
@@ -26,6 +29,7 @@ export class DepositsController {
private service: DepositsService,
private logService: OperationLogsService,
private readonly notificationsService: NotificationsService,
@InjectRepository(Student) private studentRepo: Repository<Student>,
) {}
@Get()
@@ -71,7 +75,18 @@ export class DepositsController {
ipAddress,
userAgent,
});
// TODO: Send notification for deposit_due — studentId→userId mapping unavailable
// Send deposit_due notification
try {
const student = await this.studentRepo.findOne({ where: { id: dto.studentId } });
if (student?.userId) {
void this.notificationsService.create({
recipientIds: [student.userId],
type: 'deposit_due',
title: '押金待缴',
content: `您有一笔押金待缴纳,金额: ¥${dto.amount}`,
});
}
} catch (_) { /* don't block response */ }
return result;
}
@@ -115,7 +130,18 @@ export class DepositsController {
ipAddress,
userAgent,
});
// TODO: Send notification for deposit_refunded — studentId→userId mapping unavailable
// Send deposit_refunded notification
try {
const student = await this.studentRepo.findOne({ where: { id: result.studentId } });
if (student?.userId) {
void this.notificationsService.create({
recipientIds: [student.userId],
type: 'deposit_refunded',
title: '押金已退还',
content: `您的押金已退还,退还¥${result.refundAmount},扣除¥${result.deductionAmount}`,
});
}
} catch (_) { /* don't block response */ }
return result;
}