2026-01-28 10:42:06 +08:00
|
|
|
import {
|
|
|
|
|
Entity,
|
|
|
|
|
PrimaryGeneratedColumn,
|
|
|
|
|
Column,
|
|
|
|
|
CreateDateColumn,
|
|
|
|
|
UpdateDateColumn,
|
|
|
|
|
ManyToOne,
|
|
|
|
|
JoinColumn,
|
|
|
|
|
OneToMany,
|
2026-01-28 13:03:28 +08:00
|
|
|
} from "typeorm";
|
|
|
|
|
import { AssetType, AssetStatus } from "../common/enums";
|
|
|
|
|
import { Group } from "./group.entity";
|
|
|
|
|
import { AssetLog } from "./asset-log.entity";
|
2026-01-28 10:42:06 +08:00
|
|
|
|
2026-01-28 13:03:28 +08:00
|
|
|
@Entity("assets")
|
2026-01-28 10:42:06 +08:00
|
|
|
export class Asset {
|
2026-01-28 13:03:28 +08:00
|
|
|
@PrimaryGeneratedColumn("uuid")
|
2026-01-28 10:42:06 +08:00
|
|
|
id: string;
|
|
|
|
|
|
|
|
|
|
@Column()
|
|
|
|
|
groupId: string;
|
|
|
|
|
|
2026-01-28 13:03:28 +08:00
|
|
|
@ManyToOne(() => Group, { onDelete: "CASCADE" })
|
|
|
|
|
@JoinColumn({ name: "groupId" })
|
2026-01-28 10:42:06 +08:00
|
|
|
group: Group;
|
|
|
|
|
|
2026-01-28 13:03:28 +08:00
|
|
|
@Column({ type: "enum", enum: AssetType })
|
2026-01-28 10:42:06 +08:00
|
|
|
type: AssetType;
|
|
|
|
|
|
|
|
|
|
@Column({ length: 100 })
|
|
|
|
|
name: string;
|
|
|
|
|
|
2026-01-28 13:03:28 +08:00
|
|
|
@Column({ type: "text", nullable: true, comment: "描述" })
|
2026-01-28 10:42:06 +08:00
|
|
|
description: string;
|
|
|
|
|
|
2026-01-28 13:03:28 +08:00
|
|
|
@Column({ type: "text", nullable: true, comment: "加密的账号凭据" })
|
2026-01-28 10:42:06 +08:00
|
|
|
accountCredentials?: string | null;
|
|
|
|
|
|
2026-01-28 13:03:28 +08:00
|
|
|
@Column({ default: 1, comment: "数量(用于物品)" })
|
2026-01-28 10:42:06 +08:00
|
|
|
quantity: number;
|
|
|
|
|
|
|
|
|
|
@Column({
|
2026-01-28 13:03:28 +08:00
|
|
|
type: "enum",
|
2026-01-28 10:42:06 +08:00
|
|
|
enum: AssetStatus,
|
|
|
|
|
default: AssetStatus.AVAILABLE,
|
|
|
|
|
})
|
|
|
|
|
status: AssetStatus;
|
|
|
|
|
|
2026-01-28 13:03:28 +08:00
|
|
|
@Column({ type: "varchar", nullable: true, comment: "当前借用人ID" })
|
2026-01-28 10:42:06 +08:00
|
|
|
currentBorrowerId?: string | null;
|
|
|
|
|
|
|
|
|
|
@CreateDateColumn()
|
|
|
|
|
createdAt: Date;
|
|
|
|
|
|
|
|
|
|
@UpdateDateColumn()
|
|
|
|
|
updatedAt: Date;
|
|
|
|
|
|
|
|
|
|
@OneToMany(() => AssetLog, (log) => log.asset)
|
|
|
|
|
logs: AssetLog[];
|
|
|
|
|
}
|