Skip to content

Commit

Permalink
added changes
Browse files Browse the repository at this point in the history
  • Loading branch information
AdityaRaimec22 committed Feb 1, 2024
1 parent 190dfa3 commit 8465f37
Show file tree
Hide file tree
Showing 9 changed files with 0 additions and 198 deletions.
22 changes: 0 additions & 22 deletions src/models/User.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import validator from "validator";
import type { InterfaceEvent } from "./Event";
import type { InterfaceMembershipRequest } from "./MembershipRequest";
import type { InterfaceOrganization } from "./Organization";
import type { InterfaceUserFamily } from "./userFamily";
import { createLoggingMiddleware } from "../libraries/dbLogger";
import { LOG } from "../constants";

Expand All @@ -26,13 +25,11 @@ export interface InterfaceUser {
};
adminApproved: boolean;
adminFor: PopulatedDoc<InterfaceOrganization & Document>[];
adminForUserFamily: PopulatedDoc<InterfaceUserFamily & Document>[];
appLanguageCode: string;
birthDate: Date;
createdAt: Date;
createdEvents: PopulatedDoc<InterfaceEvent & Document>[];
createdOrganizations: PopulatedDoc<InterfaceOrganization & Document>[];
createdUserFamily: PopulatedDoc<InterfaceUserFamily & Document>[];
educationGrade: string;
email: string;
employmentStatus: string;
Expand All @@ -41,7 +38,6 @@ export interface InterfaceUser {
gender: string;
image: string | undefined | null;
joinedOrganizations: PopulatedDoc<InterfaceOrganization & Document>[];
joinedUserFamily: PopulatedDoc<InterfaceUserFamily & Document>[];
lastName: string;
maritalStatus: string;
membershipRequests: PopulatedDoc<InterfaceMembershipRequest & Document>[];
Expand Down Expand Up @@ -130,12 +126,6 @@ const userSchema = new Schema(
ref: "Organization",
},
],
adminForUserFamily: [
{
type: Schema.Types.ObjectId,
ref: "Organization",
},
],
appLanguageCode: {
type: String,
required: true,
Expand All @@ -150,12 +140,6 @@ const userSchema = new Schema(
ref: "Organization",
},
],
createdUserFamily: [
{
type: Schema.Types.ObjectId,
ref: "Organization",
},
],
createdEvents: [
{
type: Schema.Types.ObjectId,
Expand Down Expand Up @@ -216,12 +200,6 @@ const userSchema = new Schema(
ref: "Organization",
},
],
joinedUserFamily: [
{
type: Schema.Types.ObjectId,
ref: "Organization",
},
],
lastName: {
type: String,
required: true,
Expand Down
11 changes: 0 additions & 11 deletions src/resolvers/Mutation/adminAddMemberToUserFamily.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,17 +64,6 @@ export const addUserToUserFamily: MutationResolvers["addUserToUserFamily"] =
USER_ALREADY_MEMBER_ERROR.PARAM
);
}
//Adds args.familyId to userJoinedFamily
await User.findOneAndUpdate(
{
_id: args.userId,
},
{
$push: {
joinedUserFamily: args.familyId,
},
}
);

// Adds args.userId to users lists on family group and return the updated family.
return await UserFamily.findOneAndUpdate(
Expand Down
14 changes: 0 additions & 14 deletions src/resolvers/Mutation/adminRemoveMemberFromUserFamily.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,20 +110,6 @@ export const removeUserFromUserFamily: MutationResolvers["removeUserFromUserFami
);
}

//Removes familyId from user joined families.
await User.findOneAndUpdate(
{
_id: args.userId,
},
{
$set: {
joinedUserFamily: currentUser?.joinedUserFamily.filter(
(userFamily) => userFamily.toString() !== args.familyId.toString()
),
},
}
);

//Removes args.userId from users list of user family ans return the updated family.
return await UserFamily.findOneAndUpdate(
{
Expand Down
24 changes: 0 additions & 24 deletions src/resolvers/Mutation/createUserFamily.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,29 +77,5 @@ export const createUserFamily: MutationResolvers["createUserFamily"] = async (
creator: context.userId,
});

await User.findOneAndUpdate(
{
_id: context.userId,
},
{
$push: {
adminForUserFamily: createdUserFamily,
joinedUserFamily: createdUserFamily,
createdUserFamily: createdUserFamily,
},
}
);

await User.updateMany(
{
_id: { $in: args.data.userIds },
},
{
$push: {
joinedUserFamily: createdUserFamily,
},
}
);

return createdUserFamily.toObject();
};
18 changes: 0 additions & 18 deletions src/resolvers/Mutation/removeUserFamily.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,24 +50,6 @@ export const removeUserFamily: MutationResolvers["removeUserFamily"] = async (
);
}

// Update user documents to remove familyId from relevant fields
await User.updateMany(
{
$or: [
{ createdOrganizations: args.familyId },
{ joinedOrganizations: args.familyId },
{ adminForUserFamily: args.familyId },
],
},
{
$pull: {
createdOrganizations: args.familyId,
joinedOrganizations: args.familyId,
adminForUserFamily: args.familyId,
},
}
);

