Skip to content

Commit

Permalink
changed handling user == null case
Browse files Browse the repository at this point in the history
  • Loading branch information
syedali237 committed Oct 15, 2024
1 parent d674674 commit d377ddb
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 97 deletions.
2 changes: 1 addition & 1 deletion eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ export default [
"import/no-duplicates": "error",
"tsdoc/syntax": "error",
"@typescript-eslint/ban-ts-comment": "error",
"@typescript-eslint/ban-types": "error",
// "@typescript-eslint/ban-types": "error",
"@typescript-eslint/no-duplicate-enum-values": "error",
"@typescript-eslint/no-explicit-any": "warn",
"@typescript-eslint/no-non-null-asserted-optional-chain": "error",
Expand Down
20 changes: 12 additions & 8 deletions src/resolvers/Mutation/sendMembershipRequest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,15 +78,16 @@ export const sendMembershipRequest: MutationResolvers["sendMembershipRequest"] =

// Checks if the user is blocked
const user = await User.findById(context.userId).lean();
if (user === null) {
throw new errors.NotFoundError(
requestContext.translate(USER_NOT_FOUND_ERROR.MESSAGE),
USER_NOT_FOUND_ERROR.CODE,
USER_NOT_FOUND_ERROR.PARAM,
);
}
// if (user === null) {
// throw new errors.NotFoundError(
// requestContext.translate(USER_NOT_FOUND_ERROR.MESSAGE),
// USER_NOT_FOUND_ERROR.CODE,
// USER_NOT_FOUND_ERROR.PARAM,
// );
// }

if (
user != null &&
organization.blockedUsers.some((blockedUser) =>
new mongoose.Types.ObjectId(blockedUser.toString()).equals(user._id),
)
Expand All @@ -105,7 +106,10 @@ export const sendMembershipRequest: MutationResolvers["sendMembershipRequest"] =
});
if (membershipRequestExists) {
// Check if the request is already in the user's document
if (!user.membershipRequests.includes(membershipRequestExists._id)) {
if (
user != null &&
!user.membershipRequests.includes(membershipRequestExists._id)
) {
// If it's not in the user's document, add it
await User.findByIdAndUpdate(
context.userId,
Expand Down
88 changes: 0 additions & 88 deletions tests/resolvers/Mutation/checkUserNull.spec.ts

This file was deleted.

0 comments on commit d377ddb

Please sign in to comment.