@hedhog/admin 0.48.10 → 0.48.12

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 (134) hide show
  1. package/dist/admin.module.d.ts.map +1 -1
  2. package/dist/admin.module.js +4 -1
  3. package/dist/admin.module.js.map +1 -1
  4. package/dist/dashboard/dashboard-core/dashboard-core.controller.d.ts +29 -0
  5. package/dist/dashboard/dashboard-core/dashboard-core.controller.d.ts.map +1 -0
  6. package/dist/dashboard/dashboard-core/dashboard-core.controller.js +38 -0
  7. package/dist/dashboard/dashboard-core/dashboard-core.controller.js.map +1 -0
  8. package/dist/dashboard/dashboard-core/dashboard-core.module.d.ts +3 -0
  9. package/dist/dashboard/dashboard-core/dashboard-core.module.d.ts.map +1 -0
  10. package/dist/dashboard/dashboard-core/dashboard-core.module.js +26 -0
  11. package/dist/dashboard/dashboard-core/dashboard-core.module.js.map +1 -0
  12. package/dist/dashboard/dashboard-core/dashboard-core.service.d.ts +29 -0
  13. package/dist/dashboard/dashboard-core/dashboard-core.service.d.ts.map +1 -0
  14. package/dist/dashboard/dashboard-core/dashboard-core.service.js +33 -0
  15. package/dist/dashboard/dashboard-core/dashboard-core.service.js.map +1 -0
  16. package/dist/dashboard/dashboard.module.d.ts.map +1 -1
  17. package/dist/dashboard/dashboard.module.js +5 -3
  18. package/dist/dashboard/dashboard.module.js.map +1 -1
  19. package/dist/index.d.ts +1 -0
  20. package/dist/index.d.ts.map +1 -1
  21. package/dist/index.js +1 -0
  22. package/dist/index.js.map +1 -1
  23. package/dist/setting/dto/create.dto.d.ts +9 -0
  24. package/dist/setting/dto/create.dto.d.ts.map +1 -0
  25. package/dist/setting/dto/create.dto.js +40 -0
  26. package/dist/setting/dto/create.dto.js.map +1 -0
  27. package/dist/setting/dto/delete.dto.d.ts +4 -0
  28. package/dist/setting/dto/delete.dto.d.ts.map +1 -0
  29. package/dist/setting/dto/delete.dto.js +23 -0
  30. package/dist/setting/dto/delete.dto.js.map +1 -0
  31. package/dist/setting/dto/setting-user.dto.d.ts +4 -0
  32. package/dist/setting/dto/setting-user.dto.d.ts.map +1 -0
  33. package/dist/setting/dto/setting-user.dto.js +21 -0
  34. package/dist/setting/dto/setting-user.dto.js.map +1 -0
  35. package/dist/setting/dto/setting.dto.d.ts +9 -0
  36. package/dist/setting/dto/setting.dto.d.ts.map +1 -0
  37. package/dist/setting/dto/setting.dto.js +34 -0
  38. package/dist/setting/dto/setting.dto.js.map +1 -0
  39. package/dist/setting/dto/update.dto.d.ts +6 -0
  40. package/dist/setting/dto/update.dto.d.ts.map +1 -0
  41. package/dist/setting/dto/update.dto.js +9 -0
  42. package/dist/setting/dto/update.dto.js.map +1 -0
  43. package/dist/setting/setting.controller.d.ts +102 -0
  44. package/dist/setting/setting.controller.d.ts.map +1 -0
  45. package/dist/setting/setting.controller.js +160 -0
  46. package/dist/setting/setting.controller.js.map +1 -0
  47. package/dist/setting/setting.module.d.ts +3 -0
  48. package/dist/setting/setting.module.d.ts.map +1 -0
  49. package/dist/setting/setting.module.js +31 -0
  50. package/dist/setting/setting.module.js.map +1 -0
  51. package/dist/setting/setting.service.d.ts +103 -0
  52. package/dist/setting/setting.service.d.ts.map +1 -0
  53. package/dist/setting/setting.service.js +333 -0
  54. package/dist/setting/setting.service.js.map +1 -0
  55. package/frontend/dashboard/components/create-panel.tsx.ejs +63 -63
  56. package/frontend/dashboard/components/dashboard.screen.tsx.ejs +116 -116
  57. package/frontend/dashboard/components/update-panel.tsx.ejs +80 -80
  58. package/frontend/dashboard/locales/en/dashboard.dashboard.json +11 -11
  59. package/frontend/dashboard/locales/pt/dashboard.dashboard.json +11 -11
  60. package/frontend/dashboard/react-query/handlers.ts.ejs +28 -28
  61. package/frontend/dashboard/react-query/requests.ts.ejs +56 -56
  62. package/frontend/dashboard-component/components/create-panel.tsx.ejs +130 -130
  63. package/frontend/dashboard-component/components/update-panel.tsx.ejs +164 -164
  64. package/frontend/dashboard-component/locales/en/dashboard.dashboard-component.json +11 -11
  65. package/frontend/dashboard-component/locales/pt/dashboard.dashboard-component.json +11 -11
  66. package/frontend/dashboard-component/react-query/handlers.ts.ejs +28 -28
  67. package/frontend/dashboard-component/react-query/requests.ts.ejs +61 -61
  68. package/frontend/dashboard-item/components/create-panel.tsx.ejs +108 -108
  69. package/frontend/dashboard-item/components/update-panel.tsx.ejs +141 -141
  70. package/frontend/dashboard-item/locales/en/dashboard.dashboard-item.json +11 -11
  71. package/frontend/dashboard-item/locales/pt/dashboard.dashboard-item.json +11 -11
  72. package/frontend/dashboard-item/react-query/handlers.ts.ejs +28 -28
  73. package/frontend/dashboard-item/react-query/requests.ts.ejs +58 -58
  74. package/frontend/dashboard-user/components/create-panel.tsx.ejs +108 -108
  75. package/frontend/dashboard-user/components/update-panel.tsx.ejs +137 -137
  76. package/frontend/dashboard-user/locales/en/dashboard.dashboard-user.json +11 -11
  77. package/frontend/dashboard-user/locales/pt/dashboard.dashboard-user.json +11 -11
  78. package/frontend/dashboard-user/react-query/handlers.ts.ejs +28 -28
  79. package/frontend/dashboard-user/react-query/requests.ts.ejs +58 -58
  80. package/hedhog/tables/dashboard.yaml +9 -0
  81. package/hedhog/tables/dashboard_component.yaml +34 -0
  82. package/hedhog/tables/dashboard_component_locale.yaml +24 -0
  83. package/hedhog/tables/dashboard_item.yaml +25 -0
  84. package/hedhog/tables/dashboard_locale.yaml +24 -0
  85. package/hedhog/tables/dashboard_user.yaml +25 -0
  86. package/hedhog/tables/menu.yaml +18 -0
  87. package/hedhog/tables/menu_locale.yaml +19 -0
  88. package/hedhog/tables/menu_screen.yaml +16 -0
  89. package/hedhog/tables/multifactor.yaml +6 -0
  90. package/hedhog/tables/multifactor_locale.yaml +19 -0
  91. package/hedhog/tables/role.yaml +6 -0
  92. package/hedhog/tables/role_locale.yaml +20 -0
  93. package/hedhog/tables/role_menu.yaml +18 -0
  94. package/hedhog/tables/role_route.yaml +18 -0
  95. package/hedhog/tables/role_screen.yaml +18 -0
  96. package/hedhog/tables/role_user.yaml +18 -0
  97. package/hedhog/tables/route.yaml +23 -0
  98. package/hedhog/tables/route_screen.yaml +18 -0
  99. package/hedhog/tables/screen.yaml +8 -0
  100. package/hedhog/tables/screen_locale.yaml +20 -0
  101. package/hedhog/tables/setting.yaml +27 -0
  102. package/hedhog/tables/setting_group.yaml +8 -0
  103. package/hedhog/tables/setting_group_locale.yaml +23 -0
  104. package/hedhog/tables/setting_locale.yaml +24 -0
  105. package/hedhog/tables/setting_user.yaml +21 -0
  106. package/hedhog/tables/translation.yaml +25 -0
  107. package/hedhog/tables/translation_namespace.yaml +6 -0
  108. package/hedhog/tables/user.yaml +18 -0
  109. package/hedhog/tables/user_activity.yaml +14 -0
  110. package/hedhog.yaml +142 -473
  111. package/isabelli.json +0 -0
  112. package/isabelli.xml +0 -0
  113. package/isabelli.yaml +0 -0
  114. package/package.json +1 -1
  115. package/src/admin.module.ts +4 -1
  116. package/src/dashboard/dashboard-component/dashboard-component.controller.ts +55 -55
  117. package/src/dashboard/dashboard-component/dto/create.dto.ts +36 -36
  118. package/src/dashboard/dashboard-component/dto/update.dto.ts +4 -4
  119. package/src/dashboard/dashboard-core/dashboard-core.controller.ts +12 -0
  120. package/src/dashboard/dashboard-core/dashboard-core.module.ts +14 -0
  121. package/src/dashboard/dashboard-core/dashboard-core.service.ts +16 -0
  122. package/src/dashboard/dashboard-item/dto/update.dto.ts +4 -4
  123. package/src/dashboard/dashboard-user/dto/update.dto.ts +4 -4
  124. package/src/dashboard/dashboard.module.ts +5 -3
  125. package/src/dashboard/index.ts +1 -1
  126. package/src/index.ts +2 -0
  127. package/src/setting/dto/create.dto.ts +21 -0
  128. package/src/setting/dto/delete.dto.ts +8 -0
  129. package/src/setting/dto/setting-user.dto.ts +6 -0
  130. package/src/setting/dto/setting.dto.ts +17 -0
  131. package/src/setting/dto/update.dto.ts +4 -0
  132. package/src/setting/setting.controller.ts +105 -0
  133. package/src/setting/setting.module.ts +18 -0
  134. package/src/setting/setting.service.ts +400 -0
