-
-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathtable-widget.entity.ts
More file actions
90 lines (77 loc) · 1.92 KB
/
Copy pathtable-widget.entity.ts
File metadata and controls
90 lines (77 loc) · 1.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
import sjson from 'secure-json-parse';
import {
AfterLoad,
BeforeInsert,
BeforeUpdate,
Column,
CreateDateColumn,
Entity,
JoinColumn,
ManyToOne,
PrimaryGeneratedColumn,
Relation,
UpdateDateColumn,
} from 'typeorm';
import { WidgetTypeEnum } from '../../enums/index.js';
import { TableSettingsEntity } from '../table-settings/common-table-settings/table-settings.entity.js';
@Entity('table_widget')
export class TableWidgetEntity {
@PrimaryGeneratedColumn('uuid')
id: string;
@Column()
field_name: string;
@Column({ default: null, type: 'varchar' })
widget_type?: WidgetTypeEnum;
@Column('json', { default: null })
widget_params: string;
@Column('json', { default: null })
widget_options: string;
@Column({ default: null })
name?: string;
@Column({ default: null })
description?: string;
@CreateDateColumn({ type: 'timestamp', default: () => 'CURRENT_TIMESTAMP' })
created_at: Date;
@UpdateDateColumn({ type: 'timestamp', nullable: true, default: null })
updated_at: Date;
@BeforeUpdate()
stringifyOptionsOnUpdate() {
try {
if (this.widget_options) {
this.widget_options = JSON.stringify(this.widget_options);
}
} catch (e) {
console.error('-> Error widget options stringify ' + e.message);
}
}
@BeforeInsert()
stringifyOptions() {
try {
if (this.widget_options) {
this.widget_options = JSON.stringify(this.widget_options);
}
} catch (e) {
console.error('-> Error widget options stringify ' + e.message);
}
}
@AfterLoad()
parseOptions() {
try {
if (this.widget_options) {
this.widget_options = sjson.parse(this.widget_options, null, {
protoAction: 'remove',
constructorAction: 'remove',
});
}
} catch (e) {
console.error('-> Error widget options parse ' + e.message);
}
}
@ManyToOne(
() => TableSettingsEntity,
(settings) => settings.table_widgets,
{ onDelete: 'CASCADE' },
)
@JoinColumn()
settings: Relation<TableSettingsEntity>;
}