@hedhog/admin 0.0.104 → 0.0.105

Sign up to get free protection for your applications and to get access to all the features.
Files changed (186) hide show
  1. package/README.md +141 -141
  2. package/dist/admin.module.js +7 -7
  3. package/dist/admin.module.js.map +1 -1
  4. package/dist/auth/auth.service.d.ts +1 -1
  5. package/dist/auth/auth.service.d.ts.map +1 -1
  6. package/dist/auth/auth.service.js +8 -8
  7. package/dist/auth/auth.service.js.map +1 -1
  8. package/dist/auth/auth.service.spec.js +16 -16
  9. package/dist/auth/auth.service.spec.js.map +1 -1
  10. package/dist/dto/with-locale.dto.d.ts +4 -0
  11. package/dist/dto/with-locale.dto.d.ts.map +1 -0
  12. package/dist/dto/{with-locales.dto.js → with-locale.dto.js} +5 -5
  13. package/dist/dto/with-locale.dto.js.map +1 -0
  14. package/dist/index.d.ts +2 -2
  15. package/dist/index.d.ts.map +1 -1
  16. package/dist/index.js +2 -2
  17. package/dist/index.js.map +1 -1
  18. package/dist/locale/locale.controller.js +1 -1
  19. package/dist/locale/locale.controller.js.map +1 -1
  20. package/dist/locale/locale.middleware.d.ts +1 -1
  21. package/dist/locale/locale.middleware.d.ts.map +1 -1
  22. package/dist/locale/locale.middleware.js +2 -2
  23. package/dist/locale/locale.middleware.js.map +1 -1
  24. package/dist/locale/locale.service.d.ts +6 -6
  25. package/dist/locale/locale.service.d.ts.map +1 -1
  26. package/dist/locale/locale.service.js +40 -40
  27. package/dist/locale/locale.service.js.map +1 -1
  28. package/dist/locale/locale.service.spec.js +14 -14
  29. package/dist/locale/locale.service.spec.js.map +1 -1
  30. package/dist/menu/menu.controller.js +3 -3
  31. package/dist/menu/menu.controller.js.map +1 -1
  32. package/dist/menu/menu.service.d.ts +3 -3
  33. package/dist/menu/menu.service.d.ts.map +1 -1
  34. package/dist/menu/menu.service.js +35 -35
  35. package/dist/menu/menu.service.js.map +1 -1
  36. package/dist/menu/menu.service.spec.js +33 -37
  37. package/dist/menu/menu.service.spec.js.map +1 -1
  38. package/dist/role/dto/create.dto.d.ts +2 -2
  39. package/dist/role/dto/create.dto.d.ts.map +1 -1
  40. package/dist/role/dto/create.dto.js +2 -2
  41. package/dist/role/dto/create.dto.js.map +1 -1
  42. package/dist/role/guards/role.guard.js +4 -4
  43. package/dist/role/guards/role.guard.js.map +1 -1
  44. package/dist/role/role.controller.js +7 -7
  45. package/dist/role/role.controller.js.map +1 -1
  46. package/dist/role/role.service.d.ts +2 -2
  47. package/dist/role/role.service.d.ts.map +1 -1
  48. package/dist/role/role.service.js +35 -35
  49. package/dist/role/role.service.js.map +1 -1
  50. package/dist/role/role.service.spec.d.ts +0 -1
  51. package/dist/role/role.service.spec.js +400 -340
  52. package/dist/role/role.service.spec.js.map +1 -1
  53. package/dist/route/route.controller.js +3 -3
  54. package/dist/route/route.controller.js.map +1 -1
  55. package/dist/route/route.service.d.ts +2 -2
  56. package/dist/route/route.service.d.ts.map +1 -1
  57. package/dist/route/route.service.js +18 -18
  58. package/dist/route/route.service.js.map +1 -1
  59. package/dist/route/route.service.spec.js +27 -27
  60. package/dist/route/route.service.spec.js.map +1 -1
  61. package/dist/screen/screen.controller.js +4 -4
  62. package/dist/screen/screen.controller.js.map +1 -1
  63. package/dist/screen/screen.service.d.ts +2 -2
  64. package/dist/screen/screen.service.d.ts.map +1 -1
  65. package/dist/screen/screen.service.js +16 -16
  66. package/dist/screen/screen.service.js.map +1 -1
  67. package/dist/screen/screen.service.spec.js +16 -16
  68. package/dist/screen/screen.service.spec.js.map +1 -1
  69. package/dist/setting/dto/setting.dto.d.ts +9 -0
  70. package/dist/setting/dto/setting.dto.d.ts.map +1 -0
  71. package/dist/setting/dto/{settings.dto.js → setting.dto.js} +6 -6
  72. package/dist/setting/dto/setting.dto.js.map +1 -0
  73. package/dist/setting/{settings.controller.d.ts → setting.controller.d.ts} +6 -6
  74. package/dist/setting/setting.controller.d.ts.map +1 -0
  75. package/dist/setting/{settings.controller.js → setting.controller.js} +20 -20
  76. package/dist/setting/setting.controller.js.map +1 -0
  77. package/dist/setting/setting.module.d.ts +3 -0
  78. package/dist/setting/setting.module.d.ts.map +1 -0
  79. package/dist/setting/{settings.module.js → setting.module.js} +6 -6
  80. package/dist/setting/setting.module.js.map +1 -0
  81. package/dist/setting/{settings.service.d.ts → setting.service.d.ts} +4 -4
  82. package/dist/setting/setting.service.d.ts.map +1 -0
  83. package/dist/setting/{settings.service.js → setting.service.js} +42 -42
  84. package/dist/setting/setting.service.js.map +1 -0
  85. package/dist/setting/setting.service.spec.d.ts +2 -0
  86. package/dist/setting/setting.service.spec.d.ts.map +1 -0
  87. package/dist/setting/{settings.service.spec.js → setting.service.spec.js} +17 -17
  88. package/dist/setting/setting.service.spec.js.map +1 -0
  89. package/dist/user/user.controller.js +3 -3
  90. package/dist/user/user.controller.js.map +1 -1
  91. package/dist/user/user.service.d.ts +2 -2
  92. package/dist/user/user.service.d.ts.map +1 -1
  93. package/dist/user/user.service.js +9 -9
  94. package/dist/user/user.service.js.map +1 -1
  95. package/dist/user/user.service.spec.js +24 -24
  96. package/dist/user/user.service.spec.js.map +1 -1
  97. package/package.json +2 -2
  98. package/src/admin.module.ts +36 -0
  99. package/src/auth/auth.controller.ts +48 -0
  100. package/src/auth/auth.module.ts +39 -0
  101. package/src/auth/auth.service.spec.ts +196 -0
  102. package/src/auth/auth.service.ts +175 -0
  103. package/src/auth/decorators/public.decorator.ts +4 -0
  104. package/src/auth/decorators/user.decorator.ts +17 -0
  105. package/src/auth/dto/forget.dto.ts +6 -0
  106. package/src/auth/dto/login.dto.ts +15 -0
  107. package/src/auth/dto/otp.dto.ts +11 -0
  108. package/src/auth/enums/multifactor-type.enum.ts +4 -0
  109. package/src/auth/guards/auth.guard.ts +50 -0
  110. package/src/auth/types/user.type.ts +8 -0
  111. package/src/dto/delete.dto.ts +8 -0
  112. package/src/dto/update-ids.dto.ts +9 -0
  113. package/src/dto/with-locale.dto.ts +8 -0
  114. package/src/index.ts +34 -0
  115. package/src/locale/dto/create.dto.ts +12 -0
  116. package/src/locale/dto/delete.dto.ts +8 -0
  117. package/src/locale/dto/set-enabled.dto.ts +9 -0
  118. package/src/locale/dto/update.dto.ts +15 -0
  119. package/src/locale/index.ts +4 -0
  120. package/src/locale/locale.controller.ts +79 -0
  121. package/src/locale/locale.decorator.ts +8 -0
  122. package/src/locale/locale.middleware.ts +34 -0
  123. package/src/locale/locale.module.ts +23 -0
  124. package/src/locale/locale.service.spec.ts +193 -0
  125. package/src/locale/locale.service.ts +366 -0
  126. package/src/menu/dto/create.dto.ts +25 -0
  127. package/src/menu/dto/order.dto.ts +8 -0
  128. package/src/menu/dto/update.dto.ts +19 -0
  129. package/src/menu/menu.controller.ts +106 -0
  130. package/src/menu/menu.module.ts +18 -0
  131. package/src/menu/menu.service.spec.ts +247 -0
  132. package/src/menu/menu.service.ts +263 -0
  133. package/src/role/decorators/role.decorator.ts +4 -0
  134. package/src/role/dto/create.dto.ts +7 -0
  135. package/src/role/dto/update.dto.ts +4 -0
  136. package/src/role/guards/role.guard.ts +122 -0
  137. package/src/role/role.controller.ts +126 -0
  138. package/src/role/role.module.ts +28 -0
  139. package/src/role/role.service.spec.ts +417 -0
  140. package/src/role/role.service.ts +302 -0
  141. package/src/route/dto/create.dto.ts +13 -0
  142. package/src/route/dto/update.dto.ts +15 -0
  143. package/src/route/route.controller.ts +91 -0
  144. package/src/route/route.module.ts +18 -0
  145. package/src/route/route.service.spec.ts +299 -0
  146. package/src/route/route.service.ts +164 -0
  147. package/src/screen/dto/create.dto.ts +19 -0
  148. package/src/screen/dto/update.dto.ts +19 -0
  149. package/src/screen/screen.controller.ts +93 -0
  150. package/src/screen/screen.module.ts +18 -0
  151. package/src/screen/screen.service.spec.ts +298 -0
  152. package/src/screen/screen.service.ts +181 -0
  153. package/src/setting/dto/create.dto.ts +1 -0
  154. package/src/setting/dto/setting-user.dto.ts +6 -0
  155. package/src/setting/dto/setting.dto.ts +17 -0
  156. package/src/setting/dto/update.dto.ts +3 -0
  157. package/src/setting/setting.controller.ts +100 -0
  158. package/src/setting/setting.module.ts +18 -0
  159. package/src/setting/setting.service.spec.ts +183 -0
  160. package/src/setting/setting.service.ts +346 -0
  161. package/src/types/http-method.ts +8 -0
  162. package/src/user/constants/user.constants.ts +1 -0
  163. package/src/user/dto/create.dto.ts +24 -0
  164. package/src/user/dto/update.dto.ts +41 -0
  165. package/src/user/user.controller.ts +75 -0
  166. package/src/user/user.module.ts +18 -0
  167. package/src/user/user.service.spec.ts +294 -0
  168. package/src/user/user.service.ts +129 -0
  169. package/tsconfig.lib.json +9 -0
  170. package/tsconfig.production.json +20 -0
  171. package/dist/dto/with-locales.dto.d.ts +0 -4
  172. package/dist/dto/with-locales.dto.d.ts.map +0 -1
  173. package/dist/dto/with-locales.dto.js.map +0 -1
  174. package/dist/setting/dto/settings.dto.d.ts +0 -9
  175. package/dist/setting/dto/settings.dto.d.ts.map +0 -1
  176. package/dist/setting/dto/settings.dto.js.map +0 -1
  177. package/dist/setting/settings.controller.d.ts.map +0 -1
  178. package/dist/setting/settings.controller.js.map +0 -1
  179. package/dist/setting/settings.module.d.ts +0 -3
  180. package/dist/setting/settings.module.d.ts.map +0 -1
  181. package/dist/setting/settings.module.js.map +0 -1
  182. package/dist/setting/settings.service.d.ts.map +0 -1
  183. package/dist/setting/settings.service.js.map +0 -1
  184. package/dist/setting/settings.service.spec.d.ts +0 -2
  185. package/dist/setting/settings.service.spec.d.ts.map +0 -1
  186. package/dist/setting/settings.service.spec.js.map +0 -1
