Feature/improve users table (#291)
* Improve users table * Engagement / Day * Registration * Update changelog
This commit is contained in:
parent
13090bf6b5
commit
77936e3bf3
@ -14,6 +14,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||||||
### Changed
|
### Changed
|
||||||
|
|
||||||
- Refactored the exchange rate service
|
- Refactored the exchange rate service
|
||||||
|
- Improved the users table in the admin control panel
|
||||||
|
|
||||||
## 1.37.0 - 13.08.2021
|
## 1.37.0 - 13.08.2021
|
||||||
|
|
||||||
|
@ -4,6 +4,7 @@ import { PrismaService } from '@ghostfolio/api/services/prisma.service';
|
|||||||
import { AdminData } from '@ghostfolio/common/interfaces';
|
import { AdminData } from '@ghostfolio/common/interfaces';
|
||||||
import { Injectable } from '@nestjs/common';
|
import { Injectable } from '@nestjs/common';
|
||||||
import { Currency } from '@prisma/client';
|
import { Currency } from '@prisma/client';
|
||||||
|
import { differenceInDays } from 'date-fns';
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class AdminService {
|
export class AdminService {
|
||||||
@ -87,8 +88,8 @@ export class AdminService {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private async getUsersWithAnalytics() {
|
private async getUsersWithAnalytics(): Promise<AdminData['users']> {
|
||||||
return await this.prismaService.user.findMany({
|
const usersWithAnalytics = await this.prismaService.user.findMany({
|
||||||
orderBy: {
|
orderBy: {
|
||||||
Analytics: {
|
Analytics: {
|
||||||
updatedAt: 'desc'
|
updatedAt: 'desc'
|
||||||
@ -115,5 +116,23 @@ export class AdminService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
return usersWithAnalytics.map(
|
||||||
|
({ _count, alias, Analytics, createdAt, id }) => {
|
||||||
|
const daysSinceRegistration =
|
||||||
|
differenceInDays(new Date(), createdAt) + 1;
|
||||||
|
const engagement = Analytics.activityCount / daysSinceRegistration;
|
||||||
|
|
||||||
|
return {
|
||||||
|
alias,
|
||||||
|
createdAt,
|
||||||
|
engagement,
|
||||||
|
id,
|
||||||
|
accountCount: _count.Account || 0,
|
||||||
|
lastActivity: Analytics.updatedAt,
|
||||||
|
transactionCount: _count.Order || 0
|
||||||
|
};
|
||||||
|
}
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -97,7 +97,7 @@
|
|||||||
<th class="mat-header-cell px-1 py-2 text-right" i18n>#</th>
|
<th class="mat-header-cell px-1 py-2 text-right" i18n>#</th>
|
||||||
<th class="mat-header-cell px-1 py-2" i18n>User</th>
|
<th class="mat-header-cell px-1 py-2" i18n>User</th>
|
||||||
<th class="mat-header-cell px-1 py-2 text-right" i18n>
|
<th class="mat-header-cell px-1 py-2 text-right" i18n>
|
||||||
Registration Date
|
Registration
|
||||||
</th>
|
</th>
|
||||||
<th class="mat-header-cell px-1 py-2 text-right" i18n>
|
<th class="mat-header-cell px-1 py-2 text-right" i18n>
|
||||||
Accounts
|
Accounts
|
||||||
@ -106,7 +106,7 @@
|
|||||||
Transactions
|
Transactions
|
||||||
</th>
|
</th>
|
||||||
<th class="mat-header-cell px-1 py-2 text-right" i18n>
|
<th class="mat-header-cell px-1 py-2 text-right" i18n>
|
||||||
Engagement
|
Engagement per Day
|
||||||
</th>
|
</th>
|
||||||
<th class="mat-header-cell px-1 py-2" i18n>Last Activitiy</th>
|
<th class="mat-header-cell px-1 py-2" i18n>Last Activitiy</th>
|
||||||
<th class="mat-header-cell px-1 py-2"></th>
|
<th class="mat-header-cell px-1 py-2"></th>
|
||||||
@ -119,19 +119,19 @@
|
|||||||
{{ userItem.alias || userItem.id }}
|
{{ userItem.alias || userItem.id }}
|
||||||
</td>
|
</td>
|
||||||
<td class="mat-cell px-1 py-2 text-right">
|
<td class="mat-cell px-1 py-2 text-right">
|
||||||
{{ userItem.createdAt | date: defaultDateFormat }}
|
{{ formatDistanceToNow(userItem.createdAt) }}
|
||||||
</td>
|
</td>
|
||||||
<td class="mat-cell px-1 py-2 text-right">
|
<td class="mat-cell px-1 py-2 text-right">
|
||||||
{{ userItem._count?.Account }}
|
{{ userItem.accountCount }}
|
||||||
</td>
|
</td>
|
||||||
<td class="mat-cell px-1 py-2 text-right">
|
<td class="mat-cell px-1 py-2 text-right">
|
||||||
{{ userItem._count?.Order }}
|
{{ userItem.transactionCount }}
|
||||||
</td>
|
</td>
|
||||||
<td class="mat-cell px-1 py-2 text-right">
|
<td class="mat-cell px-1 py-2 text-right">
|
||||||
{{ userItem.Analytics?.activityCount }}
|
{{ userItem.engagement | number: '1.0-0' }}
|
||||||
</td>
|
</td>
|
||||||
<td class="mat-cell px-1 py-2">
|
<td class="mat-cell px-1 py-2">
|
||||||
{{ formatDistanceToNow(userItem.Analytics?.updatedAt) }}
|
{{ formatDistanceToNow(userItem.lastActivity) }}
|
||||||
</td>
|
</td>
|
||||||
<td class="mat-cell px-1 py-2">
|
<td class="mat-cell px-1 py-2">
|
||||||
<button
|
<button
|
||||||
|
@ -4,12 +4,12 @@ export interface AdminData {
|
|||||||
transactionCount: number;
|
transactionCount: number;
|
||||||
userCount: number;
|
userCount: number;
|
||||||
users: {
|
users: {
|
||||||
|
accountCount: number;
|
||||||
alias: string;
|
alias: string;
|
||||||
createdAt: Date;
|
createdAt: Date;
|
||||||
Analytics: {
|
engagement: number;
|
||||||
activityCount: number;
|
|
||||||
updatedAt: Date;
|
|
||||||
};
|
|
||||||
id: string;
|
id: string;
|
||||||
|
lastActivity: Date;
|
||||||
|
transactionCount: number;
|
||||||
}[];
|
}[];
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user