fix permission for edit
This commit is contained in:
parent
67eb136ff7
commit
504e1352f6
|
|
@ -52,7 +52,11 @@ const editPost = async (post: Post): Promise<PrismaPost | null | Error> => {
|
||||||
if (originalPost === null) {
|
if (originalPost === null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
if (originalPost.authorId !== post.authorId) {
|
const user = await getUserById(post.authorId);
|
||||||
|
if (!user) {
|
||||||
|
return new Error('User not found');
|
||||||
|
}
|
||||||
|
if (originalPost.authorId !== post.authorId && user.role === 'USER') {
|
||||||
return new Error('User is not the author of this post');
|
return new Error('User is not the author of this post');
|
||||||
}
|
}
|
||||||
const editedPost = await prisma.post.update({
|
const editedPost = await prisma.post.update({
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue