Skip to content

Commit 1e1f0c0

Browse files
authored
Merge pull request #22 from aayush-05/frontendFixes
Changes required for frontend
2 parents b936f54 + b2276e2 commit 1e1f0c0

File tree

9 files changed

+66
-21
lines changed

9 files changed

+66
-21
lines changed

config/testVariables.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,17 @@ module.exports = {
4747
}
4848
email
4949
phone
50+
info {
51+
about {
52+
shortDescription
53+
designation
54+
}
55+
}
5056
isAdmin
5157
isModerator
58+
isBlocked
59+
isRemoved
60+
token
5261
}}`,
5362
})
5463
.set("Accept", "application/json");
@@ -62,10 +71,23 @@ module.exports = {
6271
email: "abc${userNo}@email.com"
6372
password: "password"
6473
) {
74+
_id
6575
name {
6676
firstName
6777
lastName
6878
}
79+
email
80+
phone
81+
info {
82+
about {
83+
shortDescription
84+
designation
85+
}
86+
}
87+
isAdmin
88+
isModerator
89+
isBlocked
90+
isRemoved
6991
token
7092
} }`,
7193
})

graphql/resolvers/auth.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ const {
1010
module.exports = {
1111
login: async (args) => {
1212
try {
13-
const user = await User.findOne({ email: args.email });
13+
const user = await User.findOne({ email: args.email }).lean();
1414
if (!user) {
1515
throw new Error(noUserError);
1616
}
@@ -20,7 +20,8 @@ module.exports = {
2020
}
2121
const token = jwt.sign(
2222
{
23-
id: user.id,
23+
id: user._id,
24+
name: user.name,
2425
},
2526
`${process.env.JWT_SECRET}`,
2627
{
@@ -29,8 +30,7 @@ module.exports = {
2930
}
3031
);
3132
return {
32-
_id: user._id,
33-
name: user.name,
33+
...user,
3434
token: token,
3535
};
3636
} catch (err) {

graphql/resolvers/category.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ module.exports = {
2828
if (!req.isAuth) {
2929
throw new Error(authenticationError);
3030
}
31-
if ((req.currentUser.isBlocked || req.currentUser.isRemoved)) {
31+
if ((req.currentUser.isBlocked || req.currentUser.isBlocked)) {
3232
throw new Error(blockRemoveUserError);
3333
}
3434
try {
@@ -52,7 +52,7 @@ module.exports = {
5252
try {
5353
const category = await Category.findById(
5454
args.categoryFindInput._id
55-
).populate('topics', ['name', 'description', 'tags', 'isArchived', 'createdBy']);
55+
).populate('topics', ['name', 'description', 'tags', 'isArchived', 'createdBy', 'parentCategory', 'chats']);
5656
if (!category) {
5757
throw new Error(categoryRemovedError);
5858
}

graphql/resolvers/organization.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,15 @@ module.exports = {
3939
getOrganization: async () => {
4040
try {
4141
const organization = await Organization.findOne().lean();
42-
return organization;
42+
if (organization == null) {
43+
return {
44+
exists: false,
45+
};
46+
}
47+
return {
48+
...organization,
49+
exists: true,
50+
};
4351
} catch (err) {
4452
console.log(err);
4553
throw err;

graphql/resolvers/user.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ const {
1414
userBlockResult,
1515
userRemoveResult,
1616
} = require("../variables/resultMessages");
17+
const { login } = require("./auth");
1718

1819
module.exports = {
1920
users: async (args, req) => {
@@ -24,7 +25,7 @@ module.exports = {
2425
if (req.currentUser.isAdmin) {
2526
const users = await User.find(
2627
{ isRemoved: false },
27-
"name email info isAdmin isModerator isActivated isRemoved"
28+
"name email info isAdmin isModerator isBlocked isRemoved"
2829
);
2930
return users;
3031
} else {
@@ -77,7 +78,11 @@ module.exports = {
7778
const saveUser = await user.save();
7879
organization.totalUsers += 1;
7980
await organization.save();
80-
return { ...saveUser._doc };
81+
const loginResponse = await login({
82+
email: args.userInput.email,
83+
password: args.userInput.password
84+
});
85+
return loginResponse;
8186
} catch (err) {
8287
console.log(err);
8388
throw err;
@@ -127,7 +132,7 @@ module.exports = {
127132
if (user.isFirstAdmin) {
128133
throw new Error(firstAdminBlockError);
129134
}
130-
user.isActivated = false;
135+
user.isBlocked = true;
131136
await user.save();
132137
const organization = await Organization.findOne();
133138
organization.blockedUsers.push(user);

graphql/schema/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ type RootQuery {
3737
}
3838
3939
type RootMutation {
40-
createUser(userInput: userInput!): user!
40+
createUser(userInput: userInput!): authData!
4141
updateUser(userInput: userInput!): user!
4242
blockUser(userFindInput: userFindInput!): resultData!
4343
removeUser(userFindInput: userFindInput!): resultData!

graphql/schema/organization.js

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,14 @@ type organizationInfo {
1010
}
1111
1212
type organization {
13-
_id: String!
14-
name: String!
15-
description: organizationDescription!
16-
contactInfo: organizationInfo!
17-
isArchived: Boolean!
18-
isUnderMaintenance: Boolean!
19-
totalUsers: Int!
13+
_id: String
14+
name: String
15+
description: organizationDescription
16+
contactInfo: organizationInfo
17+
isArchived: Boolean
18+
isUnderMaintenance: Boolean
19+
totalUsers: Int
20+
exists: Boolean
2021
}
2122
2223
input organizationDescriptionInput {

graphql/schema/user.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ type user {
3232
isFirstAdmin: Boolean!
3333
isAdmin: Boolean!
3434
isModerator: Boolean!
35-
isActivated: Boolean!
35+
isBlocked: Boolean!
3636
isRemoved: Boolean!
3737
}
3838
@@ -76,6 +76,15 @@ input userFindInput {
7676
type authData {
7777
_id: String!
7878
name: userName!
79+
email: String!
80+
phone: String
81+
socialMedia: userSocialMedia
82+
info: userInfo!
83+
isFirstAdmin: Boolean!
84+
isAdmin: Boolean!
85+
isModerator: Boolean!
86+
isBlocked: Boolean!
87+
isRemoved: Boolean!
7988
token: String!
8089
}
8190
`;

models/user.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,9 +115,9 @@ const userSchema = new Schema({
115115
type: Boolean,
116116
default: false,
117117
},
118-
isActivated: {
118+
isBlocked: {
119119
type: Boolean,
120-
default: true,
120+
default: false,
121121
},
122122
isRemoved: {
123123
type: Boolean,

0 commit comments

Comments
 (0)