fix: 归档删除改为软删除
This commit is contained in:
@@ -395,7 +395,7 @@ export class RoomsService {
|
||||
async getRoomBeds(roomId: number): Promise<Bed[]> {
|
||||
const room = await this.repo.findOne({ where: { id: roomId } });
|
||||
if (!room) throw new NotFoundException('宿舍不存在');
|
||||
return this.bedRepo.find({ where: { roomId }, order: { bedNumber: 'ASC' } });
|
||||
return this.bedRepo.find({ where: { roomId, status: Not('archived') }, order: { bedNumber: 'ASC' } });
|
||||
}
|
||||
|
||||
async getRoomAvailableBeds(roomId: number): Promise<Bed[]> {
|
||||
@@ -437,15 +437,16 @@ export class RoomsService {
|
||||
async deleteBed(roomId: number, id: number): Promise<void> {
|
||||
const bed = await this.bedRepo.findOne({ where: { id, roomId } });
|
||||
if (!bed) throw new NotFoundException('床位不存在');
|
||||
if (bed.status === 'occupied') throw new BadRequestException('该床位有人入住,无法删除');
|
||||
await this.bedRepo.remove(bed);
|
||||
if (bed.status === 'occupied') throw new BadRequestException('该床位有人入住,无法归档');
|
||||
if (bed.status === 'archived') throw new BadRequestException('该床位已归档');
|
||||
await this.bedRepo.update(id, { status: 'archived' });
|
||||
}
|
||||
|
||||
async batchCreateBeds(roomId: number, dto: BatchCreateBedDto): Promise<Bed[]> {
|
||||
const room = await this.repo.findOne({ where: { id: roomId } });
|
||||
if (!room) throw new NotFoundException('宿舍不存在');
|
||||
if (room.status === 'archived') throw new BadRequestException('已归档宿舍不能添加床位');
|
||||
const existing = await this.bedRepo.find({ where: { roomId }, order: { bedNumber: 'ASC' } });
|
||||
const existing = await this.bedRepo.find({ where: { roomId, status: Not('archived') }, order: { bedNumber: 'ASC' } });
|
||||
this.assertCanAddBedsFromCount(room, existing.length, dto.count);
|
||||
const numbers = existing.map((b) => {
|
||||
const match = b.bedNumber.match(/^\d+/);
|
||||
@@ -495,7 +496,7 @@ export class RoomsService {
|
||||
async getRoomLockers(roomId: number): Promise<Locker[]> {
|
||||
const room = await this.repo.findOne({ where: { id: roomId } });
|
||||
if (!room) throw new NotFoundException('宿舍不存在');
|
||||
return this.lockerRepo.find({ where: { roomId }, order: { lockerNumber: 'ASC' } });
|
||||
return this.lockerRepo.find({ where: { roomId, status: Not('archived') }, order: { lockerNumber: 'ASC' } });
|
||||
}
|
||||
|
||||
async getRoomAvailableLockers(roomId: number): Promise<Locker[]> {
|
||||
@@ -538,8 +539,9 @@ export class RoomsService {
|
||||
async deleteLocker(roomId: number, id: number): Promise<void> {
|
||||
const locker = await this.lockerRepo.findOne({ where: { id, roomId } });
|
||||
if (!locker) throw new NotFoundException('柜子不存在');
|
||||
if (locker.status === 'occupied') throw new BadRequestException('该柜子有人占用,无法删除');
|
||||
await this.lockerRepo.remove(locker);
|
||||
if (locker.status === 'occupied') throw new BadRequestException('该柜子有人占用,无法归档');
|
||||
if (locker.status === 'archived') throw new BadRequestException('该柜子已归档');
|
||||
await this.lockerRepo.update(id, { status: 'archived' });
|
||||
}
|
||||
|
||||
async batchCreateLockers(roomId: number, dto: BatchCreateLockerDto): Promise<Locker[]> {
|
||||
@@ -547,7 +549,7 @@ export class RoomsService {
|
||||
if (!room) throw new NotFoundException('宿舍不存在');
|
||||
if (room.status === 'archived') throw new BadRequestException('已归档宿舍不能添加柜子');
|
||||
const existing = await this.lockerRepo.find({
|
||||
where: { roomId },
|
||||
where: { roomId, status: Not('archived') },
|
||||
order: { lockerNumber: 'ASC' },
|
||||
});
|
||||
const numbers = existing.map((b) => {
|
||||
|
||||
Reference in New Issue
Block a user