refactor(rooms): remove dorm gender restrictions
This commit is contained in:
@@ -61,14 +61,8 @@ export class OccupanciesService {
|
||||
const count = await this.repo.count({ where: { roomId: dto.roomId, checkOutDate: IsNull() } });
|
||||
if (count >= room.capacity) throw new BadRequestException('宿舍已满');
|
||||
|
||||
// 房间级别性别约束
|
||||
const student = await this.studentRepo.findOne({ where: { id: dto.studentId } });
|
||||
if (!student) throw new NotFoundException('学生不存在');
|
||||
if (student.gender && room.gender && student.gender !== room.gender) {
|
||||
throw new BadRequestException(
|
||||
`该宿舍当前为${room.gender}生寝室,${student.gender}生无法入住`,
|
||||
);
|
||||
}
|
||||
|
||||
// 床位校验
|
||||
if (dto.bedId) {
|
||||
@@ -107,11 +101,6 @@ export class OccupanciesService {
|
||||
await this.lockerRepo.update(dto.lockerId, { status: 'occupied' });
|
||||
}
|
||||
|
||||
// 首位入住者确定房间性别
|
||||
if ((student.gender === '男' || student.gender === '女') && !room.gender) {
|
||||
await this.roomRepo.update(room.id, { gender: student.gender });
|
||||
}
|
||||
|
||||
// 更新宿舍状态
|
||||
if (count + 1 >= room.capacity) {
|
||||
await this.roomRepo.update(room.id, { status: 'full' });
|
||||
@@ -173,12 +162,6 @@ export class OccupanciesService {
|
||||
});
|
||||
if (count >= newRoom.capacity) throw new BadRequestException('目标宿舍已满');
|
||||
|
||||
// 换房性别约束检查
|
||||
const student = await runner.manager.findOne(Student, { where: { id: oldOcc.studentId } });
|
||||
if (student?.gender && newRoom.gender && student.gender !== newRoom.gender) {
|
||||
throw new BadRequestException(`目标宿舍为${newRoom.gender}生寝室,无法换入`);
|
||||
}
|
||||
|
||||
// 新床位校验
|
||||
if (dto.newBedId) {
|
||||
const newBed = await runner.manager.findOne(Bed, {
|
||||
@@ -223,11 +206,6 @@ export class OccupanciesService {
|
||||
await runner.manager.update(Locker, dto.newLockerId, { status: 'occupied' });
|
||||
}
|
||||
|
||||
// 首位入住者确定新房性别
|
||||
if ((student?.gender === '男' || student?.gender === '女') && !newRoom.gender) {
|
||||
await runner.manager.update(Room, newRoom.id, { gender: student.gender });
|
||||
}
|
||||
|
||||
if (count + 1 >= newRoom.capacity) {
|
||||
await runner.manager.update(Room, newRoom.id, { status: 'full' });
|
||||
}
|
||||
@@ -472,15 +450,6 @@ export class OccupanciesService {
|
||||
continue;
|
||||
}
|
||||
|
||||
// 5. 房间级别性别约束
|
||||
if (student.gender && room.gender && student.gender !== room.gender) {
|
||||
errors.push(
|
||||
`第${rowNum}行: 宿舍 ${row.roomNumber} 为${room.gender}生寝室,${row.name}(${student.gender})无法入住,跳过`,
|
||||
);
|
||||
skipped++;
|
||||
continue;
|
||||
}
|
||||
|
||||
// 6. 创建入住记录
|
||||
const checkInDate = row.checkInDate?.trim() || new Date().toISOString().split('T')[0];
|
||||
const occData: any = {
|
||||
@@ -497,16 +466,6 @@ export class OccupanciesService {
|
||||
}
|
||||
await this.repo.save(this.repo.create(occData));
|
||||
|
||||
// 7. 首位入住者确定房间性别
|
||||
if (
|
||||
!row.checkOutDate?.trim() &&
|
||||
(student.gender === '男' || student.gender === '女') &&
|
||||
!room.gender
|
||||
) {
|
||||
await this.roomRepo.update(room.id, { gender: student.gender });
|
||||
room.gender = student.gender;
|
||||
}
|
||||
|
||||
// 8. 更新宿舍状态
|
||||
if (!row.checkOutDate?.trim() && count + 1 >= room.capacity) {
|
||||
await this.roomRepo.update(room.id, { status: 'full' });
|
||||
|
||||
Reference in New Issue
Block a user