Skip to content

Commit

Permalink
Merge branch 'develop' of https://github.com/chandel-aman/talawa-api
Browse files Browse the repository at this point in the history
…into feature/feed-file-upload
  • Loading branch information
chandel-aman committed Nov 3, 2024
2 parents 63dc643 + e22122f commit 98ce5a1
Show file tree
Hide file tree
Showing 20 changed files with 431 additions and 39 deletions.
1 change: 0 additions & 1 deletion config/vitestSetup.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
// FAIL LOUDLY on unhandled promise rejections / errors
process.on("unhandledRejection", (reason) => {
// eslint-disable-next-line no-console
console.log("FAILED TO HANDLE PROMISE REJECTION");
throw reason;
});
Expand Down
3 changes: 3 additions & 0 deletions schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -1551,6 +1551,7 @@ type Query {
customDataByOrganization(organizationId: ID!): [UserCustomData!]!
customFieldsByOrganization(id: ID!): [OrganizationCustomField]
event(id: ID!): Event
eventsAttendedByUser(id: ID, orderBy: EventOrderByInput): [Event]
eventsByOrganization(id: ID, orderBy: EventOrderByInput): [Event]
eventsByOrganizationConnection(first: Int, orderBy: EventOrderByInput, skip: Int, upcomingOnly: Boolean, where: EventWhereInput): [Event!]!
fundsByOrganization(orderBy: FundOrderByInput, organizationId: ID!, where: FundWhereInput): [Fund]
Expand All @@ -1573,6 +1574,7 @@ type Query {
getNoteById(id: ID!): Note!
getPledgesByUserId(orderBy: PledgeOrderByInput, userId: ID!, where: PledgeWhereInput): [FundraisingCampaignPledge]
getPlugins: [Plugin]
getRecurringEvents(baseRecurringEventId: ID!): [Event]
getUserTag(id: ID!): UserTag
getVenueByOrgId(first: Int, orderBy: VenueOrderByInput, orgId: ID!, skip: Int, where: VenueWhereInput): [Venue]
getVolunteerMembership(orderBy: VolunteerMembershipOrderByInput, where: VolunteerMembershipWhereInput!): [VolunteerMembership]!
Expand Down Expand Up @@ -1881,6 +1883,7 @@ type User {
email: EmailAddress!
employmentStatus: EmploymentStatus
eventAdmin: [Event]
eventsAttended: [Event]
file: File
firstName: String!
gender: Gender
Expand Down
8 changes: 8 additions & 0 deletions src/models/User.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ export interface InterfaceUser {
mobile: string;
work: string;
};
eventsAttended: PopulatedDoc<InterfaceEvent & Document>[];

registeredEvents: PopulatedDoc<InterfaceEvent & Document>[];
status: string;
Expand Down Expand Up @@ -77,6 +78,7 @@ export interface InterfaceUser {
* @param phone - User's contact numbers (home, mobile, work).
* @param registeredEvents - Events the user has registered for.
* @param status - User's status (ACTIVE, BLOCKED, DELETED).
* @param eventsAttended - Events the user has attended.
* @param updatedAt - Timestamp of when the user was last updated.
*/
const userSchema = new Schema(
Expand Down Expand Up @@ -220,6 +222,12 @@ const userSchema = new Schema(
ref: "Event",
},
],
eventsAttended: [
{
type: Schema.Types.ObjectId,
ref: "Event",
},
],
status: {
type: String,
required: true,
Expand Down
20 changes: 19 additions & 1 deletion src/resolvers/Mutation/addEventAttendee.ts
Original file line number Diff line number Diff line change
Expand Up @@ -172,5 +172,23 @@ export const addEventAttendee: MutationResolvers["addEventAttendee"] = async (

await EventAttendee.create({ ...args.data });

return requestUser;
const updatedUser = await User.findByIdAndUpdate(
args.data.userId,
{
$push: {
eventsAttended: args.data.eventId,
},
},
{ new: true },
);

if (updatedUser === null) {
throw new errors.UnauthorizedError(
requestContext.translate(USER_NOT_AUTHORIZED_ERROR.MESSAGE),
USER_NOT_AUTHORIZED_ERROR.CODE,
USER_NOT_AUTHORIZED_ERROR.PARAM,
);
}

return updatedUser;
};
2 changes: 1 addition & 1 deletion src/resolvers/Mutation/updateAgendaCategory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ export const updateAgendaCategory: MutationResolvers["updateAgendaCategory"] =
{
$set: {
updatedBy: context.userId,
// eslint-disable-next-line

...(args.input as UpdateAgendaCategoryInput),
},
},
Expand Down
28 changes: 28 additions & 0 deletions src/resolvers/Query/eventsAttendedByUser.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import type { QueryResolvers } from "../../types/generatedGraphQLTypes";
import { Event } from "../../models";
import { getSort } from "./helperFunctions/getSort";

/**
* This query will fetch all the events for which user attended from the database.
* @param _parent-
* @param args - An object that contains `id` of the user and `orderBy`.
* @returns An object that contains the Event data.
* @remarks The query function uses `getSort()` function to sort the data in specified.
*/
export const eventsAttendedByUser: QueryResolvers["eventsAttendedByUser"] =
async (_parent, args) => {
const sort = getSort(args.orderBy);

return await Event.find({
registrants: {
$elemMatch: {
userId: args.id,
status: "ACTIVE",
},
},
})
.sort(sort)
.populate("creatorId", "-password")
.populate("admins", "-password")
.lean();
};
25 changes: 25 additions & 0 deletions src/resolvers/Query/getRecurringEvents.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import type { QueryResolvers } from "../../types/generatedGraphQLTypes";
import { Event } from "../../models";
import type { InterfaceEvent } from "../../models/Event";
/**
* This query will fetch all the events with the same BaseRecurringEventId from the database.
* @param _parent -
* @param args - An object that contains `baseRecurringEventId` of the base recurring event.
* @returns An array of `Event` objects that are instances of the base recurring event.
*/

export const getRecurringEvents: QueryResolvers["getRecurringEvents"] = async (
_parent,
args,
) => {
try {
const recurringEvents = await Event.find({
baseRecurringEventId: args.baseRecurringEventId,
}).lean();

return recurringEvents as InterfaceEvent[];
} catch (error) {
console.error("Error fetching recurring events:", error);
throw error;
}
};
5 changes: 5 additions & 0 deletions src/resolvers/Query/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,11 @@ import { getEventAttendeesByEventId } from "./getEventAttendeesByEventId";
import { getVenueByOrgId } from "./getVenueByOrgId";
import { getAllNotesForAgendaItem } from "./getAllNotesForAgendaItem";
import { getNoteById } from "./getNoteById";
import { eventsAttendedByUser } from "./eventsAttendedByUser";
import { getRecurringEvents } from "./getRecurringEvents";
import { getVolunteerMembership } from "./getVolunteerMembership";
import { getVolunteerRanks } from "./getVolunteerRanks";

export const Query: QueryResolvers = {
actionItemsByEvent,
actionItemsByUser,
Expand Down Expand Up @@ -85,6 +88,7 @@ export const Query: QueryResolvers = {
getNoteById,
getlanguage,
getPlugins,
getRecurringEvents,
getUserTag,
isSampleOrganization,
me,
Expand All @@ -106,6 +110,7 @@ export const Query: QueryResolvers = {
getEventAttendee,
getEventAttendeesByEventId,
getVenueByOrgId,
eventsAttendedByUser,
getVolunteerMembership,
getVolunteerRanks,
};
2 changes: 2 additions & 0 deletions src/resolvers/Query/organizationsMemberConnection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ export const organizationsMemberConnection: QueryResolvers["organizationsMemberC
registeredEvents: user.registeredEvents,
status: user.status,
updatedAt: user.updatedAt,
eventsAttended: user.eventsAttended,
}));
} else {
users = usersModel.docs.map((user) => ({
Expand Down Expand Up @@ -175,6 +176,7 @@ export const organizationsMemberConnection: QueryResolvers["organizationsMemberC
registeredEvents: user.registeredEvents,
status: user.status,
updatedAt: user.updatedAt,
eventsAttended: user.eventsAttended,
}));
}

Expand Down
1 change: 0 additions & 1 deletion src/setup/superAdmin.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* eslint-disable @typescript-eslint/explicit-function-return-type */
import inquirer from "inquirer";
import { isValidEmail } from "./isValidEmail";

Expand Down
4 changes: 4 additions & 0 deletions src/typeDefs/queries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,8 @@ export const queries = gql`
getAllNotesForAgendaItem(agendaItemId: ID!): [Note]
getRecurringEvents(baseRecurringEventId: ID!): [Event]
advertisementsConnection(
after: String
before: String
Expand Down Expand Up @@ -213,5 +215,7 @@ export const queries = gql`
): [UserData]! @auth
venue(id: ID!): Venue
eventsAttendedByUser(id: ID, orderBy: EventOrderByInput): [Event]
}
`;
1 change: 1 addition & 0 deletions src/typeDefs/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -659,6 +659,7 @@ export const types = gql`
phone: UserPhone
membershipRequests: [MembershipRequest]
registeredEvents: [Event]
eventsAttended: [Event]
pluginCreationAllowed: Boolean!
tagsAssignedWith(
after: String
Expand Down
17 changes: 17 additions & 0 deletions src/types/generatedGraphQLTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2320,6 +2320,7 @@ export type Query = {
customDataByOrganization: Array<UserCustomData>;
customFieldsByOrganization?: Maybe<Array<Maybe<OrganizationCustomField>>>;
event?: Maybe<Event>;
eventsAttendedByUser?: Maybe<Array<Maybe<Event>>>;
eventsByOrganization?: Maybe<Array<Maybe<Event>>>;
eventsByOrganizationConnection: Array<Event>;
fundsByOrganization?: Maybe<Array<Maybe<Fund>>>;
Expand All @@ -2342,6 +2343,7 @@ export type Query = {
getNoteById: Note;
getPledgesByUserId?: Maybe<Array<Maybe<FundraisingCampaignPledge>>>;
getPlugins?: Maybe<Array<Maybe<Plugin>>>;
getRecurringEvents?: Maybe<Array<Maybe<Event>>>;
getUserTag?: Maybe<UserTag>;
getVenueByOrgId?: Maybe<Array<Maybe<Venue>>>;
getVolunteerMembership: Array<Maybe<VolunteerMembership>>;
Expand Down Expand Up @@ -2452,6 +2454,12 @@ export type QueryEventArgs = {
};


export type QueryEventsAttendedByUserArgs = {
id?: InputMaybe<Scalars['ID']['input']>;
orderBy?: InputMaybe<EventOrderByInput>;
};


export type QueryEventsByOrganizationArgs = {
id?: InputMaybe<Scalars['ID']['input']>;
orderBy?: InputMaybe<EventOrderByInput>;
Expand Down Expand Up @@ -2566,6 +2574,11 @@ export type QueryGetPledgesByUserIdArgs = {
};


export type QueryGetRecurringEventsArgs = {
baseRecurringEventId: Scalars['ID']['input'];
};


export type QueryGetUserTagArgs = {
id: Scalars['ID']['input'];
};
Expand Down Expand Up @@ -2976,6 +2989,7 @@ export type User = {
email: Scalars['EmailAddress']['output'];
employmentStatus?: Maybe<EmploymentStatus>;
eventAdmin?: Maybe<Array<Maybe<Event>>>;
eventsAttended?: Maybe<Array<Maybe<Event>>>;
file?: Maybe<File>;
firstName: Scalars['String']['output'];
gender?: Maybe<Gender>;
Expand Down Expand Up @@ -4764,6 +4778,7 @@ export type QueryResolvers<ContextType = any, ParentType extends ResolversParent
customDataByOrganization?: Resolver<Array<ResolversTypes['UserCustomData']>, ParentType, ContextType, RequireFields<QueryCustomDataByOrganizationArgs, 'organizationId'>>;
customFieldsByOrganization?: Resolver<Maybe<Array<Maybe<ResolversTypes['OrganizationCustomField']>>>, ParentType, ContextType, RequireFields<QueryCustomFieldsByOrganizationArgs, 'id'>>;
event?: Resolver<Maybe<ResolversTypes['Event']>, ParentType, ContextType, RequireFields<QueryEventArgs, 'id'>>;
eventsAttendedByUser?: Resolver<Maybe<Array<Maybe<ResolversTypes['Event']>>>, ParentType, ContextType, Partial<QueryEventsAttendedByUserArgs>>;
eventsByOrganization?: Resolver<Maybe<Array<Maybe<ResolversTypes['Event']>>>, ParentType, ContextType, Partial<QueryEventsByOrganizationArgs>>;
eventsByOrganizationConnection?: Resolver<Array<ResolversTypes['Event']>, ParentType, ContextType, Partial<QueryEventsByOrganizationConnectionArgs>>;
fundsByOrganization?: Resolver<Maybe<Array<Maybe<ResolversTypes['Fund']>>>, ParentType, ContextType, RequireFields<QueryFundsByOrganizationArgs, 'organizationId'>>;
Expand All @@ -4786,6 +4801,7 @@ export type QueryResolvers<ContextType = any, ParentType extends ResolversParent
getNoteById?: Resolver<ResolversTypes['Note'], ParentType, ContextType, RequireFields<QueryGetNoteByIdArgs, 'id'>>;
getPledgesByUserId?: Resolver<Maybe<Array<Maybe<ResolversTypes['FundraisingCampaignPledge']>>>, ParentType, ContextType, RequireFields<QueryGetPledgesByUserIdArgs, 'userId'>>;
getPlugins?: Resolver<Maybe<Array<Maybe<ResolversTypes['Plugin']>>>, ParentType, ContextType>;
getRecurringEvents?: Resolver<Maybe<Array<Maybe<ResolversTypes['Event']>>>, ParentType, ContextType, RequireFields<QueryGetRecurringEventsArgs, 'baseRecurringEventId'>>;
getUserTag?: Resolver<Maybe<ResolversTypes['UserTag']>, ParentType, ContextType, RequireFields<QueryGetUserTagArgs, 'id'>>;
getVenueByOrgId?: Resolver<Maybe<Array<Maybe<ResolversTypes['Venue']>>>, ParentType, ContextType, RequireFields<QueryGetVenueByOrgIdArgs, 'orgId'>>;
getVolunteerMembership?: Resolver<Array<Maybe<ResolversTypes['VolunteerMembership']>>, ParentType, ContextType, RequireFields<QueryGetVolunteerMembershipArgs, 'where'>>;
Expand Down Expand Up @@ -4887,6 +4903,7 @@ export type UserResolvers<ContextType = any, ParentType extends ResolversParentT
email?: Resolver<ResolversTypes['EmailAddress'], ParentType, ContextType>;
employmentStatus?: Resolver<Maybe<ResolversTypes['EmploymentStatus']>, ParentType, ContextType>;
eventAdmin?: Resolver<Maybe<Array<Maybe<ResolversTypes['Event']>>>, ParentType, ContextType>;
eventsAttended?: Resolver<Maybe<Array<Maybe<ResolversTypes['Event']>>>, ParentType, ContextType>;
file?: Resolver<Maybe<ResolversTypes['File']>, ParentType, ContextType>;
firstName?: Resolver<ResolversTypes['String'], ParentType, ContextType>;
gender?: Resolver<Maybe<ResolversTypes['Gender']>, ParentType, ContextType>;
Expand Down
4 changes: 2 additions & 2 deletions tests/helpers/userAndOrg.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import type {
import { AppUserProfile, Organization, User } from "../../src/models";

export type TestOrganizationType =
// eslint-disable-next-line @typescript-eslint/no-explicit-any
(InterfaceOrganization & Document<any, any, InterfaceOrganization>) | null;
| (InterfaceOrganization & Document<any, any, InterfaceOrganization>)
| null;

export type TestUserType =
| (InterfaceUser & Document<any, any, InterfaceUser>)
Expand Down
Loading

0 comments on commit 98ce5a1

Please sign in to comment.