@@ -1,357 +1,417 @@
1
1
  "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const pagination_1 = require("@hedhog/pagination");
4
- const prisma_1 = require("@hedhog/prisma");
5
- const common_1 = require("@nestjs/common");
6
- const testing_1 = require("@nestjs/testing");
7
- const role_service_1 = require("./role.service");
2
+ /*
8
3
  describe('RoleService', () => {
9
- let roleService;
10
- let prismaService;
11
- let paginationService;
12
- beforeEach(async () => {
13
- const module = await testing_1.Test.createTestingModule({
14
- providers: [
15
- role_service_1.RoleService,
16
- {
17
- provide: prisma_1.PrismaService,
18
- useValue: {
19
- roles: {
20
- create: jest.fn(),
21
- update: jest.fn(),
22
- findUnique: jest.fn(),
23
- deleteMany: jest.fn(),
24
- findMany: jest.fn(),
25
- },
26
- role_users: {
27
- deleteMany: jest.fn(),
28
- createMany: jest.fn(),
29
- },
30
- role_menus: {
31
- deleteMany: jest.fn(),
32
- createMany: jest.fn(),
33
- },
34
- role_screens: {
35
- deleteMany: jest.fn(),
36
- createMany: jest.fn(),
37
- },
38
- role_routes: {
39
- deleteMany: jest.fn(),
40
- createMany: jest.fn(),
41
- },
42
- },
43
- },
44
- {
45
- provide: pagination_1.PaginationService,
46
- useValue: {
47
- paginate: jest.fn(),
48
- },
49
- },
50
- ],
51
- }).compile();
52
- roleService = module.get(role_service_1.RoleService);
53
- prismaService = module.get(prisma_1.PrismaService);
54
- paginationService = module.get(pagination_1.PaginationService);
4
+ let roleService: RoleService;
5
+ let prismaService: PrismaService;
6
+ let paginationService: PaginationService;
7
+
8
+ beforeEach(async () => {
9
+ const module: TestingModule = await Test.createTestingModule({
10
+ providers: [
11
+ RoleService,
12
+ {
13
+ provide: PrismaService,
14
+ useValue: {
15
+ role {
16
+ create: jest.fn(),
17
+ update: jest.fn(),
18
+ findUnique: jest.fn(),
19
+ deleteMany: jest.fn(),
20
+ findMany: jest.fn(),
21
+ },
22
+ role_user: {
23
+ deleteMany: jest.fn(),
24
+ createMany: jest.fn(),
25
+ },
26
+ role_menu: {
27
+ deleteMany: jest.fn(),
28
+ createMany: jest.fn(),
29
+ },
30
+ role_screen: {
31
+ deleteMany: jest.fn(),
32
+ createMany: jest.fn(),
33
+ },
34
+ role_route: {
35
+ deleteMany: jest.fn(),
36
+ createMany: jest.fn(),
37
+ },
38
+ },
39
+ },
40
+ {
41
+ provide: PaginationService,
42
+ useValue: {
43
+ paginate: jest.fn(),
44
+ },
45
+ },
46
+ ],
47
+ }).compile();
48
+
49
+ roleService = module.get<RoleService>(RoleService);
50
+ prismaService = module.get<PrismaService>(PrismaService);
51
+ paginationService = module.get<PaginationService>(PaginationService);
52
+ });
53
+ /*
54
+ describe('create', () => {
55
+ it('should create a new role', async () => {
56
+ const dto: CreateDTO = {
57
+ name: 'Admin',
58
+ description: 'Administrator role',
59
+ };
60
+ const result = {
61
+ id: 1,
62
+ ...dto,
63
+ created_at: new Date(),
64
+ updated_at: new Date(),
65
+ };
66
+
67
+ jest.spyOn(prismaService.role, 'create').mockResolvedValue(result);
68
+
69
+ expect(await roleService.create(dto)).toEqual(result);
55
70
  });
56
- /*
57
- describe('create', () => {
58
- it('should create a new role', async () => {
59
- const dto: CreateDTO = {
60
- name: 'Admin',
61
- description: 'Administrator role',
62
- };
63
- const result = {
64
- id: 1,
65
- ...dto,
66
- created_at: new Date(),
67
- updated_at: new Date(),
68
- };
69
-
70
- jest.spyOn(prismaService.roles, 'create').mockResolvedValue(result);
71
-
72
- expect(await roleService.create(dto)).toEqual(result);
71
+ });
72
+ */
73
+ // describe('update', () => {
74
+ // it('should update an existing role', async () => {
75
+ // const dto: UpdateDTO = {
76
+ // name: 'Admin',
77
+ // description: 'Updated description',
78
+ // };
79
+ // const result = {
80
+ // id: 1,
81
+ // ...dto,
82
+ // created_at: new Date(),
83
+ // updated_at: new Date(),
84
+ // };
85
+ // jest.spyOn(prismaService.role, 'update').mockResolvedValue(result);
86
+ // expect(await roleService.update({ id: 1, data: dto })).toEqual(result);
87
+ // });
88
+ // });
89
+ /*
90
+ describe('delete', () => {
91
+ it('should delete role', async () => {
92
+ const dto: DeleteDTO = { ids: [1, 2] };
93
+ jest
94
+ .spyOn(prismaService.role, 'deleteMany')
95
+ .mockResolvedValue({ count: 2 });
96
+
97
+ await roleService.delete(dto);
98
+ expect(prismaService.role.deleteMany).toHaveBeenCalledWith({
99
+ where: {
100
+ id: { in: dto.ids },
101
+ },
73
102
  });
74
103
  });
75
- */
76
- // describe('update', () => {
77
- // it('should update an existing role', async () => {
78
- // const dto: UpdateDTO = {
79
- // name: 'Admin',
80
- // description: 'Updated description',
81
- // };
82
- // const result = {
83
- // id: 1,
84
- // ...dto,
85
- // created_at: new Date(),
86
- // updated_at: new Date(),
87
- // };
88
- // jest.spyOn(prismaService.roles, 'update').mockResolvedValue(result);
89
- // expect(await roleService.update({ id: 1, data: dto })).toEqual(result);
90
- // });
91
- // });
92
- describe('delete', () => {
93
- it('should delete roles', async () => {
94
- const dto = { ids: [1, 2] };
95
- jest
96
- .spyOn(prismaService.roles, 'deleteMany')
97
- .mockResolvedValue({ count: 2 });
98
- await roleService.delete(dto);
99
- expect(prismaService.roles.deleteMany).toHaveBeenCalledWith({
100
- where: {
101
- id: { in: dto.ids },
102
- },
103
- });
104
- });
105
- it('should throw BadRequestException if no ids are provided', async () => {
106
- const dto = { ids: null };
107
- await expect(roleService.delete(dto)).rejects.toThrow(common_1.BadRequestException);
108
- });
104
+
105
+ it('should throw BadRequestException if no ids are provided', async () => {
106
+ const dto: DeleteDTO = { ids: null };
107
+ await expect(roleService.delete(dto)).rejects.toThrow(
108
+ BadRequestException,
109
+ );
109
110
  });
110
- describe('updateUsers', () => {
111
- it('should update users for a role', async () => {
112
- const roleId = 1;
113
- const data = { ids: [1, 2] };
114
- jest
115
- .spyOn(prismaService.role_users, 'deleteMany')
116
- .mockResolvedValue({ count: 2 });
117
- jest
118
- .spyOn(prismaService.role_users, 'createMany')
119
- .mockResolvedValue({ count: 2 });
120
- await roleService.updateUsers(roleId, data);
121
- expect(prismaService.role_users.deleteMany).toHaveBeenCalledWith({
122
- where: { role_id: roleId },
123
- });
124
- expect(prismaService.role_users.createMany).toHaveBeenCalledWith({
125
- data: data.ids.map((userId) => ({
126
- role_id: roleId,
127
- user_id: userId,
128
- })),
129
- skipDuplicates: true,
130
- });
131
- });
111
+ });
112
+
113
+ describe('updateUsers', () => {
114
+ it('should update user for a role', async () => {
115
+ const roleId = 1;
116
+ const data: UpdateIdsDTO = { ids: [1, 2] };
117
+
118
+ jest
119
+ .spyOn(prismaService.role_user, 'deleteMany')
120
+ .mockResolvedValue({ count: 2 });
121
+ jest
122
+ .spyOn(prismaService.role_user, 'createMany')
123
+ .mockResolvedValue({ count: 2 });
124
+
125
+ await roleService.updateUsers(roleId, data);
126
+
127
+ expect(prismaService.role_user.deleteMany).toHaveBeenCalledWith({
128
+ where: { role_id: roleId },
129
+ });
130
+
131
+ expect(prismaService.role_user.createMany).toHaveBeenCalledWith({
132
+ data: data.ids.map((userId) => ({
133
+ role_id: roleId,
134
+ user_id: userId,
135
+ })),
136
+ skipDuplicates: true,
137
+ });
132
138
  });
133
- describe('updateScreens', () => {
134
- it('should update screens for a role', async () => {
135
- const roleId = 1;
136
- const data = { ids: [1, 2] };
137
- jest
138
- .spyOn(prismaService.role_screens, 'deleteMany')
139
- .mockResolvedValue({ count: 2 });
140
- jest
141
- .spyOn(prismaService.role_screens, 'createMany')
142
- .mockResolvedValue({ count: 2 });
143
- await roleService.updateScreens(roleId, data);
144
- expect(prismaService.role_screens.deleteMany).toHaveBeenCalledWith({
145
- where: { role_id: roleId },
146
- });
147
- expect(prismaService.role_screens.createMany).toHaveBeenCalledWith({
148
- data: data.ids.map((screenId) => ({
149
- role_id: roleId,
150
- screen_id: screenId,
151
- })),
152
- skipDuplicates: true,
153
- });
154
- });
139
+ });
140
+
141
+ describe('updateScreens', () => {
142
+ it('should update screens for a role', async () => {
143
+ const roleId = 1;
144
+ const data: UpdateIdsDTO = { ids: [1, 2] };
145
+
146
+ jest
147
+ .spyOn(prismaService.role_screen, 'deleteMany')
148
+ .mockResolvedValue({ count: 2 });
149
+ jest
150
+ .spyOn(prismaService.role_screen, 'createMany')
151
+ .mockResolvedValue({ count: 2 });
152
+
153
+ await roleService.updateScreens(roleId, data);
154
+
155
+ expect(prismaService.role_screen.deleteMany).toHaveBeenCalledWith({
156
+ where: { role_id: roleId },
157
+ });
158
+
159
+ expect(prismaService.role_screen.createMany).toHaveBeenCalledWith({
160
+ data: data.ids.map((screenId) => ({
161
+ role_id: roleId,
162
+ screen_id: screenId,
163
+ })),
164
+ skipDuplicates: true,
165
+ });
155
166
  });
156
- describe('updateRoutes', () => {
157
- it('should update routes for a role', async () => {
158
- const roleId = 1;
159
- const data = { ids: [1, 2] };
160
- jest
161
- .spyOn(prismaService.role_routes, 'deleteMany')
162
- .mockResolvedValue({ count: 2 });
163
- jest
164
- .spyOn(prismaService.role_routes, 'createMany')
165
- .mockResolvedValue({ count: 2 });
166
- await roleService.updateRoutes(roleId, data);
167
- expect(prismaService.role_routes.deleteMany).toHaveBeenCalledWith({
168
- where: { role_id: roleId },
169
- });
170
- expect(prismaService.role_routes.createMany).toHaveBeenCalledWith({
171
- data: data.ids.map((routeId) => ({
172
- role_id: roleId,
173
- route_id: routeId,
174
- })),
175
- skipDuplicates: true,
176
- });
177
- });
167
+ });
168
+
169
+ describe('updateRoutes', () => {
170
+ it('should update route for a role', async () => {
171
+ const roleId = 1;
172
+ const data: UpdateIdsDTO = { ids: [1, 2] };
173
+
174
+ jest
175
+ .spyOn(prismaService.role_route, 'deleteMany')
176
+ .mockResolvedValue({ count: 2 });
177
+ jest
178
+ .spyOn(prismaService.role_route, 'createMany')
179
+ .mockResolvedValue({ count: 2 });
180
+
181
+ await roleService.updateRoutes(roleId, data);
182
+
183
+ expect(prismaService.role_route.deleteMany).toHaveBeenCalledWith({
184
+ where: { role_id: roleId },
185
+ });
186
+
187
+ expect(prismaService.role_route.createMany).toHaveBeenCalledWith({
188
+ data: data.ids.map((routeId) => ({
189
+ role_id: roleId,
190
+ route_id: routeId,
191
+ })),
192
+ skipDuplicates: true,
193
+ });
178
194
  });
179
- describe('updateMenus', () => {
180
- it('should update menus for a role', async () => {
181
- const roleId = 1;
182
- const data = { ids: [1, 2] };
183
- jest
184
- .spyOn(prismaService.role_menus, 'deleteMany')
185
- .mockResolvedValue({ count: 2 });
186
- jest
187
- .spyOn(prismaService.role_menus, 'createMany')
188
- .mockResolvedValue({ count: 2 });
189
- await roleService.updateMenus(roleId, data);
190
- expect(prismaService.role_menus.deleteMany).toHaveBeenCalledWith({
191
- where: { role_id: roleId },
192
- });
193
- expect(prismaService.role_menus.createMany).toHaveBeenCalledWith({
194
- data: data.ids.map((menuId) => ({
195
- role_id: roleId,
196
- menu_id: menuId,
197
- })),
198
- skipDuplicates: true,
199
- });
200
- });
195
+ });
196
+
197
+ describe('updateMenus', () => {
198
+ it('should update menu for a role', async () => {
199
+ const roleId = 1;
200
+ const data: UpdateIdsDTO = { ids: [1, 2] };
201
+
202
+ jest
203
+ .spyOn(prismaService.role_menu, 'deleteMany')
204
+ .mockResolvedValue({ count: 2 });
205
+ jest
206
+ .spyOn(prismaService.role_menu, 'createMany')
207
+ .mockResolvedValue({ count: 2 });
208
+
209
+ await roleService.updateMenus(roleId, data);
210
+
211
+ expect(prismaService.role_menu.deleteMany).toHaveBeenCalledWith({
212
+ where: { role_id: roleId },
213
+ });
214
+
215
+ expect(prismaService.role_menu.createMany).toHaveBeenCalledWith({
216
+ data: data.ids.map((menuId) => ({
217
+ role_id: roleId,
218
+ menu_id: menuId,
219
+ })),
220
+ skipDuplicates: true,
221
+ });
201
222
  });
202
- describe('listUsers', () => {
203
- it('should list users associated with a role', async () => {
204
- const roleId = 1;
205
- const paginationParams = {
206
- page: 1,
207
- pageSize: 10,
208
- search: '',
209
- sortField: '',
210
- sortOrder: pagination_1.PageOrderDirection.Asc,
211
- fields: '',
212
- };
213
- const mockPaginationResult = {
214
- data: [],
215
- total: 10,
216
- lastPage: 1,
217
- page: 1,
218
- prev: 0,
219
- next: 2,
220
- pageSize: 10,
221
- };
222
- jest
223
- .spyOn(paginationService, 'paginate')
224
- .mockResolvedValue(mockPaginationResult);
225
- await roleService.listUsers(roleId, paginationParams);
226
- expect(paginationService.paginate).toHaveBeenCalledWith(prismaService.users, paginationParams, {
227
- include: {
228
- role_users: {
229
- where: { role_id: roleId },
230
- select: { user_id: true, role_id: true },
231
- },
232
- },
233
- });
234
- });
223
+ });
224
+
225
+ describe('listUsers', () => {
226
+ it('should list user associated with a role', async () => {
227
+ const roleId = 1;
228
+ const paginationParams: PaginationDTO = {
229
+ page: 1,
230
+ pageSize: 10,
231
+ search: '',
232
+ sortField: '',
233
+ sortOrder: PageOrderDirection.Asc,
234
+ fields: '',
235
+ };
236
+ const mockPaginationResult = {
237
+ data: [],
238
+ total: 10,
239
+ lastPage: 1,
240
+ page: 1,
241
+ prev: 0,
242
+ next: 2,
243
+ pageSize: 10,
244
+ };
245
+
246
+ jest
247
+ .spyOn(paginationService, 'paginate')
248
+ .mockResolvedValue(mockPaginationResult);
249
+
250
+ await roleService.listUsers(roleId, paginationParams);
251
+
252
+ expect(paginationService.paginate).toHaveBeenCalledWith(
253
+ prismaService.user,
254
+ paginationParams,
255
+ {
256
+ include: {
257
+ role_user: {
258
+ where: { role_id: roleId },
259
+ select: { user_id: true, role_id: true },
260
+ },
261
+ },
262
+ },
263
+ );
235
264
  });
236
- describe('listMenus', () => {
237
- it('should list menus associated with a role', async () => {
238
- const locale = 'en';
239
- const roleId = 1;
240
- const paginationParams = {
241
- page: 1,
242
- pageSize: 10,
243
- search: '',
244
- sortField: '',
245
- sortOrder: pagination_1.PageOrderDirection.Asc,
246
- fields: '',
247
- };
248
- const mockPaginationResult = {
249
- data: [],
250
- total: 10,
251
- lastPage: 1,
252
- page: 1,
253
- prev: 0,
254
- next: 2,
255
- pageSize: 10,
256
- };
257
- jest
258
- .spyOn(paginationService, 'paginate')
259
- .mockResolvedValue(mockPaginationResult);
260
- await roleService.listMenus(locale, roleId, paginationParams);
261
- expect(paginationService.paginate).toHaveBeenCalledWith(prismaService.menus, paginationParams, {
262
- include: {
263
- menu_translations: {
264
- where: { locales: { code: locale } },
265
- select: { name: true },
266
- },
267
- role_menus: {
268
- where: { role_id: roleId },
269
- select: { menu_id: true, role_id: true },
270
- },
271
- },
272
- }, 'menu_translations');
273
- });
265
+ });
266
+
267
+ describe('listMenus', () => {
268
+ it('should list menu associated with a role', async () => {
269
+ const locale = 'en';
270
+ const roleId = 1;
271
+ const paginationParams: PaginationDTO = {
272
+ page: 1,
273
+ pageSize: 10,
274
+ search: '',
275
+ sortField: '',
276
+ sortOrder: PageOrderDirection.Asc,
277
+ fields: '',
278
+ };
279
+ const mockPaginationResult = {
280
+ data: [],
281
+ total: 10,
282
+ lastPage: 1,
283
+ page: 1,
284
+ prev: 0,
285
+ next: 2,
286
+ pageSize: 10,
287
+ };
288
+
289
+ jest
290
+ .spyOn(paginationService, 'paginate')
291
+ .mockResolvedValue(mockPaginationResult);
292
+
293
+ await roleService.listMenus(locale, roleId, paginationParams);
294
+
295
+ expect(paginationService.paginate).toHaveBeenCalledWith(
296
+ prismaService.menu,
297
+ paginationParams,
298
+ {
299
+ include: {
300
+ menu_locale: {
301
+ where: { locale: { code: locale } },
302
+ select: { name: true },
303
+ },
304
+ role_menu: {
305
+ where: { role_id: roleId },
306
+ select: { menu_id: true, role_id: true },
307
+ },
308
+ },
309
+ },
310
+ 'menu_locale',
311
+ );
274
312
  });
275
- describe('listRoutes', () => {
276
- it('should list routes associated with a role', async () => {
277
- const roleId = 1;
278
- const paginationParams = {
279
- page: 1,
280
- pageSize: 10,
281
- search: '',
282
- sortField: '',
283
- sortOrder: pagination_1.PageOrderDirection.Asc,
284
- fields: '',
285
- };
286
- const mockPaginationResult = {
287
- data: [],
288
- total: 10,
289
- lastPage: 1,
290
- page: 1,
291
- prev: 0,
292
- next: 2,
293
- pageSize: 10,
294
- };
295
- jest
296
- .spyOn(paginationService, 'paginate')
297
- .mockResolvedValue(mockPaginationResult);
298
- await roleService.listRoutes(roleId, paginationParams);
299
- expect(paginationService.paginate).toHaveBeenCalledWith(prismaService.routes, paginationParams, {
300
- include: {
301
- role_routes: {
302
- where: { role_id: roleId },
303
- select: { route_id: true, role_id: true },
304
- },
305
- },
306
- });
307
- });
313
+ });
314
+
315
+ describe('listRoutes', () => {
316
+ it('should list route associated with a role', async () => {
317
+ const roleId = 1;
318
+ const paginationParams: PaginationDTO = {
319
+ page: 1,
320
+ pageSize: 10,
321
+ search: '',
322
+ sortField: '',
323
+ sortOrder: PageOrderDirection.Asc,
324
+ fields: '',
325
+ };
326
+ const mockPaginationResult = {
327
+ data: [],
328
+ total: 10,
329
+ lastPage: 1,
330
+ page: 1,
331
+ prev: 0,
332
+ next: 2,
333
+ pageSize: 10,
334
+ };
335
+
336
+ jest
337
+ .spyOn(paginationService, 'paginate')
338
+ .mockResolvedValue(mockPaginationResult);
339
+
340
+ await roleService.listRoutes(roleId, paginationParams);
341
+
342
+ expect(paginationService.paginate).toHaveBeenCalledWith(
343
+ prismaService.route,
344
+ paginationParams,
345
+ {
346
+ include: {
347
+ role_route: {
348
+ where: { role_id: roleId },
349
+ select: { route_id: true, role_id: true },
350
+ },
351
+ },
352
+ },
353
+ );
308
354
  });
309
- describe('listScreens', () => {
310
- it('should list screens associated with a role', async () => {
311
- const locale = 'en';
312
- const roleId = 1;
313
- const paginationParams = {
314
- page: 1,
315
- pageSize: 10,
316
- search: '',
317
- sortField: '',
318
- sortOrder: pagination_1.PageOrderDirection.Asc,
319
- fields: '',
320
- };
321
- const mockPaginationResult = {
322
- data: [],
323
- total: 10,
324
- lastPage: 1,
325
- page: 1,
326
- prev: 0,
327
- next: 2,
328
- pageSize: 10,
329
- };
330
- jest
331
- .spyOn(paginationService, 'paginate')
332
- .mockResolvedValue(mockPaginationResult);
333
- await roleService.listScreens(locale, roleId, paginationParams);
334
- expect(paginationService.paginate).toHaveBeenCalledWith(prismaService.screens, paginationParams, {
335
- include: {
336
- screen_translations: {
337
- where: { locales: { code: locale } },
338
- select: { name: true },
339
- },
340
- role_screens: {
341
- where: { role_id: roleId },
342
- select: { screen_id: true, role_id: true },
343
- },
344
- },
345
- }, 'screen_translations');
346
- });
355
+ });
356
+
357
+ describe('listScreens', () => {
358
+ it('should list screens associated with a role', async () => {
359
+ const locale = 'en';
360
+ const roleId = 1;
361
+ const paginationParams: PaginationDTO = {
362
+ page: 1,
363
+ pageSize: 10,
364
+ search: '',
365
+ sortField: '',
366
+ sortOrder: PageOrderDirection.Asc,
367
+ fields: '',
368
+ };
369
+ const mockPaginationResult = {
370
+ data: [],
371
+ total: 10,
372
+ lastPage: 1,
373
+ page: 1,
374
+ prev: 0,
375
+ next: 2,
376
+ pageSize: 10,
377
+ };
378
+
379
+ jest
380
+ .spyOn(paginationService, 'paginate')
381
+ .mockResolvedValue(mockPaginationResult);
382
+
383
+ await roleService.listScreens(locale, roleId, paginationParams);
384
+
385
+ expect(paginationService.paginate).toHaveBeenCalledWith(
386
+ prismaService.screens,
387
+ paginationParams,
388
+ {
389
+ include: {
390
+ screen_locale: {
391
+ where: { locale: { code: locale } },
392
+ select: { name: true },
393
+ },
394
+ role_screen: {
395
+ where: { role_id: roleId },
396
+ select: { screen_id: true, role_id: true },
397
+ },
398
+ },
399
+ },
400
+ 'screen_locale',
401
+ );
347
402
  });
348
- describe('get', () => {
349
- it('should get a specific role by ID', async () => {
350
- const roleId = 1;
351
- const result = { id: roleId, name: 'Admin', description: 'Admin role' };
352
- jest.spyOn(prismaService.roles, 'findUnique').mockResolvedValue(result);
353
- expect(await roleService.get('en', roleId)).toEqual(result);
354
- });
403
+ });
404
+
405
+ describe('get', () => {
406
+ it('should get a specific role by ID', async () => {
407
+ const roleId = 1;
408
+ const result = { id: roleId, name: 'Admin', description: 'Admin role' };
409
+
410
+ jest.spyOn(prismaService.role, 'findUnique').mockResolvedValue(result);
411
+
412
+ expect(await roleService.get('en', roleId)).toEqual(result);
355
413
  });
414
+ });
356
415
  });
416
+ */
357
417
  //# sourceMappingURL=role.service.spec.js.map