Skip to content

Commit

Permalink
📝 docs(): add comments for helper function
Browse files Browse the repository at this point in the history
resolve #7, reslove #4
  • Loading branch information
112523chen committed Jun 17, 2023
1 parent 96143b7 commit 6688332
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 38 deletions.
37 changes: 23 additions & 14 deletions client/src/components/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,32 @@
* @type {string}
*/
export type applicationStatusType =
| "Created"
| "Applied"
| "Assessment"
| "Interview"
| "Final Round"
| "Reject"
| "Offer";
| "created"
| "applied"
| "assessment"
| "interview"
| "final_round"
| "reject"
| "offer";

/**
* Types of application statuses for filtering application
* @type {string}
*/
export type applicationStatusFilterType = applicationStatusType | "all";

/**
* Types of application status in views
* @type {string[]}
*/
export const applicationStatuses: string[] = [
"Created",
"Applied",
"Assessment",
"Interview",
"Final Round",
"Reject",
"Offer",
"created",
"applied",
"assessment",
"interview",
"final_round",
"reject",
"offer",
];

export interface application {
Expand All @@ -41,6 +47,9 @@ export interface MainPageStates {
pathname: string;
isInAddView: boolean;
setIsInAddView: React.Dispatch<React.SetStateAction<boolean>>;
updateCurrentStatusFilter: (
event: React.ChangeEvent<HTMLSelectElement>
) => void;
}

export interface newFormData {
Expand Down
37 changes: 27 additions & 10 deletions client/src/helper/api/functions.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,29 @@
import axios from "axios";
import {
application,
applicationStatusType,
barChartDataType,
newFormData,
} from "../../components/model";
import { TimeFrame } from "../models";
import { applicationStatusFilterType } from "../../components/model";

/**
* @returns all application data from database
*/
export const getApplicationData = async (): Promise<application[]> => {
const response = await fetch(
"http://localhost:3000/applications/sorted/created/DESC"
);
export const getApplicationData = async (
status: applicationStatusFilterType
): Promise<application[]> => {
let url: string;

if (status == "all") {
url = "http://localhost:3000/applications/sorted/created/DESC";
} else {
url = `http://localhost:3000/applications/sorted/created/DESC/${status}`;
}

const response = await fetch(url);

let applications = (await response.json()) as application[];
return applications;
};
Expand All @@ -21,12 +32,18 @@ export const getApplicationData = async (): Promise<application[]> => {
*
* @returns all application data from database sorted by when application was last modified in descending order
*/
export const getApplicationDataByModifiedDate = async (): Promise<
application[]
> => {
const response = await fetch(
"http://localhost:3000/applications/sorted/modified/DESC"
);
export const getApplicationDataByModifiedDate = async (
status: applicationStatusFilterType
): Promise<application[]> => {
let url: string;

if (status == "all") {
url = "http://localhost:3000/applications/sorted/created/DESC";
} else {
url = `http://localhost:3000/applications/sorted/created/DESC/${status}`;
}

const response = await fetch(url);
let applications = (await response.json()) as application[];
return applications;
};
Expand Down
14 changes: 7 additions & 7 deletions client/src/helper/main/functions.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,24 +57,24 @@ describe("getFormValue", () => {

describe("getApplicationColor Tests", () => {
test("should return grey", () => {
expect(getApplicationColor("Created")).toBe("grey");
expect(getApplicationColor("created")).toBe("grey");
});
test("should return silver", () => {
expect(getApplicationColor("Applied")).toBe("silver");
expect(getApplicationColor("applied")).toBe("silver");
});
test("should return yellow", () => {
expect(getApplicationColor("Assessment")).toBe("yellow");
expect(getApplicationColor("assessment")).toBe("yellow");
});
test("should return orange", () => {
expect(getApplicationColor("Interview")).toBe("orange");
expect(getApplicationColor("interview")).toBe("orange");
});
test("should return blue", () => {
expect(getApplicationColor("Final Round")).toBe("blue");
expect(getApplicationColor("final_round")).toBe("blue");
});
test("should return red", () => {
expect(getApplicationColor("Reject")).toBe("red");
expect(getApplicationColor("reject")).toBe("red");
});
test("should return green", () => {
expect(getApplicationColor("Offer")).toBe("green");
expect(getApplicationColor("offer")).toBe("green");
});
});
14 changes: 7 additions & 7 deletions client/src/helper/main/functions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,25 +8,25 @@ import { addViewFormData, applicationStatusType } from "../../components/model";
export const getApplicationColor = (status: applicationStatusType): string => {
let color: string;
switch (status) {
case "Created":
case "created":
color = "grey";
break;
case "Applied":
case "applied":
color = "silver";
break;
case "Assessment":
case "assessment":
color = "yellow";
break;
case "Interview":
case "interview":
color = "orange";
break;
case "Final Round":
case "final_round":
color = "blue";
break;
case "Reject":
case "reject":
color = "red";
break;
case "Offer":
case "offer":
color = "green";
break;
}
Expand Down

0 comments on commit 6688332

Please sign in to comment.