Improve the user table (#16)

This commit is contained in:
Thomas
2021-04-18 20:12:58 +02:00
committed by GitHub
parent 3558f52b84
commit 358f0d7eaf
6 changed files with 60 additions and 40 deletions

View File

@@ -14,7 +14,6 @@ export class AdminService {
public async get(): Promise<AdminData> {
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,20 +88,27 @@ export class AdminService {
return null;
}
private async getUserAnalytics() {
return await this.prisma.analytics.findMany({
orderBy: { updatedAt: 'desc' },
select: {
activityCount: true,
updatedAt: true,
User: {
select: {
alias: true,
createdAt: true,
id: true
}
private async getUsersWithAnalytics() {
return await this.prisma.user.findMany({
orderBy: {
Analytics: {
updatedAt: 'desc'
}
},
select: {
_count: {
select: { Order: true }
},
alias: true,
Analytics: {
select: {
activityCount: true,
updatedAt: true
}
},
createdAt: true,
id: true
},
take: 20
});
}

View File

@@ -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;
}