Skip to content

Commit 5f7b155

Browse files
feat : Event agendas - Minor improvements and fixes (PalisadoesFoundation#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>
1 parent 03fe1b8 commit 5f7b155

30 files changed

+1583
-66
lines changed

codegen.ts

+2
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,8 @@ const config: CodegenConfig = {
8989

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

92+
Note: "../models/Note#InterfaceNote",
93+
9294
Organization: "../models/Organization#InterfaceOrganization",
9395

9496
Plugin: "../models/Plugin#InterfacePlugin",

schema.graphql

+29-10
Original file line numberDiff line numberDiff line change
@@ -112,16 +112,14 @@ type AgendaItem {
112112
createdBy: User!
113113
description: String
114114
duration: String!
115-
isNote: Boolean!
116-
itemType: ItemType!
117115
organization: Organization!
118116
relatedEvent: Event
119117
sequence: Int!
120118
title: String!
121119
updatedAt: Date!
122120
updatedBy: User!
123121
urls: [String]
124-
user: String!
122+
users: [User]
125123
}
126124

127125
type AgendaSection {
@@ -290,14 +288,12 @@ input CreateAgendaItemInput {
290288
categories: [ID]
291289
description: String
292290
duration: String!
293-
isNote: Boolean!
294-
itemType: ItemType!
295291
organizationId: ID!
296292
relatedEventId: ID
297293
sequence: Int!
298-
title: String!
294+
title: String
299295
urls: [String]
300-
user: String
296+
users: [ID]
301297
}
302298

303299
input CreateAgendaSectionInput {
@@ -1071,6 +1067,7 @@ type Mutation {
10711067
createGroupChat(data: createGroupChatInput!): GroupChat!
10721068
createMember(input: UserAndOrganizationInput!): CreateMemberPayload!
10731069
createMessageChat(data: MessageChatInput!): MessageChat!
1070+
createNote(data: NoteInput!): Note!
10741071
createOrganization(data: OrganizationInput, file: String): Organization!
10751072
createPlugin(pluginCreatedBy: String!, pluginDesc: String!, pluginName: String!, uninstalledOrgs: [ID!]): Plugin!
10761073
createPost(data: PostInput!, file: String): Post
@@ -1081,6 +1078,7 @@ type Mutation {
10811078
deleteAdvertisement(id: ID!): DeleteAdvertisementPayload
10821079
deleteAgendaCategory(id: ID!): ID!
10831080
deleteDonationById(id: ID!): DeletePayload!
1081+
deleteNote(id: ID!): ID!
10841082
deleteVenue(id: ID!): Venue
10851083
editVenue(data: EditVenueInput!): Venue
10861084
forgotPassword(data: ForgotPasswordData!): Boolean!
@@ -1151,6 +1149,7 @@ type Mutation {
11511149
updateFundraisingCampaign(data: UpdateFundCampaignInput!, id: ID!): FundraisingCampaign!
11521150
updateFundraisingCampaignPledge(data: UpdateFundCampaignPledgeInput!, id: ID!): FundraisingCampaignPledge!
11531151
updateLanguage(languageCode: String!): User!
1152+
updateNote(data: UpdateNoteInput!, id: ID!): Note!
11541153
updateOrganization(data: UpdateOrganizationInput, file: String, id: ID!): Organization!
11551154
updatePluginStatus(id: ID!, orgId: ID!): Plugin!
11561155
updatePost(data: PostUpdateInput, id: ID!): Post!
@@ -1160,6 +1159,21 @@ type Mutation {
11601159
updateUserTag(input: UpdateUserTagInput!): UserTag
11611160
}
11621161

1162+
type Note {
1163+
_id: ID!
1164+
agendaItemId: ID!
1165+
content: String!
1166+
createdAt: DateTime!
1167+
createdBy: User!
1168+
updatedAt: DateTime!
1169+
updatedBy: User!
1170+
}
1171+
1172+
input NoteInput {
1173+
agendaItemId: ID!
1174+
content: String!
1175+
}
1176+
11631177
input OTPInput {
11641178
email: EmailAddress!
11651179
}
@@ -1434,6 +1448,7 @@ type Query {
14341448
getAgendaItem(id: ID!): AgendaItem
14351449
getAgendaSection(id: ID!): AgendaSection
14361450
getAllAgendaItems: [AgendaItem]
1451+
getAllNotesForAgendaItem(agendaItemId: ID!): [Note]
14371452
getCommunityData: Community
14381453
getDonationById(id: ID!): Donation!
14391454
getDonationByOrgId(orgId: ID!): [Donation]
@@ -1444,6 +1459,7 @@ type Query {
14441459
getFundById(id: ID!): Fund!
14451460
getFundraisingCampaignById(id: ID!): FundraisingCampaign!
14461461
getFundraisingCampaignPledgeById(id: ID!): FundraisingCampaignPledge!
1462+
getNoteById(id: ID!): Note!
14471463
getPlugins: [Plugin]
14481464
getVenueByOrgId(first: Int, orderBy: VenueOrderByInput, orgId: ID!, skip: Int, where: VenueWhereInput): [Venue]
14491465
getlanguage(lang_code: String!): [Translation]
@@ -1619,14 +1635,12 @@ input UpdateAgendaItemInput {
16191635
categories: [ID]
16201636
description: String
16211637
duration: String
1622-
isNote: Boolean
1623-
itemType: ItemType
16241638
relatedEvent: ID
16251639
sequence: Int
16261640
title: String
16271641
updatedBy: ID!
16281642
urls: [String]
1629-
user: String
1643+
users: [ID]
16301644
}
16311645

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

1713+
input UpdateNoteInput {
1714+
content: String
1715+
updatedBy: ID!
1716+
}
1717+
16991718
input UpdateOrganizationInput {
17001719
address: AddressInput
17011720
description: String

src/constants.ts

+17
Original file line numberDiff line numberDiff line change
@@ -538,6 +538,23 @@ export const AGENDA_SECTION_NOT_FOUND_ERROR = {
538538
MESSAGE: "agendaSection.notFound",
539539
PARAM: "agendaSection",
540540
};
541+
export const NOTE_NOT_FOUND_ERROR = {
542+
MESSAGE: "Error: Note not found",
543+
CODE: "note.notFound",
544+
PARAM: "noteValidation",
545+
};
546+
547+
export const UNAUTHORIZED_REMOVE_NOTE_ERROR = {
548+
MESSAGE: "Error: Unauthorized to remove note",
549+
CODE: "note.unauthorizedRemove",
550+
PARAM: "noteRemovalValidation",
551+
};
552+
553+
export const UNAUTHORIZED_UPDATE_NOTE_ERROR = {
554+
MESSAGE: "Error: Unauthorized to update note",
555+
CODE: "note.unauthorizedUpdate",
556+
PARAM: "noteUpdateValidation",
557+
};
541558

542559
export const USER_NOT_FOUND_ERROR = {
543560
DESC: "User not found",

src/models/AgendaItem.ts

+18-11
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import type { InterfaceUser } from "./User";
44
import type { InterfaceOrganization } from "./Organization";
55
import type { InterfaceAgendaCategory } from "./AgendaCategory";
66
import type { InterfaceEvent } from "./Event";
7+
import type { InterfaceNote } from "./Note";
78

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

3132
/**
@@ -45,15 +46,16 @@ export enum ItemType {
4546
* @param attachments - Optional array of attachment URLs.
4647
* @param createdBy - Reference to the user who created the agenda item.
4748
* @param updatedBy - Reference to the user who last updated the agenda item.
48-
* @param urls - Optional array of URLs related to the agenda item.
49-
* @param user - Optional user associated with the agenda item.
49+
* @param urls - Optional users array indicating key note users for the agenda item.
50+
* @param users - Optional user associated with the agenda item.
5051
* @param categories - Optional array of agenda categories associated with the agenda item.
5152
* @param sequence - Sequence number of the agenda item.
5253
* @param itemType - Type of the agenda item (Regular or Note).
5354
* @param createdAt - Date when the agenda item was created.
5455
* @param updatedAt - Date when the agenda item was last updated.
5556
* @param isNote - Indicates whether the agenda item is a note.
5657
* @param organization - Reference to the organization associated with the agenda item.
58+
* @param notes - Reference to the notes associated with the agenda item.
5759
*/
5860
export const AgendaItemSchema = new Schema({
5961
title: {
@@ -85,9 +87,12 @@ export const AgendaItemSchema = new Schema({
8587
urls: {
8688
type: [String],
8789
},
88-
user: {
89-
type: String,
90-
},
90+
users: [
91+
{
92+
type: Schema.Types.ObjectId,
93+
ref: "User",
94+
},
95+
],
9196
categories: [
9297
{
9398
type: Schema.Types.ObjectId,
@@ -109,14 +114,16 @@ export const AgendaItemSchema = new Schema({
109114
type: Date,
110115
// required: true,
111116
},
112-
isNote: {
113-
type: Boolean,
114-
default: false,
115-
},
116117
organization: {
117118
type: Schema.Types.ObjectId,
118119
ref: "Organization",
119120
},
121+
notes: [
122+
{
123+
type: Schema.Types.ObjectId,
124+
ref: "Note",
125+
},
126+
],
120127
});
121128

122129
const agendaItemModel = (): Model<InterfaceAgendaItem> =>

src/models/Note.ts

+50
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
import type { Model, PopulatedDoc, Types } from "mongoose";
2+
import { Schema, model, models } from "mongoose";
3+
import type { InterfaceUser } from "./User";
4+
5+
export interface InterfaceNote {
6+
_id: Types.ObjectId; // Unique identifier for the note.
7+
content: string; // Content of the note.
8+
createdBy: PopulatedDoc<InterfaceUser & Document>; // Reference to the user who created the note.
9+
updatedBy: PopulatedDoc<InterfaceUser & Document>; // Reference to the user who last updated the note.
10+
createdAt: Date; // Date when the note was created.
11+
updatedAt: Date; // Date when the note was last updated.
12+
agendaItemId: Types.ObjectId; // Reference to the agenda item associated with the note.
13+
}
14+
15+
export const NoteSchema = new Schema({
16+
content: {
17+
type: String,
18+
required: true,
19+
},
20+
createdBy: {
21+
type: Schema.Types.ObjectId,
22+
ref: "User",
23+
required: true,
24+
},
25+
updatedBy: {
26+
type: Schema.Types.ObjectId,
27+
ref: "User",
28+
},
29+
createdAt: {
30+
type: Date,
31+
required: true,
32+
default: Date.now,
33+
},
34+
updatedAt: {
35+
type: Date,
36+
default: Date.now,
37+
},
38+
agendaItemId: {
39+
type: Schema.Types.ObjectId,
40+
ref: "AgendaItem",
41+
required: true,
42+
},
43+
});
44+
45+
const noteModel = (): Model<InterfaceNote> =>
46+
model<InterfaceNote>("Note", NoteSchema);
47+
48+
export const NoteModel = (models.Note || noteModel()) as ReturnType<
49+
typeof noteModel
50+
>;

src/models/index.ts

+1
Original file line numberDiff line numberDiff line change
@@ -39,3 +39,4 @@ export * from "./SampleData";
3939
export * from "./TagUser";
4040
export * from "./Venue";
4141
export * from "./User";
42+
export * from "./Note";

src/resolvers/AgendaItem/Users.ts

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import type { AgendaItemResolvers } from "../../types/generatedGraphQLTypes";
2+
import { User } from "../../models";
3+
4+
export const users: AgendaItemResolvers["users"] = async (parent) => {
5+
const userIds = parent.users; // Assuming parent.users is an array of user ids
6+
const users = await User.find({ _id: { $in: userIds } }); // Assuming User.find() returns a promise
7+
return users;
8+
};

src/resolvers/AgendaItem/index.ts

+2
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,13 @@ import { createdBy } from "./createdBy";
44
import { updatedBy } from "./updatedBy";
55
import { relatedEvent } from "./relatedEvent";
66
import { categories } from "./categories";
7+
import { users } from "./Users";
78

89
export const AgendaItem: AgendaItemResolvers = {
910
organization,
1011
createdBy,
1112
updatedBy,
1213
relatedEvent,
1314
categories,
15+
users,
1416
};

0 commit comments

Comments
 (0)