@hedhog/admin 0.12.2 → 0.12.4

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.
Files changed (137) hide show
  1. package/dist/auth/auth.controller.d.ts +1 -10
  2. package/dist/auth/auth.controller.d.ts.map +1 -1
  3. package/dist/auth/auth.service.d.ts +1 -10
  4. package/dist/auth/auth.service.d.ts.map +1 -1
  5. package/dist/auth/auth.service.js.map +1 -1
  6. package/dist/auth/auth.service.spec.d.ts +0 -1
  7. package/dist/auth/auth.service.spec.js +171 -161
  8. package/dist/auth/auth.service.spec.js.map +1 -1
  9. package/dist/auth/consts/body.js +23 -23
  10. package/dist/menu/menu.controller.d.ts +6 -33
  11. package/dist/menu/menu.controller.d.ts.map +1 -1
  12. package/dist/menu/menu.service.d.ts +6 -33
  13. package/dist/menu/menu.service.d.ts.map +1 -1
  14. package/dist/menu/menu.service.js.map +1 -1
  15. package/dist/role/guards/role.guard.js.map +1 -1
  16. package/dist/role/role.controller.d.ts +5 -5
  17. package/dist/role/role.service.d.ts +5 -5
  18. package/dist/role/role.service.js.map +1 -1
  19. package/dist/route/route.controller.d.ts +6 -27
  20. package/dist/route/route.controller.d.ts.map +1 -1
  21. package/dist/route/route.service.d.ts +6 -27
  22. package/dist/route/route.service.d.ts.map +1 -1
  23. package/dist/route/route.service.js.map +1 -1
  24. package/dist/screen/screen.controller.d.ts +6 -24
  25. package/dist/screen/screen.controller.d.ts.map +1 -1
  26. package/dist/screen/screen.service.d.ts +6 -24
  27. package/dist/screen/screen.service.d.ts.map +1 -1
  28. package/dist/screen/screen.service.js.map +1 -1
  29. package/dist/user/user.controller.d.ts +5 -32
  30. package/dist/user/user.controller.d.ts.map +1 -1
  31. package/dist/user/user.service.d.ts +5 -32
  32. package/dist/user/user.service.d.ts.map +1 -1
  33. package/dist/user/user.service.js.map +1 -1
  34. package/dist/user/user.service.spec.d.ts +0 -1
  35. package/dist/user/user.service.spec.js +259 -250
  36. package/dist/user/user.service.spec.js.map +1 -1
  37. package/frontend/menu/components/create-panel.tsx.ejs +55 -0
  38. package/frontend/menu/components/update-panel.tsx.ejs +67 -0
  39. package/frontend/menu/locales/en/admin.menu.json +11 -0
  40. package/frontend/menu/locales/pt/admin.menu.json +11 -0
  41. package/frontend/menu/react-query/handlers.ts.ejs +28 -0
  42. package/frontend/menu/react-query/requests.ts.ejs +56 -0
  43. package/frontend/menu-locale/locales/en/admin.menu-locale.json +11 -0
  44. package/frontend/menu-locale/locales/pt/admin.menu-locale.json +11 -0
  45. package/frontend/menu-screen/locales/en/admin.menu-screen.json +11 -0
  46. package/frontend/menu-screen/locales/pt/admin.menu-screen.json +11 -0
  47. package/frontend/multifactor/components/create-panel.tsx.ejs +55 -0
  48. package/frontend/multifactor/components/update-panel.tsx.ejs +70 -0
  49. package/frontend/multifactor/locales/en/admin.multifactor.json +11 -0
  50. package/frontend/multifactor/locales/pt/admin.multifactor.json +11 -0
  51. package/frontend/multifactor/react-query/handlers.ts.ejs +28 -0
  52. package/frontend/multifactor/react-query/requests.ts.ejs +59 -0
  53. package/frontend/multifactor-locale/locales/en/admin.multifactor-locale.json +11 -0
  54. package/frontend/multifactor-locale/locales/pt/admin.multifactor-locale.json +11 -0
  55. package/frontend/screen/components/create-panel.tsx.ejs +55 -0
  56. package/frontend/screen/components/update-panel.tsx.ejs +67 -0
  57. package/frontend/screen/locales/en/admin.screen.json +11 -0
  58. package/frontend/screen/locales/pt/admin.screen.json +11 -0
  59. package/frontend/screen/react-query/handlers.ts.ejs +28 -0
  60. package/frontend/screen/react-query/requests.ts.ejs +56 -0
  61. package/frontend/screen-locale/locales/en/admin.screen-locale.json +11 -0
  62. package/frontend/screen-locale/locales/pt/admin.screen-locale.json +11 -0
  63. package/frontend/translation/components/create-panel.tsx.ejs +52 -0
  64. package/frontend/translation/components/update-panel.tsx.ejs +67 -0
  65. package/frontend/translation/fields/en.json +1 -0
  66. package/frontend/translation/fields/pt.json +1 -0
  67. package/frontend/translation/locales/en/admin.translation.json +11 -0
  68. package/frontend/translation/locales/pt/admin.translation.json +11 -0
  69. package/frontend/translation/modules/en.json +1 -0
  70. package/frontend/translation/modules/pt.json +1 -0
  71. package/frontend/translation/react-query/handlers.ts.ejs +28 -0
  72. package/frontend/translation/react-query/requests.ts.ejs +58 -0
  73. package/frontend/translation-namespace/components/create-panel.tsx.ejs +53 -0
  74. package/frontend/translation-namespace/components/update-panel.tsx.ejs +70 -0
  75. package/frontend/translation-namespace/locales/en/admin.translation-namespace.json +11 -0
  76. package/frontend/translation-namespace/locales/pt/admin.translation-namespace.json +11 -0
  77. package/frontend/translation-namespace/react-query/handlers.ts.ejs +28 -0
  78. package/frontend/translation-namespace/react-query/requests.ts.ejs +60 -0
  79. package/frontend/user/components/create-panel.tsx.ejs +52 -0
  80. package/frontend/user/components/update-panel.tsx.ejs +64 -0
  81. package/frontend/user/locales/en/admin.user.json +11 -0
  82. package/frontend/user/locales/pt/admin.user.json +11 -0
  83. package/frontend/user/react-query/handlers.ts.ejs +28 -0
  84. package/frontend/user/react-query/requests.ts.ejs +55 -0
  85. package/{bkp.hedhog.yaml → hedhog.yaml} +1012 -1012
  86. package/package.json +6 -6
  87. package/src/admin.module.ts +37 -37
  88. package/src/auth/auth.controller.ts +72 -72
  89. package/src/auth/auth.module.ts +39 -39
  90. package/src/auth/auth.service.spec.ts +196 -196
  91. package/src/auth/auth.service.ts +234 -234
  92. package/src/auth/consts/body.ts +26 -26
  93. package/src/auth/consts/subject.ts +1 -1
  94. package/src/auth/dto/forget.dto.ts +6 -6
  95. package/src/auth/dto/login.dto.ts +15 -15
  96. package/src/auth/dto/otp.dto.ts +11 -11
  97. package/src/auth/dto/reset.dto.ts +14 -14
  98. package/src/auth/enums/multifactor-type.enum.ts +4 -4
  99. package/src/auth/guards/auth.guard.ts +50 -50
  100. package/src/auth/types/user.type.ts +8 -8
  101. package/src/dto/delete.dto.ts +8 -8
  102. package/src/dto/update-ids.dto.ts +9 -9
  103. package/src/index.ts +20 -20
  104. package/src/menu/dto/create.dto.ts +25 -25
  105. package/src/menu/dto/order.dto.ts +8 -8
  106. package/src/menu/dto/update.dto.ts +19 -19
  107. package/src/menu/menu.controller.ts +105 -105
  108. package/src/menu/menu.module.ts +18 -18
  109. package/src/menu/menu.service.spec.ts +247 -247
  110. package/src/menu/menu.service.ts +263 -263
  111. package/src/role/dto/create.dto.ts +7 -7
  112. package/src/role/dto/update.dto.ts +4 -4
  113. package/src/role/guards/role.guard.ts +123 -123
  114. package/src/role/role.controller.ts +126 -126
  115. package/src/role/role.module.ts +28 -28
  116. package/src/role/role.service.spec.ts +417 -417
  117. package/src/role/role.service.ts +289 -289
  118. package/src/route/dto/create.dto.ts +13 -13
  119. package/src/route/dto/update.dto.ts +15 -15
  120. package/src/route/route.controller.ts +91 -91
  121. package/src/route/route.module.ts +18 -18
  122. package/src/route/route.service.spec.ts +300 -300
  123. package/src/route/route.service.ts +164 -164
  124. package/src/screen/dto/create.dto.ts +11 -11
  125. package/src/screen/dto/update.dto.ts +19 -19
  126. package/src/screen/screen.controller.ts +93 -93
  127. package/src/screen/screen.module.ts +18 -18
  128. package/src/screen/screen.service.spec.ts +298 -298
  129. package/src/screen/screen.service.ts +179 -179
  130. package/src/types/http-method.ts +8 -8
  131. package/src/user/constants/user.constants.ts +1 -1
  132. package/src/user/dto/create.dto.ts +24 -24
  133. package/src/user/dto/update.dto.ts +41 -41
  134. package/src/user/user.controller.ts +75 -75
  135. package/src/user/user.module.ts +18 -18
  136. package/src/user/user.service.spec.ts +294 -294
  137. package/src/user/user.service.ts +129 -129
