diff --git a/backend/typescript/graphql/index.ts b/backend/typescript/graphql/index.ts index ad2b1b4..a924a62 100644 --- a/backend/typescript/graphql/index.ts +++ b/backend/typescript/graphql/index.ts @@ -63,6 +63,7 @@ const graphQLMiddlewares = { simpleEntities: authorizedByAllRoles(), dashboardById: authorizedByAllRoles(), applicationsByRole: authorizedByAllRoles(), + applicationsById: authorizedByAllRoles(), applicationTable: authorizedByAllRoles(), userById: authorizedByAdmin(), userByEmail: authorizedByAdmin(), diff --git a/backend/typescript/graphql/resolvers/dashboardResolvers.ts b/backend/typescript/graphql/resolvers/dashboardResolvers.ts index 620d3b8..2f0dad3 100644 --- a/backend/typescript/graphql/resolvers/dashboardResolvers.ts +++ b/backend/typescript/graphql/resolvers/dashboardResolvers.ts @@ -26,6 +26,14 @@ const dashboardResolvers = { firstChoice, ); return applications; + },applicationsById: async ( + _parent: undefined, + { id }: { id: number }, + ): Promise => { + const application = await dashboardService.getApplicationsById( + id, + ); + return application; }, dashboardsByApplicationId: async ( _parent: undefined, diff --git a/backend/typescript/graphql/types/dashboardType.ts b/backend/typescript/graphql/types/dashboardType.ts index 19fb22c..05749bd 100644 --- a/backend/typescript/graphql/types/dashboardType.ts +++ b/backend/typescript/graphql/types/dashboardType.ts @@ -59,6 +59,7 @@ const dashboardType = gql` extend type Query { dashboardById(id: Int!): ApplicationDashboardDTO! applicationsByRole(firstChoice: String!): [ApplicationDTO]! + applicationsById(id: Int!): ApplicationDTO! dashboardsByApplicationId(applicationId: Int!): [ApplicationDashboardDTO]! applicationTable(role: String!): [ApplicationDashboardRowDTO]! } diff --git a/backend/typescript/migrations/applicationlist.json b/backend/typescript/migrations/applicationlist.json index a24d6ef..bc8a3e6 100644 --- a/backend/typescript/migrations/applicationlist.json +++ b/backend/typescript/migrations/applicationlist.json @@ -134,4 +134,4 @@ "timesApplied": "This is my first time!", "timestamp": 1688143336170 } -] \ No newline at end of file +] diff --git a/backend/typescript/services/implementations/appDashboardService.ts b/backend/typescript/services/implementations/appDashboardService.ts index 967a492..68ce803 100644 --- a/backend/typescript/services/implementations/appDashboardService.ts +++ b/backend/typescript/services/implementations/appDashboardService.ts @@ -99,6 +99,54 @@ class AppDashboardService implements IAppDashboardService { return applicationsByRoleDTO; } +//Takes in an application id and returns an array of applicants with same id +async getApplicationsById(id: number): Promise { + let applications: Array | null; + let applicationById: Application |undefined; + let applicationByIdDTO: ApplicationDTO; + try { + applications = await Application.findAll(); + applicationById = applications.find(application => application.id == id); + + if (applicationById === undefined) { + // Handle the case when no application is found + throw new Error(`Application with id ${id} not found`); + } + + applicationByIdDTO = { + id: applicationById.id, + academicOrCoop: applicationById.academicOrCoop, + academicYear: applicationById.academicYear, + email: applicationById.email, + firstChoiceRole: applicationById.firstChoiceRole, + firstName: applicationById.firstName, + heardFrom: applicationById.heardFrom, + lastName: applicationById.lastName, + locationPreference: applicationById.locationPreference, + program: applicationById.program, + pronouns: applicationById.pronouns, + pronounsSpecified: applicationById.pronounsSpecified, + resumeUrl: applicationById.resumeUrl, + roleSpecificQuestions: applicationById.roleSpecificQuestions, + secondChoiceRole: applicationById.secondChoiceRole, + shortAnswerQuestions: applicationById.shortAnswerQuestions, + secondChoiceStatus: applicationById.secondChoiceStatus, + status: applicationById.status, + term: applicationById.term, + timesApplied: applicationById.timesApplied, + timestamp: applicationById.timestamp + }; + } catch (error: unknown) { + Logger.error( + `Failed to get applications by id = ${id}. Reason = ${getErrorMessage( + error, + )}`, + ); + throw error; + } + return applicationByIdDTO; + } + async getDashboardsByApplicationId( applicationId: number, ): Promise { diff --git a/backend/typescript/services/interfaces/appDashboardService.ts b/backend/typescript/services/interfaces/appDashboardService.ts index f0a347b..74444bd 100644 --- a/backend/typescript/services/interfaces/appDashboardService.ts +++ b/backend/typescript/services/interfaces/appDashboardService.ts @@ -7,6 +7,7 @@ import { interface IAppDashboardService { getDashboardById(id: number): Promise; getApplicationsByRole(role: string): Promise; + getApplicationsById(id: number): Promise; getDashboardsByApplicationId( applicationId: number, ): Promise; diff --git a/backend/typescript/types.ts b/backend/typescript/types.ts index 6b2202f..da9a844 100644 --- a/backend/typescript/types.ts +++ b/backend/typescript/types.ts @@ -74,6 +74,7 @@ export type ApplicationDTO = { term: string; timesApplied: string; timestamp: bigint; + }; export type ApplicationDashboardRowDTO = {