added user count, fixed display bug, renamed db projectUserPasswordResetCode

This commit is contained in:
Zai Shi 2024-03-01 11:20:45 +01:00
parent b2b1fe2d1e
commit f6e974a571
3 changed files with 15 additions and 10 deletions

View File

@ -85,6 +85,7 @@ model ProjectUser {
projectUserAuthorizationCodes ProjectUserAuthorizationCode[]
projectUserOauthAccounts ProjectUserOauthAccount[]
projectUserEmailVerificationCode ProjectUserEmailVerificationCode[]
projectUserPasswordResetCode ProjectUserPasswordResetCode[]
primaryEmail String?
primaryEmailVerified Boolean
@ -92,9 +93,8 @@ model ProjectUser {
displayName String?
passwordHash String?
serverMetadata Json?
clientMetadata Json?
ProjectUserPasswordResetCode ProjectUserPasswordResetCode[]
serverMetadata Json?
clientMetadata Json?
@@id([projectId, projectUserId])
}

View File

@ -25,6 +25,11 @@ const fullProjectInclude = {
},
},
configOverride: true,
_count: {
select: {
users: true, // Count the users related to the project
},
},
} as const satisfies Prisma.ProjectInclude;
type FullProjectInclude = typeof fullProjectInclude;
type ProjectDB = Prisma.ProjectGetPayload<{ include: FullProjectInclude }> & {
@ -259,7 +264,7 @@ function projectJsonFromDbType(project: ProjectDB): ProjectJson {
displayName: project.displayName,
description: project.description ?? undefined,
createdAtMillis: project.createdAt.getTime(),
userCount: 0,
userCount: project._count.users,
isProductionMode: project.isProductionMode,
evaluatedConfig: {
id: project.config.id,

View File

@ -1,9 +1,9 @@
const magnitudes = [
[1_000, ""],
[1_000_000, "k"],
[1_000_000_000, "mm"],
[1_000_000_000_000, "bln"],
[1_000_000_000_000_000, "trln"],
[1_000_000_000_000, "bln"],
[1_000_000_000, "bn"],
[1_000_000, "M"],
[1_000, "k"],
] as const;
export function prettyPrintWithMagnitudes(num: number): string {
@ -13,11 +13,11 @@ export function prettyPrintWithMagnitudes(num: number): string {
if (!Number.isFinite(num)) return "∞";
for (const [magnitude, suffix] of magnitudes) {
if (num < magnitude) {
if (num >= magnitude) {
return toFixedMax(num / magnitude, 1) + suffix;
}
}
return num.toExponential(1);
return toFixedMax(num, 1); // Handle numbers less than 1,000 without suffix.
}
export function toFixedMax(num: number, maxDecimals: number): string {