-
Notifications
You must be signed in to change notification settings - Fork 0
/
entity-definition.ts
105 lines (102 loc) · 2.55 KB
/
entity-definition.ts
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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
import { EntitySchema, OrderByCondition } from "typeorm"
import { EntitySchemaOptions } from "typeorm/entity-schema/EntitySchemaOptions"
import { BaseColumnSchema } from "./src/entity/base/BaseColumnSchema"
export const definitions :Array<EntitySchemaOptions<any>> = [
//Role
{
name: "role",
tableName: "roles",
columns: {
...BaseColumnSchema,
name: {
type: String,
unique: true,
},
displayName: {
name: "display_name",
type: String,
nullable: true,
},
description: {
type: "text",
nullable: true,
}
},
relations: {
permissions: {
type: "many-to-many",
target: "permission",
joinTable: true
},
users: {
type: "many-to-many",
target: "user",
joinTable: true
}
}
},
// Permission
{
name: "permission",
tableName: "permissions",
columns: {
...BaseColumnSchema,
name: {
type: String,
unique: true,
},
displayName: {
name: "display_name",
type: String
},
description: {
type: "text",
nullable: true,
}
},
relations: {
roles: {
type: "many-to-many",
target: "permission",
joinTable: true
}
}
},
// User
{
name: "user",
tableName: "users",
columns: {
...BaseColumnSchema,
username: {
type: String,
unique: true,
},
email: {
type: String,
unique: true
},
firstName: {
name: "first_name",
type: String,
},
middleName: {
name: "middle_name",
type: String,
nullable: true
},
lastName: {
name: "last_name",
type: String,
},
},
relations: {
roles: {
type: "many-to-many",
target: "role",
joinTable: true
}
}
}
//TODO: Add more tables using the same format
]