Added Account Dublicate fucntion, improved default sorts
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
import { prisma, Prisma } from "@repo/db";
|
||||
import bcrypt from "bcryptjs";
|
||||
import { sendMailByTemplate } from "../../../../helper/mail";
|
||||
import { getServerSession } from "api/auth/[...nextauth]/auth";
|
||||
|
||||
export const getUser = async (where: Prisma.UserWhereInput) => {
|
||||
return await prisma.user.findMany({
|
||||
@@ -82,3 +83,52 @@ export const sendVerificationLink = async (userId: string) => {
|
||||
code,
|
||||
});
|
||||
};
|
||||
|
||||
export const markDuplicate = async (params: {
|
||||
duplicateUserId: string;
|
||||
canonicalPublicId: string;
|
||||
reason?: string;
|
||||
}) => {
|
||||
// Then in your function:
|
||||
const session = await getServerSession();
|
||||
if (!session?.user) throw new Error("Nicht authentifiziert");
|
||||
const canonical = await prisma.user.findUnique({
|
||||
where: { publicId: params.canonicalPublicId },
|
||||
select: { id: true },
|
||||
});
|
||||
if (!canonical) throw new Error("Original-Account (canonical) nicht gefunden");
|
||||
if (canonical.id === params.duplicateUserId)
|
||||
throw new Error("Duplikat und Original dürfen nicht identisch sein");
|
||||
|
||||
const updated = await prisma.user.update({
|
||||
where: { id: params.duplicateUserId },
|
||||
data: {
|
||||
canonicalUserId: canonical.id,
|
||||
isBanned: true,
|
||||
duplicateDetectedAt: new Date(),
|
||||
duplicateReason: params.reason ?? undefined,
|
||||
},
|
||||
});
|
||||
|
||||
await prisma.penalty.create({
|
||||
data: {
|
||||
userId: params.duplicateUserId,
|
||||
type: "BAN",
|
||||
reason: `Account als Duplikat von #${params.canonicalPublicId} markiert.`,
|
||||
createdUserId: session.user.id,
|
||||
},
|
||||
});
|
||||
return updated;
|
||||
};
|
||||
|
||||
export const clearDuplicateLink = async (duplicateUserId: string) => {
|
||||
const updated = await prisma.user.update({
|
||||
where: { id: duplicateUserId },
|
||||
data: {
|
||||
canonicalUserId: null,
|
||||
duplicateDetectedAt: null,
|
||||
duplicateReason: null,
|
||||
},
|
||||
});
|
||||
return updated;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user