@things-factory/menu-base 8.0.0-beta.9 → 8.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist-server/tsconfig.tsbuildinfo +1 -1
- package/package.json +3 -3
- package/server/index.ts +1 -0
- package/server/service/index.ts +37 -0
- package/server/service/menu/index.ts +6 -0
- package/server/service/menu/menu-mutation.ts +244 -0
- package/server/service/menu/menu-query.ts +249 -0
- package/server/service/menu/menu-type.ts +78 -0
- package/server/service/menu/menu.ts +183 -0
- package/server/service/menu-button/index.ts +6 -0
- package/server/service/menu-button/menu-button-mutation.ts +142 -0
- package/server/service/menu-button/menu-button-query.ts +59 -0
- package/server/service/menu-button/menu-button-type.ts +31 -0
- package/server/service/menu-button/menu-button.ts +86 -0
- package/server/service/menu-column/index.ts +6 -0
- package/server/service/menu-column/menu-column-mutation.ts +143 -0
- package/server/service/menu-column/menu-column-query.ts +59 -0
- package/server/service/menu-column/menu-column-type.ts +92 -0
- package/server/service/menu-column/menu-column.ts +200 -0
- package/server/service/menu-detail/index.ts +6 -0
- package/server/service/menu-detail/menu-detail-mutation.ts +142 -0
- package/server/service/menu-detail/menu-detail-query.ts +75 -0
- package/server/service/menu-detail/menu-detail-type.ts +46 -0
- package/server/service/menu-detail/menu-detail.ts +111 -0
- package/server/service/menu-detail-button/index.ts +6 -0
- package/server/service/menu-detail-button/menu-detail-button-mutation.ts +143 -0
- package/server/service/menu-detail-button/menu-detail-button-query.ts +61 -0
- package/server/service/menu-detail-button/menu-detail-button-type.ts +34 -0
- package/server/service/menu-detail-button/menu-detail-button.ts +86 -0
- package/server/service/menu-detail-column/index.ts +6 -0
- package/server/service/menu-detail-column/menu-detail-column-mutation.ts +145 -0
- package/server/service/menu-detail-column/menu-detail-column-query.ts +61 -0
- package/server/service/menu-detail-column/menu-detail-column-type.ts +92 -0
- package/server/service/menu-detail-column/menu-detail-column.ts +205 -0
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
import { Field, ID, ObjectType } from 'type-graphql'
|
|
2
|
+
import {
|
|
3
|
+
Column,
|
|
4
|
+
CreateDateColumn,
|
|
5
|
+
Entity,
|
|
6
|
+
Index,
|
|
7
|
+
JoinTable,
|
|
8
|
+
ManyToMany,
|
|
9
|
+
ManyToOne,
|
|
10
|
+
OneToMany,
|
|
11
|
+
PrimaryGeneratedColumn,
|
|
12
|
+
RelationId,
|
|
13
|
+
UpdateDateColumn
|
|
14
|
+
} from 'typeorm'
|
|
15
|
+
|
|
16
|
+
import { Domain } from '@things-factory/shell'
|
|
17
|
+
import { PrivilegeObject, Role, User } from '@things-factory/auth-base'
|
|
18
|
+
|
|
19
|
+
import { MenuButton } from '../menu-button/menu-button'
|
|
20
|
+
import { MenuColumn } from '../menu-column/menu-column'
|
|
21
|
+
|
|
22
|
+
@Entity()
|
|
23
|
+
@Index('ix_menu_0', (menu: Menu) => [menu.domain, menu.name, menu.parent, menu.role], { unique: true })
|
|
24
|
+
@Index('ix_menu_1', (menu: Menu) => [menu.domain, menu.parent])
|
|
25
|
+
@Index('ix_menu_2', (menu: Menu) => [menu.domain, menu.category, menu.menuType, menu.rank])
|
|
26
|
+
@ObjectType({ description: 'Entity for Menu' })
|
|
27
|
+
export class Menu {
|
|
28
|
+
@PrimaryGeneratedColumn('uuid')
|
|
29
|
+
@Field(type => ID)
|
|
30
|
+
readonly id: string
|
|
31
|
+
|
|
32
|
+
@ManyToOne(type => Domain)
|
|
33
|
+
@Field(type => Domain)
|
|
34
|
+
domain?: Domain
|
|
35
|
+
|
|
36
|
+
@RelationId((menu: Menu) => menu.domain)
|
|
37
|
+
domainId?: string
|
|
38
|
+
|
|
39
|
+
@Column()
|
|
40
|
+
@Field({ nullable: true })
|
|
41
|
+
name: string
|
|
42
|
+
|
|
43
|
+
@Column({ nullable: true })
|
|
44
|
+
@Field({ nullable: true })
|
|
45
|
+
description?: string
|
|
46
|
+
|
|
47
|
+
@ManyToOne(type => Menu, parent => parent.children, { nullable: true })
|
|
48
|
+
@Field({ nullable: true })
|
|
49
|
+
parent?: Menu
|
|
50
|
+
|
|
51
|
+
@RelationId((menu: Menu) => menu.parent)
|
|
52
|
+
parentId?: string
|
|
53
|
+
|
|
54
|
+
@Column({ nullable: true })
|
|
55
|
+
@Field({ nullable: true })
|
|
56
|
+
template?: string
|
|
57
|
+
|
|
58
|
+
@Column({ nullable: true })
|
|
59
|
+
@Field({ nullable: true })
|
|
60
|
+
menuType?: string
|
|
61
|
+
|
|
62
|
+
@Column({ nullable: true })
|
|
63
|
+
@Field({ nullable: true })
|
|
64
|
+
category?: string
|
|
65
|
+
|
|
66
|
+
@ManyToOne(type => Role, { nullable: true })
|
|
67
|
+
@Field(type => Role, { nullable: true })
|
|
68
|
+
role: Role
|
|
69
|
+
|
|
70
|
+
@RelationId((menu: Menu) => menu.role)
|
|
71
|
+
roleId?: string
|
|
72
|
+
|
|
73
|
+
@ManyToMany(type => Role)
|
|
74
|
+
@JoinTable({ name: 'menus_roles' })
|
|
75
|
+
@Field(type => [Role], { nullable: true })
|
|
76
|
+
roles?: Role[]
|
|
77
|
+
|
|
78
|
+
@Column('int', { nullable: true })
|
|
79
|
+
@Field({ nullable: true })
|
|
80
|
+
rank?: number
|
|
81
|
+
|
|
82
|
+
@Column({ nullable: true })
|
|
83
|
+
@Field({ nullable: true })
|
|
84
|
+
iconPath?: string
|
|
85
|
+
|
|
86
|
+
@Column({ nullable: true, default: false })
|
|
87
|
+
@Field({ nullable: true })
|
|
88
|
+
hiddenFlag?: boolean = false
|
|
89
|
+
|
|
90
|
+
@Column({ nullable: true })
|
|
91
|
+
@Field({ nullable: true })
|
|
92
|
+
routing?: string
|
|
93
|
+
|
|
94
|
+
@Column({ nullable: true })
|
|
95
|
+
@Field({ nullable: true })
|
|
96
|
+
routingType?: string
|
|
97
|
+
|
|
98
|
+
@Column({ nullable: true })
|
|
99
|
+
@Field({ nullable: true })
|
|
100
|
+
detailFormId?: string
|
|
101
|
+
|
|
102
|
+
@Column({ nullable: true })
|
|
103
|
+
@Field({ nullable: true })
|
|
104
|
+
detailLayout?: string
|
|
105
|
+
|
|
106
|
+
@Column({ nullable: true })
|
|
107
|
+
@Field({ nullable: true })
|
|
108
|
+
resourceType?: string
|
|
109
|
+
|
|
110
|
+
@Column({ nullable: true })
|
|
111
|
+
@Field({ nullable: true })
|
|
112
|
+
resourceId?: string
|
|
113
|
+
|
|
114
|
+
@Column({ nullable: true })
|
|
115
|
+
@Field({ nullable: true })
|
|
116
|
+
resourceName?: string
|
|
117
|
+
|
|
118
|
+
@Column({ nullable: true })
|
|
119
|
+
@Field({ nullable: true })
|
|
120
|
+
resourceUrl?: string
|
|
121
|
+
|
|
122
|
+
@Column({ nullable: true })
|
|
123
|
+
@Field({ nullable: true })
|
|
124
|
+
gridSaveUrl?: string
|
|
125
|
+
|
|
126
|
+
@Column({ nullable: true })
|
|
127
|
+
@Field({ nullable: true })
|
|
128
|
+
idField?: string
|
|
129
|
+
|
|
130
|
+
@Column({ nullable: true })
|
|
131
|
+
@Field({ nullable: true })
|
|
132
|
+
titleField?: string
|
|
133
|
+
|
|
134
|
+
@Column({ nullable: true })
|
|
135
|
+
@Field({ nullable: true })
|
|
136
|
+
pagination?: boolean
|
|
137
|
+
|
|
138
|
+
@Column({ nullable: true })
|
|
139
|
+
@Field({ nullable: true })
|
|
140
|
+
itemsProp?: string
|
|
141
|
+
|
|
142
|
+
@Column({ nullable: true })
|
|
143
|
+
@Field({ nullable: true })
|
|
144
|
+
totalProp?: string
|
|
145
|
+
|
|
146
|
+
@Column('int', { nullable: true })
|
|
147
|
+
@Field({ nullable: true })
|
|
148
|
+
fixedColumns?: number
|
|
149
|
+
|
|
150
|
+
@OneToMany(type => Menu, child => child.parent)
|
|
151
|
+
@Field(type => [Menu])
|
|
152
|
+
children?: Menu[]
|
|
153
|
+
|
|
154
|
+
@OneToMany(type => MenuButton, menuButton => menuButton.menu)
|
|
155
|
+
@Field(type => [MenuButton])
|
|
156
|
+
buttons?: MenuButton[]
|
|
157
|
+
|
|
158
|
+
@OneToMany(type => MenuColumn, menuColumn => menuColumn.menu)
|
|
159
|
+
@Field(type => [MenuColumn])
|
|
160
|
+
columns?: MenuColumn[]
|
|
161
|
+
|
|
162
|
+
@CreateDateColumn()
|
|
163
|
+
@Field({ nullable: true })
|
|
164
|
+
createdAt?: Date
|
|
165
|
+
|
|
166
|
+
@UpdateDateColumn()
|
|
167
|
+
@Field({ nullable: true })
|
|
168
|
+
updatedAt?: Date
|
|
169
|
+
|
|
170
|
+
@ManyToOne(type => User, { nullable: true })
|
|
171
|
+
@Field(type => User, { nullable: true })
|
|
172
|
+
creator?: User
|
|
173
|
+
|
|
174
|
+
@RelationId((menu: Menu) => menu.creator)
|
|
175
|
+
creatorId?: string
|
|
176
|
+
|
|
177
|
+
@ManyToOne(type => User, { nullable: true })
|
|
178
|
+
@Field(type => User, { nullable: true })
|
|
179
|
+
updater?: User
|
|
180
|
+
|
|
181
|
+
@RelationId((menu: Menu) => menu.updater)
|
|
182
|
+
updaterId?: string
|
|
183
|
+
}
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
import { Arg, Ctx, Directive, Mutation, Resolver } from 'type-graphql'
|
|
2
|
+
import { In } from 'typeorm'
|
|
3
|
+
|
|
4
|
+
import { Menu } from '../menu/menu'
|
|
5
|
+
import { MenuButton } from './menu-button'
|
|
6
|
+
import { MenuButtonPatch, NewMenuButton } from './menu-button-type'
|
|
7
|
+
|
|
8
|
+
@Resolver(MenuButton)
|
|
9
|
+
export class MenuButtonMutation {
|
|
10
|
+
@Directive('@transaction')
|
|
11
|
+
@Mutation(returns => MenuButton, { description: 'To create new MenuButton' })
|
|
12
|
+
async createMenuButton(
|
|
13
|
+
@Arg('menuButton') menuButton: NewMenuButton,
|
|
14
|
+
@Ctx() context: ResolverContext
|
|
15
|
+
): Promise<MenuButton> {
|
|
16
|
+
const { domain, user, tx } = context.state
|
|
17
|
+
|
|
18
|
+
return await tx.getRepository(MenuButton).save({
|
|
19
|
+
...menuButton,
|
|
20
|
+
menu: await tx
|
|
21
|
+
.getRepository(Menu)
|
|
22
|
+
.findOne({ where: { domain: { id: context.state.domain.id }, id: menuButton.menu } }),
|
|
23
|
+
domain,
|
|
24
|
+
creator: user,
|
|
25
|
+
updater: user
|
|
26
|
+
})
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
@Directive('@transaction')
|
|
30
|
+
@Mutation(returns => MenuButton, { description: 'To modify MenuButton information' })
|
|
31
|
+
async updateMenuButton(
|
|
32
|
+
@Arg('id') id: string,
|
|
33
|
+
@Arg('patch') patch: MenuButtonPatch,
|
|
34
|
+
@Ctx() context: ResolverContext
|
|
35
|
+
): Promise<MenuButton> {
|
|
36
|
+
const { domain, user, tx } = context.state
|
|
37
|
+
|
|
38
|
+
const repository = tx.getRepository(MenuButton)
|
|
39
|
+
const menuButton = await repository.findOne({
|
|
40
|
+
where: { domain: { id: domain.id }, id },
|
|
41
|
+
relations: ['menu']
|
|
42
|
+
})
|
|
43
|
+
|
|
44
|
+
if (patch.menu) {
|
|
45
|
+
patch.menu = (await tx.getRepository(Menu).findOneBy({ domain: { id: domain.id }, id: patch.menu })) as any
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
return await repository.save({
|
|
49
|
+
...menuButton,
|
|
50
|
+
...(patch as any),
|
|
51
|
+
updater: user
|
|
52
|
+
})
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
// @Directive('@transaction')
|
|
56
|
+
// @Mutation(returns => [MenuButton], { description: "To modify multiple MenuButtons' information" })
|
|
57
|
+
// async updateMultipleMenuButton(
|
|
58
|
+
// @Arg('patches', type => [MenuButtonPatch]) patches: MenuButtonPatch[],
|
|
59
|
+
// @Ctx() context: ResolverContext
|
|
60
|
+
// ): Promise<MenuButton[]> {
|
|
61
|
+
// const { domain, user, tx } = context.state
|
|
62
|
+
|
|
63
|
+
// let results = []
|
|
64
|
+
// const _createRecords = patches.filter((patch: any) => patch.cuFlag.toUpperCase() === '+')
|
|
65
|
+
// const _updateRecords = patches.filter((patch: any) => patch.cuFlag.toUpperCase() === 'M')
|
|
66
|
+
// const menuButtonRepo = tx.getRepository(MenuButton)
|
|
67
|
+
|
|
68
|
+
// if (_createRecords.length > 0) {
|
|
69
|
+
// for (let i = 0; i < _createRecords.length; i++) {
|
|
70
|
+
// const newRecord = _createRecords[i]
|
|
71
|
+
|
|
72
|
+
// const result = await menuButtonRepo.save({
|
|
73
|
+
// ...newRecord,
|
|
74
|
+
// domain,
|
|
75
|
+
// creator: user,
|
|
76
|
+
// updater: user
|
|
77
|
+
// })
|
|
78
|
+
|
|
79
|
+
// results.push({ ...result, cuFlag: '+' })
|
|
80
|
+
// }
|
|
81
|
+
// }
|
|
82
|
+
|
|
83
|
+
// if (_updateRecords.length > 0) {
|
|
84
|
+
// for (let i = 0; i < _updateRecords.length; i++) {
|
|
85
|
+
// const updateRecord = _updateRecords[i]
|
|
86
|
+
// const menuButton = await menuButtonRepo.findOne(updateRecord.id)
|
|
87
|
+
|
|
88
|
+
// const result = await menuButtonRepo.save({
|
|
89
|
+
// ...menuButton,
|
|
90
|
+
// ...updateRecord,
|
|
91
|
+
// updater: user
|
|
92
|
+
// })
|
|
93
|
+
|
|
94
|
+
// results.push({ ...result, cuFlag: 'M' })
|
|
95
|
+
// }
|
|
96
|
+
// }
|
|
97
|
+
|
|
98
|
+
// return results
|
|
99
|
+
// }
|
|
100
|
+
|
|
101
|
+
@Directive('@transaction')
|
|
102
|
+
@Mutation(returns => Boolean, { description: 'To delete MenuButton' })
|
|
103
|
+
async deleteMenuButton(@Arg('id') id: string, @Ctx() context: ResolverContext): Promise<boolean> {
|
|
104
|
+
const { domain, tx } = context.state
|
|
105
|
+
|
|
106
|
+
await tx.getRepository(MenuButton).delete({ domain: { id: domain.id }, id })
|
|
107
|
+
return true
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
@Directive('@transaction')
|
|
111
|
+
@Mutation(returns => Boolean, { description: 'To delete multiple MenuButtons' })
|
|
112
|
+
async deleteMenuButtons(
|
|
113
|
+
@Arg('ids', type => [String]) ids: string[],
|
|
114
|
+
@Ctx() context: ResolverContext
|
|
115
|
+
): Promise<boolean> {
|
|
116
|
+
const { domain, tx } = context.state
|
|
117
|
+
|
|
118
|
+
await tx.getRepository(MenuButton).delete({
|
|
119
|
+
domain: { id: domain.id },
|
|
120
|
+
id: In(ids)
|
|
121
|
+
})
|
|
122
|
+
|
|
123
|
+
return true
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
@Directive('@transaction')
|
|
127
|
+
@Mutation(returns => Boolean, { description: 'To import multiple MenuButtons' })
|
|
128
|
+
async importMenuButtons(
|
|
129
|
+
@Arg('menuButtons', type => [MenuButtonPatch]) menuButtons: MenuButtonPatch[],
|
|
130
|
+
@Ctx() context: ResolverContext
|
|
131
|
+
): Promise<boolean> {
|
|
132
|
+
const { domain, tx } = context.state
|
|
133
|
+
|
|
134
|
+
await Promise.all(
|
|
135
|
+
menuButtons.map(async (menuButton: MenuButtonPatch) => {
|
|
136
|
+
await tx.getRepository(MenuButton).save({ domain, ...(menuButton as any) })
|
|
137
|
+
})
|
|
138
|
+
)
|
|
139
|
+
|
|
140
|
+
return true
|
|
141
|
+
}
|
|
142
|
+
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { Arg, Args, Ctx, FieldResolver, Query, Resolver, Root } from 'type-graphql'
|
|
2
|
+
|
|
3
|
+
import { User } from '@things-factory/auth-base'
|
|
4
|
+
import { Domain, getQueryBuilderFromListParams, getRepository, ListParam } from '@things-factory/shell'
|
|
5
|
+
|
|
6
|
+
import { Menu } from '../menu/menu'
|
|
7
|
+
import { MenuButton } from './menu-button'
|
|
8
|
+
import { MenuButtonList } from './menu-button-type'
|
|
9
|
+
|
|
10
|
+
@Resolver(MenuButton)
|
|
11
|
+
export class MenuButtonQuery {
|
|
12
|
+
@Query(returns => MenuButton, { description: 'To fetch a MenuButton' })
|
|
13
|
+
async menuButton(@Arg('id') id: string, @Ctx() context: ResolverContext): Promise<MenuButton> {
|
|
14
|
+
const { domain } = context.state
|
|
15
|
+
|
|
16
|
+
return await getRepository(MenuButton).findOne({
|
|
17
|
+
where: { domain: { id: domain.id }, id }
|
|
18
|
+
})
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
@Query(returns => MenuButtonList, { description: 'To fetch multiple MenuButtons' })
|
|
22
|
+
async menuButtons(
|
|
23
|
+
@Args(type => ListParam) params: ListParam,
|
|
24
|
+
@Ctx() context: ResolverContext
|
|
25
|
+
): Promise<MenuButtonList> {
|
|
26
|
+
const { domain } = context.state
|
|
27
|
+
|
|
28
|
+
const queryBuilder = getQueryBuilderFromListParams({
|
|
29
|
+
domain,
|
|
30
|
+
params,
|
|
31
|
+
repository: await getRepository(MenuButton),
|
|
32
|
+
searchables: ['name', 'description']
|
|
33
|
+
})
|
|
34
|
+
|
|
35
|
+
const [items, total] = await queryBuilder.getManyAndCount()
|
|
36
|
+
|
|
37
|
+
return { items, total }
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
@FieldResolver(type => Menu)
|
|
41
|
+
async menu(@Root() menuButton: MenuButton): Promise<Menu> {
|
|
42
|
+
return menuButton.menu || (await getRepository(Menu).findOneBy({ id: menuButton.menuId }))
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
@FieldResolver(type => Domain)
|
|
46
|
+
async domain(@Root() menuButton: MenuButton): Promise<Domain> {
|
|
47
|
+
return await getRepository(Domain).findOneBy({ id: menuButton.domainId })
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
@FieldResolver(type => User)
|
|
51
|
+
async updater(@Root() menuButton: MenuButton): Promise<User> {
|
|
52
|
+
return await getRepository(User).findOneBy({ id: menuButton.updaterId })
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
@FieldResolver(type => User)
|
|
56
|
+
async creator(@Root() menuButton: MenuButton): Promise<User> {
|
|
57
|
+
return await getRepository(User).findOneBy({ id: menuButton.creatorId })
|
|
58
|
+
}
|
|
59
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { Field, InputType, Int, ObjectType } from 'type-graphql'
|
|
2
|
+
|
|
3
|
+
import { MenuButton } from './menu-button'
|
|
4
|
+
|
|
5
|
+
@InputType()
|
|
6
|
+
export class NewMenuButton {
|
|
7
|
+
@Field() menu: string
|
|
8
|
+
@Field(type => Int, { nullable: true }) rank?: number
|
|
9
|
+
@Field({ nullable: true }) style?: string
|
|
10
|
+
@Field({ nullable: true }) icon?: string
|
|
11
|
+
@Field() text: string
|
|
12
|
+
@Field({ nullable: true }) auth?: string
|
|
13
|
+
@Field({ nullable: true }) logic?: string
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
@InputType()
|
|
17
|
+
export class MenuButtonPatch {
|
|
18
|
+
@Field({ nullable: true }) menu?: string
|
|
19
|
+
@Field(type => Int, { nullable: true }) rank?: number
|
|
20
|
+
@Field({ nullable: true }) style?: string
|
|
21
|
+
@Field({ nullable: true }) icon?: string
|
|
22
|
+
@Field({ nullable: true }) text?: string
|
|
23
|
+
@Field({ nullable: true }) auth?: string
|
|
24
|
+
@Field({ nullable: true }) logic?: string
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
@ObjectType()
|
|
28
|
+
export class MenuButtonList {
|
|
29
|
+
@Field(type => [MenuButton]) items: MenuButton[]
|
|
30
|
+
@Field(type => Int) total: number
|
|
31
|
+
}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import { Field, ID, ObjectType } from 'type-graphql'
|
|
2
|
+
import {
|
|
3
|
+
Column,
|
|
4
|
+
CreateDateColumn,
|
|
5
|
+
Entity,
|
|
6
|
+
Index,
|
|
7
|
+
ManyToOne,
|
|
8
|
+
PrimaryGeneratedColumn,
|
|
9
|
+
RelationId,
|
|
10
|
+
UpdateDateColumn
|
|
11
|
+
} from 'typeorm'
|
|
12
|
+
|
|
13
|
+
import { User } from '@things-factory/auth-base'
|
|
14
|
+
import { Domain } from '@things-factory/shell'
|
|
15
|
+
|
|
16
|
+
import { Menu } from '../menu/menu'
|
|
17
|
+
|
|
18
|
+
@Entity()
|
|
19
|
+
@Index('ix_menu_button_0', (menuButton: MenuButton) => [menuButton.menu, menuButton.text], { unique: true })
|
|
20
|
+
@Index('ix_menu_button_1', (menuButton: MenuButton) => [menuButton.menu])
|
|
21
|
+
@ObjectType({ description: 'Entity for MenuButton' })
|
|
22
|
+
export class MenuButton {
|
|
23
|
+
@PrimaryGeneratedColumn('uuid')
|
|
24
|
+
@Field(type => ID)
|
|
25
|
+
readonly id: string
|
|
26
|
+
|
|
27
|
+
@ManyToOne(type => Domain)
|
|
28
|
+
@Field(type => Domain)
|
|
29
|
+
domain?: Domain
|
|
30
|
+
|
|
31
|
+
@RelationId((menuButton: MenuButton) => menuButton.domain)
|
|
32
|
+
domainId?: string
|
|
33
|
+
|
|
34
|
+
@ManyToOne(type => Menu, menu => menu.buttons)
|
|
35
|
+
@Field(type => Menu, { nullable: true })
|
|
36
|
+
menu?: Menu
|
|
37
|
+
|
|
38
|
+
@RelationId((menuButton: MenuButton) => menuButton.menu)
|
|
39
|
+
menuId?: string
|
|
40
|
+
|
|
41
|
+
@Column('int', { nullable: true })
|
|
42
|
+
@Field({ nullable: true })
|
|
43
|
+
rank?: number
|
|
44
|
+
|
|
45
|
+
@Column({ nullable: true })
|
|
46
|
+
@Field({ nullable: true })
|
|
47
|
+
style?: string
|
|
48
|
+
|
|
49
|
+
@Column({ nullable: true })
|
|
50
|
+
@Field({ nullable: true })
|
|
51
|
+
icon?: string
|
|
52
|
+
|
|
53
|
+
@Column()
|
|
54
|
+
@Field({ nullable: true })
|
|
55
|
+
text?: string
|
|
56
|
+
|
|
57
|
+
@Column({ nullable: true })
|
|
58
|
+
@Field({ nullable: true })
|
|
59
|
+
auth?: string
|
|
60
|
+
|
|
61
|
+
@Column({ nullable: true })
|
|
62
|
+
@Field({ nullable: true })
|
|
63
|
+
logic?: string
|
|
64
|
+
|
|
65
|
+
@CreateDateColumn()
|
|
66
|
+
@Field({ nullable: true })
|
|
67
|
+
createdAt?: Date
|
|
68
|
+
|
|
69
|
+
@UpdateDateColumn()
|
|
70
|
+
@Field({ nullable: true })
|
|
71
|
+
updatedAt?: Date
|
|
72
|
+
|
|
73
|
+
@ManyToOne(type => User, { nullable: true })
|
|
74
|
+
@Field(type => User, { nullable: true })
|
|
75
|
+
creator?: User
|
|
76
|
+
|
|
77
|
+
@RelationId((menuButton: MenuButton) => menuButton.creator)
|
|
78
|
+
creatorId?: string
|
|
79
|
+
|
|
80
|
+
@ManyToOne(type => User, { nullable: true })
|
|
81
|
+
@Field(type => User, { nullable: true })
|
|
82
|
+
updater?: User
|
|
83
|
+
|
|
84
|
+
@RelationId((menuButton: MenuButton) => menuButton.updater)
|
|
85
|
+
updaterId?: string
|
|
86
|
+
}
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
import { Arg, Ctx, Directive, Mutation, Resolver } from 'type-graphql'
|
|
2
|
+
import { In } from 'typeorm'
|
|
3
|
+
|
|
4
|
+
import { Menu } from '../menu/menu'
|
|
5
|
+
import { MenuColumn } from './menu-column'
|
|
6
|
+
import { MenuColumnPatch, NewMenuColumn } from './menu-column-type'
|
|
7
|
+
|
|
8
|
+
@Resolver(MenuColumn)
|
|
9
|
+
export class MenuColumnMutation {
|
|
10
|
+
@Directive('@transaction')
|
|
11
|
+
@Mutation(returns => MenuColumn, { description: 'To create new MenuColumn' })
|
|
12
|
+
async createMenuColumn(
|
|
13
|
+
@Arg('menuColumn') menuColumn: NewMenuColumn,
|
|
14
|
+
@Ctx() context: ResolverContext
|
|
15
|
+
): Promise<MenuColumn> {
|
|
16
|
+
const { domain, user, tx } = context.state
|
|
17
|
+
|
|
18
|
+
return await tx.getRepository(MenuColumn).save({
|
|
19
|
+
...menuColumn,
|
|
20
|
+
menu: await tx.getRepository(Menu).findOne({ where: { domain: { id: domain.id }, name: menuColumn.menu } }),
|
|
21
|
+
domain,
|
|
22
|
+
creator: user,
|
|
23
|
+
updater: user
|
|
24
|
+
})
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
@Directive('@transaction')
|
|
28
|
+
@Mutation(returns => MenuColumn, { description: 'To modify MenuColumn information' })
|
|
29
|
+
async updateMenuColumn(
|
|
30
|
+
@Arg('id') id: string,
|
|
31
|
+
@Arg('patch') patch: MenuColumnPatch,
|
|
32
|
+
@Ctx() context: ResolverContext
|
|
33
|
+
): Promise<MenuColumn> {
|
|
34
|
+
const { domain, user, tx } = context.state
|
|
35
|
+
|
|
36
|
+
const repository = tx.getRepository(MenuColumn)
|
|
37
|
+
|
|
38
|
+
const menuColumn = await repository.findOne({
|
|
39
|
+
where: { domain: { id: domain.id }, id },
|
|
40
|
+
relations: ['menu']
|
|
41
|
+
})
|
|
42
|
+
|
|
43
|
+
if (patch.menu) {
|
|
44
|
+
patch.menu = (await tx.getRepository(Menu).findOne({
|
|
45
|
+
where: { domain: { id: domain.id }, id: patch.menu }
|
|
46
|
+
})) as any
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
return await repository.save({
|
|
50
|
+
...menuColumn,
|
|
51
|
+
...(patch as any),
|
|
52
|
+
updater: user
|
|
53
|
+
})
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
// @Directive('@transaction')
|
|
57
|
+
// @Mutation(returns => [MenuColumn], { description: "To modify multiple MenuColumns' information" })
|
|
58
|
+
// async updateMultipleMenuColumn(
|
|
59
|
+
// @Arg('patches', type => [MenuColumnPatch]) patches: MenuColumnPatch[],
|
|
60
|
+
// @Ctx() context: ResolverContext
|
|
61
|
+
// ): Promise<MenuColumn[]> {
|
|
62
|
+
// const { domain, user, tx } = context.state
|
|
63
|
+
|
|
64
|
+
// let results = []
|
|
65
|
+
// const _createRecords = patches.filter((patch: any) => patch.cuFlag.toUpperCase() === '+')
|
|
66
|
+
// const _updateRecords = patches.filter((patch: any) => patch.cuFlag.toUpperCase() === 'M')
|
|
67
|
+
// const menuColumnRepo = tx.getRepository(MenuColumn)
|
|
68
|
+
|
|
69
|
+
// if (_createRecords.length > 0) {
|
|
70
|
+
// for (let i = 0; i < _createRecords.length; i++) {
|
|
71
|
+
// const newRecord = _createRecords[i]
|
|
72
|
+
|
|
73
|
+
// const result = await menuColumnRepo.save({
|
|
74
|
+
// ...newRecord,
|
|
75
|
+
// domain,
|
|
76
|
+
// creator: user,
|
|
77
|
+
// updater: user
|
|
78
|
+
// })
|
|
79
|
+
|
|
80
|
+
// results.push({ ...result, cuFlag: '+' })
|
|
81
|
+
// }
|
|
82
|
+
// }
|
|
83
|
+
|
|
84
|
+
// if (_updateRecords.length > 0) {
|
|
85
|
+
// for (let i = 0; i < _updateRecords.length; i++) {
|
|
86
|
+
// const newRecord = _updateRecords[i]
|
|
87
|
+
// const menuColumn = await menuColumnRepo.findOneBy({ id: newRecord.id })
|
|
88
|
+
|
|
89
|
+
// const result = await menuColumnRepo.save({
|
|
90
|
+
// ...menuColumn,
|
|
91
|
+
// ...newRecord,
|
|
92
|
+
// updater: user
|
|
93
|
+
// })
|
|
94
|
+
|
|
95
|
+
// results.push({ ...result, cuFlag: 'M' })
|
|
96
|
+
// }
|
|
97
|
+
// }
|
|
98
|
+
|
|
99
|
+
// return results
|
|
100
|
+
// }
|
|
101
|
+
|
|
102
|
+
@Directive('@transaction')
|
|
103
|
+
@Mutation(returns => Boolean, { description: 'To delete MenuColumn' })
|
|
104
|
+
async deleteMenuColumn(@Arg('id') id: string, @Ctx() context: ResolverContext): Promise<boolean> {
|
|
105
|
+
const { domain, tx } = context.state
|
|
106
|
+
|
|
107
|
+
await tx.getRepository(MenuColumn).delete({ domain: { id: domain.id }, id })
|
|
108
|
+
return true
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
@Directive('@transaction')
|
|
112
|
+
@Mutation(returns => Boolean, { description: 'To delete multiple MenuColumns' })
|
|
113
|
+
async deleteMenuColumns(
|
|
114
|
+
@Arg('ids', type => [String]) ids: string[],
|
|
115
|
+
@Ctx() context: ResolverContext
|
|
116
|
+
): Promise<boolean> {
|
|
117
|
+
const { domain, tx } = context.state
|
|
118
|
+
|
|
119
|
+
await tx.getRepository(MenuColumn).delete({
|
|
120
|
+
domain: { id: domain.id },
|
|
121
|
+
id: In(ids)
|
|
122
|
+
})
|
|
123
|
+
|
|
124
|
+
return true
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
@Directive('@transaction')
|
|
128
|
+
@Mutation(returns => Boolean, { description: 'To import multiple MenuColumns' })
|
|
129
|
+
async importMenuColumns(
|
|
130
|
+
@Arg('menuColumns', type => [MenuColumnPatch]) menuColumns: MenuColumnPatch[],
|
|
131
|
+
@Ctx() context: ResolverContext
|
|
132
|
+
): Promise<boolean> {
|
|
133
|
+
const { domain, tx } = context.state
|
|
134
|
+
|
|
135
|
+
await Promise.all(
|
|
136
|
+
menuColumns.map(async (menuColumn: MenuColumnPatch) => {
|
|
137
|
+
await tx.getRepository(MenuColumn).save({ domain, ...(menuColumn as any) })
|
|
138
|
+
})
|
|
139
|
+
)
|
|
140
|
+
|
|
141
|
+
return true
|
|
142
|
+
}
|
|
143
|
+
}
|