refactor(db): migrate app pages and APIs from Prisma facade to Drizzle (2)
Co-authored-by: Cursor <[email protected]>
This commit is contained in:
1 parent
7c39aef5d9
commit
2cd0863cb8
40 files changed
+1046
-703
No files matched your search
@@ -1,7 +1,8 @@
|
|||||||
|
import { asc, count } from "drizzle-orm";
|
||||||
import Link from "next/link";
|
import Link from "next/link";
|
||||||
import { getTranslations } from "next-intl/server";
|
import { getTranslations } from "next-intl/server";
|
||||||
import { ContentCard, EmptyState } from "@/components/public/ui";
|
import { ContentCard, EmptyState } from "@/components/public/ui";
|
||||||
import { prisma } from "@/lib/prisma";
|
import { db, WebsiteRareValueCategories, WebsiteRareValues } from "@/lib/db";
|
||||||
import { siteSettings } from "@/lib/services/site-settings";
|
import { siteSettings } from "@/lib/services/site-settings";
|
||||||
|
|
||||||
export const revalidate = 300;
|
export const revalidate = 300;
|
||||||
@@ -19,10 +20,18 @@ export default async function RareValuesPage() {
|
|||||||
const t = await getTranslations("pages.rares");
|
const t = await getTranslations("pages.rares");
|
||||||
let categories: CategoryRow[] = [];
|
let categories: CategoryRow[] = [];
|
||||||
try {
|
try {
|
||||||
categories = await prisma.websiteRareValueCategories.findMany({
|
categories = await db
|
||||||
orderBy: [{ priority: "asc" }, { name: "asc" }],
|
.select({
|
||||||
select: { id: true, name: true, badge: true, priority: true },
|
id: WebsiteRareValueCategories.id,
|
||||||
});
|
name: WebsiteRareValueCategories.name,
|
||||||
|
badge: WebsiteRareValueCategories.badge,
|
||||||
|
priority: WebsiteRareValueCategories.priority,
|
||||||
|
})
|
||||||
|
.from(WebsiteRareValueCategories)
|
||||||
|
.orderBy(
|
||||||
|
asc(WebsiteRareValueCategories.priority),
|
||||||
|
asc(WebsiteRareValueCategories.name),
|
||||||
|
);
|
||||||
} catch {
|
} catch {
|
||||||
categories = [];
|
categories = [];
|
||||||
}
|
}
|
||||||
@@ -30,12 +39,15 @@ export default async function RareValuesPage() {
|
|||||||
// Per-category rare counts (grouped so we avoid N queries).
|
// Per-category rare counts (grouped so we avoid N queries).
|
||||||
const counts = new Map<string, number>();
|
const counts = new Map<string, number>();
|
||||||
try {
|
try {
|
||||||
const grouped = await prisma.websiteRareValues.groupBy({
|
const grouped = await db
|
||||||
by: ["categoryId"],
|
.select({
|
||||||
_count: { _all: true },
|
categoryId: WebsiteRareValues.categoryId,
|
||||||
});
|
value: count(),
|
||||||
|
})
|
||||||
|
.from(WebsiteRareValues)
|
||||||
|
.groupBy(WebsiteRareValues.categoryId);
|
||||||
for (const g of grouped) {
|
for (const g of grouped) {
|
||||||
counts.set(String(g.categoryId), g._count._all);
|
counts.set(String(g.categoryId), Number(g.value));
|
||||||
}
|
}
|
||||||
} catch {
|
} catch {
|
||||||
// leave counts empty -> shown as 0
|
// leave counts empty -> shown as 0
|
||||||
@@ -55,7 +67,7 @@ export default async function RareValuesPage() {
|
|||||||
<div className="card-grid sm-2 lg-3">
|
<div className="card-grid sm-2 lg-3">
|
||||||
{categories.map((c) => {
|
{categories.map((c) => {
|
||||||
const id = String(c.id);
|
const id = String(c.id);
|
||||||
const count = counts.get(id) ?? 0;
|
const rareCount = counts.get(id) ?? 0;
|
||||||
const badgeSrc =
|
const badgeSrc =
|
||||||
badgesBase && c.badge ? `${badgesBase}/${c.badge}.gif` : "";
|
badgesBase && c.badge ? `${badgesBase}/${c.badge}.gif` : "";
|
||||||
return (
|
return (
|
||||||
@@ -83,7 +95,7 @@ export default async function RareValuesPage() {
|
|||||||
<div className="content-card-head-text">
|
<div className="content-card-head-text">
|
||||||
<p className="content-card-title">{c.name}</p>
|
<p className="content-card-title">{c.name}</p>
|
||||||
<p className="content-card-subtitle">
|
<p className="content-card-subtitle">
|
||||||
{t("rareCount", { count })}
|
{t("rareCount", { count: rareCount })}
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -1,8 +1,9 @@
|
|||||||
|
import { eq } from "drizzle-orm";
|
||||||
import { redirect } from "next/navigation";
|
import { redirect } from "next/navigation";
|
||||||
import { getTranslations } from "next-intl/server";
|
import { getTranslations } from "next-intl/server";
|
||||||
import { ContentCard, StatBlock } from "@/components/public/ui";
|
import { ContentCard, StatBlock } from "@/components/public/ui";
|
||||||
import { auth } from "@/lib/auth";
|
import { auth } from "@/lib/auth";
|
||||||
import { prisma } from "@/lib/prisma";
|
import { db, User } from "@/lib/db";
|
||||||
import RedeemForm from "./RedeemForm";
|
import RedeemForm from "./RedeemForm";
|
||||||
|
|
||||||
export const dynamic = "force-dynamic";
|
export const dynamic = "force-dynamic";
|
||||||
@@ -17,10 +18,12 @@ export default async function RedeemPage() {
|
|||||||
// Show the signed-in user's current credit balance for context (fail soft).
|
// Show the signed-in user's current credit balance for context (fail soft).
|
||||||
let user: { username: string; credits: number } | null = null;
|
let user: { username: string; credits: number } | null = null;
|
||||||
try {
|
try {
|
||||||
user = await prisma.user.findUnique({
|
const [row] = await db
|
||||||
where: { id },
|
.select({ username: User.username, credits: User.credits })
|
||||||
select: { username: true, credits: true },
|
.from(User)
|
||||||
});
|
.where(eq(User.id, id))
|
||||||
|
.limit(1);
|
||||||
|
user = row ?? null;
|
||||||
} catch {
|
} catch {
|
||||||
user = null;
|
user = null;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
import { count, desc, eq } from "drizzle-orm";
|
||||||
import { headers } from "next/headers";
|
import { headers } from "next/headers";
|
||||||
import Image from "next/image";
|
import Image from "next/image";
|
||||||
import Link from "next/link";
|
import Link from "next/link";
|
||||||
@@ -8,9 +9,9 @@ import { LanguageSwitcher } from "@/components/language-switcher";
|
|||||||
import { Reveal } from "@/components/motion-reveal";
|
import { Reveal } from "@/components/motion-reveal";
|
||||||
import { ThemeSwitcher } from "@/components/theme-switcher";
|
import { ThemeSwitcher } from "@/components/theme-switcher";
|
||||||
import { cached } from "@/lib/cache";
|
import { cached } from "@/lib/cache";
|
||||||
|
import { db, User } from "@/lib/db";
|
||||||
import { avatarImageUrl } from "@/lib/format";
|
import { avatarImageUrl } from "@/lib/format";
|
||||||
import { resolveHotelName } from "@/lib/hotel-name";
|
import { resolveHotelName } from "@/lib/hotel-name";
|
||||||
import { prisma } from "@/lib/prisma";
|
|
||||||
import { captchaConfig } from "@/lib/services/captcha";
|
import { captchaConfig } from "@/lib/services/captcha";
|
||||||
import { siteSettings } from "@/lib/services/site-settings";
|
import { siteSettings } from "@/lib/services/site-settings";
|
||||||
|
|
||||||
@@ -32,21 +33,23 @@ export default async function RegisterPage() {
|
|||||||
|
|
||||||
const [online, recentUsers, latestUsers] = await Promise.all([
|
const [online, recentUsers, latestUsers] = await Promise.all([
|
||||||
cached("online_count", 10_000, () =>
|
cached("online_count", 10_000, () =>
|
||||||
prisma.user.count({ where: { online: "1" } }),
|
db
|
||||||
|
.select({ total: count() })
|
||||||
|
.from(User)
|
||||||
|
.where(eq(User.online, "1"))
|
||||||
|
.then((rows) => rows[0]?.total ?? 0),
|
||||||
).catch(() => 0),
|
).catch(() => 0),
|
||||||
prisma.user
|
db
|
||||||
.findMany({
|
.select({ username: User.username, look: User.look })
|
||||||
where: { online: "1" },
|
.from(User)
|
||||||
select: { username: true, look: true },
|
.where(eq(User.online, "1"))
|
||||||
take: 8,
|
.limit(8)
|
||||||
})
|
|
||||||
.catch(() => []),
|
.catch(() => []),
|
||||||
prisma.user
|
db
|
||||||
.findMany({
|
.select({ username: User.username, look: User.look })
|
||||||
orderBy: { accountCreated: "desc" },
|
.from(User)
|
||||||
select: { username: true, look: true },
|
.orderBy(desc(User.accountCreated))
|
||||||
take: 8,
|
.limit(8)
|
||||||
})
|
|
||||||
.catch(() => []),
|
.catch(() => []),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
|||||||
@@ -1,8 +1,9 @@
|
|||||||
|
import { eq } from "drizzle-orm";
|
||||||
import type { Metadata } from "next";
|
import type { Metadata } from "next";
|
||||||
import Link from "next/link";
|
import Link from "next/link";
|
||||||
import { notFound } from "next/navigation";
|
import { notFound } from "next/navigation";
|
||||||
import { ContentCard, EmptyState, StatBlock } from "@/components/public/ui";
|
import { ContentCard, EmptyState, StatBlock } from "@/components/public/ui";
|
||||||
import { prisma } from "@/lib/prisma";
|
import { db, Rooms, User } from "@/lib/db";
|
||||||
|
|
||||||
export const revalidate = 300;
|
export const revalidate = 300;
|
||||||
|
|
||||||
@@ -31,24 +32,25 @@ function parseRoomId(raw: string): number | null {
|
|||||||
async function getRoom(raw: string) {
|
async function getRoom(raw: string) {
|
||||||
const id = parseRoomId(raw);
|
const id = parseRoomId(raw);
|
||||||
if (id === null) return null;
|
if (id === null) return null;
|
||||||
return prisma.rooms
|
const [room] = await db
|
||||||
.findUnique({
|
.select({
|
||||||
where: { id },
|
id: Rooms.id,
|
||||||
select: {
|
ownerId: Rooms.ownerId,
|
||||||
id: true,
|
ownerName: Rooms.ownerName,
|
||||||
ownerId: true,
|
name: Rooms.name,
|
||||||
ownerName: true,
|
description: Rooms.description,
|
||||||
name: true,
|
state: Rooms.state,
|
||||||
description: true,
|
users: Rooms.users,
|
||||||
state: true,
|
usersMax: Rooms.usersMax,
|
||||||
users: true,
|
category: Rooms.category,
|
||||||
usersMax: true,
|
score: Rooms.score,
|
||||||
category: true,
|
tags: Rooms.tags,
|
||||||
score: true,
|
|
||||||
tags: true,
|
|
||||||
},
|
|
||||||
})
|
})
|
||||||
.catch(() => null);
|
.from(Rooms)
|
||||||
|
.where(eq(Rooms.id, id))
|
||||||
|
.limit(1)
|
||||||
|
.catch(() => []);
|
||||||
|
return room ?? null;
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function generateMetadata({
|
export async function generateMetadata({
|
||||||
@@ -83,12 +85,14 @@ export default async function RoomPage({
|
|||||||
// owner_name column if the account row is missing or the query degrades.
|
// owner_name column if the account row is missing or the query degrades.
|
||||||
const owner =
|
const owner =
|
||||||
room.ownerId > 0
|
room.ownerId > 0
|
||||||
? await prisma.user
|
? (
|
||||||
.findUnique({
|
await db
|
||||||
where: { id: room.ownerId },
|
.select({ username: User.username })
|
||||||
select: { username: true },
|
.from(User)
|
||||||
})
|
.where(eq(User.id, room.ownerId))
|
||||||
.catch(() => null)
|
.limit(1)
|
||||||
|
.catch(() => [])
|
||||||
|
)[0]
|
||||||
: null;
|
: null;
|
||||||
const ownerName = owner?.username || room.ownerName || "Unknown";
|
const ownerName = owner?.username || room.ownerName || "Unknown";
|
||||||
|
|
||||||
|
|||||||
@@ -1,8 +1,9 @@
|
|||||||
|
import { and, eq, like } from "drizzle-orm";
|
||||||
import type { Metadata } from "next";
|
import type { Metadata } from "next";
|
||||||
import Image from "next/image";
|
import Image from "next/image";
|
||||||
import Link from "next/link";
|
import Link from "next/link";
|
||||||
|
import { db, Rooms, User } from "@/lib/db";
|
||||||
import { avatarImageUrl } from "@/lib/format";
|
import { avatarImageUrl } from "@/lib/format";
|
||||||
import { prisma } from "@/lib/prisma";
|
|
||||||
import { siteSettings } from "@/lib/services/site-settings";
|
import { siteSettings } from "@/lib/services/site-settings";
|
||||||
|
|
||||||
export const metadata: Metadata = { title: "Search" };
|
export const metadata: Metadata = { title: "Search" };
|
||||||
@@ -43,38 +44,31 @@ export default async function SearchPage({
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
const users = await prisma.user
|
const users = await db
|
||||||
.findMany({
|
.select({
|
||||||
where: {
|
id: User.id,
|
||||||
username: { contains: query },
|
username: User.username,
|
||||||
},
|
look: User.look,
|
||||||
select: {
|
motto: User.motto,
|
||||||
id: true,
|
online: User.online,
|
||||||
username: true,
|
rank: User.rank,
|
||||||
look: true,
|
|
||||||
motto: true,
|
|
||||||
online: true,
|
|
||||||
rank: true,
|
|
||||||
},
|
|
||||||
take: 30,
|
|
||||||
})
|
})
|
||||||
|
.from(User)
|
||||||
|
.where(like(User.username, `%${query}%`))
|
||||||
|
.limit(30)
|
||||||
.catch(() => []);
|
.catch(() => []);
|
||||||
|
|
||||||
const rooms = await prisma.rooms
|
const rooms = await db
|
||||||
.findMany({
|
.select({
|
||||||
where: {
|
id: Rooms.id,
|
||||||
name: { contains: query },
|
name: Rooms.name,
|
||||||
state: "open",
|
ownerName: Rooms.ownerName,
|
||||||
},
|
users: Rooms.users,
|
||||||
select: {
|
usersMax: Rooms.usersMax,
|
||||||
id: true,
|
|
||||||
name: true,
|
|
||||||
ownerName: true,
|
|
||||||
users: true,
|
|
||||||
usersMax: true,
|
|
||||||
},
|
|
||||||
take: 12,
|
|
||||||
})
|
})
|
||||||
|
.from(Rooms)
|
||||||
|
.where(and(like(Rooms.name, `%${query}%`), eq(Rooms.state, "open")))
|
||||||
|
.limit(12)
|
||||||
.catch(() => []);
|
.catch(() => []);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
import { eq } from "drizzle-orm";
|
||||||
import Link from "next/link";
|
import Link from "next/link";
|
||||||
import { redirect } from "next/navigation";
|
import { redirect } from "next/navigation";
|
||||||
import { getTranslations } from "next-intl/server";
|
import { getTranslations } from "next-intl/server";
|
||||||
@@ -11,8 +12,8 @@ import { env } from "@/env";
|
|||||||
import { auth } from "@/lib/auth";
|
import { auth } from "@/lib/auth";
|
||||||
import { LaravelEncrypter } from "@/lib/auth/laravel-encrypter";
|
import { LaravelEncrypter } from "@/lib/auth/laravel-encrypter";
|
||||||
import { totpKeyUri } from "@/lib/auth/totp";
|
import { totpKeyUri } from "@/lib/auth/totp";
|
||||||
|
import { db, User } from "@/lib/db";
|
||||||
import { resolveHotelName } from "@/lib/hotel-name";
|
import { resolveHotelName } from "@/lib/hotel-name";
|
||||||
import { prisma } from "@/lib/prisma";
|
|
||||||
|
|
||||||
export const dynamic = "force-dynamic";
|
export const dynamic = "force-dynamic";
|
||||||
|
|
||||||
@@ -37,14 +38,16 @@ export default async function TwoFactorPage({
|
|||||||
twoFactorRecoveryCodes: string | null;
|
twoFactorRecoveryCodes: string | null;
|
||||||
} | null = null;
|
} | null = null;
|
||||||
try {
|
try {
|
||||||
user = await prisma.user.findUnique({
|
const [row] = await db
|
||||||
where: { id },
|
.select({
|
||||||
select: {
|
twoFactorSecret: User.twoFactorSecret,
|
||||||
twoFactorSecret: true,
|
twoFactorConfirmedAt: User.twoFactorConfirmedAt,
|
||||||
twoFactorConfirmedAt: true,
|
twoFactorRecoveryCodes: User.twoFactorRecoveryCodes,
|
||||||
twoFactorRecoveryCodes: true,
|
})
|
||||||
},
|
.from(User)
|
||||||
});
|
.where(eq(User.id, id))
|
||||||
|
.limit(1);
|
||||||
|
user = row ?? null;
|
||||||
} catch {
|
} catch {
|
||||||
user = null;
|
user = null;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
import { eq } from "drizzle-orm";
|
||||||
import Image from "next/image";
|
import Image from "next/image";
|
||||||
import Link from "next/link";
|
import Link from "next/link";
|
||||||
import { redirect } from "next/navigation";
|
import { redirect } from "next/navigation";
|
||||||
@@ -5,8 +6,8 @@ import { getTranslations } from "next-intl/server";
|
|||||||
import { updateMotto } from "@/actions/user-settings";
|
import { updateMotto } from "@/actions/user-settings";
|
||||||
import { Reveal } from "@/components/motion-reveal";
|
import { Reveal } from "@/components/motion-reveal";
|
||||||
import { auth } from "@/lib/auth";
|
import { auth } from "@/lib/auth";
|
||||||
|
import { db, User } from "@/lib/db";
|
||||||
import { avatarImageUrl } from "@/lib/format";
|
import { avatarImageUrl } from "@/lib/format";
|
||||||
import { prisma } from "@/lib/prisma";
|
|
||||||
import { siteSettings } from "@/lib/services/site-settings";
|
import { siteSettings } from "@/lib/services/site-settings";
|
||||||
|
|
||||||
export const dynamic = "force-dynamic";
|
export const dynamic = "force-dynamic";
|
||||||
@@ -25,10 +26,17 @@ export default async function SettingsPage() {
|
|||||||
mail: string | null;
|
mail: string | null;
|
||||||
} | null = null;
|
} | null = null;
|
||||||
try {
|
try {
|
||||||
user = await prisma.user.findUnique({
|
const [row] = await db
|
||||||
where: { id },
|
.select({
|
||||||
select: { username: true, motto: true, look: true, mail: true },
|
username: User.username,
|
||||||
});
|
motto: User.motto,
|
||||||
|
look: User.look,
|
||||||
|
mail: User.mail,
|
||||||
|
})
|
||||||
|
.from(User)
|
||||||
|
.where(eq(User.id, id))
|
||||||
|
.limit(1);
|
||||||
|
user = row ?? null;
|
||||||
} catch {
|
} catch {
|
||||||
user = null;
|
user = null;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,10 +1,11 @@
|
|||||||
|
import { desc, eq, sql } from "drizzle-orm";
|
||||||
import { redirect } from "next/navigation";
|
import { redirect } from "next/navigation";
|
||||||
import { getTranslations } from "next-intl/server";
|
import { getTranslations } from "next-intl/server";
|
||||||
import { signOutEverywhere } from "@/actions/sessions";
|
import { signOutEverywhere } from "@/actions/sessions";
|
||||||
import { ContentCard, EmptyState } from "@/components/public/ui";
|
import { ContentCard, EmptyState } from "@/components/public/ui";
|
||||||
import { auth } from "@/lib/auth";
|
import { auth } from "@/lib/auth";
|
||||||
|
import { db, WebsiteLoginLogs } from "@/lib/db";
|
||||||
import { formatDate } from "@/lib/format-date";
|
import { formatDate } from "@/lib/format-date";
|
||||||
import { prisma } from "@/lib/prisma";
|
|
||||||
|
|
||||||
export const dynamic = "force-dynamic";
|
export const dynamic = "force-dynamic";
|
||||||
|
|
||||||
@@ -54,20 +55,30 @@ export default async function SessionsPage({
|
|||||||
const userId = Number(session.user.id);
|
const userId = Number(session.user.id);
|
||||||
const { signedOutAll } = await searchParams;
|
const { signedOutAll } = await searchParams;
|
||||||
|
|
||||||
const logins = await prisma.websiteLoginLogs
|
const logins = await db
|
||||||
.findMany({
|
.select({
|
||||||
where: { userId },
|
id: WebsiteLoginLogs.id,
|
||||||
orderBy: { id: "desc" },
|
ip: WebsiteLoginLogs.ip,
|
||||||
take: 30,
|
userAgent: WebsiteLoginLogs.userAgent,
|
||||||
select: { id: true, ip: true, userAgent: true, createdAt: true },
|
createdAt: WebsiteLoginLogs.createdAt,
|
||||||
})
|
})
|
||||||
|
.from(WebsiteLoginLogs)
|
||||||
|
.where(eq(WebsiteLoginLogs.userId, userId))
|
||||||
|
.orderBy(desc(WebsiteLoginLogs.id))
|
||||||
|
.limit(30)
|
||||||
.catch(() => []);
|
.catch(() => []);
|
||||||
|
|
||||||
type Failed = { id: number; ip_address: string; attempted_at: Date | string };
|
type Failed = { id: number; ip_address: string; attempted_at: Date | string };
|
||||||
const failed = await prisma.$queryRaw<Failed[]>`
|
let failed: Failed[] = [];
|
||||||
|
try {
|
||||||
|
const [rows] = (await db.execute(sql`
|
||||||
SELECT id, ip_address, attempted_at FROM failed_logins
|
SELECT id, ip_address, attempted_at FROM failed_logins
|
||||||
WHERE username = ${session.user.name} ORDER BY id DESC LIMIT 15
|
WHERE username = ${session.user.name} ORDER BY id DESC LIMIT 15
|
||||||
`.catch(() => [] as Failed[]);
|
`)) as unknown as [Failed[], unknown];
|
||||||
|
failed = rows ?? [];
|
||||||
|
} catch {
|
||||||
|
failed = [];
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<main style={{ display: "grid", gap: "1.5rem" }}>
|
<main style={{ display: "grid", gap: "1.5rem" }}>
|
||||||
|
|||||||
File diff suppressed because it is too large.
Load diff
@@ -1,8 +1,9 @@
|
|||||||
|
import { eq } from "drizzle-orm";
|
||||||
import { redirect } from "next/navigation";
|
import { redirect } from "next/navigation";
|
||||||
import { getTranslations } from "next-intl/server";
|
import { getTranslations } from "next-intl/server";
|
||||||
import { ContentCard, StatBlock } from "@/components/public/ui";
|
import { ContentCard, StatBlock } from "@/components/public/ui";
|
||||||
import { auth } from "@/lib/auth";
|
import { auth } from "@/lib/auth";
|
||||||
import { prisma } from "@/lib/prisma";
|
import { db, User } from "@/lib/db";
|
||||||
import {
|
import {
|
||||||
creditsPerUnit,
|
creditsPerUnit,
|
||||||
isPayPalConfigured,
|
isPayPalConfigured,
|
||||||
@@ -27,10 +28,12 @@ export default async function TopUpPage({
|
|||||||
// Current credits balance for context (fail soft).
|
// Current credits balance for context (fail soft).
|
||||||
let user: { username: string; credits: number } | null = null;
|
let user: { username: string; credits: number } | null = null;
|
||||||
try {
|
try {
|
||||||
user = await prisma.user.findUnique({
|
const [row] = await db
|
||||||
where: { id },
|
.select({ username: User.username, credits: User.credits })
|
||||||
select: { username: true, credits: true },
|
.from(User)
|
||||||
});
|
.where(eq(User.id, id))
|
||||||
|
.limit(1);
|
||||||
|
user = row ?? null;
|
||||||
} catch {
|
} catch {
|
||||||
user = null;
|
user = null;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,8 @@
|
|||||||
|
import { asc, desc, eq, gte } from "drizzle-orm";
|
||||||
import Link from "next/link";
|
import Link from "next/link";
|
||||||
import { getTranslations } from "next-intl/server";
|
import { getTranslations } from "next-intl/server";
|
||||||
import { ContentCard, EmptyState } from "@/components/public/ui";
|
import { ContentCard, EmptyState } from "@/components/public/ui";
|
||||||
import { prisma } from "@/lib/prisma";
|
import { db, User, WebsiteTeams } from "@/lib/db";
|
||||||
import { siteSettings } from "@/lib/services/site-settings";
|
import { siteSettings } from "@/lib/services/site-settings";
|
||||||
|
|
||||||
export const revalidate = 300;
|
export const revalidate = 300;
|
||||||
@@ -30,30 +31,35 @@ export default async function StaffPage() {
|
|||||||
|
|
||||||
let staff: StaffMember[] = [];
|
let staff: StaffMember[] = [];
|
||||||
try {
|
try {
|
||||||
staff = await prisma.user.findMany({
|
staff = await db
|
||||||
where: { rank: { gte: minStaffRank } },
|
.select({
|
||||||
select: { username: true, look: true, rank: true, motto: true },
|
username: User.username,
|
||||||
orderBy: [{ rank: "desc" }, { username: "asc" }],
|
look: User.look,
|
||||||
take: 100,
|
rank: User.rank,
|
||||||
});
|
motto: User.motto,
|
||||||
|
})
|
||||||
|
.from(User)
|
||||||
|
.where(gte(User.rank, minStaffRank))
|
||||||
|
.orderBy(desc(User.rank), asc(User.username))
|
||||||
|
.limit(100);
|
||||||
} catch {
|
} catch {
|
||||||
staff = [];
|
staff = [];
|
||||||
}
|
}
|
||||||
|
|
||||||
let teams: Team[] = [];
|
let teams: Team[] = [];
|
||||||
try {
|
try {
|
||||||
const rows = await prisma.websiteTeams.findMany({
|
const rows = await db
|
||||||
where: { hiddenRank: false },
|
.select({
|
||||||
select: {
|
id: WebsiteTeams.id,
|
||||||
id: true,
|
rankName: WebsiteTeams.rankName,
|
||||||
rankName: true,
|
badge: WebsiteTeams.badge,
|
||||||
badge: true,
|
jobDescription: WebsiteTeams.jobDescription,
|
||||||
jobDescription: true,
|
staffColor: WebsiteTeams.staffColor,
|
||||||
staffColor: true,
|
})
|
||||||
},
|
.from(WebsiteTeams)
|
||||||
orderBy: { id: "asc" },
|
.where(eq(WebsiteTeams.hiddenRank, false))
|
||||||
});
|
.orderBy(asc(WebsiteTeams.id));
|
||||||
teams = rows.map((t) => ({ ...t, id: String(t.id) }));
|
teams = rows.map((row) => ({ ...row, id: String(row.id) }));
|
||||||
} catch {
|
} catch {
|
||||||
teams = [];
|
teams = [];
|
||||||
}
|
}
|
||||||
@@ -69,14 +75,14 @@ export default async function StaffPage() {
|
|||||||
subtitle={t("ranksSubtitle")}
|
subtitle={t("ranksSubtitle")}
|
||||||
>
|
>
|
||||||
<div className="card-grid sm-2 lg-3">
|
<div className="card-grid sm-2 lg-3">
|
||||||
{teams.map((t) => (
|
{teams.map((team) => (
|
||||||
<div key={t.id} className="card">
|
<div key={team.id} className="card">
|
||||||
<h3 style={{ margin: "0 0 0.25rem", color: t.staffColor }}>
|
<h3 style={{ margin: "0 0 0.25rem", color: team.staffColor }}>
|
||||||
{t.rankName}
|
{team.rankName}
|
||||||
</h3>
|
</h3>
|
||||||
{t.jobDescription ? (
|
{team.jobDescription ? (
|
||||||
<p className="muted" style={{ margin: 0 }}>
|
<p className="muted" style={{ margin: 0 }}>
|
||||||
{t.jobDescription}
|
{team.jobDescription}
|
||||||
</p>
|
</p>
|
||||||
) : null}
|
) : null}
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
File diff suppressed because it is too large.
Load diff
@@ -1,8 +1,9 @@
|
|||||||
|
import { eq } from "drizzle-orm";
|
||||||
import { CheckCircle2, Clock, MailX } from "lucide-react";
|
import { CheckCircle2, Clock, MailX } from "lucide-react";
|
||||||
import Link from "next/link";
|
import Link from "next/link";
|
||||||
import { getTranslations } from "next-intl/server";
|
import { getTranslations } from "next-intl/server";
|
||||||
import { isValidVerificationToken } from "@/actions/email-verify";
|
import { isValidVerificationToken } from "@/actions/email-verify";
|
||||||
import { prisma } from "@/lib/prisma";
|
import { db, User } from "@/lib/db";
|
||||||
|
|
||||||
export const dynamic = "force-dynamic";
|
export const dynamic = "force-dynamic";
|
||||||
|
|
||||||
@@ -88,19 +89,20 @@ export default async function VerifyPage({
|
|||||||
const ok = await isValidVerificationToken(normalisedEmail, token);
|
const ok = await isValidVerificationToken(normalisedEmail, token);
|
||||||
if (ok) {
|
if (ok) {
|
||||||
try {
|
try {
|
||||||
const user = await prisma.user.findFirst({
|
const [user] = await db
|
||||||
where: { mail: normalisedEmail },
|
.select({ id: User.id, mailVerified: User.mailVerified })
|
||||||
select: { id: true, mailVerified: true },
|
.from(User)
|
||||||
});
|
.where(eq(User.mail, normalisedEmail))
|
||||||
|
.limit(1);
|
||||||
if (!user) {
|
if (!user) {
|
||||||
status = "invalid";
|
status = "invalid";
|
||||||
} else if (user.mailVerified === "1") {
|
} else if (user.mailVerified === "1") {
|
||||||
status = "already";
|
status = "already";
|
||||||
} else {
|
} else {
|
||||||
await prisma.user.update({
|
await db
|
||||||
where: { id: user.id },
|
.update(User)
|
||||||
data: { mailVerified: "1" },
|
.set({ mailVerified: "1" })
|
||||||
});
|
.where(eq(User.id, user.id));
|
||||||
status = "verified";
|
status = "verified";
|
||||||
}
|
}
|
||||||
} catch {
|
} catch {
|
||||||
|
|||||||
@@ -1,8 +1,9 @@
|
|||||||
|
import { asc } from "drizzle-orm";
|
||||||
import { redirect } from "next/navigation";
|
import { redirect } from "next/navigation";
|
||||||
import { getTranslations } from "next-intl/server";
|
import { getTranslations } from "next-intl/server";
|
||||||
import { StatusCard } from "@/components/admin/dashboard";
|
import { StatusCard } from "@/components/admin/dashboard";
|
||||||
|
import { Achievements, db } from "@/lib/db";
|
||||||
import { canAccess, getAdminContext, PERMS } from "@/lib/permissions";
|
import { canAccess, getAdminContext, PERMS } from "@/lib/permissions";
|
||||||
import { prisma } from "@/lib/prisma";
|
|
||||||
|
|
||||||
type Achievement = {
|
type Achievement = {
|
||||||
name: string;
|
name: string;
|
||||||
@@ -24,18 +25,22 @@ export default async function AdminAchievements() {
|
|||||||
|
|
||||||
let achievements: Achievement[];
|
let achievements: Achievement[];
|
||||||
try {
|
try {
|
||||||
achievements = await prisma.achievements.findMany({
|
achievements = await db
|
||||||
select: {
|
.select({
|
||||||
name: true,
|
name: Achievements.name,
|
||||||
category: true,
|
category: Achievements.category,
|
||||||
level: true,
|
level: Achievements.level,
|
||||||
rewardAmount: true,
|
rewardAmount: Achievements.rewardAmount,
|
||||||
rewardType: true,
|
rewardType: Achievements.rewardType,
|
||||||
points: true,
|
points: Achievements.points,
|
||||||
progressNeeded: true,
|
progressNeeded: Achievements.progressNeeded,
|
||||||
},
|
})
|
||||||
orderBy: [{ category: "asc" }, { name: "asc" }, { level: "asc" }],
|
.from(Achievements)
|
||||||
});
|
.orderBy(
|
||||||
|
asc(Achievements.category),
|
||||||
|
asc(Achievements.name),
|
||||||
|
asc(Achievements.level),
|
||||||
|
);
|
||||||
} catch {
|
} catch {
|
||||||
achievements = [];
|
achievements = [];
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,11 +1,12 @@
|
|||||||
|
import { eq } from "drizzle-orm";
|
||||||
import { Megaphone } from "lucide-react";
|
import { Megaphone } from "lucide-react";
|
||||||
import Link from "next/link";
|
import Link from "next/link";
|
||||||
import { notFound, redirect } from "next/navigation";
|
import { notFound, redirect } from "next/navigation";
|
||||||
import { getTranslations } from "next-intl/server";
|
import { getTranslations } from "next-intl/server";
|
||||||
import { updateAd } from "@/actions/admin-ads";
|
import { updateAd } from "@/actions/admin-ads";
|
||||||
import { Button } from "@/components/ui/button";
|
import { Button } from "@/components/ui/button";
|
||||||
|
import { db, WebsiteAds } from "@/lib/db";
|
||||||
import { canAccess, getAdminContext, PERMS } from "@/lib/permissions";
|
import { canAccess, getAdminContext, PERMS } from "@/lib/permissions";
|
||||||
import { prisma } from "@/lib/prisma";
|
|
||||||
import { EditAdDeleteButton } from "../ads-table";
|
import { EditAdDeleteButton } from "../ads-table";
|
||||||
|
|
||||||
export default async function EditAd({
|
export default async function EditAd({
|
||||||
@@ -19,9 +20,14 @@ export default async function EditAd({
|
|||||||
}
|
}
|
||||||
|
|
||||||
const { id } = await params;
|
const { id } = await params;
|
||||||
let ad: Awaited<ReturnType<typeof prisma.websiteAds.findUnique>> = null;
|
let ad: typeof WebsiteAds.$inferSelect | null = null;
|
||||||
try {
|
try {
|
||||||
ad = await prisma.websiteAds.findUnique({ where: { id: BigInt(id) } });
|
const [row] = await db
|
||||||
|
.select()
|
||||||
|
.from(WebsiteAds)
|
||||||
|
.where(eq(WebsiteAds.id, BigInt(id)))
|
||||||
|
.limit(1);
|
||||||
|
ad = row ?? null;
|
||||||
} catch {
|
} catch {
|
||||||
notFound();
|
notFound();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,11 +1,12 @@
|
|||||||
|
import { desc } from "drizzle-orm";
|
||||||
import Link from "next/link";
|
import Link from "next/link";
|
||||||
import { redirect } from "next/navigation";
|
import { redirect } from "next/navigation";
|
||||||
import { getTranslations } from "next-intl/server";
|
import { getTranslations } from "next-intl/server";
|
||||||
import { StatusCard } from "@/components/admin/dashboard";
|
import { StatusCard } from "@/components/admin/dashboard";
|
||||||
import { Button } from "@/components/ui/button";
|
import { Button } from "@/components/ui/button";
|
||||||
|
import { db, WebsiteAds } from "@/lib/db";
|
||||||
import { formatDate } from "@/lib/format-date";
|
import { formatDate } from "@/lib/format-date";
|
||||||
import { canAccess, getAdminContext, PERMS } from "@/lib/permissions";
|
import { canAccess, getAdminContext, PERMS } from "@/lib/permissions";
|
||||||
import { prisma } from "@/lib/prisma";
|
|
||||||
import { AdsTable } from "./ads-table";
|
import { AdsTable } from "./ads-table";
|
||||||
|
|
||||||
export default async function AdminAds() {
|
export default async function AdminAds() {
|
||||||
@@ -15,12 +16,13 @@ export default async function AdminAds() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const t = await getTranslations("pages.admin.ads");
|
const t = await getTranslations("pages.admin.ads");
|
||||||
let ads: Awaited<ReturnType<typeof prisma.websiteAds.findMany>>;
|
let ads: (typeof WebsiteAds.$inferSelect)[] = [];
|
||||||
try {
|
try {
|
||||||
ads = await prisma.websiteAds.findMany({
|
ads = await db
|
||||||
orderBy: { id: "desc" },
|
.select()
|
||||||
take: 500,
|
.from(WebsiteAds)
|
||||||
});
|
.orderBy(desc(WebsiteAds.id))
|
||||||
|
.limit(500);
|
||||||
} catch {
|
} catch {
|
||||||
ads = [];
|
ads = [];
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,11 +1,12 @@
|
|||||||
|
import { desc } from "drizzle-orm";
|
||||||
import { redirect } from "next/navigation";
|
import { redirect } from "next/navigation";
|
||||||
import { getTranslations } from "next-intl/server";
|
import { getTranslations } from "next-intl/server";
|
||||||
import { sendHotelAlert } from "@/actions/admin-alerts";
|
import { sendHotelAlert } from "@/actions/admin-alerts";
|
||||||
import { StatusCard } from "@/components/admin/dashboard";
|
import { StatusCard } from "@/components/admin/dashboard";
|
||||||
import { Button } from "@/components/ui/button";
|
import { Button } from "@/components/ui/button";
|
||||||
|
import { AlertLogs, db } from "@/lib/db";
|
||||||
import { formatDate } from "@/lib/format-date";
|
import { formatDate } from "@/lib/format-date";
|
||||||
import { canAccess, getAdminContext, PERMS } from "@/lib/permissions";
|
import { canAccess, getAdminContext, PERMS } from "@/lib/permissions";
|
||||||
import { prisma } from "@/lib/prisma";
|
|
||||||
|
|
||||||
const CRITICAL = new Set(["critical", "error", "danger"]);
|
const CRITICAL = new Set(["critical", "error", "danger"]);
|
||||||
const WARNING = new Set(["warning", "warn"]);
|
const WARNING = new Set(["warning", "warn"]);
|
||||||
@@ -58,12 +59,13 @@ export default async function AdminAlerts() {
|
|||||||
|
|
||||||
const t = await getTranslations("pages.admin.alerts");
|
const t = await getTranslations("pages.admin.alerts");
|
||||||
|
|
||||||
let alerts: Awaited<ReturnType<typeof prisma.alertLogs.findMany>>;
|
let alerts: (typeof AlertLogs.$inferSelect)[] = [];
|
||||||
try {
|
try {
|
||||||
alerts = await prisma.alertLogs.findMany({
|
alerts = await db
|
||||||
orderBy: { id: "desc" },
|
.select()
|
||||||
take: 100,
|
.from(AlertLogs)
|
||||||
});
|
.orderBy(desc(AlertLogs.id))
|
||||||
|
.limit(100);
|
||||||
} catch {
|
} catch {
|
||||||
alerts = [];
|
alerts = [];
|
||||||
}
|
}
|
||||||
|
|||||||
File diff suppressed because it is too large.
Load diff
File diff suppressed because it is too large.
Load diff
File diff suppressed because it is too large.
Load diff
@@ -1,12 +1,13 @@
|
|||||||
|
import { desc, inArray } from "drizzle-orm";
|
||||||
import Link from "next/link";
|
import Link from "next/link";
|
||||||
import { redirect } from "next/navigation";
|
import { redirect } from "next/navigation";
|
||||||
import { getTranslations } from "next-intl/server";
|
import { getTranslations } from "next-intl/server";
|
||||||
import { dismissApplication } from "@/actions/admin-applications";
|
import { dismissApplication } from "@/actions/admin-applications";
|
||||||
import { StatusCard } from "@/components/admin/dashboard";
|
import { StatusCard } from "@/components/admin/dashboard";
|
||||||
import { Button } from "@/components/ui/button";
|
import { Button } from "@/components/ui/button";
|
||||||
|
import { db, User, WebsiteStaffApplications } from "@/lib/db";
|
||||||
import { formatDate } from "@/lib/format-date";
|
import { formatDate } from "@/lib/format-date";
|
||||||
import { canAccess, getAdminContext, PERMS } from "@/lib/permissions";
|
import { canAccess, getAdminContext, PERMS } from "@/lib/permissions";
|
||||||
import { prisma } from "@/lib/prisma";
|
|
||||||
|
|
||||||
type ApplicationRow = {
|
type ApplicationRow = {
|
||||||
id: bigint;
|
id: bigint;
|
||||||
@@ -25,10 +26,11 @@ export default async function AdminApplications() {
|
|||||||
const t = await getTranslations("pages.admin.applications");
|
const t = await getTranslations("pages.admin.applications");
|
||||||
let applications: ApplicationRow[];
|
let applications: ApplicationRow[];
|
||||||
try {
|
try {
|
||||||
applications = await prisma.websiteStaffApplications.findMany({
|
applications = await db
|
||||||
orderBy: { createdAt: "desc" },
|
.select()
|
||||||
take: 100,
|
.from(WebsiteStaffApplications)
|
||||||
});
|
.orderBy(desc(WebsiteStaffApplications.createdAt))
|
||||||
|
.limit(100);
|
||||||
} catch {
|
} catch {
|
||||||
applications = [];
|
applications = [];
|
||||||
}
|
}
|
||||||
@@ -38,10 +40,10 @@ export default async function AdminApplications() {
|
|||||||
if (applications.length > 0) {
|
if (applications.length > 0) {
|
||||||
try {
|
try {
|
||||||
const ids = Array.from(new Set(applications.map((a) => a.userId)));
|
const ids = Array.from(new Set(applications.map((a) => a.userId)));
|
||||||
const users = await prisma.user.findMany({
|
const users = await db
|
||||||
where: { id: { in: ids } },
|
.select({ id: User.id, username: User.username })
|
||||||
select: { id: true, username: true },
|
.from(User)
|
||||||
});
|
.where(inArray(User.id, ids));
|
||||||
for (const u of users) userMap.set(u.id, u.username);
|
for (const u of users) userMap.set(u.id, u.username);
|
||||||
} catch {
|
} catch {
|
||||||
// no DB — fall back to raw ids
|
// no DB — fall back to raw ids
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
import { eq } from "drizzle-orm";
|
||||||
import { Newspaper } from "lucide-react";
|
import { Newspaper } from "lucide-react";
|
||||||
import Link from "next/link";
|
import Link from "next/link";
|
||||||
import { notFound, redirect } from "next/navigation";
|
import { notFound, redirect } from "next/navigation";
|
||||||
@@ -5,8 +6,8 @@ import { getTranslations } from "next-intl/server";
|
|||||||
import { deleteArticle, updateArticle } from "@/actions/admin-articles";
|
import { deleteArticle, updateArticle } from "@/actions/admin-articles";
|
||||||
import { ArticleForm } from "@/components/admin/article-form";
|
import { ArticleForm } from "@/components/admin/article-form";
|
||||||
import { Button } from "@/components/ui/button";
|
import { Button } from "@/components/ui/button";
|
||||||
|
import { db, WebsiteArticles } from "@/lib/db";
|
||||||
import { canAccess, getAdminContext, PERMS } from "@/lib/permissions";
|
import { canAccess, getAdminContext, PERMS } from "@/lib/permissions";
|
||||||
import { prisma } from "@/lib/prisma";
|
|
||||||
|
|
||||||
export default async function EditArticle({
|
export default async function EditArticle({
|
||||||
params,
|
params,
|
||||||
@@ -23,19 +24,19 @@ export default async function EditArticle({
|
|||||||
const { id } = await params;
|
const { id } = await params;
|
||||||
const { error } = await searchParams;
|
const { error } = await searchParams;
|
||||||
const t = await getTranslations("pages.admin.articles");
|
const t = await getTranslations("pages.admin.articles");
|
||||||
const article = await prisma.websiteArticles
|
const [article] = await db
|
||||||
.findUnique({
|
.select({
|
||||||
where: { id: BigInt(id) },
|
id: WebsiteArticles.id,
|
||||||
select: {
|
slug: WebsiteArticles.slug,
|
||||||
id: true,
|
title: WebsiteArticles.title,
|
||||||
slug: true,
|
shortStory: WebsiteArticles.shortStory,
|
||||||
title: true,
|
fullStory: WebsiteArticles.fullStory,
|
||||||
shortStory: true,
|
image: WebsiteArticles.image,
|
||||||
fullStory: true,
|
|
||||||
image: true,
|
|
||||||
},
|
|
||||||
})
|
})
|
||||||
.catch(() => null);
|
.from(WebsiteArticles)
|
||||||
|
.where(eq(WebsiteArticles.id, BigInt(id)))
|
||||||
|
.limit(1)
|
||||||
|
.catch(() => []);
|
||||||
if (!article) notFound();
|
if (!article) notFound();
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
import { desc, inArray } from "drizzle-orm";
|
||||||
import { Newspaper } from "lucide-react";
|
import { Newspaper } from "lucide-react";
|
||||||
import Link from "next/link";
|
import Link from "next/link";
|
||||||
import { redirect } from "next/navigation";
|
import { redirect } from "next/navigation";
|
||||||
@@ -6,9 +7,9 @@ import { AdminPageShell } from "@/components/admin/admin-page-shell";
|
|||||||
import { ArticleCard } from "@/components/admin/article-card";
|
import { ArticleCard } from "@/components/admin/article-card";
|
||||||
import { StatusCard } from "@/components/admin/dashboard";
|
import { StatusCard } from "@/components/admin/dashboard";
|
||||||
import { Button } from "@/components/ui/button";
|
import { Button } from "@/components/ui/button";
|
||||||
|
import { db, User, WebsiteArticles } from "@/lib/db";
|
||||||
import { formatDate } from "@/lib/format-date";
|
import { formatDate } from "@/lib/format-date";
|
||||||
import { canAccess, getAdminContext, PERMS } from "@/lib/permissions";
|
import { canAccess, getAdminContext, PERMS } from "@/lib/permissions";
|
||||||
import { prisma } from "@/lib/prisma";
|
|
||||||
|
|
||||||
export default async function AdminArticles({
|
export default async function AdminArticles({
|
||||||
searchParams,
|
searchParams,
|
||||||
@@ -22,19 +23,18 @@ export default async function AdminArticles({
|
|||||||
|
|
||||||
const { error } = await searchParams;
|
const { error } = await searchParams;
|
||||||
const t = await getTranslations("pages.admin.articles");
|
const t = await getTranslations("pages.admin.articles");
|
||||||
const articles = await prisma.websiteArticles
|
const articles = await db
|
||||||
.findMany({
|
.select({
|
||||||
orderBy: { createdAt: "desc" },
|
id: WebsiteArticles.id,
|
||||||
select: {
|
title: WebsiteArticles.title,
|
||||||
id: true,
|
slug: WebsiteArticles.slug,
|
||||||
title: true,
|
image: WebsiteArticles.image,
|
||||||
slug: true,
|
createdAt: WebsiteArticles.createdAt,
|
||||||
image: true,
|
userId: WebsiteArticles.userId,
|
||||||
createdAt: true,
|
|
||||||
userId: true,
|
|
||||||
},
|
|
||||||
take: 50,
|
|
||||||
})
|
})
|
||||||
|
.from(WebsiteArticles)
|
||||||
|
.orderBy(desc(WebsiteArticles.createdAt))
|
||||||
|
.limit(50)
|
||||||
.catch(() => []);
|
.catch(() => []);
|
||||||
|
|
||||||
const authorMap = new Map<number, string>();
|
const authorMap = new Map<number, string>();
|
||||||
@@ -42,11 +42,10 @@ export default async function AdminArticles({
|
|||||||
.map((a) => a.userId)
|
.map((a) => a.userId)
|
||||||
.filter((id): id is number => Boolean(id));
|
.filter((id): id is number => Boolean(id));
|
||||||
if (authorIds.length > 0) {
|
if (authorIds.length > 0) {
|
||||||
const authors = await prisma.user
|
const authors = await db
|
||||||
.findMany({
|
.select({ id: User.id, username: User.username })
|
||||||
where: { id: { in: authorIds } },
|
.from(User)
|
||||||
select: { id: true, username: true },
|
.where(inArray(User.id, authorIds))
|
||||||
})
|
|
||||||
.catch(() => []);
|
.catch(() => []);
|
||||||
for (const u of authors) authorMap.set(u.id, u.username);
|
for (const u of authors) authorMap.set(u.id, u.username);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,10 +1,11 @@
|
|||||||
|
import { asc } from "drizzle-orm";
|
||||||
import { redirect } from "next/navigation";
|
import { redirect } from "next/navigation";
|
||||||
import { getTranslations } from "next-intl/server";
|
import { getTranslations } from "next-intl/server";
|
||||||
import { uploadBadge } from "@/actions/admin-badge-upload";
|
import { uploadBadge } from "@/actions/admin-badge-upload";
|
||||||
import { giveBadge } from "@/actions/admin-badges";
|
import { giveBadge } from "@/actions/admin-badges";
|
||||||
import { Button } from "@/components/ui/button";
|
import { Button } from "@/components/ui/button";
|
||||||
|
import { db, WebsiteBadges } from "@/lib/db";
|
||||||
import { canAccess, getAdminContext, PERMS } from "@/lib/permissions";
|
import { canAccess, getAdminContext, PERMS } from "@/lib/permissions";
|
||||||
import { prisma } from "@/lib/prisma";
|
|
||||||
|
|
||||||
export const metadata = { title: "Badges" };
|
export const metadata = { title: "Badges" };
|
||||||
|
|
||||||
@@ -21,12 +22,13 @@ export default async function AdminBadges({
|
|||||||
const t = await getTranslations("pages.admin.badges");
|
const t = await getTranslations("pages.admin.badges");
|
||||||
const { uploaded, error } = await searchParams;
|
const { uploaded, error } = await searchParams;
|
||||||
|
|
||||||
let badges: Awaited<ReturnType<typeof prisma.websiteBadges.findMany>>;
|
let badges: (typeof WebsiteBadges.$inferSelect)[] = [];
|
||||||
try {
|
try {
|
||||||
badges = await prisma.websiteBadges.findMany({
|
badges = await db
|
||||||
orderBy: { badgeName: "asc" },
|
.select()
|
||||||
take: 500,
|
.from(WebsiteBadges)
|
||||||
});
|
.orderBy(asc(WebsiteBadges.badgeName))
|
||||||
|
.limit(500);
|
||||||
} catch {
|
} catch {
|
||||||
badges = [];
|
badges = [];
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
|
import { asc } from "drizzle-orm";
|
||||||
import { redirect } from "next/navigation";
|
import { redirect } from "next/navigation";
|
||||||
|
import { db, WebsiteBanner } from "@/lib/db";
|
||||||
import { canAccess, getAdminContext, PERMS } from "@/lib/permissions";
|
import { canAccess, getAdminContext, PERMS } from "@/lib/permissions";
|
||||||
import { prisma } from "@/lib/prisma";
|
|
||||||
import { BannersManager } from "./banners-manager";
|
import { BannersManager } from "./banners-manager";
|
||||||
|
|
||||||
export default async function BannersPage() {
|
export default async function BannersPage() {
|
||||||
@@ -9,9 +10,10 @@ export default async function BannersPage() {
|
|||||||
redirect("/admin");
|
redirect("/admin");
|
||||||
}
|
}
|
||||||
|
|
||||||
const banners = await prisma.websiteBanner.findMany({
|
const banners = await db
|
||||||
orderBy: { sortOrder: "asc" },
|
.select()
|
||||||
});
|
.from(WebsiteBanner)
|
||||||
|
.orderBy(asc(WebsiteBanner.sortOrder));
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="space-y-6">
|
<div className="space-y-6">
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
import { desc, eq, gt, or } from "drizzle-orm";
|
||||||
import { Ban } from "lucide-react";
|
import { Ban } from "lucide-react";
|
||||||
import { redirect } from "next/navigation";
|
import { redirect } from "next/navigation";
|
||||||
import { getTranslations } from "next-intl/server";
|
import { getTranslations } from "next-intl/server";
|
||||||
@@ -5,10 +6,10 @@ import { createBan, liftBan } from "@/actions/admin-bans";
|
|||||||
import { AdminPageShell } from "@/components/admin/admin-page-shell";
|
import { AdminPageShell } from "@/components/admin/admin-page-shell";
|
||||||
import { StatusCard } from "@/components/admin/dashboard";
|
import { StatusCard } from "@/components/admin/dashboard";
|
||||||
import { Button } from "@/components/ui/button";
|
import { Button } from "@/components/ui/button";
|
||||||
import { activeBanWhere, unixNow } from "@/lib/bans";
|
import { unixNow } from "@/lib/bans";
|
||||||
|
import { Ban as BanTable, db } from "@/lib/db";
|
||||||
import { formatDate } from "@/lib/format-date";
|
import { formatDate } from "@/lib/format-date";
|
||||||
import { canAccess, getAdminContext, PERMS } from "@/lib/permissions";
|
import { canAccess, getAdminContext, PERMS } from "@/lib/permissions";
|
||||||
import { prisma } from "@/lib/prisma";
|
|
||||||
|
|
||||||
export default async function AdminBans() {
|
export default async function AdminBans() {
|
||||||
const { session, permissions } = await getAdminContext();
|
const { session, permissions } = await getAdminContext();
|
||||||
@@ -18,13 +19,14 @@ export default async function AdminBans() {
|
|||||||
|
|
||||||
const t = await getTranslations("pages.admin.bans");
|
const t = await getTranslations("pages.admin.bans");
|
||||||
const now = unixNow();
|
const now = unixNow();
|
||||||
let bans: Awaited<ReturnType<typeof prisma.ban.findMany>> = [];
|
let bans: (typeof BanTable.$inferSelect)[] = [];
|
||||||
try {
|
try {
|
||||||
bans = await prisma.ban.findMany({
|
bans = await db
|
||||||
where: activeBanWhere(now),
|
.select()
|
||||||
orderBy: { timestamp: "desc" },
|
.from(BanTable)
|
||||||
take: 100,
|
.where(or(eq(BanTable.banExpire, 0), gt(BanTable.banExpire, now)))
|
||||||
});
|
.orderBy(desc(BanTable.timestamp))
|
||||||
|
.limit(100);
|
||||||
} catch {
|
} catch {
|
||||||
bans = [];
|
bans = [];
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,9 +1,10 @@
|
|||||||
|
import { asc, eq } from "drizzle-orm";
|
||||||
import Link from "next/link";
|
import Link from "next/link";
|
||||||
import { notFound, redirect } from "next/navigation";
|
import { notFound, redirect } from "next/navigation";
|
||||||
import { getTranslations } from "next-intl/server";
|
import { getTranslations } from "next-intl/server";
|
||||||
|
import { CalendarCampaigns, CalendarRewards, db } from "@/lib/db";
|
||||||
import { formatDate } from "@/lib/format-date";
|
import { formatDate } from "@/lib/format-date";
|
||||||
import { canAccess, getAdminContext, PERMS } from "@/lib/permissions";
|
import { canAccess, getAdminContext, PERMS } from "@/lib/permissions";
|
||||||
import { prisma } from "@/lib/prisma";
|
|
||||||
|
|
||||||
type Campaign = {
|
type Campaign = {
|
||||||
id: number;
|
id: number;
|
||||||
@@ -48,18 +49,20 @@ export default async function AdminCalendarCampaign({
|
|||||||
|
|
||||||
let campaign: Campaign | null = null;
|
let campaign: Campaign | null = null;
|
||||||
try {
|
try {
|
||||||
campaign = await prisma.calendarCampaigns.findUnique({
|
const [row] = await db
|
||||||
where: { id: campaignId },
|
.select({
|
||||||
select: {
|
id: CalendarCampaigns.id,
|
||||||
id: true,
|
name: CalendarCampaigns.name,
|
||||||
name: true,
|
image: CalendarCampaigns.image,
|
||||||
image: true,
|
startTimestamp: CalendarCampaigns.startTimestamp,
|
||||||
startTimestamp: true,
|
totalDays: CalendarCampaigns.totalDays,
|
||||||
totalDays: true,
|
lockExpired: CalendarCampaigns.lockExpired,
|
||||||
lockExpired: true,
|
enabled: CalendarCampaigns.enabled,
|
||||||
enabled: true,
|
})
|
||||||
},
|
.from(CalendarCampaigns)
|
||||||
});
|
.where(eq(CalendarCampaigns.id, campaignId))
|
||||||
|
.limit(1);
|
||||||
|
campaign = row ?? null;
|
||||||
} catch {
|
} catch {
|
||||||
campaign = null;
|
campaign = null;
|
||||||
}
|
}
|
||||||
@@ -67,25 +70,25 @@ export default async function AdminCalendarCampaign({
|
|||||||
|
|
||||||
let rewards: Reward[] = [];
|
let rewards: Reward[] = [];
|
||||||
try {
|
try {
|
||||||
rewards = await prisma.calendarRewards.findMany({
|
rewards = await db
|
||||||
where: { campaignId },
|
.select({
|
||||||
select: {
|
id: CalendarRewards.id,
|
||||||
id: true,
|
campaignId: CalendarRewards.campaignId,
|
||||||
campaignId: true,
|
productName: CalendarRewards.productName,
|
||||||
productName: true,
|
customImage: CalendarRewards.customImage,
|
||||||
customImage: true,
|
credits: CalendarRewards.credits,
|
||||||
credits: true,
|
pixels: CalendarRewards.pixels,
|
||||||
pixels: true,
|
points: CalendarRewards.points,
|
||||||
points: true,
|
pointsType: CalendarRewards.pointsType,
|
||||||
pointsType: true,
|
badge: CalendarRewards.badge,
|
||||||
badge: true,
|
itemId: CalendarRewards.itemId,
|
||||||
itemId: true,
|
subscriptionType: CalendarRewards.subscriptionType,
|
||||||
subscriptionType: true,
|
subscriptionDays: CalendarRewards.subscriptionDays,
|
||||||
subscriptionDays: true,
|
})
|
||||||
},
|
.from(CalendarRewards)
|
||||||
orderBy: { id: "asc" },
|
.where(eq(CalendarRewards.campaignId, campaignId))
|
||||||
take: 500,
|
.orderBy(asc(CalendarRewards.id))
|
||||||
});
|
.limit(500);
|
||||||
} catch {
|
} catch {
|
||||||
rewards = [];
|
rewards = [];
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,10 +1,11 @@
|
|||||||
|
import { count, desc } from "drizzle-orm";
|
||||||
import Link from "next/link";
|
import Link from "next/link";
|
||||||
import { redirect } from "next/navigation";
|
import { redirect } from "next/navigation";
|
||||||
import { getTranslations } from "next-intl/server";
|
import { getTranslations } from "next-intl/server";
|
||||||
import { StatusCard } from "@/components/admin/dashboard";
|
import { StatusCard } from "@/components/admin/dashboard";
|
||||||
|
import { CalendarCampaigns, CalendarRewards, db } from "@/lib/db";
|
||||||
import { formatDate } from "@/lib/format-date";
|
import { formatDate } from "@/lib/format-date";
|
||||||
import { canAccess, getAdminContext, PERMS } from "@/lib/permissions";
|
import { canAccess, getAdminContext, PERMS } from "@/lib/permissions";
|
||||||
import { prisma } from "@/lib/prisma";
|
|
||||||
|
|
||||||
type Campaign = {
|
type Campaign = {
|
||||||
id: number;
|
id: number;
|
||||||
@@ -27,19 +28,19 @@ export default async function AdminCalendar() {
|
|||||||
let campaigns: Campaign[] = [];
|
let campaigns: Campaign[] = [];
|
||||||
let loadError = false;
|
let loadError = false;
|
||||||
try {
|
try {
|
||||||
campaigns = await prisma.calendarCampaigns.findMany({
|
campaigns = await db
|
||||||
select: {
|
.select({
|
||||||
id: true,
|
id: CalendarCampaigns.id,
|
||||||
name: true,
|
name: CalendarCampaigns.name,
|
||||||
image: true,
|
image: CalendarCampaigns.image,
|
||||||
startTimestamp: true,
|
startTimestamp: CalendarCampaigns.startTimestamp,
|
||||||
totalDays: true,
|
totalDays: CalendarCampaigns.totalDays,
|
||||||
lockExpired: true,
|
lockExpired: CalendarCampaigns.lockExpired,
|
||||||
enabled: true,
|
enabled: CalendarCampaigns.enabled,
|
||||||
},
|
})
|
||||||
orderBy: { id: "desc" },
|
.from(CalendarCampaigns)
|
||||||
take: 200,
|
.orderBy(desc(CalendarCampaigns.id))
|
||||||
});
|
.limit(200);
|
||||||
} catch {
|
} catch {
|
||||||
campaigns = [];
|
campaigns = [];
|
||||||
loadError = true;
|
loadError = true;
|
||||||
@@ -48,13 +49,16 @@ export default async function AdminCalendar() {
|
|||||||
const rewardCounts = new Map<number, number>();
|
const rewardCounts = new Map<number, number>();
|
||||||
let totalRewards = 0;
|
let totalRewards = 0;
|
||||||
try {
|
try {
|
||||||
const grouped = await prisma.calendarRewards.groupBy({
|
const grouped = await db
|
||||||
by: ["campaignId"],
|
.select({
|
||||||
_count: { _all: true },
|
campaignId: CalendarRewards.campaignId,
|
||||||
});
|
total: count(),
|
||||||
|
})
|
||||||
|
.from(CalendarRewards)
|
||||||
|
.groupBy(CalendarRewards.campaignId);
|
||||||
for (const g of grouped) {
|
for (const g of grouped) {
|
||||||
rewardCounts.set(g.campaignId, g._count._all);
|
rewardCounts.set(g.campaignId, Number(g.total));
|
||||||
totalRewards += g._count._all;
|
totalRewards += Number(g.total);
|
||||||
}
|
}
|
||||||
} catch {
|
} catch {
|
||||||
loadError = true;
|
loadError = true;
|
||||||
|
|||||||
@@ -1,9 +1,10 @@
|
|||||||
|
import { asc, eq } from "drizzle-orm";
|
||||||
import { ChevronRight } from "lucide-react";
|
import { ChevronRight } from "lucide-react";
|
||||||
import Link from "next/link";
|
import Link from "next/link";
|
||||||
import { notFound, redirect } from "next/navigation";
|
import { notFound, redirect } from "next/navigation";
|
||||||
import { Fragment } from "react";
|
import { Fragment } from "react";
|
||||||
|
import { CatalogPages, db } from "@/lib/db";
|
||||||
import { canAccess, getAdminContext, PERMS } from "@/lib/permissions";
|
import { canAccess, getAdminContext, PERMS } from "@/lib/permissions";
|
||||||
import { prisma } from "@/lib/prisma";
|
|
||||||
import { loadCatalogItemsData } from "@/lib/services/catalog-items-loader";
|
import { loadCatalogItemsData } from "@/lib/services/catalog-items-loader";
|
||||||
import { getAncestors } from "@/lib/services/catalog-tree";
|
import { getAncestors } from "@/lib/services/catalog-tree";
|
||||||
import { CatalogDetailTabs } from "./catalog-detail-tabs";
|
import { CatalogDetailTabs } from "./catalog-detail-tabs";
|
||||||
@@ -22,18 +23,24 @@ export default async function CatalogEditPage({
|
|||||||
const pageId = parseInt(id, 10);
|
const pageId = parseInt(id, 10);
|
||||||
if (Number.isNaN(pageId)) notFound();
|
if (Number.isNaN(pageId)) notFound();
|
||||||
|
|
||||||
const catalogPage = await prisma.catalogPages.findUnique({
|
const [catalogPage] = await db
|
||||||
where: { id: pageId },
|
.select()
|
||||||
});
|
.from(CatalogPages)
|
||||||
|
.where(eq(CatalogPages.id, pageId))
|
||||||
|
.limit(1);
|
||||||
|
|
||||||
if (!catalogPage) notFound();
|
if (!catalogPage) notFound();
|
||||||
|
|
||||||
const [children, itemsData, ancestors] = await Promise.all([
|
const [children, itemsData, ancestors] = await Promise.all([
|
||||||
prisma.catalogPages.findMany({
|
db
|
||||||
where: { parentId: pageId },
|
.select({
|
||||||
orderBy: { orderNum: "asc" },
|
id: CatalogPages.id,
|
||||||
select: { id: true, caption: true, enabled: true },
|
caption: CatalogPages.caption,
|
||||||
}),
|
enabled: CatalogPages.enabled,
|
||||||
|
})
|
||||||
|
.from(CatalogPages)
|
||||||
|
.where(eq(CatalogPages.parentId, pageId))
|
||||||
|
.orderBy(asc(CatalogPages.orderNum)),
|
||||||
loadCatalogItemsData(pageId),
|
loadCatalogItemsData(pageId),
|
||||||
getAncestors(catalogPage.parentId),
|
getAncestors(catalogPage.parentId),
|
||||||
]);
|
]);
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
|
import { asc, eq } from "drizzle-orm";
|
||||||
import { notFound, redirect } from "next/navigation";
|
import { notFound, redirect } from "next/navigation";
|
||||||
|
import { CatalogItemsBc, CatalogPagesBc, db } from "@/lib/db";
|
||||||
import { canAccess, getAdminContext, PERMS } from "@/lib/permissions";
|
import { canAccess, getAdminContext, PERMS } from "@/lib/permissions";
|
||||||
import { prisma } from "@/lib/prisma";
|
|
||||||
import { BcPageDetail } from "../bc-manager";
|
import { BcPageDetail } from "../bc-manager";
|
||||||
|
|
||||||
export default async function BcPageDetailPage({
|
export default async function BcPageDetailPage({
|
||||||
@@ -19,13 +20,18 @@ export default async function BcPageDetailPage({
|
|||||||
|
|
||||||
const canEdit = canAccess(permissions, PERMS.CATALOG_EDIT, session.user.rank);
|
const canEdit = canAccess(permissions, PERMS.CATALOG_EDIT, session.user.rank);
|
||||||
|
|
||||||
const bcPage = await prisma.catalogPagesBc.findUnique({ where: { id } });
|
const [bcPage] = await db
|
||||||
|
.select()
|
||||||
|
.from(CatalogPagesBc)
|
||||||
|
.where(eq(CatalogPagesBc.id, id))
|
||||||
|
.limit(1);
|
||||||
if (!bcPage) notFound();
|
if (!bcPage) notFound();
|
||||||
|
|
||||||
const bcItems = await prisma.catalogItemsBc.findMany({
|
const bcItems = await db
|
||||||
where: { pageId: id },
|
.select()
|
||||||
orderBy: { orderNumber: "asc" },
|
.from(CatalogItemsBc)
|
||||||
});
|
.where(eq(CatalogItemsBc.pageId, id))
|
||||||
|
.orderBy(asc(CatalogItemsBc.orderNumber));
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<BcPageDetail
|
<BcPageDetail
|
||||||
|
|||||||
+176
-98
File diff suppressed because it is too large.
Load diff
@@ -1,4 +1,5 @@
|
|||||||
import os from "node:os";
|
import os from "node:os";
|
||||||
|
import { count, desc, inArray } from "drizzle-orm";
|
||||||
import { Terminal } from "lucide-react";
|
import { Terminal } from "lucide-react";
|
||||||
import { redirect } from "next/navigation";
|
import { redirect } from "next/navigation";
|
||||||
import { getTranslations } from "next-intl/server";
|
import { getTranslations } from "next-intl/server";
|
||||||
@@ -11,9 +12,9 @@ import {
|
|||||||
} from "@/components/admin/dashboard";
|
} from "@/components/admin/dashboard";
|
||||||
import { fetchOpsHealth } from "@/lib/admin/ops-health";
|
import { fetchOpsHealth } from "@/lib/admin/ops-health";
|
||||||
import { fetchOpsOnlineUsers } from "@/lib/admin/ops-online-users";
|
import { fetchOpsOnlineUsers } from "@/lib/admin/ops-online-users";
|
||||||
|
import { db, EmulatorErrors, StaffActivities, User } from "@/lib/db";
|
||||||
import { formatDate } from "@/lib/format-date";
|
import { formatDate } from "@/lib/format-date";
|
||||||
import { canAccess, getAdminContext, PERMS } from "@/lib/permissions";
|
import { canAccess, getAdminContext, PERMS } from "@/lib/permissions";
|
||||||
import { prisma } from "@/lib/prisma";
|
|
||||||
import { siteSettings } from "@/lib/services/site-settings";
|
import { siteSettings } from "@/lib/services/site-settings";
|
||||||
import { CommandocentrumControls } from "./commandocentrum-controls";
|
import { CommandocentrumControls } from "./commandocentrum-controls";
|
||||||
|
|
||||||
@@ -46,22 +47,29 @@ export default async function CommandoCentrum() {
|
|||||||
|
|
||||||
const t = await getTranslations("pages.admin.commandocentrum");
|
const t = await getTranslations("pages.admin.commandocentrum");
|
||||||
|
|
||||||
const [totalUsers, errors, health, maintenance, activity, onlineRoster] =
|
const [totalUsersRows, errors, health, maintenance, activity, onlineRoster] =
|
||||||
await Promise.all([
|
await Promise.all([
|
||||||
prisma.user.count().catch(() => -1),
|
db
|
||||||
prisma.emulatorErrors
|
.select({ total: count() })
|
||||||
.findMany({ orderBy: { timestamp: "desc" }, take: 50 })
|
.from(User)
|
||||||
|
.catch(() => [{ total: -1 }]),
|
||||||
|
db
|
||||||
|
.select()
|
||||||
|
.from(EmulatorErrors)
|
||||||
|
.orderBy(desc(EmulatorErrors.timestamp))
|
||||||
|
.limit(50)
|
||||||
.catch(() => []),
|
.catch(() => []),
|
||||||
fetchOpsHealth(),
|
fetchOpsHealth(),
|
||||||
siteSettings.getBool("maintenance_enabled", false),
|
siteSettings.getBool("maintenance_enabled", false),
|
||||||
prisma.staffActivities
|
db
|
||||||
.findMany({ orderBy: { createdAt: "desc" }, take: 12 })
|
.select()
|
||||||
.catch(
|
.from(StaffActivities)
|
||||||
() =>
|
.orderBy(desc(StaffActivities.createdAt))
|
||||||
[] as Awaited<ReturnType<typeof prisma.staffActivities.findMany>>,
|
.limit(12)
|
||||||
),
|
.catch(() => [] as (typeof StaffActivities.$inferSelect)[]),
|
||||||
fetchOpsOnlineUsers(40),
|
fetchOpsOnlineUsers(40),
|
||||||
]);
|
]);
|
||||||
|
const totalUsers = Number(totalUsersRows[0]?.total ?? -1);
|
||||||
|
|
||||||
const dbOk = health.dbOk;
|
const dbOk = health.dbOk;
|
||||||
const redisOk = health.redisOk;
|
const redisOk = health.redisOk;
|
||||||
@@ -74,11 +82,10 @@ export default async function CommandoCentrum() {
|
|||||||
).filter((n) => n > 0);
|
).filter((n) => n > 0);
|
||||||
let nameById = new Map<number, string>();
|
let nameById = new Map<number, string>();
|
||||||
if (staffIds.length) {
|
if (staffIds.length) {
|
||||||
const users = await prisma.user
|
const users = await db
|
||||||
.findMany({
|
.select({ id: User.id, username: User.username })
|
||||||
where: { id: { in: staffIds } },
|
.from(User)
|
||||||
select: { id: true, username: true },
|
.where(inArray(User.id, staffIds))
|
||||||
})
|
|
||||||
.catch(() => []);
|
.catch(() => []);
|
||||||
nameById = new Map(users.map((u) => [u.id, u.username]));
|
nameById = new Map(users.map((u) => [u.id, u.username]));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,8 +1,9 @@
|
|||||||
|
import { count, desc } from "drizzle-orm";
|
||||||
import { redirect } from "next/navigation";
|
import { redirect } from "next/navigation";
|
||||||
import { getTranslations } from "next-intl/server";
|
import { getTranslations } from "next-intl/server";
|
||||||
import { Card, CardContent } from "@/components/ui/card";
|
import { Card, CardContent } from "@/components/ui/card";
|
||||||
|
import { db, EmulatorErrors } from "@/lib/db";
|
||||||
import { canAccess, getAdminContext, PERMS } from "@/lib/permissions";
|
import { canAccess, getAdminContext, PERMS } from "@/lib/permissions";
|
||||||
import { prisma } from "@/lib/prisma";
|
|
||||||
|
|
||||||
export default async function EmulatorErrorsPage({
|
export default async function EmulatorErrorsPage({
|
||||||
searchParams,
|
searchParams,
|
||||||
@@ -19,15 +20,17 @@ export default async function EmulatorErrorsPage({
|
|||||||
const page = Math.max(1, Number(params.page) || 1);
|
const page = Math.max(1, Number(params.page) || 1);
|
||||||
const perPage = 50;
|
const perPage = 50;
|
||||||
|
|
||||||
const [errors, total] = await Promise.all([
|
const [errors, totalRows] = await Promise.all([
|
||||||
prisma.emulatorErrors.findMany({
|
db
|
||||||
orderBy: { id: "desc" },
|
.select()
|
||||||
skip: (page - 1) * perPage,
|
.from(EmulatorErrors)
|
||||||
take: perPage,
|
.orderBy(desc(EmulatorErrors.id))
|
||||||
}),
|
.limit(perPage)
|
||||||
prisma.emulatorErrors.count(),
|
.offset((page - 1) * perPage),
|
||||||
|
db.select({ total: count() }).from(EmulatorErrors),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
const total = Number(totalRows[0]?.total ?? 0);
|
||||||
const lastPage = Math.ceil(total / perPage);
|
const lastPage = Math.ceil(total / perPage);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
import { count, desc, eq, gte } from "drizzle-orm";
|
||||||
import { AlertTriangle, Database, HeartPulse, Server } from "lucide-react";
|
import { AlertTriangle, Database, HeartPulse, Server } from "lucide-react";
|
||||||
import Link from "next/link";
|
import Link from "next/link";
|
||||||
import { redirect } from "next/navigation";
|
import { redirect } from "next/navigation";
|
||||||
@@ -5,26 +6,31 @@ import { getTranslations } from "next-intl/server";
|
|||||||
import { Badge } from "@/components/ui/badge";
|
import { Badge } from "@/components/ui/badge";
|
||||||
import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card";
|
import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card";
|
||||||
import { fetchOpsHealth } from "@/lib/admin/ops-health";
|
import { fetchOpsHealth } from "@/lib/admin/ops-health";
|
||||||
|
import { db, EmulatorErrors, EmulatorSettings } from "@/lib/db";
|
||||||
import { canAccess, getAdminContext, PERMS } from "@/lib/permissions";
|
import { canAccess, getAdminContext, PERMS } from "@/lib/permissions";
|
||||||
import { prisma } from "@/lib/prisma";
|
|
||||||
import { HealthCheckClient } from "./health-check-client";
|
import { HealthCheckClient } from "./health-check-client";
|
||||||
|
|
||||||
async function getDevOpsData() {
|
async function getDevOpsData() {
|
||||||
const now = Math.floor(Date.now() / 1000);
|
const now = Math.floor(Date.now() / 1000);
|
||||||
const dayAgo = now - 86400;
|
const dayAgo = now - 86400;
|
||||||
|
|
||||||
const [health, recentErrors, errorsToday, emuVersion] = await Promise.all([
|
const [health, recentErrors, errorsTodayRows, emuVersionRows] =
|
||||||
|
await Promise.all([
|
||||||
fetchOpsHealth(),
|
fetchOpsHealth(),
|
||||||
prisma.emulatorErrors.findMany({
|
db
|
||||||
orderBy: { id: "desc" },
|
.select()
|
||||||
take: 20,
|
.from(EmulatorErrors)
|
||||||
}),
|
.orderBy(desc(EmulatorErrors.id))
|
||||||
prisma.emulatorErrors.count({
|
.limit(20),
|
||||||
where: { timestamp: { gte: dayAgo } },
|
db
|
||||||
}),
|
.select({ total: count() })
|
||||||
prisma.emulatorSettings.findFirst({
|
.from(EmulatorErrors)
|
||||||
where: { key: "version" },
|
.where(gte(EmulatorErrors.timestamp, dayAgo)),
|
||||||
}),
|
db
|
||||||
|
.select({ value: EmulatorSettings.value })
|
||||||
|
.from(EmulatorSettings)
|
||||||
|
.where(eq(EmulatorSettings.key, "version"))
|
||||||
|
.limit(1),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
@@ -32,8 +38,8 @@ async function getDevOpsData() {
|
|||||||
dbLatency: health.dbLatencyMs,
|
dbLatency: health.dbLatencyMs,
|
||||||
redisOk: health.redisOk,
|
redisOk: health.redisOk,
|
||||||
recentErrors,
|
recentErrors,
|
||||||
errorsToday,
|
errorsToday: Number(errorsTodayRows[0]?.total ?? 0),
|
||||||
emuVersion: emuVersion?.value ?? "Unknown",
|
emuVersion: emuVersionRows[0]?.value ?? "Unknown",
|
||||||
onlineUsers: health.onlineUsers,
|
onlineUsers: health.onlineUsers,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
import { asc } from "drizzle-orm";
|
||||||
import { redirect } from "next/navigation";
|
import { redirect } from "next/navigation";
|
||||||
import { getTranslations } from "next-intl/server";
|
import { getTranslations } from "next-intl/server";
|
||||||
import {
|
import {
|
||||||
@@ -6,8 +7,8 @@ import {
|
|||||||
updateEmailTemplate,
|
updateEmailTemplate,
|
||||||
} from "@/actions/admin-email-templates";
|
} from "@/actions/admin-email-templates";
|
||||||
import { Button } from "@/components/ui/button";
|
import { Button } from "@/components/ui/button";
|
||||||
|
import { db, EmailTemplates } from "@/lib/db";
|
||||||
import { canAccess, getAdminContext, PERMS } from "@/lib/permissions";
|
import { canAccess, getAdminContext, PERMS } from "@/lib/permissions";
|
||||||
import { prisma } from "@/lib/prisma";
|
|
||||||
|
|
||||||
export default async function AdminEmailTemplates() {
|
export default async function AdminEmailTemplates() {
|
||||||
const { session, permissions } = await getAdminContext();
|
const { session, permissions } = await getAdminContext();
|
||||||
@@ -17,12 +18,12 @@ export default async function AdminEmailTemplates() {
|
|||||||
|
|
||||||
const t = await getTranslations("pages.admin.emailTemplates");
|
const t = await getTranslations("pages.admin.emailTemplates");
|
||||||
|
|
||||||
let templates: Awaited<ReturnType<typeof prisma.emailTemplates.findMany>> =
|
let templates: (typeof EmailTemplates.$inferSelect)[] = [];
|
||||||
[];
|
|
||||||
try {
|
try {
|
||||||
templates = await prisma.emailTemplates.findMany({
|
templates = await db
|
||||||
orderBy: { name: "asc" },
|
.select()
|
||||||
});
|
.from(EmailTemplates)
|
||||||
|
.orderBy(asc(EmailTemplates.name));
|
||||||
} catch {
|
} catch {
|
||||||
templates = [];
|
templates = [];
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
import { asc, count } from "drizzle-orm";
|
||||||
import { redirect } from "next/navigation";
|
import { redirect } from "next/navigation";
|
||||||
import { getTranslations } from "next-intl/server";
|
import { getTranslations } from "next-intl/server";
|
||||||
import {
|
import {
|
||||||
@@ -6,8 +7,8 @@ import {
|
|||||||
} from "@/actions/admin-emulator";
|
} from "@/actions/admin-emulator";
|
||||||
import { StatusCard } from "@/components/admin/dashboard";
|
import { StatusCard } from "@/components/admin/dashboard";
|
||||||
import { Button } from "@/components/ui/button";
|
import { Button } from "@/components/ui/button";
|
||||||
|
import { db, EmulatorSettings, EmulatorTexts } from "@/lib/db";
|
||||||
import { canAccess, getAdminContext, PERMS } from "@/lib/permissions";
|
import { canAccess, getAdminContext, PERMS } from "@/lib/permissions";
|
||||||
import { prisma } from "@/lib/prisma";
|
|
||||||
|
|
||||||
const TEXTS_LIMIT = 300;
|
const TEXTS_LIMIT = 300;
|
||||||
|
|
||||||
@@ -21,9 +22,10 @@ export default async function AdminEmulator() {
|
|||||||
|
|
||||||
let settings: { key: string; value: string }[] = [];
|
let settings: { key: string; value: string }[] = [];
|
||||||
try {
|
try {
|
||||||
settings = await prisma.emulatorSettings.findMany({
|
settings = await db
|
||||||
orderBy: { key: "asc" },
|
.select({ key: EmulatorSettings.key, value: EmulatorSettings.value })
|
||||||
});
|
.from(EmulatorSettings)
|
||||||
|
.orderBy(asc(EmulatorSettings.key));
|
||||||
} catch {
|
} catch {
|
||||||
settings = [];
|
settings = [];
|
||||||
}
|
}
|
||||||
@@ -31,15 +33,17 @@ export default async function AdminEmulator() {
|
|||||||
let texts: { key: string; value: string }[] = [];
|
let texts: { key: string; value: string }[] = [];
|
||||||
let textsCount = 0;
|
let textsCount = 0;
|
||||||
try {
|
try {
|
||||||
textsCount = await prisma.emulatorTexts.count();
|
const [row] = await db.select({ total: count() }).from(EmulatorTexts);
|
||||||
|
textsCount = Number(row?.total ?? 0);
|
||||||
} catch {
|
} catch {
|
||||||
textsCount = 0;
|
textsCount = 0;
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
texts = await prisma.emulatorTexts.findMany({
|
texts = await db
|
||||||
orderBy: { key: "asc" },
|
.select({ key: EmulatorTexts.key, value: EmulatorTexts.value })
|
||||||
take: TEXTS_LIMIT,
|
.from(EmulatorTexts)
|
||||||
});
|
.orderBy(asc(EmulatorTexts.key))
|
||||||
|
.limit(TEXTS_LIMIT);
|
||||||
} catch {
|
} catch {
|
||||||
texts = [];
|
texts = [];
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,11 +1,12 @@
|
|||||||
|
import { asc, eq, inArray } from "drizzle-orm";
|
||||||
import { CalendarDays, Gift, Trophy, Users } from "lucide-react";
|
import { CalendarDays, Gift, Trophy, Users } from "lucide-react";
|
||||||
import { notFound, redirect } from "next/navigation";
|
import { notFound, redirect } from "next/navigation";
|
||||||
import { getTranslations } from "next-intl/server";
|
import { getTranslations } from "next-intl/server";
|
||||||
import { AdminBreadcrumb } from "@/components/admin/admin-breadcrumb";
|
import { AdminBreadcrumb } from "@/components/admin/admin-breadcrumb";
|
||||||
import { Badge } from "@/components/ui/badge";
|
import { Badge } from "@/components/ui/badge";
|
||||||
import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card";
|
import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card";
|
||||||
|
import { db, User, WebsiteEvent, WebsiteEventType } from "@/lib/db";
|
||||||
import { canAccess, getAdminContext, PERMS } from "@/lib/permissions";
|
import { canAccess, getAdminContext, PERMS } from "@/lib/permissions";
|
||||||
import { prisma } from "@/lib/prisma";
|
|
||||||
import { EventForm } from "../event-form";
|
import { EventForm } from "../event-form";
|
||||||
import { EventPrizesManager } from "./event-prizes";
|
import { EventPrizesManager } from "./event-prizes";
|
||||||
import { EventRegistrations } from "./event-registrations";
|
import { EventRegistrations } from "./event-registrations";
|
||||||
@@ -28,22 +29,23 @@ export default async function EventDetailPage({
|
|||||||
const t = await getTranslations("pages.admin.events");
|
const t = await getTranslations("pages.admin.events");
|
||||||
const tHubs = await getTranslations("pages.admin.hubs");
|
const tHubs = await getTranslations("pages.admin.hubs");
|
||||||
|
|
||||||
const event = await prisma.websiteEvent.findUnique({
|
const event = await db.query.WebsiteEvent.findFirst({
|
||||||
where: { id: eventId },
|
where: eq(WebsiteEvent.id, eventId),
|
||||||
include: {
|
with: {
|
||||||
type: true,
|
type: true,
|
||||||
prizes: { orderBy: { position: "asc" } },
|
prizes: { orderBy: (p, { asc: a }) => [a(p.position)] },
|
||||||
winners: { orderBy: { position: "asc" } },
|
winners: { orderBy: (w, { asc: a }) => [a(w.position)] },
|
||||||
registrations: { orderBy: { createdAt: "desc" } },
|
registrations: { orderBy: (r, { desc: d }) => [d(r.createdAt)] },
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!event) notFound();
|
if (!event) notFound();
|
||||||
|
|
||||||
const eventTypes = await prisma.websiteEventType.findMany({
|
const eventTypes = await db
|
||||||
where: { isActive: 1 },
|
.select()
|
||||||
orderBy: { name: "asc" },
|
.from(WebsiteEventType)
|
||||||
});
|
.where(eq(WebsiteEventType.isActive, 1))
|
||||||
|
.orderBy(asc(WebsiteEventType.name));
|
||||||
|
|
||||||
// Fetch usernames for registrations and winners
|
// Fetch usernames for registrations and winners
|
||||||
const userIds = [
|
const userIds = [
|
||||||
@@ -52,10 +54,10 @@ export default async function EventDetailPage({
|
|||||||
];
|
];
|
||||||
const users =
|
const users =
|
||||||
userIds.length > 0
|
userIds.length > 0
|
||||||
? await prisma.user.findMany({
|
? await db
|
||||||
where: { id: { in: [...new Set(userIds)] } },
|
.select({ id: User.id, username: User.username })
|
||||||
select: { id: true, username: true },
|
.from(User)
|
||||||
})
|
.where(inArray(User.id, [...new Set(userIds)]))
|
||||||
: [];
|
: [];
|
||||||
const userMap = new Map(users.map((u) => [u.id, u.username]));
|
const userMap = new Map(users.map((u) => [u.id, u.username]));
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,8 @@
|
|||||||
|
import { asc, eq } from "drizzle-orm";
|
||||||
import { redirect } from "next/navigation";
|
import { redirect } from "next/navigation";
|
||||||
import { getTranslations } from "next-intl/server";
|
import { getTranslations } from "next-intl/server";
|
||||||
|
import { db, WebsiteEventType } from "@/lib/db";
|
||||||
import { canAccess, getAdminContext, PERMS } from "@/lib/permissions";
|
import { canAccess, getAdminContext, PERMS } from "@/lib/permissions";
|
||||||
import { prisma } from "@/lib/prisma";
|
|
||||||
import { EventForm } from "../event-form";
|
import { EventForm } from "../event-form";
|
||||||
|
|
||||||
export default async function CreateEventPage() {
|
export default async function CreateEventPage() {
|
||||||
@@ -11,10 +12,11 @@ export default async function CreateEventPage() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const t = await getTranslations("pages.admin.events");
|
const t = await getTranslations("pages.admin.events");
|
||||||
const eventTypes = await prisma.websiteEventType.findMany({
|
const eventTypes = await db
|
||||||
where: { isActive: 1 },
|
.select()
|
||||||
orderBy: { name: "asc" },
|
.from(WebsiteEventType)
|
||||||
});
|
.where(eq(WebsiteEventType.isActive, 1))
|
||||||
|
.orderBy(asc(WebsiteEventType.name));
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="space-y-6">
|
<div className="space-y-6">
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
|
import { asc } from "drizzle-orm";
|
||||||
import { redirect } from "next/navigation";
|
import { redirect } from "next/navigation";
|
||||||
|
import { db, WebsiteEventType } from "@/lib/db";
|
||||||
import { canAccess, getAdminContext, PERMS } from "@/lib/permissions";
|
import { canAccess, getAdminContext, PERMS } from "@/lib/permissions";
|
||||||
import { prisma } from "@/lib/prisma";
|
|
||||||
import { EventTypesManager } from "./event-types-manager";
|
import { EventTypesManager } from "./event-types-manager";
|
||||||
|
|
||||||
export default async function EventTypesPage() {
|
export default async function EventTypesPage() {
|
||||||
@@ -9,9 +10,10 @@ export default async function EventTypesPage() {
|
|||||||
redirect("/admin/events");
|
redirect("/admin/events");
|
||||||
}
|
}
|
||||||
|
|
||||||
const eventTypes = await prisma.websiteEventType.findMany({
|
const eventTypes = await db
|
||||||
orderBy: { name: "asc" },
|
.select()
|
||||||
});
|
.from(WebsiteEventType)
|
||||||
|
.orderBy(asc(WebsiteEventType.name));
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="space-y-6">
|
<div className="space-y-6">
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
|
import { eq } from "drizzle-orm";
|
||||||
import { redirect } from "next/navigation";
|
import { redirect } from "next/navigation";
|
||||||
|
import { db, WebsiteSetting } from "@/lib/db";
|
||||||
import { canAccess, getAdminContext, PERMS } from "@/lib/permissions";
|
import { canAccess, getAdminContext, PERMS } from "@/lib/permissions";
|
||||||
import { prisma } from "@/lib/prisma";
|
|
||||||
import { FaviconForm } from "./favicon-form";
|
import { FaviconForm } from "./favicon-form";
|
||||||
|
|
||||||
export default async function AdminFaviconPage() {
|
export default async function AdminFaviconPage() {
|
||||||
@@ -11,9 +12,11 @@ export default async function AdminFaviconPage() {
|
|||||||
|
|
||||||
let faviconUrl: string | null = null;
|
let faviconUrl: string | null = null;
|
||||||
try {
|
try {
|
||||||
const setting = await prisma.websiteSetting.findUnique({
|
const [setting] = await db
|
||||||
where: { key: "cms_favicon" },
|
.select({ value: WebsiteSetting.value })
|
||||||
});
|
.from(WebsiteSetting)
|
||||||
|
.where(eq(WebsiteSetting.key, "cms_favicon"))
|
||||||
|
.limit(1);
|
||||||
faviconUrl = setting?.value ?? null;
|
faviconUrl = setting?.value ?? null;
|
||||||
} catch {
|
} catch {
|
||||||
faviconUrl = null;
|
faviconUrl = null;
|
||||||
|
|||||||
Reference in new issue
Block a user