Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions config/testVariables.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,17 @@ module.exports = {
}
email
phone
info {
about {
shortDescription
designation
}
}
isAdmin
isModerator
isBlocked
isRemoved
token
}}`,
})
.set("Accept", "application/json");
Expand All @@ -62,10 +71,23 @@ module.exports = {
email: "abc${userNo}@email.com"
password: "password"
) {
_id
name {
firstName
lastName
}
email
phone
info {
about {
shortDescription
designation
}
}
isAdmin
isModerator
isBlocked
isRemoved
token
} }`,
})
Expand Down
8 changes: 4 additions & 4 deletions graphql/resolvers/auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const {
module.exports = {
login: async (args) => {
try {
const user = await User.findOne({ email: args.email });
const user = await User.findOne({ email: args.email }).lean();
if (!user) {
throw new Error(noUserError);
}
Expand All @@ -20,7 +20,8 @@ module.exports = {
}
const token = jwt.sign(
{
id: user.id,
id: user._id,
name: user.name,
},
`${process.env.JWT_SECRET}`,
{
Expand All @@ -29,8 +30,7 @@ module.exports = {
}
);
return {
_id: user._id,
name: user.name,
...user,
token: token,
};
} catch (err) {
Expand Down
4 changes: 2 additions & 2 deletions graphql/resolvers/category.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ module.exports = {
if (!req.isAuth) {
throw new Error(authenticationError);
}
if ((req.currentUser.isBlocked || req.currentUser.isRemoved)) {
if ((req.currentUser.isBlocked || req.currentUser.isBlocked)) {
throw new Error(blockRemoveUserError);
}
try {
Expand All @@ -52,7 +52,7 @@ module.exports = {
try {
const category = await Category.findById(
args.categoryFindInput._id
).populate('topics', ['name', 'description', 'tags', 'isArchived', 'createdBy']);
).populate('topics', ['name', 'description', 'tags', 'isArchived', 'createdBy', 'parentCategory', 'chats']);
if (!category) {
throw new Error(categoryRemovedError);
}
Expand Down
10 changes: 9 additions & 1 deletion graphql/resolvers/organization.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,15 @@ module.exports = {
getOrganization: async () => {
try {
const organization = await Organization.findOne().lean();
return organization;
if (organization == null) {
return {
exists: false,
};
}
return {
...organization,
exists: true,
};
} catch (err) {
console.log(err);
throw err;
Expand Down
11 changes: 8 additions & 3 deletions graphql/resolvers/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ const {
userBlockResult,
userRemoveResult,
} = require("../variables/resultMessages");
const { login } = require("./auth");

module.exports = {
users: async (args, req) => {
Expand All @@ -24,7 +25,7 @@ module.exports = {
if (req.currentUser.isAdmin) {
const users = await User.find(
{ isRemoved: false },
"name email info isAdmin isModerator isActivated isRemoved"
"name email info isAdmin isModerator isBlocked isRemoved"
);
return users;
} else {
Expand Down Expand Up @@ -77,7 +78,11 @@ module.exports = {
const saveUser = await user.save();
organization.totalUsers += 1;
await organization.save();
return { ...saveUser._doc };
const loginResponse = await login({
email: args.userInput.email,
password: args.userInput.password
});
return loginResponse;
} catch (err) {
console.log(err);
throw err;
Expand Down Expand Up @@ -127,7 +132,7 @@ module.exports = {
if (user.isFirstAdmin) {
throw new Error(firstAdminBlockError);
}
user.isActivated = false;
user.isBlocked = true;
await user.save();
const organization = await Organization.findOne();
organization.blockedUsers.push(user);
Expand Down
2 changes: 1 addition & 1 deletion graphql/schema/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ type RootQuery {
}

type RootMutation {
createUser(userInput: userInput!): user!
createUser(userInput: userInput!): authData!
updateUser(userInput: userInput!): user!
blockUser(userFindInput: userFindInput!): resultData!
removeUser(userFindInput: userFindInput!): resultData!
Expand Down
15 changes: 8 additions & 7 deletions graphql/schema/organization.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,14 @@ type organizationInfo {
}

type organization {
_id: String!
name: String!
description: organizationDescription!
contactInfo: organizationInfo!
isArchived: Boolean!
isUnderMaintenance: Boolean!
totalUsers: Int!
_id: String
name: String
description: organizationDescription
contactInfo: organizationInfo
isArchived: Boolean
isUnderMaintenance: Boolean
totalUsers: Int
exists: Boolean
}

input organizationDescriptionInput {
Expand Down
11 changes: 10 additions & 1 deletion graphql/schema/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ type user {
isFirstAdmin: Boolean!
isAdmin: Boolean!
isModerator: Boolean!
isActivated: Boolean!
isBlocked: Boolean!
isRemoved: Boolean!
}

Expand Down Expand Up @@ -76,6 +76,15 @@ input userFindInput {
type authData {
_id: String!
name: userName!
email: String!
phone: String
socialMedia: userSocialMedia
info: userInfo!
isFirstAdmin: Boolean!
isAdmin: Boolean!
isModerator: Boolean!
isBlocked: Boolean!
isRemoved: Boolean!
token: String!
}
`;
4 changes: 2 additions & 2 deletions models/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,9 @@ const userSchema = new Schema({
type: Boolean,
default: false,
},
isActivated: {
isBlocked: {
type: Boolean,
default: true,
default: false,
},
isRemoved: {
type: Boolean,
Expand Down