fix: address code review findings for analytics and security
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import { DrizzleClient } from "@shared/db/DrizzleClient";
|
||||
import { users, transactions, moderationCases, inventory } from "@db/schema";
|
||||
import { desc, sql, and, gte } from "drizzle-orm";
|
||||
import { users, transactions, moderationCases, inventory, type User } from "@db/schema";
|
||||
import { desc, sql, gte } from "drizzle-orm";
|
||||
import type { RecentEvent, ActivityData } from "./dashboard.types";
|
||||
import { TransactionType } from "@shared/lib/constants";
|
||||
|
||||
@@ -39,18 +39,18 @@ export const dashboardService = {
|
||||
const allUsers = await DrizzleClient.select().from(users);
|
||||
|
||||
const totalWealth = allUsers.reduce(
|
||||
(acc: bigint, u: any) => acc + (u.balance || 0n),
|
||||
(acc: bigint, u: User) => acc + (u.balance || 0n),
|
||||
0n
|
||||
);
|
||||
|
||||
const avgLevel = allUsers.length > 0
|
||||
? Math.round(
|
||||
allUsers.reduce((acc: number, u: any) => acc + (u.level || 1), 0) / allUsers.length
|
||||
allUsers.reduce((acc: number, u: User) => acc + (u.level || 1), 0) / allUsers.length
|
||||
)
|
||||
: 1;
|
||||
|
||||
const topStreak = allUsers.reduce(
|
||||
(max: number, u: any) => Math.max(max, u.dailyStreak || 0),
|
||||
(max: number, u: User) => Math.max(max, u.dailyStreak || 0),
|
||||
0
|
||||
);
|
||||
|
||||
@@ -83,7 +83,7 @@ export const dashboardService = {
|
||||
},
|
||||
});
|
||||
|
||||
return recentTx.map((tx: any) => ({
|
||||
return recentTx.map((tx) => ({
|
||||
type: 'info' as const,
|
||||
message: `${tx.user?.username || 'Unknown'}: ${tx.description || 'Transaction'}`,
|
||||
timestamp: tx.createdAt || new Date(),
|
||||
@@ -103,11 +103,11 @@ export const dashboardService = {
|
||||
where: gte(moderationCases.createdAt, oneDayAgo),
|
||||
});
|
||||
|
||||
return recentCases.map((modCase: any) => ({
|
||||
return recentCases.map((modCase) => ({
|
||||
type: modCase.type === 'warn' || modCase.type === 'ban' ? 'error' : 'info',
|
||||
message: `${modCase.type.toUpperCase()}: ${modCase.username} - ${modCase.reason}`,
|
||||
timestamp: modCase.createdAt || new Date(),
|
||||
icon: getModerationIcon(modCase.type),
|
||||
icon: getModerationIcon(modCase.type as string),
|
||||
}));
|
||||
},
|
||||
|
||||
|
||||
Reference in New Issue
Block a user