homemanager-be/src/objects/storage/entities/stored-item.entity.ts

84 lines
1.9 KiB
TypeScript
Raw Normal View History

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