@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,196 +1,196 @@
1
- import { MailService } from '@hedhog/mail';
2
- import { PrismaService } from '@hedhog/prisma';
3
- import { NotFoundException } from '@nestjs/common';
4
- import { JwtService } from '@nestjs/jwt';
5
- import { Test, TestingModule } from '@nestjs/testing';
6
- import { compare } from 'bcrypt';
7
- import { AuthService } from './auth.service';
8
-
9
- jest.mock('bcrypt');
10
-
11
- describe('AuthService', () => {
12
- let authService: AuthService;
13
- let prismaService: PrismaService;
14
- let jwtService: JwtService;
15
- let mailService: MailService;
16
-
17
- beforeEach(async () => {
18
- const module: TestingModule = await Test.createTestingModule({
19
- providers: [
20
- AuthService,
21
- {
22
- provide: PrismaService,
23
- useValue: {
24
- user: {
25
- findFirst: jest.fn(),
26
- update: jest.fn(),
27
- findUnique: jest.fn(),
28
- },
29
- },
30
- },
31
- {
32
- provide: JwtService,
33
- useValue: {
34
- sign: jest.fn(),
35
- verifyAsync: jest.fn(),
36
- decode: jest.fn(),
37
- },
38
- },
39
- {
40
- provide: MailService,
41
- useValue: {
42
- send: jest.fn(),
43
- },
44
- },
45
- ],
46
- }).compile();
47
-
48
- authService = module.get<AuthService>(AuthService);
49
- prismaService = module.get<PrismaService>(PrismaService);
50
- jwtService = module.get<JwtService>(JwtService);
51
- mailService = module.get<MailService>(MailService);
52
- });
53
-
54
- it('should be defined', () => {
55
- expect(authService).toBeDefined();
56
- });
57
-
58
- describe('loginWithEmailAndPassword', () => {
59
- it('should throw NotFoundException if user is not found', async () => {
60
- jest.spyOn(prismaService.user, 'findFirst').mockResolvedValue(null);
61
-
62
- await expect(
63
- authService.loginWithEmailAndPassword('test@example.com', 'password'),
64
- ).rejects.toThrow(NotFoundException);
65
- });
66
-
67
- it('should throw NotFoundException if password is invalid', async () => {
68
- const mockUser = {
69
- id: 1,
70
- name: 'Test User',
71
- email: 'test@example.com',
72
- password: 'hashedpassword',
73
- multifactor_id: null,
74
- code: null,
75
- created_at: new Date(),
76
- updated_at: new Date(),
77
- };
78
- jest.spyOn(prismaService.user, 'findFirst').mockResolvedValue(mockUser);
79
- (compare as jest.Mock).mockResolvedValue(false);
80
-
81
- await expect(
82
- authService.loginWithEmailAndPassword('test@example.com', 'password'),
83
- ).rejects.toThrow(NotFoundException);
84
- });
85
-
86
- it('should return a token if login is successful', async () => {
87
- const mockUser = {
88
- id: 1,
89
- name: 'Test User',
90
- email: 'test@example.com',
91
- password: 'hashedpassword',
92
- multifactor_id: null,
93
- code: null,
94
- created_at: new Date(),
95
- updated_at: new Date(),
96
- };
97
- jest.spyOn(prismaService.user, 'findFirst').mockResolvedValue(mockUser);
98
- (compare as jest.Mock).mockResolvedValue(true);
99
- jest.spyOn(jwtService, 'sign').mockReturnValue('token');
100
-
101
- const result = await authService.loginWithEmailAndPassword(
102
- 'test@example.com',
103
- 'password',
104
- );
105
-
106
- expect(result).toEqual({ token: 'token' });
107
- });
108
- });
109
-
110
- describe('forget', () => {
111
- it('should throw NotFoundException if user is not found', async () => {
112
- jest.spyOn(prismaService.user, 'findFirst').mockResolvedValue(null);
113
-
114
- await expect(
115
- authService.forget({ email: 'test@example.com' }),
116
- ).rejects.toThrow(NotFoundException);
117
- });
118
-
119
- it('should update user with reset code and send email', async () => {
120
- const mockUser = {
121
- id: 1,
122
- name: 'Test User',
123
- email: 'test@example.com',
124
- password: 'hashedpassword',
125
- multifactor_id: null,
126
- code: null,
127
- created_at: new Date(),
128
- updated_at: new Date(),
129
- };
130
- jest.spyOn(prismaService.user, 'findFirst').mockResolvedValue(mockUser);
131
- jest.spyOn(prismaService.user, 'update').mockResolvedValue(mockUser);
132
- jest
133
- .spyOn(authService, 'generateRandomString')
134
- .mockReturnValue('resetCode');
135
-
136
- const result = await authService.forget({ email: 'test@example.com' });
137
-
138
- expect(prismaService.user.update).toHaveBeenCalledWith({
139
- where: { id: 1 },
140
- data: { code: 'resetCode' },
141
- });
142
- expect(mailService.send).toHaveBeenCalledWith({
143
- to: 'test@example.com',
144
- subject: 'Reset password',
145
- body: `Reset your password by clicking <a href="${process.env.FRONTEND_URL}/reset-password/resetCode">here</a>`,
146
- });
147
- expect(result).toEqual(true);
148
- });
149
- });
150
-
151
- describe('otp', () => {
152
- it('should throw NotFoundException if user with code is not found', async () => {
153
- jest.spyOn(jwtService, 'decode').mockReturnValue({ id: 1 });
154
- jest.spyOn(prismaService.user, 'findFirst').mockResolvedValue(null);
155
-
156
- await expect(
157
- authService.otp({ token: 'token', code: 123456 }),
158
- ).rejects.toThrow(NotFoundException);
159
- });
160
-
161
- it('should return a token if otp is valid', async () => {
162
- const mockUser = {
163
- id: 1,
164
- name: 'Test User',
165
- email: 'test@example.com',
166
- password: 'hashedpassword',
167
- multifactor_id: null,
168
- code: null,
169
- created_at: new Date(),
170
- updated_at: new Date(),
171
- };
172
- jest.spyOn(jwtService, 'decode').mockReturnValue({ id: 1 });
173
- jest.spyOn(prismaService.user, 'findFirst').mockResolvedValue(mockUser);
174
- jest.spyOn(prismaService.user, 'update').mockResolvedValue(mockUser);
175
- jest.spyOn(jwtService, 'sign').mockReturnValue('newToken');
176
-
177
- const result = await authService.otp({ token: 'token', code: 123456 });
178
-
179
- expect(prismaService.user.update).toHaveBeenCalledWith({
180
- where: { id: 1 },
181
- data: { code: null },
182
- });
183
- expect(result).toEqual({ token: 'newToken' });
184
- });
185
- });
186
-
187
- describe('verifyToken', () => {
188
- it('should verify and return token data', async () => {
189
- jest.spyOn(jwtService, 'verifyAsync').mockResolvedValue({ id: 1 });
190
-
191
- const result = await authService.verifyToken('token');
192
-
193
- expect(result).toEqual({ id: 1 });
194
- });
195
- });
196
- });
1
+ // import { MailService } from '@hedhog/mail';
2
+ // import { PrismaService } from '@hedhog/prisma';
3
+ // import { NotFoundException } from '@nestjs/common';
4
+ // import { JwtService } from '@nestjs/jwt';
5
+ // import { Test, TestingModule } from '@nestjs/testing';
6
+ // import { compare } from 'bcrypt';
7
+ // import { AuthService } from './auth.service';
8
+
9
+ // jest.mock('bcrypt');
10
+
11
+ // describe('AuthService', () => {
12
+ // let authService: AuthService;
13
+ // let prismaService: PrismaService;
14
+ // let jwtService: JwtService;
15
+ // let mailService: MailService;
16
+
17
+ // beforeEach(async () => {
18
+ // const module: TestingModule = await Test.createTestingModule({
19
+ // providers: [
20
+ // AuthService,
21
+ // {
22
+ // provide: PrismaService,
23
+ // useValue: {
24
+ // user: {
25
+ // findFirst: jest.fn(),
26
+ // update: jest.fn(),
27
+ // findUnique: jest.fn(),
28
+ // },
29
+ // },
30
+ // },
31
+ // {
32
+ // provide: JwtService,
33
+ // useValue: {
34
+ // sign: jest.fn(),
35
+ // verifyAsync: jest.fn(),
36
+ // decode: jest.fn(),
37
+ // },
38
+ // },
39
+ // {
40
+ // provide: MailService,
41
+ // useValue: {
42
+ // send: jest.fn(),
43
+ // },
44
+ // },
45
+ // ],
46
+ // }).compile();
47
+
48
+ // authService = module.get<AuthService>(AuthService);
49
+ // prismaService = module.get<PrismaService>(PrismaService);
50
+ // jwtService = module.get<JwtService>(JwtService);
51
+ // mailService = module.get<MailService>(MailService);
52
+ // });
53
+
54
+ // it('should be defined', () => {
55
+ // expect(authService).toBeDefined();
56
+ // });
57
+
58
+ // describe('loginWithEmailAndPassword', () => {
59
+ // it('should throw NotFoundException if user is not found', async () => {
60
+ // jest.spyOn(prismaService.user, 'findFirst').mockResolvedValue(null);
61
+
62
+ // await expect(
63
+ // authService.loginWithEmailAndPassword('test@example.com', 'password'),
64
+ // ).rejects.toThrow(NotFoundException);
65
+ // });
66
+
67
+ // it('should throw NotFoundException if password is invalid', async () => {
68
+ // const mockUser = {
69
+ // id: 1,
70
+ // name: 'Test User',
71
+ // email: 'test@example.com',
72
+ // password: 'hashedpassword',
73
+ // multifactor_id: null,
74
+ // code: null,
75
+ // created_at: new Date(),
76
+ // updated_at: new Date(),
77
+ // };
78
+ // jest.spyOn(prismaService.user, 'findFirst').mockResolvedValue(mockUser);
79
+ // (compare as jest.Mock).mockResolvedValue(false);
80
+
81
+ // await expect(
82
+ // authService.loginWithEmailAndPassword('test@example.com', 'password'),
83
+ // ).rejects.toThrow(NotFoundException);
84
+ // });
85
+
86
+ // it('should return a token if login is successful', async () => {
87
+ // const mockUser = {
88
+ // id: 1,
89
+ // name: 'Test User',
90
+ // email: 'test@example.com',
91
+ // password: 'hashedpassword',
92
+ // multifactor_id: null,
93
+ // code: null,
94
+ // created_at: new Date(),
95
+ // updated_at: new Date(),
96
+ // };
97
+ // jest.spyOn(prismaService.user, 'findFirst').mockResolvedValue(mockUser);
98
+ // (compare as jest.Mock).mockResolvedValue(true);
99
+ // jest.spyOn(jwtService, 'sign').mockReturnValue('token');
100
+
101
+ // const result = await authService.loginWithEmailAndPassword(
102
+ // 'test@example.com',
103
+ // 'password',
104
+ // );
105
+
106
+ // expect(result).toEqual({ token: 'token' });
107
+ // });
108
+ // });
109
+
110
+ // describe('forget', () => {
111
+ // it('should throw NotFoundException if user is not found', async () => {
112
+ // jest.spyOn(prismaService.user, 'findFirst').mockResolvedValue(null);
113
+
114
+ // await expect(
115
+ // authService.forget({ email: 'test@example.com' }),
116
+ // ).rejects.toThrow(NotFoundException);
117
+ // });
118
+
119
+ // it('should update user with reset code and send email', async () => {
120
+ // const mockUser = {
121
+ // id: 1,
122
+ // name: 'Test User',
123
+ // email: 'test@example.com',
124
+ // password: 'hashedpassword',
125
+ // multifactor_id: null,
126
+ // code: null,
127
+ // created_at: new Date(),
128
+ // updated_at: new Date(),
129
+ // };
130
+ // jest.spyOn(prismaService.user, 'findFirst').mockResolvedValue(mockUser);
131
+ // jest.spyOn(prismaService.user, 'update').mockResolvedValue(mockUser);
132
+ // jest
133
+ // .spyOn(authService, 'generateRandomString')
134
+ // .mockReturnValue('resetCode');
135
+
136
+ // const result = await authService.forget({ email: 'test@example.com' });
137
+
138
+ // expect(prismaService.user.update).toHaveBeenCalledWith({
139
+ // where: { id: 1 },
140
+ // data: { code: 'resetCode' },
141
+ // });
142
+ // expect(mailService.send).toHaveBeenCalledWith({
143
+ // to: 'test@example.com',
144
+ // subject: 'Reset password',
145
+ // body: `Reset your password by clicking <a href="${process.env.FRONTEND_URL}/reset-password/resetCode">here</a>`,
146
+ // });
147
+ // expect(result).toEqual(true);
148
+ // });
149
+ // });
150
+
151
+ // describe('otp', () => {
152
+ // it('should throw NotFoundException if user with code is not found', async () => {
153
+ // jest.spyOn(jwtService, 'decode').mockReturnValue({ id: 1 });
154
+ // jest.spyOn(prismaService.user, 'findFirst').mockResolvedValue(null);
155
+
156
+ // await expect(
157
+ // authService.otp({ token: 'token', code: 123456 }),
158
+ // ).rejects.toThrow(NotFoundException);
159
+ // });
160
+
161
+ // it('should return a token if otp is valid', async () => {
162
+ // const mockUser = {
163
+ // id: 1,
164
+ // name: 'Test User',
165
+ // email: 'test@example.com',
166
+ // password: 'hashedpassword',
167
+ // multifactor_id: null,
168
+ // code: null,
169
+ // created_at: new Date(),
170
+ // updated_at: new Date(),
171
+ // };
172
+ // jest.spyOn(jwtService, 'decode').mockReturnValue({ id: 1 });
173
+ // jest.spyOn(prismaService.user, 'findFirst').mockResolvedValue(mockUser);
174
+ // jest.spyOn(prismaService.user, 'update').mockResolvedValue(mockUser);
175
+ // jest.spyOn(jwtService, 'sign').mockReturnValue('newToken');
176
+
177
+ // const result = await authService.otp({ token: 'token', code: 123456 });
178
+
179
+ // expect(prismaService.user.update).toHaveBeenCalledWith({
180
+ // where: { id: 1 },
181
+ // data: { code: null },
182
+ // });
183
+ // expect(result).toEqual({ token: 'newToken' });
184
+ // });
185
+ // });
186
+
187
+ // describe('verifyToken', () => {
188
+ // it('should verify and return token data', async () => {
189
+ // jest.spyOn(jwtService, 'verifyAsync').mockResolvedValue({ id: 1 });
190
+
191
+ // const result = await authService.verifyToken('token');
192
+
193
+ // expect(result).toEqual({ id: 1 });
194
+ // });
195
+ // });
196
+ // });