Skip to content

Commit

Permalink
Merge branch 'checkin-checkoout' of https://github.com/git-init-priya…
Browse files Browse the repository at this point in the history
…nshu/talawa-api-clone into checkin-checkoout
  • Loading branch information
git-init-priyanshu committed Mar 30, 2024
2 parents 6932ce9 + abf6eff commit 203314e
Show file tree
Hide file tree
Showing 36 changed files with 1,567 additions and 68 deletions.
4 changes: 4 additions & 0 deletions codegen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,12 @@ const config: CodegenConfig = {
EventAttendee: "../models/EventAttendee#InterfaceEventAttendee",

UserFamily: "../models/userFamily#InterfaceUserFamily",

EventVolunteer: "../models/EventVolunteer#InterfaceEventVolunteer",

EventVolunteerGroup:
"../models/EventVolunteerGroup#InterfaceEventVolunteerGroup",

Feedback: "../models/Feedback#InterfaceFeedback",
Fund: "../models/Fund#InterfaceFund",
FundraisingCampaign:
Expand Down
29 changes: 29 additions & 0 deletions schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -708,15 +708,35 @@ type EventVolunteer {
createdAt: DateTime!
creator: User
event: Event
group: EventVolunteerGroup
isAssigned: Boolean
isInvited: Boolean
response: String
updatedAt: DateTime!
user: User!
}

type EventVolunteerGroup {
_id: ID!
createdAt: DateTime!
creator: User
event: Event
leader: User!
name: String
updatedAt: DateTime!
volunteers: [EventVolunteer]
volunteersRequired: Int
}

input EventVolunteerGroupInput {
eventId: ID!
name: String
volunteersRequired: Int
}

input EventVolunteerInput {
eventId: ID!
groupId: ID!
userId: ID!
}

Expand Down Expand Up @@ -1045,6 +1065,7 @@ type Mutation {
createDonation(amount: Float!, nameOfOrg: String!, nameOfUser: String!, orgId: ID!, payPalId: ID!, userId: ID!): Donation!
createEvent(data: EventInput!, recurrenceRuleData: RecurrenceRuleInput): Event!
createEventVolunteer(data: EventVolunteerInput!): EventVolunteer!
createEventVolunteerGroup(data: EventVolunteerGroupInput!): EventVolunteerGroup!
createFund(data: FundInput!): Fund!
createFundraisingCampaign(data: FundCampaignInput!): FundraisingCampaign!
createFundraisingCampaignPledge(data: FundCampaignPledgeInput!): FundraisingCampaignPledge!
Expand Down Expand Up @@ -1088,6 +1109,7 @@ type Mutation {
removeEvent(id: ID!, recurringEventDeleteType: RecurringEventMutationType): Event!
removeEventAttendee(data: EventAttendeeInput!): User!
removeEventVolunteer(id: ID!): EventVolunteer!
removeEventVolunteerGroup(id: ID!): EventVolunteerGroup!
removeFund(id: ID!): Fund!
removeFundraisingCampaign(id: ID!): FundraisingCampaign!
removeFundraisingCampaignPledge(id: ID!): FundraisingCampaignPledge!
Expand Down Expand Up @@ -1126,6 +1148,7 @@ type Mutation {
updateCommunity(data: UpdateCommunityInput!): Boolean!
updateEvent(data: UpdateEventInput, id: ID!, recurrenceRuleData: RecurrenceRuleInput, recurringEventUpdateType: RecurringEventMutationType): Event!
updateEventVolunteer(data: UpdateEventVolunteerInput, id: ID!): EventVolunteer!
updateEventVolunteerGroup(data: UpdateEventVolunteerGroupInput, id: ID!): EventVolunteerGroup!
updateFund(data: UpdateFundInput!, id: ID!): Fund!
updateFundraisingCampaign(data: UpdateFundCampaignInput!, id: ID!): FundraisingCampaign!
updateFundraisingCampaignPledge(data: UpdateFundCampaignPledgeInput!, id: ID!): FundraisingCampaignPledge!
Expand Down Expand Up @@ -1630,6 +1653,12 @@ input UpdateEventInput {
title: String
}

input UpdateEventVolunteerGroupInput {
eventId: ID
name: String
volunteersRequired: Int
}

input UpdateEventVolunteerInput {
eventId: ID
isAssigned: Boolean
Expand Down
7 changes: 7 additions & 0 deletions src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -592,6 +592,13 @@ export const EVENT_VOLUNTEER_NOT_FOUND_ERROR = {
PARAM: "eventVolunteers",
};

export const EVENT_VOLUNTEER_GROUP_NOT_FOUND_ERROR = {
DESC: "Volunteer group not found",
CODE: "eventVolunteerGroup.notFound",
MESSAGE: "eventVolunteerGroup.notFound",
PARAM: "eventVolunteerGroup",
};

export const EVENT_VOLUNTEER_INVITE_USER_MISTMATCH = {
DESC: "Current User is not the user of Event Volunteer",
CODE: "eventVolunteer.userMismatch",
Expand Down
79 changes: 46 additions & 33 deletions src/models/Event.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,70 +2,75 @@ import type { Types, PopulatedDoc, Document, Model } from "mongoose";
import { Schema, model, models } from "mongoose";
import type { InterfaceOrganization } from "./Organization";
import type { InterfaceUser } from "./User";
import type { InterfaceRecurrenceRule } from "./RecurrenceRule";
import { createLoggingMiddleware } from "../libraries/dbLogger";
import type { InterfaceEventVolunteerGroup } from "./EventVolunteerGroup";
import type { InterfaceRecurrenceRule } from "./RecurrenceRule";
import type { InterfaceAgendaItem } from "./AgendaItem";

/**
* This is an interface representing a document for an event in the database(MongoDB).
*/
export interface InterfaceEvent {
_id: Types.ObjectId;
title: string;
description: string;
admins: PopulatedDoc<InterfaceUser & Document>[];
allDay: boolean;
attendees: string | undefined;
images: string[];
location: string | undefined;
latitude: number | undefined;
longitude: number;
recurring: boolean;
isRecurringEventException: boolean;
isBaseRecurringEvent: boolean;
recurrenceRuleId: PopulatedDoc<InterfaceRecurrenceRule & Document>;
baseRecurringEventId: PopulatedDoc<InterfaceEvent & Document>;
allDay: boolean;
startDate: string;
createdAt: Date;
creatorId: PopulatedDoc<InterfaceUser & Document>;
description: string;
endDate: string | undefined;
startTime: string | undefined;
endTime: string | undefined;
images: string[];
isBaseRecurringEvent: boolean;
isPublic: boolean;
isRecurringEventException: boolean;
isRegisterable: boolean;
creatorId: PopulatedDoc<InterfaceUser & Document>;
admins: PopulatedDoc<InterfaceUser & Document>[];
latitude: number | undefined;
location: string | undefined;
longitude: number;
organization: PopulatedDoc<InterfaceOrganization & Document>;
recurrance: string;
recurrenceRuleId: PopulatedDoc<InterfaceRecurrenceRule & Document>;
recurring: boolean;
startDate: string;
startTime: string | undefined;
status: string;
createdAt: Date;
title: string;
updatedAt: Date;
volunteerGroups: PopulatedDoc<InterfaceEventVolunteerGroup & Document>[];
agendaItems: PopulatedDoc<InterfaceAgendaItem & Document>[];
}

/**
* This is the Structure of the Event
* @param title - Title of the event
* @param description - Description of the event
* @param admins - Admins
* @param allDay - Is the event occuring all day
* @param attendees - Attendees
* @param images -Event Flyer
* @param location - Location of the event
* @param latitude - Latitude
* @param longitude - Longitude
* @param recurring - Is the event recurring
* @param isRecurringEventException - Is the event an exception to the recurring pattern it was following
* @param isBaseRecurringEvent - Is the event a true recurring event that is used for generating new instances
* @param recurrenceRuleId - Id of the recurrence rule document containing the recurrence pattern for the event
* @param baseRecurringEventId - Id of the true recurring event used for generating this instance
* @param allDay - Is the event occuring all day
* @param startDate - Start Date
* @param createdAt - Timestamp of event creation
* @param creatorId - Creator of the event
* @param description - Description of the event
* @param endDate - End date
* @param startTime - Start Time
* @param endTime - End Time
* @param images -Event Flyer
* @param isBaseRecurringEvent - Is the event a true recurring event that is used for generating new instances
* @param isPublic - Is the event public
* @param isRecurringEventException - Is the event an exception to the recurring pattern it was following
* @param isRegisterable - Is the event Registrable
* @param creatorId - Creator of the event
* @param admins - Admins
* @param latitude - Latitude
* @param location - Location of the event
* @param longitude - Longitude
* @param organization - Organization
* @param recurrance - Periodicity of recurrance of the event
* @param recurrenceRuleId - Id of the recurrence rule document containing the recurrence pattern for the event
* @param recurring - Is the event recurring
* @param startDate - Start Date
* @param startTime - Start Time
* @param status - whether the event is active, blocked, or deleted.
* @param createdAt - Timestamp of event creation
* @param title - Title of the event
* @param updatedAt - Timestamp of event updation
* @param volunteerGroups - event volunteer groups for the event
*/

const eventSchema = new Schema(
Expand Down Expand Up @@ -183,6 +188,14 @@ const eventSchema = new Schema(
enum: ["ACTIVE", "BLOCKED", "DELETED"],
default: "ACTIVE",
},
volunteerGroups: [
{
type: Schema.Types.ObjectId,
ref: "EventVolunteerGroup",
required: true,
default: [],
},
],
},
{
timestamps: true,
Expand Down
6 changes: 6 additions & 0 deletions src/models/EventVolunteer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@ import { Schema, model, models } from "mongoose";
import type { InterfaceUser } from "./User";
import type { InterfaceEvent } from "./Event";
import { createLoggingMiddleware } from "../libraries/dbLogger";
import type { InterfaceEventVolunteerGroup } from "./EventVolunteerGroup";

export interface InterfaceEventVolunteer {
_id: Types.ObjectId;
createdAt: Date;
creatorId: PopulatedDoc<InterfaceUser & Document>;
eventId: PopulatedDoc<InterfaceEvent & Document>;
groupId: PopulatedDoc<InterfaceEventVolunteerGroup & Document>;
isAssigned: boolean;
isInvited: boolean;
response: string;
Expand All @@ -27,6 +29,10 @@ const eventVolunteerSchema = new Schema(
type: Schema.Types.ObjectId,
ref: "Event",
},
groupId: {
type: Schema.Types.ObjectId,
ref: "EventVolunteerGroup",
},
response: {
type: String,
enum: ["YES", "NO", null],
Expand Down
68 changes: 68 additions & 0 deletions src/models/EventVolunteerGroup.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
import type { PopulatedDoc, Document, Model, Types } from "mongoose";
import { Schema, model, models } from "mongoose";
import type { InterfaceUser } from "./User";
import type { InterfaceEvent } from "./Event";
import { createLoggingMiddleware } from "../libraries/dbLogger";
import type { InterfaceEventVolunteer } from "./EventVolunteer";

export interface InterfaceEventVolunteerGroup {
_id: Types.ObjectId;
createdAt: Date;
creatorId: PopulatedDoc<InterfaceUser & Document>;
eventId: PopulatedDoc<InterfaceEvent & Document>;
leaderId: PopulatedDoc<InterfaceUser & Document>;
name: string;
updatedAt: Date;
volunteers: PopulatedDoc<InterfaceEventVolunteer & Document>[];
volunteersRequired?: number;
}

const eventVolunteerGroupSchema = new Schema(
{
creatorId: {
type: Schema.Types.ObjectId,
ref: "User",
required: true,
},
eventId: {
type: Schema.Types.ObjectId,
ref: "Event",
required: true,
},
leaderId: {
type: Schema.Types.ObjectId,
ref: "User",
required: true,
},
name: {
type: String,
required: true,
},
volunteers: [
{
type: Schema.Types.ObjectId,
ref: "EventVolunteer",
default: [],
},
],
volunteersRequired: {
type: Number,
},
},
{
timestamps: true,
},
);

// Enable logging on changes in EventVolunteer collection
createLoggingMiddleware(eventVolunteerGroupSchema, "EventVolunteerGroup");

const eventVolunteerGroupModel = (): Model<InterfaceEventVolunteerGroup> =>
model<InterfaceEventVolunteerGroup>(
"EventVolunteerGroup",
eventVolunteerGroupSchema,
);

// This syntax is needed to prevent Mongoose OverwriteModelError while running tests.
export const EventVolunteerGroup = (models.EventVolunteerGroup ||
eventVolunteerGroupModel()) as ReturnType<typeof eventVolunteerGroupModel>;
1 change: 1 addition & 0 deletions src/models/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export * from "./Donation";
export * from "./Event";
export * from "./EventAttendee";
export * from "./EventVolunteer";
export * from "./EventVolunteerGroup";
export * from "./Feedback";
export * from "./File";
export * from "./Fund";
Expand Down
8 changes: 8 additions & 0 deletions src/resolvers/EventVolunteer/group.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { EventVolunteerGroup } from "../../models";
import type { EventVolunteerResolvers } from "../../types/generatedGraphQLTypes";

export const group: EventVolunteerResolvers["group"] = async (parent) => {
return await EventVolunteerGroup.findOne({
_id: parent.groupId,
}).lean();
};
2 changes: 2 additions & 0 deletions src/resolvers/EventVolunteer/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@ import type { EventVolunteerResolvers } from "../../types/generatedGraphQLTypes"
import { event } from "./event";
import { creator } from "./creator";
import { user } from "./user";
import { group } from "./group";

export const EventVolunteer: EventVolunteerResolvers = {
creator,
event,
group,
user,
};
10 changes: 10 additions & 0 deletions src/resolvers/EventVolunteerGroup/creator.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { User } from "../../models";
import type { EventVolunteerGroupResolvers } from "../../types/generatedGraphQLTypes";

export const creator: EventVolunteerGroupResolvers["creator"] = async (
parent,
) => {
return await User.findOne({
_id: parent.creatorId,
}).lean();
};
8 changes: 8 additions & 0 deletions src/resolvers/EventVolunteerGroup/event.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { Event } from "../../models";
import type { EventVolunteerGroupResolvers } from "../../types/generatedGraphQLTypes";

export const event: EventVolunteerGroupResolvers["event"] = async (parent) => {
return await Event.findOne({
_id: parent.eventId,
}).lean();
};
10 changes: 10 additions & 0 deletions src/resolvers/EventVolunteerGroup/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import type { EventVolunteerGroupResolvers } from "../../types/generatedGraphQLTypes";
import { leader } from "./leader";
import { creator } from "./creator";
import { event } from "./event";

export const EventVolunteerGroup: EventVolunteerGroupResolvers = {
creator,
leader,
event,
};
12 changes: 12 additions & 0 deletions src/resolvers/EventVolunteerGroup/leader.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { User } from "../../models";
import type { InterfaceUser } from "../../models";
import type { EventVolunteerGroupResolvers } from "../../types/generatedGraphQLTypes";

export const leader: EventVolunteerGroupResolvers["leader"] = async (
parent,
) => {
const groupLeader = await User.findOne({
_id: parent.leaderId,
}).lean();
return groupLeader as InterfaceUser;
};
Loading

0 comments on commit 203314e

Please sign in to comment.