Handout management

This commit is contained in:
Bastian Wagner
2024-10-20 14:49:42 +02:00
parent 5e2b900b18
commit aa9abdd512
37 changed files with 754 additions and 67 deletions

View File

@@ -0,0 +1,33 @@
import {
Column,
CreateDateColumn,
Entity,
ManyToOne,
OneToMany,
PrimaryGeneratedColumn,
UpdateDateColumn,
} from 'typeorm';
import { Key } from './key.entity';
import { KeySystem } from './system.entity';
import { ICustomer } from '../interface';
@Entity()
export class Customer implements ICustomer {
@PrimaryGeneratedColumn('uuid')
id: string;
@Column({ nullable: false, unique: false })
name: string;
@OneToMany(() => Key, (key) => key.customer)
keys: Key[];
@ManyToOne(() => KeySystem)
system: KeySystem;
@CreateDateColumn({ name: 'created_at' })
createdAt: Date;
@UpdateDateColumn({ name: 'updatet_at' })
updatedAt: Date;
}

View File

@@ -4,3 +4,5 @@ export * from './role.entity';
export * from './cylinder.entity';
export * from './key.entity';
export * from './key_activity.entity';
export * from './customer.entity';
export * from './key-handout.entity';

View File

@@ -0,0 +1,38 @@
import {
BeforeInsert,
Column,
CreateDateColumn,
Entity,
ManyToOne,
PrimaryGeneratedColumn,
} from 'typeorm';
import { Key } from './key.entity';
import { Customer } from './customer.entity';
@Entity()
export class KeyHandout {
@PrimaryGeneratedColumn('uuid')
id: string;
@ManyToOne(() => Key)
key: Key;
@Column()
direction: 'out' | 'return';
@ManyToOne(() => Customer)
customer: Customer;
@Column()
timestamp: Date;
@CreateDateColumn()
created: Date;
@BeforeInsert()
insertTimestamp() {
if (this.timestamp == null) {
this.timestamp = new Date();
}
}
}

View File

@@ -8,6 +8,7 @@ import {
} from 'typeorm';
import { Cylinder } from './cylinder.entity';
import { IKey } from '../interface/key.interface';
import { Customer } from './customer.entity';
@Entity()
export class Key implements IKey {
@@ -26,6 +27,9 @@ export class Key implements IKey {
@ManyToOne(() => Cylinder, (cylinder) => cylinder.keys)
cylinder: Cylinder;
@ManyToOne(() => Customer, (customer) => customer.keys)
customer: Customer;
@CreateDateColumn({ name: 'created_at' })
createdAt: Date;

View File

@@ -8,6 +8,7 @@ import {
import { User } from './user.entity';
import { IKey } from '../interface/key.interface';
import { Cylinder } from './cylinder.entity';
import { Customer } from './customer.entity';
@Entity()
export class KeyActivity implements IKey {
@@ -29,6 +30,9 @@ export class KeyActivity implements IKey {
@ManyToOne(() => Cylinder)
cylinder: Cylinder;
@ManyToOne(() => Customer)
customer: Customer;
@CreateDateColumn({ name: 'created_at' })
createdAt: Date;