@hed-hog/core 0.0.170 → 0.0.172

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 (52) hide show
  1. package/dist/dashboard/dashboard-component/dashboard-component.controller.d.ts +70 -1
  2. package/dist/dashboard/dashboard-component/dashboard-component.controller.d.ts.map +1 -1
  3. package/dist/dashboard/dashboard-component/dashboard-component.controller.js +13 -3
  4. package/dist/dashboard/dashboard-component/dashboard-component.controller.js.map +1 -1
  5. package/dist/dashboard/dashboard-component/dashboard-component.service.d.ts +70 -1
  6. package/dist/dashboard/dashboard-component/dashboard-component.service.d.ts.map +1 -1
  7. package/dist/dashboard/dashboard-component/dashboard-component.service.js +33 -4
  8. package/dist/dashboard/dashboard-component/dashboard-component.service.js.map +1 -1
  9. package/dist/dashboard/dashboard-component-role/dashboard-component-role.controller.d.ts +122 -0
  10. package/dist/dashboard/dashboard-component-role/dashboard-component-role.controller.d.ts.map +1 -0
  11. package/dist/dashboard/dashboard-component-role/dashboard-component-role.controller.js +83 -0
  12. package/dist/dashboard/dashboard-component-role/dashboard-component-role.controller.js.map +1 -0
  13. package/dist/dashboard/dashboard-component-role/dashboard-component-role.module.d.ts +3 -0
  14. package/dist/dashboard/dashboard-component-role/dashboard-component-role.module.d.ts.map +1 -0
  15. package/dist/dashboard/dashboard-component-role/dashboard-component-role.module.js +26 -0
  16. package/dist/dashboard/dashboard-component-role/dashboard-component-role.module.js.map +1 -0
  17. package/dist/dashboard/dashboard-component-role/dashboard-component-role.service.d.ts +125 -0
  18. package/dist/dashboard/dashboard-component-role/dashboard-component-role.service.d.ts.map +1 -0
  19. package/dist/dashboard/dashboard-component-role/dashboard-component-role.service.js +143 -0
  20. package/dist/dashboard/dashboard-component-role/dashboard-component-role.service.js.map +1 -0
  21. package/dist/dashboard/dashboard-component-role/dto/create.dto.d.ts +5 -0
  22. package/dist/dashboard/dashboard-component-role/dto/create.dto.d.ts.map +1 -0
  23. package/dist/dashboard/dashboard-component-role/dto/create.dto.js +25 -0
  24. package/dist/dashboard/dashboard-component-role/dto/create.dto.js.map +1 -0
  25. package/dist/dashboard/dashboard-component-role/dto/index.d.ts +2 -0
  26. package/dist/dashboard/dashboard-component-role/dto/index.d.ts.map +1 -0
  27. package/dist/dashboard/dashboard-component-role/dto/index.js +18 -0
  28. package/dist/dashboard/dashboard-component-role/dto/index.js.map +1 -0
  29. package/dist/dashboard/dashboard-core/dashboard-core.controller.d.ts +15 -9
  30. package/dist/dashboard/dashboard-core/dashboard-core.controller.d.ts.map +1 -1
  31. package/dist/dashboard/dashboard-core/dashboard-core.controller.js +13 -4
  32. package/dist/dashboard/dashboard-core/dashboard-core.controller.js.map +1 -1
  33. package/dist/dashboard/dashboard-core/dashboard-core.service.d.ts +16 -9
  34. package/dist/dashboard/dashboard-core/dashboard-core.service.d.ts.map +1 -1
  35. package/dist/dashboard/dashboard-core/dashboard-core.service.js +52 -38
  36. package/dist/dashboard/dashboard-core/dashboard-core.service.js.map +1 -1
  37. package/dist/dashboard/dashboard.module.d.ts.map +1 -1
  38. package/dist/dashboard/dashboard.module.js +2 -0
  39. package/dist/dashboard/dashboard.module.js.map +1 -1
  40. package/hedhog/data/role.yaml +14 -0
  41. package/hedhog/data/route.yaml +34 -4
  42. package/package.json +4 -4
  43. package/src/dashboard/dashboard-component/dashboard-component.controller.ts +7 -2
  44. package/src/dashboard/dashboard-component/dashboard-component.service.ts +44 -4
  45. package/src/dashboard/dashboard-component-role/dashboard-component-role.controller.ts +57 -0
  46. package/src/dashboard/dashboard-component-role/dashboard-component-role.module.ts +13 -0
  47. package/src/dashboard/dashboard-component-role/dashboard-component-role.service.ts +170 -0
  48. package/src/dashboard/dashboard-component-role/dto/create.dto.ts +9 -0
  49. package/src/dashboard/dashboard-component-role/dto/index.ts +1 -0
  50. package/src/dashboard/dashboard-core/dashboard-core.controller.ts +8 -3
  51. package/src/dashboard/dashboard-core/dashboard-core.service.ts +61 -46
  52. package/src/dashboard/dashboard.module.ts +2 -0
