@hedhog/admin 0.11.1 → 0.12.2

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 (54) hide show
  1. package/{hedhog.yaml → bkp.hedhog.yaml} +1012 -814
  2. package/dist/auth/consts/body.js +23 -23
  3. package/package.json +43 -43
  4. package/src/admin.module.ts +37 -37
  5. package/src/auth/auth.controller.ts +72 -72
  6. package/src/auth/auth.module.ts +39 -39
  7. package/src/auth/auth.service.spec.ts +196 -196
  8. package/src/auth/auth.service.ts +234 -234
  9. package/src/auth/consts/body.ts +26 -26
  10. package/src/auth/consts/subject.ts +1 -1
  11. package/src/auth/dto/forget.dto.ts +6 -6
  12. package/src/auth/dto/login.dto.ts +15 -15
  13. package/src/auth/dto/otp.dto.ts +11 -11
  14. package/src/auth/dto/reset.dto.ts +14 -14
  15. package/src/auth/enums/multifactor-type.enum.ts +4 -4
  16. package/src/auth/guards/auth.guard.ts +50 -50
  17. package/src/auth/types/user.type.ts +8 -8
  18. package/src/dto/delete.dto.ts +8 -8
  19. package/src/dto/update-ids.dto.ts +9 -9
  20. package/src/index.ts +20 -20
  21. package/src/menu/dto/create.dto.ts +25 -25
  22. package/src/menu/dto/order.dto.ts +8 -8
  23. package/src/menu/dto/update.dto.ts +19 -19
  24. package/src/menu/menu.controller.ts +105 -105
  25. package/src/menu/menu.module.ts +18 -18
  26. package/src/menu/menu.service.spec.ts +247 -247
  27. package/src/menu/menu.service.ts +263 -263
  28. package/src/role/dto/create.dto.ts +7 -7
  29. package/src/role/dto/update.dto.ts +4 -4
  30. package/src/role/guards/role.guard.ts +123 -123
  31. package/src/role/role.controller.ts +126 -126
  32. package/src/role/role.module.ts +28 -28
  33. package/src/role/role.service.spec.ts +417 -417
  34. package/src/role/role.service.ts +289 -289
  35. package/src/route/dto/create.dto.ts +13 -13
  36. package/src/route/dto/update.dto.ts +15 -15
  37. package/src/route/route.controller.ts +91 -91
  38. package/src/route/route.module.ts +18 -18
  39. package/src/route/route.service.spec.ts +300 -300
  40. package/src/route/route.service.ts +164 -164
  41. package/src/screen/dto/create.dto.ts +11 -11
  42. package/src/screen/dto/update.dto.ts +19 -19
  43. package/src/screen/screen.controller.ts +93 -93
  44. package/src/screen/screen.module.ts +18 -18
  45. package/src/screen/screen.service.spec.ts +298 -298
  46. package/src/screen/screen.service.ts +179 -179
  47. package/src/types/http-method.ts +8 -8
  48. package/src/user/constants/user.constants.ts +1 -1
  49. package/src/user/dto/create.dto.ts +24 -24
  50. package/src/user/dto/update.dto.ts +41 -41
  51. package/src/user/user.controller.ts +75 -75
  52. package/src/user/user.module.ts +18 -18
  53. package/src/user/user.service.spec.ts +294 -294
  54. package/src/user/user.service.ts +129 -129
