import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger'; import { Building } from 'src/objects/building/entities/building.entity'; import { User } from 'src/objects/user/user.entity'; import { Column, CreateDateColumn, Entity, ManyToOne, OneToMany, PrimaryGeneratedColumn, UpdateDateColumn, } from 'typeorm'; import { StoredItemTransaction } from './item-transaction.entity'; import { Item } from './item.entity'; import { Storage } from './storage.entity'; @Entity() export class StoredItem { @ApiProperty() @PrimaryGeneratedColumn() id: number; @ApiProperty({ type: () => Item }) @ManyToOne(() => Item, { onDelete: 'CASCADE', onUpdate: 'CASCADE', }) item: Item; @ApiPropertyOptional({ type: () => Storage, nullable: true }) @ManyToOne(() => Storage, { nullable: true, onDelete: 'SET NULL', onUpdate: 'CASCADE', }) storage?: Storage; @ApiProperty({ type: () => Building }) @ManyToOne(() => Building, { nullable: true, onDelete: 'CASCADE', onUpdate: 'CASCADE', }) building: Building; @ApiPropertyOptional() @Column({ nullable: true }) notes?: string; @ApiProperty({ type: () => User, nullable: true }) @ManyToOne(() => User, { onDelete: 'SET NULL', nullable: true, }) addedBy: User; @ApiPropertyOptional({ type: () => StoredItemTransaction, isArray: true }) @OneToMany( () => StoredItemTransaction, (transaction) => transaction.storedItem, ) transactions?: StoredItemTransaction[]; @ApiPropertyOptional() @Column({ nullable: true, type: 'datetime' }) expiresAt?: Date; @ApiPropertyOptional() @Column({ nullable: true, type: 'datetime' }) acquiredAt?: Date; @ApiPropertyOptional() @Column({ nullable: true, type: 'datetime' }) consumedAt?: Date; @ApiProperty() @CreateDateColumn() createdAt: Date; @ApiProperty() @UpdateDateColumn() updatedAt: Date; }