fix: restore CampusScope injection, fix batchCreate bed/locker numbering
This commit is contained in:
@@ -17,6 +17,7 @@ export class RoomsService {
|
|||||||
@InjectRepository(Room) private repo: Repository<Room>,
|
@InjectRepository(Room) private repo: Repository<Room>,
|
||||||
@InjectRepository(Occupancy) private occRepo: Repository<Occupancy>,
|
@InjectRepository(Occupancy) private occRepo: Repository<Occupancy>,
|
||||||
@InjectRepository(RoomExpense) private roomExpRepo: Repository<RoomExpense>,
|
@InjectRepository(RoomExpense) private roomExpRepo: Repository<RoomExpense>,
|
||||||
|
private readonly scope: CampusScope,
|
||||||
@InjectRepository(Bed) private bedRepo: Repository<Bed>,
|
@InjectRepository(Bed) private bedRepo: Repository<Bed>,
|
||||||
@InjectRepository(Locker) private lockerRepo: Repository<Locker>,
|
@InjectRepository(Locker) private lockerRepo: Repository<Locker>,
|
||||||
) {}
|
) {}
|
||||||
@@ -377,8 +378,12 @@ export class RoomsService {
|
|||||||
const room = await this.repo.findOne({ where: { id: roomId } });
|
const room = await this.repo.findOne({ where: { id: roomId } });
|
||||||
if (!room) throw new NotFoundException('宿舍不存在');
|
if (!room) throw new NotFoundException('宿舍不存在');
|
||||||
if (room.status === 'archived') throw new BadRequestException('已归档宿舍不能添加床位');
|
if (room.status === 'archived') throw new BadRequestException('已归档宿舍不能添加床位');
|
||||||
const existing = await this.bedRepo.count({ where: { roomId } });
|
const existing = await this.bedRepo.find({ where: { roomId }, order: { bedNumber: 'ASC' } });
|
||||||
const start = existing + 1;
|
const numbers = existing.map(b => {
|
||||||
|
const match = b.bedNumber.match(/^\d+/);
|
||||||
|
return match ? parseInt(match[0]) : 0;
|
||||||
|
});
|
||||||
|
const start = numbers.length > 0 ? Math.max(...numbers) + 1 : 1;
|
||||||
const beds: Bed[] = [];
|
const beds: Bed[] = [];
|
||||||
for (let i = 0; i < dto.count; i++) {
|
for (let i = 0; i < dto.count; i++) {
|
||||||
beds.push(this.bedRepo.create({ roomId, bedNumber: `${start + i}号床` }));
|
beds.push(this.bedRepo.create({ roomId, bedNumber: `${start + i}号床` }));
|
||||||
@@ -435,8 +440,12 @@ export class RoomsService {
|
|||||||
const room = await this.repo.findOne({ where: { id: roomId } });
|
const room = await this.repo.findOne({ where: { id: roomId } });
|
||||||
if (!room) throw new NotFoundException('宿舍不存在');
|
if (!room) throw new NotFoundException('宿舍不存在');
|
||||||
if (room.status === 'archived') throw new BadRequestException('已归档宿舍不能添加柜子');
|
if (room.status === 'archived') throw new BadRequestException('已归档宿舍不能添加柜子');
|
||||||
const existing = await this.lockerRepo.count({ where: { roomId } });
|
const existing = await this.lockerRepo.find({ where: { roomId }, order: { lockerNumber: 'ASC' } });
|
||||||
const start = existing + 1;
|
const numbers = existing.map(b => {
|
||||||
|
const match = b.lockerNumber.match(/^\d+/);
|
||||||
|
return match ? parseInt(match[0]) : 0;
|
||||||
|
});
|
||||||
|
const start = numbers.length > 0 ? Math.max(...numbers) + 1 : 1;
|
||||||
const lockers: Locker[] = [];
|
const lockers: Locker[] = [];
|
||||||
for (let i = 0; i < dto.count; i++) {
|
for (let i = 0; i < dto.count; i++) {
|
||||||
lockers.push(this.lockerRepo.create({ roomId, lockerNumber: `${start + i}号柜` }));
|
lockers.push(this.lockerRepo.create({ roomId, lockerNumber: `${start + i}号柜` }));
|
||||||
|
|||||||
Reference in New Issue
Block a user