use admin linked user as comment author so avatar and name are correct

This commit is contained in:
2026-03-22 07:15:13 +02:00
parent 0128a050f7
commit 9f4b92cc36

View File

@@ -157,11 +157,19 @@ export default async function commentRoutes(app: FastifyInstance) {
const cleanBody = body.body.replace(INVISIBLE_RE, '');
const isAdmin = !!req.adminId;
// use admin's linked user as author when commenting as admin
let commentAuthorId = req.user!.id;
if (isAdmin) {
const adminUser = await prisma.adminUser.findUnique({ where: { id: req.adminId! }, select: { linkedUserId: true } });
if (adminUser?.linkedUserId) commentAuthorId = adminUser.linkedUserId;
}
const comment = await prisma.comment.create({
data: {
body: cleanBody,
postId: post.id,
authorId: req.user!.id,
authorId: commentAuthorId,
replyToId: body.replyToId ?? null,
isAdmin,
adminUserId: req.adminId ?? null,