feat: add Student-User association and activate all notification TODOs
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { Module } from '@nestjs/common';
|
||||
import { TypeOrmModule } from '@nestjs/typeorm';
|
||||
import { Student } from '../entities/student.entity';
|
||||
import { Deposit } from '../entities/deposit.entity';
|
||||
import { DepositInstallment } from '../entities/deposit-installment.entity';
|
||||
import { DepositsService } from './deposits.service';
|
||||
@@ -8,7 +9,7 @@ import { OperationLogsModule } from '../operation-logs/operation-logs.module';
|
||||
import { NotificationsModule } from '../notifications/notifications.module';
|
||||
|
||||
@Module({
|
||||
imports: [TypeOrmModule.forFeature([Deposit, DepositInstallment]), OperationLogsModule, NotificationsModule],
|
||||
imports: [TypeOrmModule.forFeature([Deposit, DepositInstallment, Student]), OperationLogsModule, NotificationsModule],
|
||||
controllers: [DepositsController],
|
||||
providers: [DepositsService],
|
||||
exports: [DepositsService],
|
||||
|
||||
Reference in New Issue
Block a user