feat: 增加宿舍查寝功能
This commit is contained in:
58
apps/server/src/entities/room-inspection.entity.ts
Normal file
58
apps/server/src/entities/room-inspection.entity.ts
Normal file
@@ -0,0 +1,58 @@
|
||||
import {
|
||||
Column,
|
||||
CreateDateColumn,
|
||||
Entity,
|
||||
JoinColumn,
|
||||
ManyToOne,
|
||||
OneToMany,
|
||||
PrimaryGeneratedColumn,
|
||||
Unique,
|
||||
UpdateDateColumn,
|
||||
} from 'typeorm';
|
||||
import { Room } from './room.entity';
|
||||
import { User } from './user.entity';
|
||||
import { RoomInspectionDetail } from './room-inspection-detail.entity';
|
||||
|
||||
export type RoomInspectionSource = 'manual' | 'automatic';
|
||||
|
||||
@Entity('room_inspections')
|
||||
@Unique('uq_room_inspections_date_room', ['inspectionDate', 'roomId'])
|
||||
export class RoomInspection {
|
||||
@PrimaryGeneratedColumn()
|
||||
id: number;
|
||||
|
||||
@Column({ name: 'inspection_date', type: 'date' })
|
||||
inspectionDate: string;
|
||||
|
||||
@Column({ name: 'room_id' })
|
||||
roomId: number;
|
||||
|
||||
@ManyToOne(() => Room, { onDelete: 'CASCADE' })
|
||||
@JoinColumn({ name: 'room_id' })
|
||||
room: Room;
|
||||
|
||||
@Column({ name: 'inspector_id', type: 'integer', nullable: true })
|
||||
inspectorId: number | null;
|
||||
|
||||
@ManyToOne(() => User, { nullable: true, onDelete: 'SET NULL' })
|
||||
@JoinColumn({ name: 'inspector_id' })
|
||||
inspector: User | null;
|
||||
|
||||
@Column({ name: 'inspector_name', length: 50 })
|
||||
inspectorName: string;
|
||||
|
||||
@Column({ type: 'varchar', length: 20, default: 'manual' })
|
||||
source: RoomInspectionSource;
|
||||
|
||||
@Column({ name: 'submitted_at', type: 'datetime' })
|
||||
submittedAt: Date;
|
||||
|
||||
@CreateDateColumn({ name: 'created_at' })
|
||||
createdAt: Date;
|
||||
|
||||
@UpdateDateColumn({ name: 'updated_at' })
|
||||
updatedAt: Date;
|
||||
|
||||
@OneToMany(() => RoomInspectionDetail, (detail) => detail.inspection)
|
||||
details: RoomInspectionDetail[];
|
||||
}
|
||||
Reference in New Issue
Block a user