@@ -1,129 +1,129 @@
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 { genSalt, hash } from 'bcrypt';
10
- import { DeleteDTO } from '../dto/delete.dto';
11
- import { UpdateIdsDTO } from '../dto/update-ids.dto';
12
- import { SALT_ROUNDS } from './constants/user.constants';
13
- import { CreateDTO } from './dto/create.dto';
14
- import { UpdateDTO } from './dto/update.dto';
15
-
16
- @Injectable()
17
- export class UserService {
18
- constructor(
19
- @Inject(forwardRef(() => PrismaService))
20
- private readonly prismaService: PrismaService,
21
- @Inject(forwardRef(() => PaginationService))
22
- private readonly paginationService: PaginationService,
23
- ) {}
24
-
25
- async listRoles(userId: number, paginationParams: PaginationDTO) {
26
- return this.paginationService.paginate(
27
- this.prismaService.role,
28
- paginationParams,
29
- {
30
- include: {
31
- role_user: {
32
- where: {
33
- user_id: userId,
34
- },
35
- select: {
36
- user_id: true,
37
- role_id: true,
38
- },
39
- },
40
- },
41
- },
42
- );
43
- }
44
-
45
- async updateRoles(userId: number, { ids }: UpdateIdsDTO) {
46
- await this.prismaService.role_user.deleteMany({
47
- where: {
48
- user_id: userId,
49
- },
50
- });
51
-
52
- return this.prismaService.role_user.createMany({
53
- data: ids.map((role) => {
54
- return {
55
- user_id: userId,
56
- role_id: role,
57
- };
58
- }),
59
- skipDuplicates: true,
60
- });
61
- }
62
-
63
- async list(paginationParams: PaginationDTO) {
64
- const fields = ['name', 'email'];
65
- const OR = this.prismaService.createInsensitiveSearch(
66
- fields,
67
- paginationParams,
68
- );
69
-
70
- return this.paginationService.paginate(
71
- this.prismaService.user,
72
- paginationParams,
73
- {
74
- where: {
75
- OR,
76
- },
77
- },
78
- );
79
- }
80
-
81
- async get(userId: number) {
82
- return this.prismaService.user.findUnique({ where: { id: userId } });
83
- }
84
-
85
- async hashPassword(password: string): Promise<string> {
86
- const salt = await genSalt(SALT_ROUNDS);
87
- return hash(password, salt);
88
- }
89
-
90
- async create({ email, name, password }: CreateDTO) {
91
- const hashedPassword = await this.hashPassword(password);
92
-
93
- return this.prismaService.user.create({
94
- data: {
95
- email,
96
- name,
97
- password: hashedPassword,
98
- },
99
- });
100
- }
101
-
102
- async update({ id, data }: { id: number; data: UpdateDTO }) {
103
- return this.prismaService.user.update({
104
- where: { id },
105
- data,
106
- });
107
- }
108
-
109
- async delete({ ids }: DeleteDTO) {
110
- if (ids == undefined || ids == null) {
111
- throw new BadRequestException(
112
- `You must select at least one user to delete.`,
113
- );
114
- }
115
-
116
- return this.prismaService.user.deleteMany({
117
- where: {
118
- id: {
119
- in: ids,
120
- },
121
- email: {
122
- not: {
123
- startsWith: 'root@',
124
- },
125
- },
126
- },
127
- });
128
- }
129
- }
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 { genSalt, hash } from 'bcrypt';
10
+ import { DeleteDTO } from '../dto/delete.dto';
11
+ import { UpdateIdsDTO } from '../dto/update-ids.dto';
12
+ import { SALT_ROUNDS } from './constants/user.constants';
13
+ import { CreateDTO } from './dto/create.dto';
14
+ import { UpdateDTO } from './dto/update.dto';
15
+
16
+ @Injectable()
17
+ export class UserService {
18
+ constructor(
19
+ @Inject(forwardRef(() => PrismaService))
20
+ private readonly prismaService: PrismaService,
21
+ @Inject(forwardRef(() => PaginationService))
22
+ private readonly paginationService: PaginationService,
23
+ ) {}
24
+
25
+ async listRoles(userId: number, paginationParams: PaginationDTO) {
26
+ return this.paginationService.paginate(
27
+ this.prismaService.role,
28
+ paginationParams,
29
+ {
30
+ include: {
31
+ role_user: {
32
+ where: {
33
+ user_id: userId,
34
+ },
35
+ select: {
36
+ user_id: true,
37
+ role_id: true,
38
+ },
39
+ },
40
+ },
41
+ },
42
+ );
43
+ }
44
+
45
+ async updateRoles(userId: number, { ids }: UpdateIdsDTO) {
46
+ await this.prismaService.role_user.deleteMany({
47
+ where: {
48
+ user_id: userId,
49
+ },
50
+ });
51
+
52
+ return this.prismaService.role_user.createMany({
53
+ data: ids.map((role) => {
54
+ return {
55
+ user_id: userId,
56
+ role_id: role,
57
+ };
58
+ }),
59
+ skipDuplicates: true,
60
+ });
61
+ }
62
+
63
+ async list(paginationParams: PaginationDTO) {
64
+ const fields = ['name', 'email'];
65
+ const OR = this.prismaService.createInsensitiveSearch(
66
+ fields,
67
+ paginationParams,
68
+ );
69
+
70
+ return this.paginationService.paginate(
71
+ this.prismaService.user,
72
+ paginationParams,
73
+ {
74
+ where: {
75
+ OR,
76
+ },
77
+ },
78
+ );
79
+ }
80
+
81
+ async get(userId: number) {
82
+ return this.prismaService.user.findUnique({ where: { id: userId } });
83
+ }
84
+
85
+ async hashPassword(password: string): Promise<string> {
86
+ const salt = await genSalt(SALT_ROUNDS);
87
+ return hash(password, salt);
88
+ }
89
+
90
+ async create({ email, name, password }: CreateDTO) {
91
+ const hashedPassword = await this.hashPassword(password);
92
+
93
+ return this.prismaService.user.create({
94
+ data: {
95
+ email,
96
+ name,
97
+ password: hashedPassword,
98
+ },
99
+ });
100
+ }
101
+
102
+ async update({ id, data }: { id: number; data: UpdateDTO }) {
103
+ return this.prismaService.user.update({
104
+ where: { id },
105
+ data,
106
+ });
107
+ }
108
+
109
+ async delete({ ids }: DeleteDTO) {
110
+ if (ids == undefined || ids == null) {
111
+ throw new BadRequestException(
112
+ `You must select at least one user to delete.`,
113
+ );
114
+ }
115
+
116
+ return this.prismaService.user.deleteMany({
117
+ where: {
118
+ id: {
119
+ in: ids,
120
+ },
121
+ email: {
122
+ not: {
123
+ startsWith: 'root@',
124
+ },
125
+ },
126
+ },
127
+ });
128
+ }
129
+ }