use admin linked user as comment author so avatar and name are correct
This commit is contained in:
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user