From 358f0d7eaf4fe9739c71f806f838899c49377027 Mon Sep 17 00:00:00 2001 From: Thomas <4159106+dtslvr@users.noreply.github.com> Date: Sun, 18 Apr 2021 20:12:58 +0200 Subject: [PATCH] Improve the user table (#16) --- CHANGELOG.md | 1 + apps/api/src/app/admin/admin.service.ts | 31 ++++++++----- .../admin/interfaces/admin-data.interface.ts | 10 ++--- .../app/pages/admin/admin-page.component.ts | 8 ++-- .../src/app/pages/admin/admin-page.html | 44 ++++++++++++------- .../src/app/pages/admin/admin-page.scss | 2 +- 6 files changed, 58 insertions(+), 38 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 74c0f6031..c77e9bb1a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,6 +18,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Changed the about page for the new license - Optimized the data management for historical data - Optimized the exchange rate service +- Improved the user table in the admin control panel ### Fixed diff --git a/apps/api/src/app/admin/admin.service.ts b/apps/api/src/app/admin/admin.service.ts index 8d49eefbe..c5f7c10c9 100644 --- a/apps/api/src/app/admin/admin.service.ts +++ b/apps/api/src/app/admin/admin.service.ts @@ -14,7 +14,6 @@ export class AdminService { public async get(): Promise { return { - analytics: await this.getUserAnalytics(), exchangeRates: [ { label1: Currency.EUR, @@ -64,7 +63,8 @@ export class AdminService { ], lastDataGathering: await this.getLastDataGathering(), transactionCount: await this.prisma.order.count(), - userCount: await this.prisma.user.count() + userCount: await this.prisma.user.count(), + users: await this.getUsersWithAnalytics() }; } @@ -88,19 +88,26 @@ export class AdminService { return null; } - private async getUserAnalytics() { - return await this.prisma.analytics.findMany({ - orderBy: { updatedAt: 'desc' }, + private async getUsersWithAnalytics() { + return await this.prisma.user.findMany({ + orderBy: { + Analytics: { + updatedAt: 'desc' + } + }, select: { - activityCount: true, - updatedAt: true, - User: { + _count: { + select: { Order: true } + }, + alias: true, + Analytics: { select: { - alias: true, - createdAt: true, - id: true + activityCount: true, + updatedAt: true } - } + }, + createdAt: true, + id: true }, take: 20 }); diff --git a/apps/api/src/app/admin/interfaces/admin-data.interface.ts b/apps/api/src/app/admin/interfaces/admin-data.interface.ts index d89bac655..0fe960323 100644 --- a/apps/api/src/app/admin/interfaces/admin-data.interface.ts +++ b/apps/api/src/app/admin/interfaces/admin-data.interface.ts @@ -1,5 +1,9 @@ export interface AdminData { - analytics: { + exchangeRates: { label1: string; label2: string; value: number }[]; + lastDataGathering: Date | 'IN_PROGRESS'; + transactionCount: number; + userCount: number; + users: { activityCount: number; updatedAt: Date; User: { @@ -7,8 +11,4 @@ export interface AdminData { id: string; }; }[]; - exchangeRates: { label1: string; label2: string; value: number }[]; - lastDataGathering: Date | 'IN_PROGRESS'; - transactionCount: number; - userCount: number; } diff --git a/apps/client/src/app/pages/admin/admin-page.component.ts b/apps/client/src/app/pages/admin/admin-page.component.ts index accce45e8..4c543cf9b 100644 --- a/apps/client/src/app/pages/admin/admin-page.component.ts +++ b/apps/client/src/app/pages/admin/admin-page.component.ts @@ -15,13 +15,13 @@ import { DataService } from '../../services/data.service'; styleUrls: ['./admin-page.scss'] }) export class AdminPageComponent implements OnInit { - public analytics: AdminData['analytics']; public dataGatheringInProgress: boolean; public defaultDateFormat = DEFAULT_DATE_FORMAT; public exchangeRates: { label1: string; label2: string; value: number }[]; public lastDataGathering: string; public transactionCount: number; public userCount: number; + public users: AdminData['users']; private unsubscribeSubject = new Subject(); @@ -44,14 +44,14 @@ export class AdminPageComponent implements OnInit { .pipe(takeUntil(this.unsubscribeSubject)) .subscribe( ({ - analytics, exchangeRates, lastDataGathering, transactionCount, - userCount + userCount, + users }) => { - this.analytics = analytics; this.exchangeRates = exchangeRates; + this.users = users; if (isValid(parseISO(lastDataGathering?.toString()))) { this.lastDataGathering = formatDistanceToNow( diff --git a/apps/client/src/app/pages/admin/admin-page.html b/apps/client/src/app/pages/admin/admin-page.html index 832d5ef18..d8b17cafe 100644 --- a/apps/client/src/app/pages/admin/admin-page.html +++ b/apps/client/src/app/pages/admin/admin-page.html @@ -67,33 +67,45 @@
-

Analytics

- +

Users

+ - +
- - + - - + + + - - + + - - - diff --git a/apps/client/src/app/pages/admin/admin-page.scss b/apps/client/src/app/pages/admin/admin-page.scss index 580045ad0..5ccd9216e 100644 --- a/apps/client/src/app/pages/admin/admin-page.scss +++ b/apps/client/src/app/pages/admin/admin-page.scss @@ -3,7 +3,7 @@ display: block; table { - &.analytics { + &.users { table-layout: fixed; tr {
User + + User + Registration Date EngagementLast Activitiy + Transactions + + Engagement + + Last Activitiy +
- {{ analyticsItem.User.alias || analyticsItem.User.id }} +
+ {{ userItem.alias || userItem.id }} + + {{ userItem.createdAt | date: defaultDateFormat }} - {{ analyticsItem.User.createdAt | date: defaultDateFormat }} + + {{ userItem._count.Order }} - {{ analyticsItem.activityCount }} + + {{ userItem.Analytics.activityCount }} - {{ formatDistanceToNow(analyticsItem.updatedAt) }} + + {{ formatDistanceToNow(userItem.Analytics.updatedAt) }}