Skip to content

Commit

Permalink
Merge pull request #40 from uwblueprint/INTF23-fetchApplicationById
Browse files Browse the repository at this point in the history
[INTF23] API implementation for fetching application by reviewID
  • Loading branch information
HeetShah authored Nov 10, 2023
2 parents ee9594e + 18dd800 commit f7580fd
Show file tree
Hide file tree
Showing 7 changed files with 61 additions and 1 deletion.
1 change: 1 addition & 0 deletions backend/typescript/graphql/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ const graphQLMiddlewares = {
simpleEntities: authorizedByAllRoles(),
dashboardById: authorizedByAllRoles(),
applicationsByRole: authorizedByAllRoles(),
applicationsById: authorizedByAllRoles(),
applicationTable: authorizedByAllRoles(),
userById: authorizedByAdmin(),
userByEmail: authorizedByAdmin(),
Expand Down
8 changes: 8 additions & 0 deletions backend/typescript/graphql/resolvers/dashboardResolvers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,14 @@ const dashboardResolvers = {
firstChoice,
);
return applications;
},applicationsById: async (

Check failure on line 29 in backend/typescript/graphql/resolvers/dashboardResolvers.ts

View workflow job for this annotation

GitHub Actions / run-lint

Insert `⏎····`
_parent: undefined,
{ id }: { id: number },
): Promise<ApplicationDTO> => {
const application = await dashboardService.getApplicationsById(

Check failure on line 33 in backend/typescript/graphql/resolvers/dashboardResolvers.ts

View workflow job for this annotation

GitHub Actions / run-lint

Replace `⏎········id,⏎······` with `id`
id,
);
return application;
},
dashboardsByApplicationId: async (
_parent: undefined,
Expand Down
1 change: 1 addition & 0 deletions backend/typescript/graphql/types/dashboardType.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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]!
}
Expand Down
2 changes: 1 addition & 1 deletion backend/typescript/migrations/applicationlist.json
Original file line number Diff line number Diff line change
Expand Up @@ -134,4 +134,4 @@
"timesApplied": "This is my first time!",
"timestamp": 1688143336170
}
]
]
48 changes: 48 additions & 0 deletions backend/typescript/services/implementations/appDashboardService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<ApplicationDTO> {
let applications: Array<Application> | 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<ApplicationDashboardDTO[]> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
interface IAppDashboardService {
getDashboardById(id: number): Promise<ApplicationDashboardDTO>;
getApplicationsByRole(role: string): Promise<ApplicationDTO[]>;
getApplicationsById(id: number): Promise<ApplicationDTO>;
getDashboardsByApplicationId(
applicationId: number,
): Promise<ApplicationDashboardDTO[]>;
Expand Down
1 change: 1 addition & 0 deletions backend/typescript/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ export type ApplicationDTO = {
term: string;
timesApplied: string;
timestamp: bigint;

};

export type ApplicationDashboardRowDTO = {
Expand Down

0 comments on commit f7580fd

Please sign in to comment.