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 cleanBody = body.body.replace(INVISIBLE_RE, '');
|
||||||
const isAdmin = !!req.adminId;
|
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({
|
const comment = await prisma.comment.create({
|
||||||
data: {
|
data: {
|
||||||
body: cleanBody,
|
body: cleanBody,
|
||||||
postId: post.id,
|
postId: post.id,
|
||||||
authorId: req.user!.id,
|
authorId: commentAuthorId,
|
||||||
replyToId: body.replyToId ?? null,
|
replyToId: body.replyToId ?? null,
|
||||||
isAdmin,
|
isAdmin,
|
||||||
adminUserId: req.adminId ?? null,
|
adminUserId: req.adminId ?? null,
|
||||||
|
|||||||
Reference in New Issue
Block a user