Skip to content

Commit

Permalink
feat : Event agendas - Minor improvements and fixes (PalisadoesFounda…
Browse files Browse the repository at this point in the history
…tion#2254)

* Added a unit test for app user profile

* Updated 100% coverage for updateAdvertisement

* ran prettier

* fixed linting error

* Ran prettier again

* Changed user to users

* Added a field level resolver for Users

* Removed redundant isNote boolean type

* Added a new note model

* Added mutation resolvers for notes

* Added queries for notes

* test

* Added tests for delta files

* Ran prettier

* Added necessary tests for note specific queries

* Fixed formatting errors

* Minor changes

* test

* Test

* format fix

---------

Co-authored-by: Peter Harrison <16875803+palisadoes@users.noreply.github.com>
Atharva-Kanherkar and palisadoes authored Apr 22, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
1 parent 03fe1b8 commit 5f7b155
Showing 30 changed files with 1,583 additions and 66 deletions.
2 changes: 2 additions & 0 deletions codegen.ts
Original file line number Diff line number Diff line change
@@ -89,6 +89,8 @@ const config: CodegenConfig = {

Message: "../models/Message#InterfaceMessage",

Note: "../models/Note#InterfaceNote",

Organization: "../models/Organization#InterfaceOrganization",

Plugin: "../models/Plugin#InterfacePlugin",
39 changes: 29 additions & 10 deletions schema.graphql
Original file line number Diff line number Diff line change
@@ -112,16 +112,14 @@ type AgendaItem {
createdBy: User!
description: String
duration: String!
isNote: Boolean!
itemType: ItemType!
organization: Organization!
relatedEvent: Event
sequence: Int!
title: String!
updatedAt: Date!
updatedBy: User!
urls: [String]
user: String!
users: [User]
}

type AgendaSection {
@@ -290,14 +288,12 @@ input CreateAgendaItemInput {
categories: [ID]
description: String
duration: String!
isNote: Boolean!
itemType: ItemType!
organizationId: ID!
relatedEventId: ID
sequence: Int!
title: String!
title: String
urls: [String]
user: String
users: [ID]
}

input CreateAgendaSectionInput {
@@ -1071,6 +1067,7 @@ type Mutation {
createGroupChat(data: createGroupChatInput!): GroupChat!
createMember(input: UserAndOrganizationInput!): CreateMemberPayload!
createMessageChat(data: MessageChatInput!): MessageChat!
createNote(data: NoteInput!): Note!
createOrganization(data: OrganizationInput, file: String): Organization!
createPlugin(pluginCreatedBy: String!, pluginDesc: String!, pluginName: String!, uninstalledOrgs: [ID!]): Plugin!
createPost(data: PostInput!, file: String): Post
@@ -1081,6 +1078,7 @@ type Mutation {
deleteAdvertisement(id: ID!): DeleteAdvertisementPayload
deleteAgendaCategory(id: ID!): ID!
deleteDonationById(id: ID!): DeletePayload!
deleteNote(id: ID!): ID!
deleteVenue(id: ID!): Venue
editVenue(data: EditVenueInput!): Venue
forgotPassword(data: ForgotPasswordData!): Boolean!
@@ -1151,6 +1149,7 @@ type Mutation {
updateFundraisingCampaign(data: UpdateFundCampaignInput!, id: ID!): FundraisingCampaign!
updateFundraisingCampaignPledge(data: UpdateFundCampaignPledgeInput!, id: ID!): FundraisingCampaignPledge!
updateLanguage(languageCode: String!): User!
updateNote(data: UpdateNoteInput!, id: ID!): Note!
updateOrganization(data: UpdateOrganizationInput, file: String, id: ID!): Organization!
updatePluginStatus(id: ID!, orgId: ID!): Plugin!
updatePost(data: PostUpdateInput, id: ID!): Post!
@@ -1160,6 +1159,21 @@ type Mutation {
updateUserTag(input: UpdateUserTagInput!): UserTag
}

type Note {
_id: ID!
agendaItemId: ID!
content: String!
createdAt: DateTime!
createdBy: User!
updatedAt: DateTime!
updatedBy: User!
}

input NoteInput {
agendaItemId: ID!
content: String!
}

input OTPInput {
email: EmailAddress!
}
@@ -1434,6 +1448,7 @@ type Query {
getAgendaItem(id: ID!): AgendaItem
getAgendaSection(id: ID!): AgendaSection
getAllAgendaItems: [AgendaItem]
getAllNotesForAgendaItem(agendaItemId: ID!): [Note]
getCommunityData: Community
getDonationById(id: ID!): Donation!
getDonationByOrgId(orgId: ID!): [Donation]
@@ -1444,6 +1459,7 @@ type Query {
getFundById(id: ID!): Fund!
getFundraisingCampaignById(id: ID!): FundraisingCampaign!
getFundraisingCampaignPledgeById(id: ID!): FundraisingCampaignPledge!
getNoteById(id: ID!): Note!
getPlugins: [Plugin]
getVenueByOrgId(first: Int, orderBy: VenueOrderByInput, orgId: ID!, skip: Int, where: VenueWhereInput): [Venue]
getlanguage(lang_code: String!): [Translation]
@@ -1619,14 +1635,12 @@ input UpdateAgendaItemInput {
categories: [ID]
description: String
duration: String
isNote: Boolean
itemType: ItemType
relatedEvent: ID
sequence: Int
title: String
updatedBy: ID!
urls: [String]
user: String
users: [ID]
}

input UpdateAgendaSectionInput {
@@ -1696,6 +1710,11 @@ input UpdateFundInput {
taxDeductible: Boolean
}

input UpdateNoteInput {
content: String
updatedBy: ID!
}

input UpdateOrganizationInput {
address: AddressInput
description: String
17 changes: 17 additions & 0 deletions src/constants.ts
Original file line number Diff line number Diff line change
@@ -538,6 +538,23 @@ export const AGENDA_SECTION_NOT_FOUND_ERROR = {
MESSAGE: "agendaSection.notFound",
PARAM: "agendaSection",
};
export const NOTE_NOT_FOUND_ERROR = {
MESSAGE: "Error: Note not found",
CODE: "note.notFound",
PARAM: "noteValidation",
};

export const UNAUTHORIZED_REMOVE_NOTE_ERROR = {
MESSAGE: "Error: Unauthorized to remove note",
CODE: "note.unauthorizedRemove",
PARAM: "noteRemovalValidation",
};

export const UNAUTHORIZED_UPDATE_NOTE_ERROR = {
MESSAGE: "Error: Unauthorized to update note",
CODE: "note.unauthorizedUpdate",
PARAM: "noteUpdateValidation",
};

export const USER_NOT_FOUND_ERROR = {
DESC: "User not found",
29 changes: 18 additions & 11 deletions src/models/AgendaItem.ts
Original file line number Diff line number Diff line change
@@ -4,6 +4,7 @@ import type { InterfaceUser } from "./User";
import type { InterfaceOrganization } from "./Organization";
import type { InterfaceAgendaCategory } from "./AgendaCategory";
import type { InterfaceEvent } from "./Event";
import type { InterfaceNote } from "./Note";

/**
* This is an interface representing a document for an agenda item in the database (MongoDB).
@@ -17,15 +18,15 @@ export interface InterfaceAgendaItem {
createdBy: PopulatedDoc<InterfaceUser & Document>; // Reference to the user who created the agenda item.
updatedBy: PopulatedDoc<InterfaceUser & Document>; // Reference to the user who last updated the agenda item.
urls?: string[]; // Optional array of URLs related to the agenda item.
user?: string; // Optional user associated with the agenda item.
users?: PopulatedDoc<InterfaceUser & Document>[]; // Optional users array indicating key note users for the agenda item.
relatedEvent: PopulatedDoc<InterfaceEvent & Document>; // Reference to the event associated with the agenda item.
categories?: PopulatedDoc<InterfaceAgendaCategory & Document>[]; // Optional array of agenda categories associated with the agenda item.
sequence: number; // Sequence number of the agenda item.
itemType: ItemType; // Type of the agenda item (Regular or Note).
createdAt: Date; // Date when the agenda item was created.
updatedAt: Date; // Date when the agenda item was last updated.
isNote: boolean; // Indicates whether the agenda item is a note.
organization: PopulatedDoc<InterfaceOrganization & Document>; // Reference to the organization associated with the agenda item.
notes: PopulatedDoc<InterfaceNote & Document>[]; // Reference to the notes associated with the agenda item.
}

/**
@@ -45,15 +46,16 @@ export enum ItemType {
* @param attachments - Optional array of attachment URLs.
* @param createdBy - Reference to the user who created the agenda item.
* @param updatedBy - Reference to the user who last updated the agenda item.
* @param urls - Optional array of URLs related to the agenda item.
* @param user - Optional user associated with the agenda item.
* @param urls - Optional users array indicating key note users for the agenda item.
* @param users - Optional user associated with the agenda item.
* @param categories - Optional array of agenda categories associated with the agenda item.
* @param sequence - Sequence number of the agenda item.
* @param itemType - Type of the agenda item (Regular or Note).
* @param createdAt - Date when the agenda item was created.
* @param updatedAt - Date when the agenda item was last updated.
* @param isNote - Indicates whether the agenda item is a note.
* @param organization - Reference to the organization associated with the agenda item.
* @param notes - Reference to the notes associated with the agenda item.
*/
export const AgendaItemSchema = new Schema({
title: {
@@ -85,9 +87,12 @@ export const AgendaItemSchema = new Schema({
urls: {
type: [String],
},
user: {
type: String,
},
users: [
{
type: Schema.Types.ObjectId,
ref: "User",
},
],
categories: [
{
type: Schema.Types.ObjectId,
@@ -109,14 +114,16 @@ export const AgendaItemSchema = new Schema({
type: Date,
// required: true,
},
isNote: {
type: Boolean,
default: false,
},
organization: {
type: Schema.Types.ObjectId,
ref: "Organization",
},
notes: [
{
type: Schema.Types.ObjectId,
ref: "Note",
},
],
});

const agendaItemModel = (): Model<InterfaceAgendaItem> =>
50 changes: 50 additions & 0 deletions src/models/Note.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import type { Model, PopulatedDoc, Types } from "mongoose";
import { Schema, model, models } from "mongoose";
import type { InterfaceUser } from "./User";

export interface InterfaceNote {
_id: Types.ObjectId; // Unique identifier for the note.
content: string; // Content of the note.
createdBy: PopulatedDoc<InterfaceUser & Document>; // Reference to the user who created the note.
updatedBy: PopulatedDoc<InterfaceUser & Document>; // Reference to the user who last updated the note.
createdAt: Date; // Date when the note was created.
updatedAt: Date; // Date when the note was last updated.
agendaItemId: Types.ObjectId; // Reference to the agenda item associated with the note.
}

export const NoteSchema = new Schema({
content: {
type: String,
required: true,
},
createdBy: {
type: Schema.Types.ObjectId,
ref: "User",
required: true,
},
updatedBy: {
type: Schema.Types.ObjectId,
ref: "User",
},
createdAt: {
type: Date,
required: true,
default: Date.now,
},
updatedAt: {
type: Date,
default: Date.now,
},
agendaItemId: {
type: Schema.Types.ObjectId,
ref: "AgendaItem",
required: true,
},
});

const noteModel = (): Model<InterfaceNote> =>
model<InterfaceNote>("Note", NoteSchema);

export const NoteModel = (models.Note || noteModel()) as ReturnType<
typeof noteModel
>;
1 change: 1 addition & 0 deletions src/models/index.ts
Original file line number Diff line number Diff line change
@@ -39,3 +39,4 @@ export * from "./SampleData";
export * from "./TagUser";
export * from "./Venue";
export * from "./User";
export * from "./Note";
8 changes: 8 additions & 0 deletions src/resolvers/AgendaItem/Users.ts
Original file line number Diff line number Diff line change
@@ -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;
};
2 changes: 2 additions & 0 deletions src/resolvers/AgendaItem/index.ts
Original file line number Diff line number Diff line change
@@ -4,11 +4,13 @@ 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,
createdBy,
updatedBy,
relatedEvent,
categories,
users,
};
Loading

0 comments on commit 5f7b155

Please sign in to comment.