fix(occupancies): assign room resources during transfers

This commit is contained in:
2026-07-13 12:01:48 +08:00
parent 8cadf8970e
commit 2874ab7bee
6 changed files with 156 additions and 13 deletions

View File

@@ -0,0 +1,28 @@
import { validate } from 'class-validator';
import { CheckInDto, TransferRoomDto } from './occupancy.dto';
describe('manual occupancy DTO bed requirements', () => {
it('requires a bed for manual check-in', async () => {
const dto = Object.assign(new CheckInDto(), {
studentId: 1,
roomId: 2,
checkInDate: '2026-07-13',
});
const errors = await validate(dto);
expect(errors.some((error) => error.property === 'bedId')).toBe(true);
});
it('requires a new bed for a room transfer while keeping the locker optional', async () => {
const dto = Object.assign(new TransferRoomDto(), {
newRoomId: 3,
transferDate: '2026-07-13',
});
const errors = await validate(dto);
expect(errors.some((error) => error.property === 'newBedId')).toBe(true);
expect(errors.some((error) => error.property === 'newLockerId')).toBe(false);
});
});

View File

@@ -25,9 +25,8 @@ export class CheckInDto {
@IsOptional()
@IsInt()
responsibleOrganizationId?: number;
@IsOptional()
@IsInt()
bedId?: number; // 后续改 required
bedId: number;
@IsOptional()
@IsInt()
@@ -58,9 +57,8 @@ export class TransferRoomDto {
@IsString()
oldBillingEndDate?: string; // 旧房计费截止日,默认=transferDate
@IsOptional()
@IsInt()
newBedId?: number;
newBedId: number;
@IsOptional()
@IsInt()

View File

@@ -28,7 +28,10 @@ describe('OccupanciesService — responsible organization', () => {
roomRepo,
studentRepo,
{} as Repository<Deposit>,
{} as Repository<Bed>,
{
findOne: jest.fn().mockResolvedValue({ id: 4, roomId: 2, status: 'available' }),
update: jest.fn(),
} as any as Repository<Bed>,
{} as Repository<Locker>,
{} as Repository<any>,
{} as DataSource,
@@ -38,6 +41,7 @@ describe('OccupanciesService — responsible organization', () => {
studentId: 3,
roomId: 2,
checkInDate: '2026-07-10',
bedId: 4,
});
expect(occupancyRepo.create).toHaveBeenCalledWith(