@hedhog/admin 0.0.104 → 0.0.106
Sign up to get free protection for your applications and to get access to all the features.
- package/README.md +141 -141
- package/dist/admin.module.d.ts.map +1 -1
- package/dist/admin.module.js +8 -7
- package/dist/admin.module.js.map +1 -1
- package/dist/auth/auth.service.d.ts +1 -1
- package/dist/auth/auth.service.d.ts.map +1 -1
- package/dist/auth/auth.service.js +8 -8
- package/dist/auth/auth.service.js.map +1 -1
- package/dist/auth/auth.service.spec.js +16 -16
- package/dist/auth/auth.service.spec.js.map +1 -1
- package/dist/dto/with-locale.dto.d.ts +4 -0
- package/dist/dto/with-locale.dto.d.ts.map +1 -0
- package/dist/dto/{with-locales.dto.js → with-locale.dto.js} +5 -5
- package/dist/dto/with-locale.dto.js.map +1 -0
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -2
- package/dist/index.js.map +1 -1
- package/dist/locale/locale.controller.d.ts +1 -1
- package/dist/locale/locale.controller.d.ts.map +1 -1
- package/dist/locale/locale.controller.js +4 -4
- package/dist/locale/locale.controller.js.map +1 -1
- package/dist/locale/locale.middleware.d.ts +1 -1
- package/dist/locale/locale.middleware.d.ts.map +1 -1
- package/dist/locale/locale.middleware.js +2 -2
- package/dist/locale/locale.middleware.js.map +1 -1
- package/dist/locale/locale.service.d.ts +6 -6
- package/dist/locale/locale.service.d.ts.map +1 -1
- package/dist/locale/locale.service.js +43 -43
- package/dist/locale/locale.service.js.map +1 -1
- package/dist/locale/locale.service.spec.js +14 -14
- package/dist/locale/locale.service.spec.js.map +1 -1
- package/dist/menu/menu.controller.js +3 -3
- package/dist/menu/menu.controller.js.map +1 -1
- package/dist/menu/menu.service.d.ts +3 -3
- package/dist/menu/menu.service.d.ts.map +1 -1
- package/dist/menu/menu.service.js +35 -35
- package/dist/menu/menu.service.js.map +1 -1
- package/dist/menu/menu.service.spec.js +33 -37
- package/dist/menu/menu.service.spec.js.map +1 -1
- package/dist/role/dto/create.dto.d.ts +2 -2
- package/dist/role/dto/create.dto.d.ts.map +1 -1
- package/dist/role/dto/create.dto.js +2 -2
- package/dist/role/dto/create.dto.js.map +1 -1
- package/dist/role/guards/role.guard.js +4 -4
- package/dist/role/guards/role.guard.js.map +1 -1
- package/dist/role/role.controller.d.ts.map +1 -1
- package/dist/role/role.controller.js +9 -9
- package/dist/role/role.controller.js.map +1 -1
- package/dist/role/role.service.d.ts +2 -2
- package/dist/role/role.service.d.ts.map +1 -1
- package/dist/role/role.service.js +35 -35
- package/dist/role/role.service.js.map +1 -1
- package/dist/role/role.service.spec.d.ts +0 -1
- package/dist/role/role.service.spec.js +400 -340
- package/dist/role/role.service.spec.js.map +1 -1
- package/dist/route/route.controller.js +3 -3
- package/dist/route/route.controller.js.map +1 -1
- package/dist/route/route.service.d.ts +2 -2
- package/dist/route/route.service.d.ts.map +1 -1
- package/dist/route/route.service.js +19 -19
- package/dist/route/route.service.js.map +1 -1
- package/dist/route/route.service.spec.js +27 -27
- package/dist/route/route.service.spec.js.map +1 -1
- package/dist/screen/screen.controller.d.ts +1 -1
- package/dist/screen/screen.controller.d.ts.map +1 -1
- package/dist/screen/screen.controller.js +8 -8
- package/dist/screen/screen.controller.js.map +1 -1
- package/dist/screen/screen.service.d.ts +3 -3
- package/dist/screen/screen.service.d.ts.map +1 -1
- package/dist/screen/screen.service.js +18 -18
- package/dist/screen/screen.service.js.map +1 -1
- package/dist/screen/screen.service.spec.js +16 -16
- package/dist/screen/screen.service.spec.js.map +1 -1
- package/dist/setting/dto/setting.dto.d.ts +9 -0
- package/dist/setting/dto/setting.dto.d.ts.map +1 -0
- package/dist/setting/dto/{settings.dto.js → setting.dto.js} +6 -6
- package/dist/setting/dto/setting.dto.js.map +1 -0
- package/dist/setting/{settings.controller.d.ts → setting.controller.d.ts} +8 -8
- package/dist/setting/setting.controller.d.ts.map +1 -0
- package/dist/setting/{settings.controller.js → setting.controller.js} +26 -26
- package/dist/setting/setting.controller.js.map +1 -0
- package/dist/setting/setting.module.d.ts +3 -0
- package/dist/setting/setting.module.d.ts.map +1 -0
- package/dist/setting/{settings.module.js → setting.module.js} +6 -6
- package/dist/setting/setting.module.js.map +1 -0
- package/dist/setting/{settings.service.d.ts → setting.service.d.ts} +6 -6
- package/dist/setting/setting.service.d.ts.map +1 -0
- package/dist/setting/{settings.service.js → setting.service.js} +44 -44
- package/dist/setting/setting.service.js.map +1 -0
- package/dist/setting/setting.service.spec.d.ts +2 -0
- package/dist/setting/setting.service.spec.d.ts.map +1 -0
- package/dist/setting/{settings.service.spec.js → setting.service.spec.js} +17 -17
- package/dist/setting/setting.service.spec.js.map +1 -0
- package/dist/user/user.controller.d.ts +2 -2
- package/dist/user/user.controller.d.ts.map +1 -1
- package/dist/user/user.controller.js +8 -8
- package/dist/user/user.controller.js.map +1 -1
- package/dist/user/user.service.d.ts +3 -3
- package/dist/user/user.service.d.ts.map +1 -1
- package/dist/user/user.service.js +10 -10
- package/dist/user/user.service.js.map +1 -1
- package/dist/user/user.service.spec.js +62 -49
- package/dist/user/user.service.spec.js.map +1 -1
- package/package.json +2 -2
- package/src/admin.module.ts +37 -0
- package/src/auth/auth.controller.ts +48 -0
- package/src/auth/auth.module.ts +39 -0
- package/src/auth/auth.service.spec.ts +196 -0
- package/src/auth/auth.service.ts +175 -0
- package/src/auth/decorators/public.decorator.ts +4 -0
- package/src/auth/decorators/user.decorator.ts +17 -0
- package/src/auth/dto/forget.dto.ts +6 -0
- package/src/auth/dto/login.dto.ts +15 -0
- package/src/auth/dto/otp.dto.ts +11 -0
- package/src/auth/enums/multifactor-type.enum.ts +4 -0
- package/src/auth/guards/auth.guard.ts +50 -0
- package/src/auth/types/user.type.ts +8 -0
- package/src/dto/delete.dto.ts +8 -0
- package/src/dto/update-ids.dto.ts +9 -0
- package/src/dto/with-locale.dto.ts +8 -0
- package/src/index.ts +34 -0
- package/src/locale/dto/create.dto.ts +12 -0
- package/src/locale/dto/delete.dto.ts +8 -0
- package/src/locale/dto/set-enabled.dto.ts +9 -0
- package/src/locale/dto/update.dto.ts +15 -0
- package/src/locale/index.ts +4 -0
- package/src/locale/locale.controller.ts +79 -0
- package/src/locale/locale.decorator.ts +8 -0
- package/src/locale/locale.middleware.ts +34 -0
- package/src/locale/locale.module.ts +23 -0
- package/src/locale/locale.service.spec.ts +193 -0
- package/src/locale/locale.service.ts +366 -0
- package/src/menu/dto/create.dto.ts +25 -0
- package/src/menu/dto/order.dto.ts +8 -0
- package/src/menu/dto/update.dto.ts +19 -0
- package/src/menu/menu.controller.ts +106 -0
- package/src/menu/menu.module.ts +18 -0
- package/src/menu/menu.service.spec.ts +247 -0
- package/src/menu/menu.service.ts +263 -0
- package/src/role/decorators/role.decorator.ts +4 -0
- package/src/role/dto/create.dto.ts +7 -0
- package/src/role/dto/update.dto.ts +4 -0
- package/src/role/guards/role.guard.ts +122 -0
- package/src/role/role.controller.ts +126 -0
- package/src/role/role.module.ts +28 -0
- package/src/role/role.service.spec.ts +417 -0
- package/src/role/role.service.ts +302 -0
- package/src/route/dto/create.dto.ts +13 -0
- package/src/route/dto/update.dto.ts +15 -0
- package/src/route/route.controller.ts +91 -0
- package/src/route/route.module.ts +18 -0
- package/src/route/route.service.spec.ts +299 -0
- package/src/route/route.service.ts +164 -0
- package/src/screen/dto/create.dto.ts +19 -0
- package/src/screen/dto/update.dto.ts +19 -0
- package/src/screen/screen.controller.ts +93 -0
- package/src/screen/screen.module.ts +18 -0
- package/src/screen/screen.service.spec.ts +298 -0
- package/src/screen/screen.service.ts +181 -0
- package/src/setting/dto/create.dto.ts +1 -0
- package/src/setting/dto/setting-user.dto.ts +6 -0
- package/src/setting/dto/setting.dto.ts +17 -0
- package/src/setting/dto/update.dto.ts +3 -0
- package/src/setting/setting.controller.ts +100 -0
- package/src/setting/setting.module.ts +18 -0
- package/src/setting/setting.service.spec.ts +183 -0
- package/src/setting/setting.service.ts +346 -0
- package/src/types/http-method.ts +8 -0
- package/src/user/constants/user.constants.ts +1 -0
- package/src/user/dto/create.dto.ts +24 -0
- package/src/user/dto/update.dto.ts +41 -0
- package/src/user/user.controller.ts +75 -0
- package/src/user/user.module.ts +18 -0
- package/src/user/user.service.spec.ts +294 -0
- package/src/user/user.service.ts +129 -0
- package/tsconfig.lib.json +9 -0
- package/tsconfig.production.json +20 -0
- package/dist/dto/with-locales.dto.d.ts +0 -4
- package/dist/dto/with-locales.dto.d.ts.map +0 -1
- package/dist/dto/with-locales.dto.js.map +0 -1
- package/dist/setting/dto/settings.dto.d.ts +0 -9
- package/dist/setting/dto/settings.dto.d.ts.map +0 -1
- package/dist/setting/dto/settings.dto.js.map +0 -1
- package/dist/setting/settings.controller.d.ts.map +0 -1
- package/dist/setting/settings.controller.js.map +0 -1
- package/dist/setting/settings.module.d.ts +0 -3
- package/dist/setting/settings.module.d.ts.map +0 -1
- package/dist/setting/settings.module.js.map +0 -1
- package/dist/setting/settings.service.d.ts.map +0 -1
- package/dist/setting/settings.service.js.map +0 -1
- package/dist/setting/settings.service.spec.d.ts +0 -2
- package/dist/setting/settings.service.spec.d.ts.map +0 -1
- package/dist/setting/settings.service.spec.js.map +0 -1
@@ -0,0 +1,302 @@
|
|
1
|
+
import { PaginationDTO, PaginationService } from '@hedhog/pagination';
|
2
|
+
import { PrismaService } from '@hedhog/prisma';
|
3
|
+
import { getWithLocale } from '@hedhog/utils';
|
4
|
+
import {
|
5
|
+
BadRequestException,
|
6
|
+
Inject,
|
7
|
+
Injectable,
|
8
|
+
forwardRef,
|
9
|
+
} from '@nestjs/common';
|
10
|
+
import { DeleteDTO } from '../dto/delete.dto';
|
11
|
+
import { UpdateIdsDTO } from '../dto/update-ids.dto';
|
12
|
+
import { LocaleService } from '../locale';
|
13
|
+
import { CreateDTO } from './dto/create.dto';
|
14
|
+
import { UpdateDTO } from './dto/update.dto';
|
15
|
+
|
16
|
+
@Injectable()
|
17
|
+
export class RoleService {
|
18
|
+
constructor(
|
19
|
+
@Inject(forwardRef(() => PrismaService))
|
20
|
+
private readonly prismaService: PrismaService,
|
21
|
+
@Inject(forwardRef(() => PaginationService))
|
22
|
+
private readonly paginationService: PaginationService,
|
23
|
+
@Inject(forwardRef(() => LocaleService))
|
24
|
+
private readonly localeService: LocaleService,
|
25
|
+
) {}
|
26
|
+
|
27
|
+
async updateUsers(roleId: number, { ids }: UpdateIdsDTO) {
|
28
|
+
await this.prismaService.role_user.deleteMany({
|
29
|
+
where: {
|
30
|
+
role_id: roleId,
|
31
|
+
},
|
32
|
+
});
|
33
|
+
|
34
|
+
return this.prismaService.role_user.createMany({
|
35
|
+
data: ids.map((userId) => ({
|
36
|
+
role_id: roleId,
|
37
|
+
user_id: userId,
|
38
|
+
})),
|
39
|
+
skipDuplicates: true,
|
40
|
+
});
|
41
|
+
}
|
42
|
+
|
43
|
+
async updateScreens(roleId: number, data: UpdateIdsDTO) {
|
44
|
+
await this.prismaService.role_screen.deleteMany({
|
45
|
+
where: {
|
46
|
+
role_id: roleId,
|
47
|
+
},
|
48
|
+
});
|
49
|
+
|
50
|
+
return this.prismaService.role_screen.createMany({
|
51
|
+
data: data.ids.map((screenId) => ({
|
52
|
+
role_id: roleId,
|
53
|
+
screen_id: screenId,
|
54
|
+
})),
|
55
|
+
skipDuplicates: true,
|
56
|
+
});
|
57
|
+
}
|
58
|
+
|
59
|
+
async updateRoutes(roleId: number, data: UpdateIdsDTO) {
|
60
|
+
await this.prismaService.role_route.deleteMany({
|
61
|
+
where: {
|
62
|
+
role_id: roleId,
|
63
|
+
},
|
64
|
+
});
|
65
|
+
|
66
|
+
return this.prismaService.role_route.createMany({
|
67
|
+
data: data.ids.map((routeId) => ({
|
68
|
+
role_id: roleId,
|
69
|
+
route_id: routeId,
|
70
|
+
})),
|
71
|
+
skipDuplicates: true,
|
72
|
+
});
|
73
|
+
}
|
74
|
+
|
75
|
+
async updateMenus(roleId: number, data: UpdateIdsDTO) {
|
76
|
+
await this.prismaService.role_menu.deleteMany({
|
77
|
+
where: {
|
78
|
+
role_id: roleId,
|
79
|
+
},
|
80
|
+
});
|
81
|
+
|
82
|
+
return this.prismaService.role_menu.createMany({
|
83
|
+
data: data.ids.map((menuId) => ({
|
84
|
+
role_id: roleId,
|
85
|
+
menu_id: menuId,
|
86
|
+
})),
|
87
|
+
skipDuplicates: true,
|
88
|
+
});
|
89
|
+
}
|
90
|
+
|
91
|
+
async listUsers(roleId: number, paginationParams: PaginationDTO) {
|
92
|
+
return this.paginationService.paginate(
|
93
|
+
this.prismaService.user,
|
94
|
+
paginationParams,
|
95
|
+
{
|
96
|
+
include: {
|
97
|
+
role_user: {
|
98
|
+
where: {
|
99
|
+
role_id: roleId,
|
100
|
+
},
|
101
|
+
select: {
|
102
|
+
user_id: true,
|
103
|
+
role_id: true,
|
104
|
+
},
|
105
|
+
},
|
106
|
+
},
|
107
|
+
},
|
108
|
+
);
|
109
|
+
}
|
110
|
+
|
111
|
+
async listMenus(
|
112
|
+
locale: string,
|
113
|
+
roleId: number,
|
114
|
+
paginationParams: PaginationDTO,
|
115
|
+
) {
|
116
|
+
return this.paginationService.paginate(
|
117
|
+
this.prismaService.menu,
|
118
|
+
paginationParams,
|
119
|
+
{
|
120
|
+
include: {
|
121
|
+
menu_locale: {
|
122
|
+
where: {
|
123
|
+
locale: {
|
124
|
+
code: locale,
|
125
|
+
},
|
126
|
+
},
|
127
|
+
select: {
|
128
|
+
name: true,
|
129
|
+
},
|
130
|
+
},
|
131
|
+
role_menu: {
|
132
|
+
where: {
|
133
|
+
role_id: roleId,
|
134
|
+
},
|
135
|
+
select: {
|
136
|
+
menu_id: true,
|
137
|
+
role_id: true,
|
138
|
+
},
|
139
|
+
},
|
140
|
+
},
|
141
|
+
},
|
142
|
+
'menu_locale',
|
143
|
+
);
|
144
|
+
}
|
145
|
+
|
146
|
+
async listRoutes(roleId: number, paginationParams: PaginationDTO) {
|
147
|
+
return this.paginationService.paginate(
|
148
|
+
this.prismaService.route,
|
149
|
+
paginationParams,
|
150
|
+
{
|
151
|
+
include: {
|
152
|
+
role_route: {
|
153
|
+
where: {
|
154
|
+
role_id: roleId,
|
155
|
+
},
|
156
|
+
select: {
|
157
|
+
route_id: true,
|
158
|
+
role_id: true,
|
159
|
+
},
|
160
|
+
},
|
161
|
+
},
|
162
|
+
},
|
163
|
+
);
|
164
|
+
}
|
165
|
+
|
166
|
+
async listScreens(
|
167
|
+
locale: string,
|
168
|
+
roleId: number,
|
169
|
+
paginationParams: PaginationDTO,
|
170
|
+
) {
|
171
|
+
return this.paginationService.paginate(
|
172
|
+
this.prismaService.screen,
|
173
|
+
paginationParams,
|
174
|
+
{
|
175
|
+
include: {
|
176
|
+
screen_locale: {
|
177
|
+
where: {
|
178
|
+
locale: {
|
179
|
+
code: locale,
|
180
|
+
},
|
181
|
+
},
|
182
|
+
select: {
|
183
|
+
name: true,
|
184
|
+
},
|
185
|
+
},
|
186
|
+
role_screen: {
|
187
|
+
where: {
|
188
|
+
role_id: roleId,
|
189
|
+
},
|
190
|
+
select: {
|
191
|
+
screen_id: true,
|
192
|
+
role_id: true,
|
193
|
+
},
|
194
|
+
},
|
195
|
+
},
|
196
|
+
},
|
197
|
+
'screen_locale',
|
198
|
+
);
|
199
|
+
}
|
200
|
+
|
201
|
+
async getRoles(locale: string, paginationParams: PaginationDTO) {
|
202
|
+
const fields = [];
|
203
|
+
|
204
|
+
const OR: any[] = this.prismaService.createInsensitiveSearch(
|
205
|
+
fields,
|
206
|
+
paginationParams,
|
207
|
+
);
|
208
|
+
|
209
|
+
return this.paginationService.paginate(
|
210
|
+
this.prismaService.role,
|
211
|
+
paginationParams,
|
212
|
+
{
|
213
|
+
where: {
|
214
|
+
OR,
|
215
|
+
},
|
216
|
+
include: {
|
217
|
+
role_locale: {
|
218
|
+
where: {
|
219
|
+
locale: {
|
220
|
+
code: locale,
|
221
|
+
},
|
222
|
+
},
|
223
|
+
select: {
|
224
|
+
name: true,
|
225
|
+
description: true,
|
226
|
+
},
|
227
|
+
},
|
228
|
+
},
|
229
|
+
},
|
230
|
+
'role_locale',
|
231
|
+
);
|
232
|
+
}
|
233
|
+
|
234
|
+
async get(locale: string, roleId: number) {
|
235
|
+
return getWithLocale(
|
236
|
+
locale,
|
237
|
+
'role_locale',
|
238
|
+
await this.prismaService.role.findUnique({
|
239
|
+
where: { id: roleId },
|
240
|
+
include: {
|
241
|
+
role_locale: {
|
242
|
+
where: {
|
243
|
+
locale: {
|
244
|
+
enabled: true,
|
245
|
+
},
|
246
|
+
},
|
247
|
+
select: {
|
248
|
+
name: true,
|
249
|
+
description: true,
|
250
|
+
locale: {
|
251
|
+
select: {
|
252
|
+
code: true,
|
253
|
+
},
|
254
|
+
},
|
255
|
+
},
|
256
|
+
},
|
257
|
+
},
|
258
|
+
}),
|
259
|
+
);
|
260
|
+
}
|
261
|
+
|
262
|
+
async create({ slug, locale }: CreateDTO) {
|
263
|
+
return this.localeService.createModelWithLocale(
|
264
|
+
'role',
|
265
|
+
'role_id',
|
266
|
+
{ slug },
|
267
|
+
locale,
|
268
|
+
);
|
269
|
+
}
|
270
|
+
|
271
|
+
async update({
|
272
|
+
id,
|
273
|
+
data: { locale, slug },
|
274
|
+
}: {
|
275
|
+
id: number;
|
276
|
+
data: UpdateDTO;
|
277
|
+
}) {
|
278
|
+
return this.localeService.updateModelWithLocale(
|
279
|
+
'role',
|
280
|
+
'role_id',
|
281
|
+
id,
|
282
|
+
{ slug },
|
283
|
+
locale,
|
284
|
+
);
|
285
|
+
}
|
286
|
+
|
287
|
+
async delete({ ids }: DeleteDTO) {
|
288
|
+
if (ids == undefined || ids == null) {
|
289
|
+
throw new BadRequestException(
|
290
|
+
`You must select at least one permission to delete.`,
|
291
|
+
);
|
292
|
+
}
|
293
|
+
|
294
|
+
return this.prismaService.role.deleteMany({
|
295
|
+
where: {
|
296
|
+
id: {
|
297
|
+
in: ids,
|
298
|
+
},
|
299
|
+
},
|
300
|
+
});
|
301
|
+
}
|
302
|
+
}
|
@@ -0,0 +1,13 @@
|
|
1
|
+
import { IsIn, IsString } from 'class-validator';
|
2
|
+
import { HttpMethod } from '../../types/http-method';
|
3
|
+
|
4
|
+
export class CreateDTO {
|
5
|
+
@IsString({ message: 'The url must be a valid string.' })
|
6
|
+
url: string;
|
7
|
+
|
8
|
+
@IsString({ message: 'The method must be a string.' })
|
9
|
+
@IsIn(['GET', 'POST', 'PUT', 'DELETE', 'PATCH', 'OPTIONS', 'HEAD'], {
|
10
|
+
message: 'The method must be a valid HTTP method.',
|
11
|
+
})
|
12
|
+
method: HttpMethod;
|
13
|
+
}
|
@@ -0,0 +1,15 @@
|
|
1
|
+
import { IsIn, IsOptional, IsString } from 'class-validator';
|
2
|
+
import { HttpMethod } from '../../types/http-method';
|
3
|
+
|
4
|
+
export class UpdateDTO {
|
5
|
+
@IsString({ message: 'The url must be a valid string.' })
|
6
|
+
@IsOptional()
|
7
|
+
url?: string;
|
8
|
+
|
9
|
+
@IsString({ message: 'The method must be a string.' })
|
10
|
+
@IsOptional()
|
11
|
+
@IsIn(['GET', 'POST', 'PUT', 'DELETE', 'PATCH', 'OPTIONS', 'HEAD'], {
|
12
|
+
message: 'The method must be a valid HTTP method.',
|
13
|
+
})
|
14
|
+
method?: HttpMethod;
|
15
|
+
}
|
@@ -0,0 +1,91 @@
|
|
1
|
+
import { Pagination, PaginationDTO } from '@hedhog/pagination';
|
2
|
+
import {
|
3
|
+
Body,
|
4
|
+
Controller,
|
5
|
+
Delete,
|
6
|
+
forwardRef,
|
7
|
+
Get,
|
8
|
+
Inject,
|
9
|
+
Param,
|
10
|
+
ParseIntPipe,
|
11
|
+
Patch,
|
12
|
+
Post,
|
13
|
+
} from '@nestjs/common';
|
14
|
+
import { DeleteDTO } from '../dto/delete.dto';
|
15
|
+
import { UpdateIdsDTO } from '../dto/update-ids.dto';
|
16
|
+
import { Locale } from '../locale';
|
17
|
+
import { Role } from '../role/decorators/role.decorator';
|
18
|
+
import { CreateDTO } from './dto/create.dto';
|
19
|
+
import { UpdateDTO } from './dto/update.dto';
|
20
|
+
import { RouteService } from './route.service';
|
21
|
+
|
22
|
+
@Role()
|
23
|
+
@Controller('route')
|
24
|
+
export class RouteController {
|
25
|
+
constructor(
|
26
|
+
@Inject(forwardRef(() => RouteService))
|
27
|
+
private readonly routeService: RouteService,
|
28
|
+
) {}
|
29
|
+
|
30
|
+
@Get()
|
31
|
+
async getRoutes(@Pagination() paginationParams) {
|
32
|
+
return this.routeService.getRoutes(paginationParams);
|
33
|
+
}
|
34
|
+
|
35
|
+
@Get(':routeId')
|
36
|
+
async getRouteById(@Param('routeId', ParseIntPipe) routeId: number) {
|
37
|
+
return this.routeService.getRouteById(routeId);
|
38
|
+
}
|
39
|
+
|
40
|
+
@Post()
|
41
|
+
async create(@Body() { url, method }: CreateDTO) {
|
42
|
+
return this.routeService.create({ url, method });
|
43
|
+
}
|
44
|
+
|
45
|
+
@Patch(':routeId')
|
46
|
+
async update(
|
47
|
+
@Param('routeId', ParseIntPipe) routeId: number,
|
48
|
+
@Body() data: UpdateDTO,
|
49
|
+
) {
|
50
|
+
return this.routeService.update({ id: routeId, data });
|
51
|
+
}
|
52
|
+
|
53
|
+
@Delete()
|
54
|
+
async delete(@Body() data: DeleteDTO) {
|
55
|
+
return this.routeService.delete(data);
|
56
|
+
}
|
57
|
+
|
58
|
+
@Get(':routeId/role')
|
59
|
+
async listRoles(
|
60
|
+
@Param('routeId', ParseIntPipe) routeId: number,
|
61
|
+
@Pagination() paginationParams: PaginationDTO,
|
62
|
+
@Locale() locale,
|
63
|
+
) {
|
64
|
+
return this.routeService.listRoles(locale, routeId, paginationParams);
|
65
|
+
}
|
66
|
+
|
67
|
+
@Patch(':routeId/role')
|
68
|
+
async updateRoles(
|
69
|
+
@Param('routeId', ParseIntPipe) routeId: number,
|
70
|
+
@Body() data: UpdateIdsDTO,
|
71
|
+
) {
|
72
|
+
return this.routeService.updateRoles(routeId, data);
|
73
|
+
}
|
74
|
+
|
75
|
+
@Get(':routeId/screens')
|
76
|
+
async listScreens(
|
77
|
+
@Param('routeId', ParseIntPipe) routeId: number,
|
78
|
+
@Pagination() paginationParams: PaginationDTO,
|
79
|
+
@Locale() locale,
|
80
|
+
) {
|
81
|
+
return this.routeService.listScreens(locale, routeId, paginationParams);
|
82
|
+
}
|
83
|
+
|
84
|
+
@Patch(':routeId/screens')
|
85
|
+
async updateScreens(
|
86
|
+
@Param('routeId', ParseIntPipe) routeId: number,
|
87
|
+
@Body() data: UpdateIdsDTO,
|
88
|
+
) {
|
89
|
+
return this.routeService.updateScreens(routeId, data);
|
90
|
+
}
|
91
|
+
}
|
@@ -0,0 +1,18 @@
|
|
1
|
+
import { PaginationModule } from '@hedhog/pagination';
|
2
|
+
import { PrismaModule } from '@hedhog/prisma';
|
3
|
+
import { Module, forwardRef } from '@nestjs/common';
|
4
|
+
import { RouteController } from './route.controller';
|
5
|
+
import { RouteService } from './route.service';
|
6
|
+
import { AuthModule } from '../auth/auth.module';
|
7
|
+
|
8
|
+
@Module({
|
9
|
+
providers: [RouteService],
|
10
|
+
exports: [RouteService],
|
11
|
+
controllers: [RouteController],
|
12
|
+
imports: [
|
13
|
+
forwardRef(() => AuthModule),
|
14
|
+
forwardRef(() => PrismaModule),
|
15
|
+
forwardRef(() => PaginationModule),
|
16
|
+
],
|
17
|
+
})
|
18
|
+
export class RouteModule {}
|