Refactor code
This commit is contained in:
@ -1,12 +1,10 @@
|
||||
"use server";
|
||||
|
||||
import { prisma } from "@/lib/prisma";
|
||||
import type { CountRow } from "@/types/dashboard";
|
||||
|
||||
type CountRow<K extends string> = {
|
||||
[P in K]: string;
|
||||
} & { _count: { _all: number } };
|
||||
|
||||
function toCountMapSafe(rows: any[], key: string) {
|
||||
// Aggregates dashboard stats for admin overview cards and tables.
|
||||
function toCountMapSafe<K extends string>(rows: Array<CountRow<K>>, key: K) {
|
||||
const out: Record<string, number> = {};
|
||||
for (const r of rows) out[String(r[key])] = Number(r?._count?._all ?? 0);
|
||||
return out;
|
||||
|
||||
Reference in New Issue
Block a user