forked from wangziqi/gongxue-base
feat: add Student-User association and activate all notification TODOs
This commit is contained in:
@@ -13,6 +13,9 @@ import {
|
||||
UseInterceptors,
|
||||
UploadedFile,
|
||||
} from '@nestjs/common';
|
||||
import { InjectRepository } from '@nestjs/typeorm';
|
||||
import { Repository } from 'typeorm';
|
||||
import { Student } from '../entities/student.entity';
|
||||
import { FileInterceptor } from '@nestjs/platform-express';
|
||||
import type { Response } from 'express';
|
||||
import { OccupanciesService } from './occupancies.service';
|
||||
@@ -32,6 +35,7 @@ export class OccupanciesController {
|
||||
private service: OccupanciesService,
|
||||
private logService: OperationLogsService,
|
||||
private readonly notificationsService: NotificationsService,
|
||||
@InjectRepository(Student) private studentRepo: Repository<Student>,
|
||||
) {}
|
||||
|
||||
@Get()
|
||||
@@ -81,7 +85,18 @@ export class OccupanciesController {
|
||||
ipAddress,
|
||||
userAgent,
|
||||
});
|
||||
// TODO: Send notification for check_in — studentId→userId mapping unavailable
|
||||
// Send check_in notification
|
||||
try {
|
||||
const student = await this.studentRepo.findOne({ where: { id: dto.studentId } });
|
||||
if (student?.userId) {
|
||||
void this.notificationsService.create({
|
||||
recipientIds: [student.userId],
|
||||
type: NotificationType.CHECK_IN,
|
||||
title: '入住通知',
|
||||
content: `您已入住房间 #${dto.roomId}`,
|
||||
});
|
||||
}
|
||||
} catch (_) { /* don't block response */ }
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -100,7 +115,18 @@ export class OccupanciesController {
|
||||
ipAddress,
|
||||
userAgent,
|
||||
});
|
||||
// TODO: Send notification for check_out — studentId→userId mapping unavailable
|
||||
// Send check_out notification
|
||||
try {
|
||||
const student = await this.studentRepo.findOne({ where: { id: result.studentId } });
|
||||
if (student?.userId) {
|
||||
void this.notificationsService.create({
|
||||
recipientIds: [student.userId],
|
||||
type: NotificationType.CHECK_OUT,
|
||||
title: '退宿通知',
|
||||
content: `您已退宿房间 #${result.roomId}`,
|
||||
});
|
||||
}
|
||||
} catch (_) { /* don't block response */ }
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user