@@ -25,10 +25,14 @@ export class DashboardCoreService {
25
25
  });
26
26
  }
27
27
 
28
- async getStatistics() {
28
+ calculateChange(current: number, previous: number){
29
+ if (previous === 0) return current === 0 ? 0 : 100;
30
+ return Number((((current - previous) / previous) * 100).toFixed(1));
31
+ };
32
+
33
+ async getUserStatistics() {
29
34
  const now = new Date();
30
35
  const todayStart = new Date(now.getFullYear(), now.getMonth(), now.getDate());
31
- const sevenDaysAgo = new Date(now.getTime() - 7 * 24 * 60 * 60 * 1000);
32
36
  const twelveMonthsAgo = new Date(now.getFullYear() - 1, now.getMonth(), 1);
33
37
  const currentMonthStart = new Date(now.getFullYear(), now.getMonth(), 1);
34
38
  const lastMonthStart = new Date(now.getFullYear(), now.getMonth() - 1, 1);
@@ -37,64 +41,28 @@ export class DashboardCoreService {
37
41
  const [
38
42
  sessionsTodayCount,
39
43
  activeUsersCount,
40
- emailsSentCount,
41
44
  rolesCount,
42
45
  sessionsCurrentMonth,
43
46
  usersCurrentMonth,
44
- emailsCurrentMonth,
45
47
  rolesCurrentMonth,
46
48
  sessionsLastMonth,
47
49
  usersLastMonth,
48
- emailsLastMonth,
49
50
  rolesLastMonth,
50
51
  ] = await Promise.all([
51
52
  this.prismaService.user_session.count({ where: { created_at: { gte: todayStart } } }),
52
53
  this.prismaService.user.count(),
53
- this.prismaService.mail_sent.count(),
54
54
  this.prismaService.role.count(),
55
55
  this.prismaService.user_session.count({ where: { created_at: { gte: currentMonthStart } } }),
56
56
  this.prismaService.user.count({ where: { created_at: { gte: currentMonthStart } } }),
57
- this.prismaService.mail_sent.count({ where: { created_at: { gte: currentMonthStart } } }),
58
57
  this.prismaService.role.count({ where: { created_at: { gte: currentMonthStart } } }),
59
58
  this.prismaService.user_session.count({ where: { created_at: { gte: lastMonthStart, lte: lastMonthEnd } } }),
60
59
  this.prismaService.user.count({ where: { created_at: { gte: lastMonthStart, lte: lastMonthEnd } } }),
61
- this.prismaService.mail_sent.count({ where: { created_at: { gte: lastMonthStart, lte: lastMonthEnd } } }),
62
60
  this.prismaService.role.count({ where: { created_at: { gte: lastMonthStart, lte: lastMonthEnd } } }),
63
61
  ]);
64
62
 
65
- const calculateChange = (current: number, previous: number) => {
66
- if (previous === 0) {
67
- return current === 0 ? 0 : 100;
68
- }
69
- return Number((((current - previous) / previous) * 100).toFixed(1));
70
- };
71
-
72
- const sessionsChange = calculateChange(sessionsCurrentMonth, sessionsLastMonth);
73
- const usersChange = calculateChange(usersCurrentMonth, usersLastMonth);
74
- const emailsChange = calculateChange(emailsCurrentMonth, emailsLastMonth);
75
- const rolesChange = calculateChange(rolesCurrentMonth, rolesLastMonth);
76
-
77
- const emailsPerWeek = await this.prismaService.$queryRaw<
78
- Array<{ day: Date; sent: bigint }>
79
- >`
80
- SELECT
81
- DATE("created_at") as day,
82
- COUNT(*) as sent
83
- FROM "mail_sent"
84
- WHERE "created_at" >= ${sevenDaysAgo}
85
- GROUP BY DATE("created_at")
86
- ORDER BY day ASC
87
- `;
88
-
89
- const weekDays = ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'];
90
- const emailWeekData = emailsPerWeek.map((item) => {
91
- const dayOfWeek = new Date(item.day).getDay();
92
- return {
93
- day: weekDays[dayOfWeek],
94
- sent: Number(item.sent),
95
- };
96
- });
97
-
63
+ const sessionsChange = this.calculateChange(sessionsCurrentMonth, sessionsLastMonth);
64
+ const usersChange = this.calculateChange(usersCurrentMonth, usersLastMonth);
65
+ const rolesChange = this.calculateChange(rolesCurrentMonth, rolesLastMonth);
98
66
  const permissionDistribution = await this.prismaService.$queryRaw<
99
67
  Array<{ name: string; value: bigint }>
100
68
  >`
@@ -171,17 +139,12 @@ export class DashboardCoreService {
171
139
  value: activeUsersCount,
172
140
  change: usersChange,
173
141
  },
174
- emailsSent: {
175
- value: emailsSentCount,
176
- change: emailsChange,
177
- },
178
142
  roles: {
179
143
  value: rolesCount,
180
144
  change: rolesChange,
181
145
  },
182
146
  },
183
147
  charts: {
184
- emailsPerWeek: emailWeekData,
185
148
  permissionDistribution: permissionsData,
186
149
  sessionActivity: sessionActivityData,
187
150
  userGrowth: userGrowthData,
@@ -189,6 +152,58 @@ export class DashboardCoreService {
189
152
  };
190
153
  }
191
154
 
155
+ async getMailStatistics(){
156
+ const now = new Date();
157
+ const currentMonthStart = new Date(now.getFullYear(), now.getMonth(), 1);
158
+ const lastMonthStart = new Date(now.getFullYear(), now.getMonth() - 1, 1);
159
+ const lastMonthEnd = new Date(now.getFullYear(), now.getMonth(), 0, 23, 59, 59);
160
+ const sevenDaysAgo = new Date(now.getTime() - 7 * 24 * 60 * 60 * 1000);
161
+
162
+ const [
163
+ emailsSentCount,
164
+ emailsCurrentMonth,
165
+ emailsLastMonth,
166
+ ] = await Promise.all([
167
+ this.prismaService.mail_sent.count(),
168
+ this.prismaService.mail_sent.count({ where: { created_at: { gte: currentMonthStart } } }),
169
+ this.prismaService.mail_sent.count({ where: { created_at: { gte: lastMonthStart, lte: lastMonthEnd } } }),
170
+ ]);
171
+
172
+ const emailsChange = this.calculateChange(emailsCurrentMonth, emailsLastMonth);
173
+ const emailsPerWeek = await this.prismaService.$queryRaw<
174
+ Array<{ day: Date; sent: bigint }>
175
+ >`
176
+ SELECT
177
+ DATE("created_at") as day,
178
+ COUNT(*) as sent
179
+ FROM "mail_sent"
180
+ WHERE "created_at" >= ${sevenDaysAgo}
181
+ GROUP BY DATE("created_at")
182
+ ORDER BY day ASC
183
+ `;
184
+
185
+ const weekDays = ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'];
186
+ const emailWeekData = emailsPerWeek.map((item) => {
187
+ const dayOfWeek = new Date(item.day).getDay();
188
+ return {
189
+ day: weekDays[dayOfWeek],
190
+ sent: Number(item.sent),
191
+ };
192
+ });
193
+
194
+ return {
195
+ cards: {
196
+ emailsSent: {
197
+ value: emailsSentCount,
198
+ change: emailsChange,
199
+ },
200
+ },
201
+ charts: {
202
+ emailsPerWeek: emailWeekData,
203
+ },
204
+ };
205
+ }
206
+
192
207
  async getUserLayout(userId: number, slug: string, localeCode: string) {
193
208
  const dashboard = await this.prismaService.dashboard.findFirst({ where: { slug } });
194
209
 
@@ -1,6 +1,7 @@
1
1
  import { LocaleModule } from '@hed-hog/api-locale';
2
2
  import { PrismaModule } from '@hed-hog/api-prisma';
3
3
  import { forwardRef, Module } from '@nestjs/common';
4
+ import { DashboardComponentRoleModule } from './dashboard-component-role/dashboard-component-role.module';
4
5
  import { DashboardComponentModule } from './dashboard-component/dashboard-component.module';
5
6
  import { DashboardCoreModule } from './dashboard-core/dashboard-core.module';
6
7
  import { DashboardItemModule } from './dashboard-item/dashboard-item.module';
@@ -13,6 +14,7 @@ import { DashboardCrudModule } from './dashboard/dashboard.module';
13
14
  forwardRef(() => PrismaModule),
14
15
  forwardRef(() => DashboardCrudModule),
15
16
  forwardRef(() => DashboardComponentModule),
17
+ forwardRef(() => DashboardComponentRoleModule),
16
18
  forwardRef(() => DashboardItemModule),
17
19
  forwardRef(() => DashboardUserModule),
18
20
  forwardRef(() => DashboardCoreModule),