Skip to content

Commit

Permalink
mend
Browse files Browse the repository at this point in the history
  • Loading branch information
mutsinziisaac committed Dec 3, 2024
1 parent fb3ec49 commit 0edbbe5
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 14 deletions.
2 changes: 1 addition & 1 deletion src/models/blogModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ const blogSchema = new Schema({

isHidden: {
type: Boolean,
default: false,
default: true,
},
author: {
type: Schema.Types.ObjectId,
Expand Down
14 changes: 1 addition & 13 deletions src/resolvers/blogResolvers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,11 +138,6 @@ export const blogResolvers = {
if (!userWithRole) {
throw new CustomGraphQLError("User not found or not logged in");
}
const roleName = (userWithRole.role as any)?.roleName;

if (!["applicant", "trainee"].includes(roleName)) {
throw new CustomGraphQLError("Only Trainness can create blogs");
}
try {
const existingRecord = await BlogModel.findOne({
title: args.blogFields.title,
Expand Down Expand Up @@ -188,13 +183,6 @@ export const blogResolvers = {
throw new CustomGraphQLError("User not found or not logged in");
}

const roleName = (userWithRole.role as any)?.roleName;

// Check if user has permission to update blogs
if (!["applicant", "trainee", "admin"].includes(roleName)) {
throw new CustomGraphQLError("You do not have permission to update blogs");
}

try {
// Check if blog exists
const existingBlog = await BlogModel.findById(id);
Expand All @@ -203,7 +191,7 @@ export const blogResolvers = {
}

// Optional: Check if user is the original author
if (roleName !== "admin" && existingBlog.author.toString() !== context.currentUser?._id.toString()) {
if (existingBlog.author.toString() !== context.currentUser?._id.toString()) {
throw new CustomGraphQLError("You can only update your own blogs");
}

Expand Down

0 comments on commit 0edbbe5

Please sign in to comment.