Skip to content

Commit 2a75eab

Browse files
Merge pull request #486 from Breedar/assetsEntity
designed the entity and database schema for the assets module
2 parents fb7f8ea + 860246a commit 2a75eab

File tree

4 files changed

+220
-0
lines changed

4 files changed

+220
-0
lines changed
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import {
2+
Entity,
3+
PrimaryGeneratedColumn,
4+
Column,
5+
ManyToOne,
6+
CreateDateColumn,
7+
} from 'typeorm';
8+
import { User } from '../users/user.entity';
9+
10+
@Entity('asset_documents')
11+
export class AssetDocument {
12+
@PrimaryGeneratedColumn('uuid')
13+
id: string;
14+
15+
@Column()
16+
assetId: string;
17+
18+
@Column()
19+
name: string;
20+
21+
@Column()
22+
url: string;
23+
24+
@Column({ default: 'application/octet-stream' })
25+
type: string;
26+
27+
@Column({ nullable: true })
28+
size: number | null;
29+
30+
@ManyToOne(() => User, { eager: true })
31+
uploadedBy: User;
32+
33+
@CreateDateColumn()
34+
createdAt: Date;
35+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import {
2+
Entity,
3+
PrimaryGeneratedColumn,
4+
Column,
5+
ManyToOne,
6+
JoinColumn,
7+
CreateDateColumn,
8+
} from 'typeorm';
9+
import { Asset } from './asset.entity';
10+
import { User } from '../users/user.entity';
11+
import { AssetHistoryAction } from './enums';
12+
13+
@Entity('asset_history')
14+
export class AssetHistory {
15+
@PrimaryGeneratedColumn('uuid')
16+
id: string;
17+
18+
@ManyToOne(() => Asset, { onDelete: 'CASCADE' })
19+
@JoinColumn({ name: 'assetId' })
20+
asset: Asset;
21+
22+
@Column()
23+
assetId: string;
24+
25+
@Column({ type: 'enum', enum: AssetHistoryAction })
26+
action: AssetHistoryAction;
27+
28+
@Column()
29+
description: string;
30+
31+
@Column({ type: 'jsonb', nullable: true })
32+
previousValue: Record<string, unknown> | null;
33+
34+
@Column({ type: 'jsonb', nullable: true })
35+
newValue: Record<string, unknown> | null;
36+
37+
@ManyToOne(() => User, { eager: true, nullable: true })
38+
@JoinColumn({ name: 'performedById' })
39+
performedBy: User | null;
40+
41+
@CreateDateColumn()
42+
createdAt: Date;
43+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import {
2+
Entity,
3+
PrimaryGeneratedColumn,
4+
Column,
5+
ManyToOne,
6+
JoinColumn,
7+
CreateDateColumn,
8+
UpdateDateColumn,
9+
} from 'typeorm';
10+
import { User } from '../users/user.entity';
11+
12+
@Entity('asset_notes')
13+
export class AssetNote {
14+
@PrimaryGeneratedColumn('uuid')
15+
id: string;
16+
17+
@Column()
18+
assetId: string;
19+
20+
@Column('text')
21+
content: string;
22+
23+
@ManyToOne(() => User, { eager: true })
24+
createdBy: User;
25+
26+
@CreateDateColumn()
27+
createdAt: Date;
28+
29+
@UpdateDateColumn()
30+
updatedAt: Date;
31+
}

backend/src/assets/asset.entity.ts

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
import {
2+
Entity,
3+
PrimaryGeneratedColumn,
4+
Column,
5+
ManyToOne,
6+
JoinColumn,
7+
CreateDateColumn,
8+
UpdateDateColumn,
9+
} from 'typeorm';
10+
import { User } from '../users/user.entity';
11+
import { Department } from '../departments/department.entity';
12+
import { Category } from '../categories/category.entity';
13+
import { AssetStatus, AssetCondition, StellarStatus } from './enums';
14+
15+
@Entity('assets')
16+
export class Asset {
17+
@PrimaryGeneratedColumn('uuid')
18+
id: string;
19+
20+
@Column({ unique: true })
21+
assetId: string;
22+
23+
@Column()
24+
name: string;
25+
26+
@Column({ nullable: true, type: 'text' })
27+
description: string | null;
28+
29+
@ManyToOne(() => Category, { eager: true, nullable: false })
30+
@JoinColumn({ name: 'categoryId' })
31+
category: Category;
32+
33+
@Column({ nullable: true })
34+
serialNumber: string | null;
35+
36+
@Column({ nullable: true, type: 'date' })
37+
purchaseDate: Date | null;
38+
39+
@Column({ nullable: true, type: 'decimal', precision: 15, scale: 2 })
40+
purchasePrice: number | null;
41+
42+
@Column({ nullable: true, type: 'decimal', precision: 15, scale: 2 })
43+
currentValue: number | null;
44+
45+
@Column({ nullable: true, type: 'date' })
46+
warrantyExpiration: Date | null;
47+
48+
@Column({ type: 'enum', enum: AssetStatus, default: AssetStatus.ACTIVE })
49+
status: AssetStatus;
50+
51+
@Column({ type: 'enum', enum: AssetCondition, default: AssetCondition.NEW })
52+
condition: AssetCondition;
53+
54+
@ManyToOne(() => Department, { eager: true, nullable: false })
55+
@JoinColumn({ name: 'departmentId' })
56+
department: Department;
57+
58+
@Column({ nullable: true })
59+
location: string | null;
60+
61+
@ManyToOne(() => User, { eager: true, nullable: true })
62+
@JoinColumn({ name: 'assignedToId' })
63+
assignedTo: User | null;
64+
65+
@Column({ type: 'simple-array', nullable: true })
66+
imageUrls: string[] | null;
67+
68+
@Column({ type: 'jsonb', nullable: true })
69+
customFields: Record<string, unknown> | null;
70+
71+
@Column({ type: 'simple-array', nullable: true })
72+
tags: string[] | null;
73+
74+
@Column({ nullable: true })
75+
manufacturer: string | null;
76+
77+
@Column({ nullable: true })
78+
model: string | null;
79+
80+
@Column({ nullable: true })
81+
barcode: string | null;
82+
83+
@Column({ nullable: true })
84+
qrCode: string | null;
85+
86+
@Column({ nullable: true, type: 'text' })
87+
notes: string | null;
88+
89+
@Column({ nullable: true })
90+
stellarAssetId: string | null;
91+
92+
@Column({ nullable: true })
93+
stellarTxHash: string | null;
94+
95+
@Column({ type: 'enum', enum: StellarStatus, default: StellarStatus.NOT_REGISTERED })
96+
stellarStatus: StellarStatus;
97+
98+
@ManyToOne(() => User, { nullable: true })
99+
@JoinColumn({ name: 'createdById' })
100+
createdBy: User | null;
101+
102+
@ManyToOne(() => User, { nullable: true })
103+
@JoinColumn({ name: 'updatedById' })
104+
updatedBy: User | null;
105+
106+
@CreateDateColumn()
107+
createdAt: Date;
108+
109+
@UpdateDateColumn()
110+
updatedAt: Date;
111+
}

0 commit comments

Comments
 (0)