@@ -0,0 +1,400 @@
1
+ import path = require('path');
2
+ import { itemTranslations } from '@hedhog/core';
3
+ import { PaginationDTO, PaginationService } from '@hedhog/pagination';
4
+ import { PrismaService } from '@hedhog/prisma';
5
+ import {
6
+ BadRequestException,
7
+ Inject,
8
+ Injectable,
9
+ forwardRef,
10
+ } from '@nestjs/common';
11
+ import { CreateDTO } from './dto/create.dto';
12
+ import { DeleteDTO } from './dto/delete.dto';
13
+ import { SettingDTO } from './dto/setting.dto';
14
+ import { UpdateDTO } from './dto/update.dto';
15
+
16
+ @Injectable()
17
+ export class SettingService {
18
+ constructor(
19
+ @Inject(forwardRef(() => PrismaService))
20
+ private readonly prismaService: PrismaService,
21
+ @Inject(forwardRef(() => PaginationService))
22
+ private readonly paginationService: PaginationService,
23
+ ) {}
24
+
25
+ async setManySettings(data: SettingDTO) {
26
+ const transaction = [];
27
+
28
+ for (const { slug, value } of data.setting) {
29
+ transaction.push(
30
+ this.prismaService.setting.updateMany({
31
+ where: {
32
+ slug,
33
+ },
34
+ data: {
35
+ value,
36
+ },
37
+ }),
38
+ );
39
+ }
40
+
41
+ await this.prismaService.$transaction(transaction);
42
+ return { success: true };
43
+ }
44
+
45
+ async getSettingFromGroup(locale: any, paginationParams: any, slug: string) {
46
+ const fields = ['slug', 'value'];
47
+
48
+ paginationParams.pageSize = 100;
49
+
50
+ const OR: any[] = this.prismaService.createInsensitiveSearch(
51
+ fields,
52
+ paginationParams,
53
+ );
54
+
55
+ const result = await this.paginationService.paginate(
56
+ this.prismaService.setting,
57
+ paginationParams,
58
+ {
59
+ where: {
60
+ AND: {
61
+ setting_group: {
62
+ slug,
63
+ },
64
+ OR,
65
+ },
66
+ },
67
+ include: {
68
+ setting_group: {
69
+ include: {
70
+ setting_group_locale: {
71
+ where: {
72
+ locale: {
73
+ code: locale,
74
+ },
75
+ },
76
+ select: {
77
+ name: true,
78
+ description: true,
79
+ },
80
+ },
81
+ },
82
+ },
83
+ setting_locale: {
84
+ where: {
85
+ locale: {
86
+ code: locale,
87
+ },
88
+ },
89
+ select: {
90
+ name: true,
91
+ description: true,
92
+ },
93
+ },
94
+ },
95
+ },
96
+ 'setting_locale',
97
+ );
98
+
99
+ result.data = result.data.map((setting: any) => {
100
+ setting.setting_group = itemTranslations(
101
+ 'setting_group_locale',
102
+ setting.setting_group,
103
+ );
104
+ return setting;
105
+ });
106
+
107
+ return result;
108
+ }
109
+
110
+ async listSettingGroups(locale: string, paginationParams: PaginationDTO) {
111
+ const fields = ['slug', 'icon'];
112
+
113
+ paginationParams.pageSize = 100;
114
+
115
+ const OR: any[] = this.prismaService.createInsensitiveSearch(
116
+ fields,
117
+ paginationParams,
118
+ );
119
+
120
+ const result = await this.paginationService.paginate(
121
+ this.prismaService.setting_group,
122
+ paginationParams,
123
+ {
124
+ where: {
125
+ OR,
126
+ },
127
+ include: {
128
+ setting_group_locale: {
129
+ where: {
130
+ locale: {
131
+ code: locale,
132
+ },
133
+ },
134
+ select: {
135
+ name: true,
136
+ description: true,
137
+ },
138
+ },
139
+ },
140
+ },
141
+ 'setting_group_locale',
142
+ );
143
+
144
+ return result;
145
+ }
146
+
147
+ async listSettings(locale: string, paginationParams: PaginationDTO) {
148
+ const fields = ['slug', 'value'];
149
+
150
+ const OR: any[] = this.prismaService.createInsensitiveSearch(
151
+ fields,
152
+ paginationParams,
153
+ );
154
+
155
+ const result = await this.paginationService.paginate(
156
+ this.prismaService.setting,
157
+ paginationParams,
158
+ {
159
+ where: {
160
+ OR,
161
+ },
162
+ include: {
163
+ setting_group: {
164
+ include: {
165
+ setting_group_locale: {
166
+ where: {
167
+ locale: {
168
+ code: locale,
169
+ },
170
+ },
171
+ select: {
172
+ name: true,
173
+ description: true,
174
+ },
175
+ },
176
+ },
177
+ },
178
+ setting_locale: {
179
+ where: {
180
+ locale: {
181
+ code: locale,
182
+ },
183
+ },
184
+ select: {
185
+ name: true,
186
+ description: true,
187
+ },
188
+ },
189
+ },
190
+ },
191
+ 'setting_locale',
192
+ );
193
+
194
+ result.data = result.data.map((setting: any) => {
195
+ setting.setting_group = itemTranslations(
196
+ 'setting_group_locale',
197
+ setting.setting_group,
198
+ );
199
+ return setting;
200
+ });
201
+
202
+ return result;
203
+ }
204
+
205
+ async get(settingId: number) {
206
+ return this.prismaService.setting.findUnique({
207
+ where: { id: settingId },
208
+ });
209
+ }
210
+
211
+ async create(data: CreateDTO) {
212
+ return this.prismaService.setting.create({
213
+ data: {
214
+ slug: data.slug,
215
+ type: data.type as any,
216
+ value: data.value,
217
+ user_override: data.user_override,
218
+ setting_group: {
219
+ connect: {
220
+ id: data.group_id,
221
+ },
222
+ },
223
+ },
224
+ });
225
+ }
226
+
227
+ async update({ id, data }: { id: number; data: UpdateDTO }) {
228
+ return this.prismaService.setting.update({
229
+ where: { id },
230
+ data: {
231
+ slug: data.slug,
232
+ type: data.type as any,
233
+ value: data.value,
234
+ user_override: data.user_override,
235
+ setting_group: {
236
+ connect: {
237
+ id: data.group_id,
238
+ },
239
+ },
240
+ },
241
+ });
242
+ }
243
+
244
+ async updateFromSlug(slug: string, data: UpdateDTO) {
245
+ const { id } = await this.prismaService.setting.findFirst({
246
+ where: {
247
+ slug,
248
+ },
249
+ });
250
+
251
+ if (!id) {
252
+ throw new BadRequestException(`Setting with slug ${slug} not found.`);
253
+ }
254
+
255
+ return this.update({
256
+ id,
257
+ data,
258
+ });
259
+ }
260
+
261
+ async delete({ ids }: DeleteDTO) {
262
+ if (ids == undefined || ids == null) {
263
+ throw new BadRequestException(
264
+ `You must select at least one setting to delete.`,
265
+ );
266
+ }
267
+
268
+ return this.prismaService.setting.deleteMany({
269
+ where: {
270
+ id: {
271
+ in: ids,
272
+ },
273
+ },
274
+ });
275
+ }
276
+
277
+ async setSettingUserValue(user_id: number, slug: string, value: string) {
278
+ const user = await this.prismaService.user.findUnique({
279
+ where: {
280
+ id: user_id,
281
+ },
282
+ select: {
283
+ id: true,
284
+ },
285
+ });
286
+
287
+ if (!user) {
288
+ throw new BadRequestException(`User with id ${user_id} not found.`);
289
+ }
290
+
291
+ const setting = await this.prismaService.setting.findFirst({
292
+ where: {
293
+ slug,
294
+ user_override: true,
295
+ },
296
+ });
297
+
298
+ if (!setting) {
299
+ throw new BadRequestException(
300
+ `Setting with slug ${slug} not found or user can not override.`,
301
+ );
302
+ }
303
+
304
+ return await this.prismaService.setting_user.upsert({
305
+ where: {
306
+ user_id_setting_id: {
307
+ setting_id: setting.id,
308
+ user_id: user.id,
309
+ },
310
+ },
311
+ create: {
312
+ setting_id: setting.id,
313
+ value,
314
+ user_id: user.id,
315
+ },
316
+ update: {
317
+ value,
318
+ },
319
+ select: {
320
+ setting_id: true,
321
+ user_id: true,
322
+ value: true,
323
+ },
324
+ });
325
+ }
326
+
327
+ async getSettingValues(slug: string | string[]) {
328
+ slug = Array.isArray(slug) ? slug : [slug];
329
+
330
+ let setting = await this.prismaService.setting.findMany({
331
+ where: {
332
+ slug: {
333
+ in: slug,
334
+ },
335
+ },
336
+ select: {
337
+ id: true,
338
+ value: true,
339
+ slug: true,
340
+ type: true,
341
+ user_override: true,
342
+ },
343
+ });
344
+
345
+ const slugUserOverride = setting.filter((setting) => setting.user_override);
346
+
347
+ const settingUser = await this.prismaService.setting_user.findMany({
348
+ where: {
349
+ setting_id: {
350
+ in: slugUserOverride.map((setting) => setting.id),
351
+ },
352
+ },
353
+ select: {
354
+ value: true,
355
+ setting_id: true,
356
+ },
357
+ });
358
+
359
+ const data: Record<string, any> = {};
360
+
361
+ setting.forEach((setting) => {
362
+ switch (setting.type) {
363
+ case 'boolean':
364
+ data[setting.slug] = setting.value === 'true';
365
+ break;
366
+ case 'number':
367
+ data[setting.slug] = Number(setting.value);
368
+ break;
369
+ case 'array':
370
+ case 'json':
371
+ data[setting.slug] = JSON.parse(setting.value);
372
+ break;
373
+ default:
374
+ data[setting.slug] = setting.value;
375
+ }
376
+ });
377
+
378
+ settingUser.forEach((setting) => {
379
+ data[slugUserOverride.find((s) => s.id === setting.setting_id).slug] =
380
+ setting.value;
381
+ });
382
+
383
+ return data;
384
+ }
385
+
386
+ async getUserSettings(user_id: number) {
387
+ return this.prismaService.setting_user.findMany({
388
+ where: {
389
+ user_id,
390
+ },
391
+ include: {
392
+ setting: {
393
+ select: {
394
+ slug: true,
395
+ },
396
+ },
397
+ },
398
+ });
399
+ }
400
+ }