diff --git a/src/resolvers/AgendaItem/Users.ts b/src/resolvers/AgendaItem/Users.ts new file mode 100644 index 00000000000..93810885c1d --- /dev/null +++ b/src/resolvers/AgendaItem/Users.ts @@ -0,0 +1,8 @@ +import type { AgendaItemResolvers } from "../../types/generatedGraphQLTypes"; +import { User } from "../../models"; + +export const users: AgendaItemResolvers["users"] = async (parent) => { + const userIds = parent.users; // Assuming parent.users is an array of user ids + const users = await User.find({ _id: { $in: userIds } }); // Assuming User.find() returns a promise + return users; +}; diff --git a/src/resolvers/AgendaItem/index.ts b/src/resolvers/AgendaItem/index.ts index c37b4c47e25..03519212a59 100644 --- a/src/resolvers/AgendaItem/index.ts +++ b/src/resolvers/AgendaItem/index.ts @@ -4,6 +4,7 @@ import { createdBy } from "./createdBy"; import { updatedBy } from "./updatedBy"; import { relatedEvent } from "./relatedEvent"; import { categories } from "./categories"; +import { users } from "./Users"; export const AgendaItem: AgendaItemResolvers = { organization, @@ -11,4 +12,5 @@ export const AgendaItem: AgendaItemResolvers = { updatedBy, relatedEvent, categories, + users, }; diff --git a/tests/resolvers/AgendaItem/Users.spec.ts b/tests/resolvers/AgendaItem/Users.spec.ts new file mode 100644 index 00000000000..892d3645f8b --- /dev/null +++ b/tests/resolvers/AgendaItem/Users.spec.ts @@ -0,0 +1,76 @@ +import type mongoose from "mongoose"; +import { afterAll, beforeAll, describe, expect, it } from "vitest"; +import { AgendaItemModel, Organization, Event } from "../../../src/models"; +import { users as usersResolver } from "../../../src/resolvers/AgendaItem/Users"; +import type { TestAgendaItemType } from "../../helpers/agendaItem"; +import { connect, disconnect } from "../../helpers/db"; +import type { + TestOrganizationType, + createTestUser, + type TestUserType, +} from "../../helpers/userAndOrg"; + +import type { TestEventType } from "../../helpers/events"; + +let MONGOOSE_INSTANCE: typeof mongoose; +let testUser1: TestUserType; +let testUser2: TestUserType; +let testAgendaItem: TestAgendaItemType; +let testOrganization: TestOrganizationType; +let testEvent: TestEventType; + +beforeAll(async () => { + MONGOOSE_INSTANCE = await connect(); + testUser1 = await createTestUser(); + testUser2 = await createTestUser(); + testOrganization = await Organization.create({ + name: "name", + description: "description", + isPublic: true, + creator: testUser1?._id, + admins: [testUser1?._id, testUser2?._id], + members: [testUser1?._id, testUser2?._id], + creatorId: testUser1?._id, + }); + testEvent = await Event.create({ + title: "title", + description: "description", + allDay: true, + startDate: new Date(), + recurring: true, + isPublic: true, + isRegisterable: true, + creator: testUser1?._id, + admins: [testUser1?._id, testUser2?._id], + registrants: [], + organization: testOrganization?._id, + creatorId: testUser1?._id, + }); + + testAgendaItem = await AgendaItemModel.create({ + title: "Regular Agenda Item", + description: "Description for the regular agenda item", + duration: "1 hour", + relatedEventId: testEvent?._id, + sequence: 1, + itemType: "Regular", + organizationId: testOrganization?._id, + isNote: false, + createdBy: testUser1?._id, + createdAt: Date.now(), + updatedBy: testUser1?._id, + updatedAt: Date.now(), + users: [testUser1?._id, testUser2?._id], // Assuming users field is an array of user ids + }); +}); + +afterAll(async () => { + await disconnect(MONGOOSE_INSTANCE); +}); + +describe("AgendaItem.Users", () => { + it("Should return the users of the agenda item", async () => { + const users = await usersResolver?.(testAgendaItem, {}, {}); + expect(users).toEqual([testUser1, testUser2]); + }); +});