Skip to content

Commit 811e98f

Browse files
authored
allow trainee to create blog (#152)
1 parent 010cb80 commit 811e98f

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

Diff for: src/resolvers/blogResolvers.ts

+7-5
Original file line numberDiff line numberDiff line change
@@ -102,12 +102,14 @@ export const blogResolvers = {
102102
context.currentUser?._id
103103
).populate("role");
104104

105-
if (
106-
!userWithRole ||
107-
(userWithRole.role as any)?.roleName !== "applicant"
108-
) {
109-
throw new CustomGraphQLError("Only Trainness can create blogs");
105+
if (!userWithRole) {
106+
throw new CustomGraphQLError("User not found or not logged in");
110107
}
108+
const roleName = (userWithRole.role as any)?.roleName;
109+
110+
if (!["applicant", "trainee"].includes(roleName)) {
111+
throw new CustomGraphQLError("Only Trainness can create blogs");
112+
}
111113
try {
112114
const existingRecord = await BlogModel.findOne({
113115
title: args.blogFields.title,

0 commit comments

Comments
 (0)