// Deletes the UserFamily.
await UserFamily.deleteOne({
_id: userFamily._id,
Expand Down
12 changes: 0 additions & 12 deletions tests/resolvers/Mutation/adminAddMemberToUserFamily.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import { beforeAll, afterAll, describe, it, expect, vi } from "vitest";
import type { TestUserType } from "../../helpers/userAndUserFamily";
import type { TestUserFamilyType } from "../../helpers/userAndUserFamily";
import { createTestUserAndUserFamily } from "../../helpers/userAndUserFamily";
import { User } from "../../../src/models";

let testUser: TestUserType;
let testUserFamily: TestUserFamilyType;
Expand Down Expand Up @@ -125,17 +124,6 @@ describe("resolver -> mutation -> addUserToUserFamily", () => {
}
);

await User.updateOne(
{
_id: testUser?._id,
},
{
$addToSet: {
joinedUserFamily: testUserFamily?._id,
},
}
);

const args: MutationAddUserToUserFamilyArgs = {
familyId: testUserFamily?.id,
userId: testUser?.id,
Expand Down
29 changes: 0 additions & 29 deletions tests/resolvers/Mutation/adminRemoveMemberFromUserFamily.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,30 +44,6 @@ beforeAll(async () => {
admins: [testUsers[2]?._id, testUsers[1]?._id],
creator: testUsers[2]?._id,
});

await User.updateOne(
{
_id: testUsers[2]?._id,
},
{
$push: {
joinedUserFamily: testUserFamily._id,
adminForUserFamily: testUserFamily._id,
createdUserFamily: testUserFamily._id,
},
}
);

await User.updateMany(
{
_id: { $in: [testUsers[0]?._id, testUsers[1]?._id, testUsers[4]?._id] },
},
{
$push: {
joinedUserFamily: testUserFamily._id,
},
}
);
});

afterAll(async () => {
Expand Down Expand Up @@ -301,12 +277,7 @@ describe("resolver -> Mutation -> removerUserFromUserFamily", () => {
context
);

const removedUser = await User.findOne({
_id: testUsers[4]?.id,
});

expect(updatedUserFamily?.users).not.toContain(testUsers[4]?._id);
expect(removedUser?.joinedUserFamily).not.toContain(testUserFamily?._id);
} catch (error: any) {
expect(spy).toHaveBeenCalledWith(USER_NOT_FOUND_ERROR.MESSAGE);
expect(error.message).toEqual(
Expand Down
43 changes: 0 additions & 43 deletions tests/resolvers/Mutation/createUserFamily.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,6 @@ beforeAll(async () => {

testUser = resultsArray;
testUser2 = secondUser;
// const { requestContext } = await import("../../../src/libraries");
// vi.spyOn(requestContext, "translate").mockImplementation(
// (message) => message
// );
});

afterAll(async () => {
Expand Down Expand Up @@ -161,45 +157,6 @@ describe("resolvers -> Mutation -> createUserFamily", () => {
}
});

it(`Updated the User to contain user Family`, async () => {
const args: MutationCreateUserFamilyArgs = {
data: {
title: "title",
userIds: [testUser?._id, testUser2?._id],
},
};

const context = {
userId: testUser?.id,
};

const { createUserFamily: createUserFamilyResolver } = await import(
"../../../src/resolvers/Mutation/createUserFamily"
);

const createUserFamilyPayload = await createUserFamilyResolver?.(
{},
args,
context
);

const updatedUsers = await User.find({
_id: { $in: [testUser?._id, testUser2?._id] },
});

updatedUsers.forEach((user) => {
expect(user.joinedUserFamily).toContainEqual(
createUserFamilyPayload?._id
);
});
expect(updatedUsers[0].createdUserFamily).toContainEqual(
createUserFamilyPayload?._id
);
expect(updatedUsers[0].adminForUserFamily).toContainEqual(
createUserFamilyPayload?._id
);
});

it(`creates the user Family and returns it`, async () => {
const args: MutationCreateUserFamilyArgs = {
data: {
Expand Down
25 changes: 0 additions & 25 deletions tests/resolvers/Mutation/removeUserFamily.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import {
type TestUserType,
} from "../../helpers/userAndUserFamily";
import type { TestUserFamilyType } from "../../helpers/userAndUserFamily";
import { User } from "../../../src/models";

let MONGOOSE_INSTANCE: typeof mongoose;
let testUsers: TestUserType[];
Expand All @@ -43,30 +42,6 @@ beforeAll(async () => {
creator: tempUser1,
users: [tempUser1, tempUser2],
});

await User.updateOne(
{
_id: testUsers[0]?._id,
},
{
$set: {
createdUserFamily: [testUserFamily._id],
adminForUserFamily: [testUserFamily._id],
joinedUserFamily: [testUserFamily._id],
},
}
);

await User.updateOne(
{
_id: testUsers[1]?._id,
},
{
$set: {
joinedUserFamily: [testUserFamily._id],
},
}
);
});

afterAll(async () => {
Expand Down

0 comments on commit 8465f37

Please sign in to comment.