@@ -1,179 +1,179 @@
1
- import { PaginationDTO, PaginationService } from '@hedhog/pagination';
2
- import { PrismaService } from '@hedhog/prisma';
3
- import {
4
- BadRequestException,
5
- Inject,
6
- Injectable,
7
- forwardRef,
8
- } from '@nestjs/common';
9
- import { DeleteDTO } from '../dto/delete.dto';
10
- import { UpdateIdsDTO } from '../dto/update-ids.dto';
11
- import { CreateDTO } from './dto/create.dto';
12
- import { UpdateDTO } from './dto/update.dto';
13
-
14
- @Injectable()
15
- export class ScreenService {
16
- constructor(
17
- @Inject(forwardRef(() => PrismaService))
18
- private readonly prismaService: PrismaService,
19
- @Inject(forwardRef(() => PaginationService))
20
- private readonly paginationService: PaginationService,
21
- ) {}
22
-
23
- async updateRoles(screenId: number, data: UpdateIdsDTO) {
24
- await this.prismaService.role_screen.deleteMany({
25
- where: {
26
- screen_id: screenId,
27
- },
28
- });
29
-
30
- return this.prismaService.role_screen.createMany({
31
- data: data.ids.map((roleId) => ({
32
- screen_id: screenId,
33
- role_id: roleId,
34
- })),
35
- skipDuplicates: true,
36
- });
37
- }
38
- async updateRoutes(screenId: number, { ids }: UpdateIdsDTO) {
39
- ids = (
40
- await this.prismaService.route.findMany({
41
- where: {
42
- id: {
43
- in: ids,
44
- },
45
- },
46
- select: {
47
- id: true,
48
- },
49
- })
50
- ).map((route) => route.id);
51
-
52
- await this.prismaService.route_screen.deleteMany({
53
- where: {
54
- screen_id: screenId,
55
- },
56
- });
57
-
58
- return this.prismaService.route_screen.createMany({
59
- data: ids.map((routeId) => ({
60
- screen_id: screenId,
61
- route_id: routeId,
62
- })),
63
- skipDuplicates: true,
64
- });
65
- }
66
- async listRoutes(screenId: number, paginationParams: PaginationDTO) {
67
- return this.paginationService.paginate(
68
- this.prismaService.route,
69
- paginationParams,
70
- {
71
- include: {
72
- route_screen: {
73
- where: {
74
- screen_id: screenId,
75
- },
76
- select: {
77
- route_id: true,
78
- screen_id: true,
79
- },
80
- },
81
- },
82
- },
83
- );
84
- }
85
-
86
- async listRoles(
87
- locale: string,
88
- screenId: number,
89
- paginationParams: PaginationDTO,
90
- ) {
91
- return this.paginationService.paginate(
92
- this.prismaService.role,
93
- paginationParams,
94
- {
95
- include: {
96
- role_screen: {
97
- where: {
98
- screen_id: screenId,
99
- },
100
- select: {
101
- role_id: true,
102
- screen_id: true,
103
- },
104
- },
105
- },
106
- },
107
- );
108
- }
109
-
110
- async list(locale: string, paginationParams: PaginationDTO) {
111
- const fields = ['slug', 'icon'];
112
- const OR: any[] = this.prismaService.createInsensitiveSearch(
113
- fields,
114
- paginationParams,
115
- );
116
-
117
- const result = await this.paginationService.paginate(
118
- this.prismaService.screen,
119
- paginationParams,
120
- {
121
- where: {
122
- OR,
123
- },
124
- include: {
125
- screen_locale: {
126
- where: {
127
- locale: {
128
- code: locale,
129
- },
130
- },
131
- select: {
132
- name: true,
133
- description: true,
134
- },
135
- },
136
- },
137
- },
138
- 'screen_locale',
139
- );
140
-
141
- return result;
142
- }
143
-
144
- async get(screenId: number) {
145
- return this.prismaService.screen.findUnique({ where: { id: screenId } });
146
- }
147
-
148
- async create({ slug, icon }: CreateDTO) {
149
- return this.prismaService.screen.create({
150
- data: {
151
- slug,
152
- icon,
153
- },
154
- });
155
- }
156
-
157
- async update({ id, data }: { id: number; data: UpdateDTO }) {
158
- return this.prismaService.screen.update({
159
- where: { id },
160
- data,
161
- });
162
- }
163
-
164
- async delete({ ids }: DeleteDTO) {
165
- if (ids == undefined || ids == null) {
166
- throw new BadRequestException(
167
- `You must select at least one screen to delete.`,
168
- );
169
- }
170
-
171
- return this.prismaService.screen.deleteMany({
172
- where: {
173
- id: {
174
- in: ids,
175
- },
176
- },
177
- });
178
- }
179
- }
1
+ import { PaginationDTO, PaginationService } from '@hedhog/pagination';
2
+ import { PrismaService } from '@hedhog/prisma';
3
+ import {
4
+ BadRequestException,
5
+ Inject,
6
+ Injectable,
7
+ forwardRef,
8
+ } from '@nestjs/common';
9
+ import { DeleteDTO } from '../dto/delete.dto';
10
+ import { UpdateIdsDTO } from '../dto/update-ids.dto';
11
+ import { CreateDTO } from './dto/create.dto';
12
+ import { UpdateDTO } from './dto/update.dto';
13
+
14
+ @Injectable()
15
+ export class ScreenService {
16
+ constructor(
17
+ @Inject(forwardRef(() => PrismaService))
18
+ private readonly prismaService: PrismaService,
19
+ @Inject(forwardRef(() => PaginationService))
20
+ private readonly paginationService: PaginationService,
21
+ ) { }
22
+
23
+ async updateRoles(screenId: number, data: UpdateIdsDTO) {
24
+ await (this.prismaService as any).role_screen.deleteMany({
25
+ where: {
26
+ screen_id: screenId,
27
+ },
28
+ });
29
+
30
+ return (this.prismaService as any).role_screen.createMany({
31
+ data: data.ids.map((roleId) => ({
32
+ screen_id: screenId,
33
+ role_id: roleId,
34
+ })),
35
+ skipDuplicates: true,
36
+ });
37
+ }
38
+ async updateRoutes(screenId: number, { ids }: UpdateIdsDTO) {
39
+ ids = (
40
+ await (this.prismaService as any).route.findMany({
41
+ where: {
42
+ id: {
43
+ in: ids,
44
+ },
45
+ },
46
+ select: {
47
+ id: true,
48
+ },
49
+ })
50
+ ).map((route) => route.id);
51
+
52
+ await (this.prismaService as any).route_screen.deleteMany({
53
+ where: {
54
+ screen_id: screenId,
55
+ },
56
+ });
57
+
58
+ return (this.prismaService as any).route_screen.createMany({
59
+ data: ids.map((routeId) => ({
60
+ screen_id: screenId,
61
+ route_id: routeId,
62
+ })),
63
+ skipDuplicates: true,
64
+ });
65
+ }
66
+ async listRoutes(screenId: number, paginationParams: PaginationDTO) {
67
+ return this.paginationService.paginate(
68
+ (this.prismaService as any).route,
69
+ paginationParams,
70
+ {
71
+ include: {
72
+ route_screen: {
73
+ where: {
74
+ screen_id: screenId,
75
+ },
76
+ select: {
77
+ route_id: true,
78
+ screen_id: true,
79
+ },
80
+ },
81
+ },
82
+ },
83
+ );
84
+ }
85
+
86
+ async listRoles(
87
+ locale: string,
88
+ screenId: number,
89
+ paginationParams: PaginationDTO,
90
+ ) {
91
+ return this.paginationService.paginate(
92
+ (this.prismaService as any).role,
93
+ paginationParams,
94
+ {
95
+ include: {
96
+ role_screen: {
97
+ where: {
98
+ screen_id: screenId,
99
+ },
100
+ select: {
101
+ role_id: true,
102
+ screen_id: true,
103
+ },
104
+ },
105
+ },
106
+ },
107
+ );
108
+ }
109
+
110
+ async list(locale: string, paginationParams: PaginationDTO) {
111
+ const fields = ['slug', 'icon'];
112
+ const OR: any[] = (this.prismaService as any).createInsensitiveSearch(
113
+ fields,
114
+ paginationParams,
115
+ );
116
+
117
+ const result = await this.paginationService.paginate(
118
+ (this.prismaService as any).screen,
119
+ paginationParams,
120
+ {
121
+ where: {
122
+ OR,
123
+ },
124
+ include: {
125
+ screen_locale: {
126
+ where: {
127
+ locale: {
128
+ code: locale,
129
+ },
130
+ },
131
+ select: {
132
+ name: true,
133
+ description: true,
134
+ },
135
+ },
136
+ },
137
+ },
138
+ 'screen_locale',
139
+ );
140
+
141
+ return result;
142
+ }
143
+
144
+ async get(screenId: number) {
145
+ return (this.prismaService as any).screen.findUnique({ where: { id: screenId } });
146
+ }
147
+
148
+ async create({ slug, icon }: CreateDTO) {
149
+ return (this.prismaService as any).screen.create({
150
+ data: {
151
+ slug,
152
+ icon,
153
+ },
154
+ });
155
+ }
156
+
157
+ async update({ id, data }: { id: number; data: UpdateDTO }) {
158
+ return (this.prismaService as any).screen.update({
159
+ where: { id },
160
+ data,
161
+ });
162
+ }
163
+
164
+ async delete({ ids }: DeleteDTO) {
165
+ if (ids == undefined || ids == null) {
166
+ throw new BadRequestException(
167
+ `You must select at least one screen to delete.`,
168
+ );
169
+ }
170
+
171
+ return (this.prismaService as any).screen.deleteMany({
172
+ where: {
173
+ id: {
174
+ in: ids,
175
+ },
176
+ },
177
+ });
178
+ }
179
+ }
@@ -1,8 +1,8 @@
1
- export type HttpMethod =
2
- | 'GET'
3
- | 'POST'
4
- | 'PUT'
5
- | 'DELETE'
6
- | 'PATCH'
7
- | 'OPTIONS'
8
- | 'HEAD';
1
+ export type HttpMethod =
2
+ | 'GET'
3
+ | 'POST'
4
+ | 'PUT'
5
+ | 'DELETE'
6
+ | 'PATCH'
7
+ | 'OPTIONS'
8
+ | 'HEAD';
@@ -1 +1 @@
1
- export const SALT_ROUNDS = 10;
1
+ export const SALT_ROUNDS = 10;
@@ -1,24 +1,24 @@
1
- import { IsEmail, IsString, IsStrongPassword } from 'class-validator';
2
-
3
- export class CreateDTO {
4
- @IsString({ message: 'O nome deve ser uma string' })
5
- name: string;
6
-
7
- @IsEmail({}, { message: 'O email deve ser um email válido' })
8
- email: string;
9
-
10
- @IsStrongPassword(
11
- {
12
- minLength: 6,
13
- minLowercase: 1,
14
- minUppercase: 0,
15
- minNumbers: 0,
16
- minSymbols: 0,
17
- },
18
- {
19
- message:
20
- 'A senha deve ter pelo menos 6 caracteres, contendo pelo menos uma letra minúscula',
21
- },
22
- )
23
- password: string;
24
- }
1
+ import { IsEmail, IsString, IsStrongPassword } from 'class-validator';
2
+
3
+ export class CreateDTO {
4
+ @IsString({ message: 'O nome deve ser uma string' })
5
+ name: string;
6
+
7
+ @IsEmail({}, { message: 'O email deve ser um email válido' })
8
+ email: string;
9
+
10
+ @IsStrongPassword(
11
+ {
12
+ minLength: 6,
13
+ minLowercase: 1,
14
+ minUppercase: 0,
15
+ minNumbers: 0,
16
+ minSymbols: 0,
17
+ },
18
+ {
19
+ message:
20
+ 'A senha deve ter pelo menos 6 caracteres, contendo pelo menos uma letra minúscula',
21
+ },
22
+ )
23
+ password: string;
24
+ }
@@ -1,41 +1,41 @@
1
- import {
2
- IsEmail,
3
- IsInt,
4
- IsOptional,
5
- IsString,
6
- IsStrongPassword,
7
- } from 'class-validator';
8
-
9
- export class UpdateDTO {
10
- @IsString({ message: 'The name must be a string' })
11
- @IsOptional()
12
- name?: string;
13
-
14
- @IsEmail({}, { message: 'The email must be a valid email' })
15
- @IsOptional()
16
- email?: string;
17
-
18
- @IsOptional()
19
- @IsStrongPassword(
20
- {
21
- minLength: 6,
22
- minLowercase: 1,
23
- minUppercase: 0,
24
- minNumbers: 0,
25
- minSymbols: 0,
26
- },
27
- {
28
- message:
29
- 'The password must be at least 6 characters long and contain at least one lowercase',
30
- },
31
- )
32
- password?: string;
33
-
34
- @IsOptional()
35
- @IsInt({ message: 'The multifactor_id must be an integer' })
36
- multifactor_id?: number;
37
-
38
- @IsOptional()
39
- @IsString({ message: 'The code must be a string' })
40
- code?: string;
41
- }
1
+ import {
2
+ IsEmail,
3
+ IsInt,
4
+ IsOptional,
5
+ IsString,
6
+ IsStrongPassword,
7
+ } from 'class-validator';
8
+
9
+ export class UpdateDTO {
10
+ @IsString({ message: 'The name must be a string' })
11
+ @IsOptional()
12
+ name?: string;
13
+
14
+ @IsEmail({}, { message: 'The email must be a valid email' })
15
+ @IsOptional()
16
+ email?: string;
17
+
18
+ @IsOptional()
19
+ @IsStrongPassword(
20
+ {
21
+ minLength: 6,
22
+ minLowercase: 1,
23
+ minUppercase: 0,
24
+ minNumbers: 0,
25
+ minSymbols: 0,
26
+ },
27
+ {
28
+ message:
29
+ 'The password must be at least 6 characters long and contain at least one lowercase',
30
+ },
31
+ )
32
+ password?: string;
33
+
34
+ @IsOptional()
35
+ @IsInt({ message: 'The multifactor_id must be an integer' })
36
+ multifactor_id?: number;
37
+
38
+ @IsOptional()
39
+ @IsString({ message: 'The code must be a string' })
40
+ code?: string;
41
+ }
@@ -1,75 +1,75 @@
1
- import { Pagination } from '@hedhog/pagination';
2
- import {
3
- Body,
4
- Controller,
5
- Delete,
6
- Get,
7
- Inject,
8
- Param,
9
- ParseIntPipe,
10
- Patch,
11
- Post,
12
- forwardRef,
13
- } from '@nestjs/common';
14
- import { DeleteDTO } from '../dto/delete.dto';
15
- import { UpdateIdsDTO } from '../dto/update-ids.dto';
16
- import { Role } from '@hedhog/core';
17
- import { CreateDTO } from './dto/create.dto';
18
- import { UpdateDTO } from './dto/update.dto';
19
- import { UserService } from './user.service';
20
-
21
- @Role()
22
- @Controller('user')
23
- export class UserController {
24
- constructor(
25
- @Inject(forwardRef(() => UserService))
26
- private readonly userService: UserService,
27
- ) {}
28
-
29
- @Get()
30
- async list(@Pagination() paginationParams) {
31
- return this.userService.list(paginationParams);
32
- }
33
-
34
- @Get(':userId/role')
35
- async listRoles(
36
- @Param('userId', ParseIntPipe) userId: number,
37
- @Pagination() paginationParams,
38
- ) {
39
- return this.userService.listRoles(userId, paginationParams);
40
- }
41
-
42
- @Patch(':userId/role')
43
- async updateRoles(
44
- @Param('userId', ParseIntPipe) userId: number,
45
- @Body() data: UpdateIdsDTO,
46
- ) {
47
- return this.userService.updateRoles(userId, data);
48
- }
49
-
50
- @Get(':userId')
51
- async get(@Param('userId', ParseIntPipe) userId: number) {
52
- return this.userService.get(userId);
53
- }
54
-
55
- @Post()
56
- create(@Body() data: CreateDTO) {
57
- return this.userService.create(data);
58
- }
59
-
60
- @Patch(':userId')
61
- async update(
62
- @Param('userId', ParseIntPipe) userId: number,
63
- @Body() data: UpdateDTO,
64
- ) {
65
- return this.userService.update({
66
- id: userId,
67
- data,
68
- });
69
- }
70
-
71
- @Delete()
72
- async delete(@Body() data: DeleteDTO) {
73
- return this.userService.delete(data);
74
- }
75
- }
1
+ import { Pagination } from '@hedhog/pagination';
2
+ import {
3
+ Body,
4
+ Controller,
5
+ Delete,
6
+ Get,
7
+ Inject,
8
+ Param,
9
+ ParseIntPipe,
10
+ Patch,
11
+ Post,
12
+ forwardRef,
13
+ } from '@nestjs/common';
14
+ import { DeleteDTO } from '../dto/delete.dto';
15
+ import { UpdateIdsDTO } from '../dto/update-ids.dto';
16
+ import { Role } from '@hedhog/core';
17
+ import { CreateDTO } from './dto/create.dto';
18
+ import { UpdateDTO } from './dto/update.dto';
19
+ import { UserService } from './user.service';
20
+
21
+ @Role()
22
+ @Controller('user')
23
+ export class UserController {
24
+ constructor(
25
+ @Inject(forwardRef(() => UserService))
26
+ private readonly userService: UserService,
27
+ ) {}
28
+
29
+ @Get()
30
+ async list(@Pagination() paginationParams) {
31
+ return this.userService.list(paginationParams);
32
+ }
33
+
34
+ @Get(':userId/role')
35
+ async listRoles(
36
+ @Param('userId', ParseIntPipe) userId: number,
37
+ @Pagination() paginationParams,
38
+ ) {
39
+ return this.userService.listRoles(userId, paginationParams);
40
+ }
41
+
42
+ @Patch(':userId/role')
43
+ async updateRoles(
44
+ @Param('userId', ParseIntPipe) userId: number,
45
+ @Body() data: UpdateIdsDTO,
46
+ ) {
47
+ return this.userService.updateRoles(userId, data);
48
+ }
49
+
50
+ @Get(':userId')
51
+ async get(@Param('userId', ParseIntPipe) userId: number) {
52
+ return this.userService.get(userId);
53
+ }
54
+
55
+ @Post()
56
+ create(@Body() data: CreateDTO) {
57
+ return this.userService.create(data);
58
+ }
59
+
60
+ @Patch(':userId')
61
+ async update(
62
+ @Param('userId', ParseIntPipe) userId: number,
63
+ @Body() data: UpdateDTO,
64
+ ) {
65
+ return this.userService.update({
66
+ id: userId,
67
+ data,
68
+ });
69
+ }
70
+
71
+ @Delete()
72
+ async delete(@Body() data: DeleteDTO) {
73
+ return this.userService.delete(data);
74
+ }
75
+ }