Skip to content

Commit

Permalink
CHE-189 Code clean up for linter
Browse files Browse the repository at this point in the history
  • Loading branch information
brok3turtl3 committed Jun 8, 2024
1 parent 9a4c998 commit fc44442
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 49 deletions.
53 changes: 24 additions & 29 deletions client/src/pages/UpdateApplicationPage/UpdateApplicationPage.tsx
Original file line number Diff line number Diff line change
@@ -1,57 +1,54 @@
import React, { useState, useEffect } from "react";
import { useNavigate, useParams } from "react-router-dom";
import axios from "axios";
import { useAppSelector, useAppDispatch } from "../../app/hooks";
import { updateApplication } from "../../features/applications/applicationSlice";
import { IApplicationFormData, IStatus } from "../../../types/applications";
import React, { useState, useEffect } from 'react';
import { useNavigate, useParams } from 'react-router-dom';
import axios from 'axios';
import { useAppSelector, useAppDispatch } from '../../app/hooks';
import { updateApplication } from '../../features/applications/applicationSlice';
import { IApplicationFormData, IStatus } from '../../../types/applications';

const UpdateApplicationPage = (): JSX.Element => {
const { id } = useParams<{ id: string }>();
console.log("id:", id);
console.log('id:', id);
const user = useAppSelector((state) => state.user.userData);
const { application, status, error } = useAppSelector(
(state) => state.application
);
const { status } = useAppSelector((state) => state.application);
const dispatch = useAppDispatch();
const navigate = useNavigate();

const [statuses, setStatuses] = useState<IStatus[]>([]);
const [formData, setFormData] = useState<IApplicationFormData>({
title: "",
company: "",
location: "",
description: "",
url: "",
title: '',
company: '',
location: '',
description: '',
url: '',
status_id: 1,
user_id: user?._id || "",
user_id: user?._id || '',
quick_apply: false,
date_applied: new Date().toISOString().split("T")[0],
general_notes: "",
date_applied: new Date().toISOString().split('T')[0],
general_notes: '',
job_id: 0,
});

useEffect(() => {
async function fetchStatuses() {
try {
const response = await axios.get("/api/applications/statuses");
const response = await axios.get('/api/applications/statuses');
setStatuses(response.data);
} catch (error) {
console.error("Error fetching statuses:", error);
console.error('Error fetching statuses:', error);
}
}

async function fetchApplication() {
try {
console.log("HITTT!!!!!");
const response = await axios.get(`/api/applications/${id}`);
const applicationData = response.data;
applicationData.date_applied = new Date(applicationData.date_applied)
.toISOString()
.split("T")[0];
.split('T')[0];

setFormData(applicationData);
} catch (error) {
console.error("Error fetching application:", error);
console.error('Error fetching application:', error);
}
}

Expand All @@ -62,16 +59,14 @@ const UpdateApplicationPage = (): JSX.Element => {
const handleSubmit = (e: React.FormEvent) => {
e.preventDefault();
dispatch(updateApplication({ id: Number(id), ...formData }));
navigate("/app/applications");
navigate('/app/applications');
};

const handleChange = (
e: React.ChangeEvent<
HTMLInputElement | HTMLSelectElement | HTMLTextAreaElement
>
e: React.ChangeEvent<HTMLInputElement | HTMLSelectElement | HTMLTextAreaElement>,
) => {
const { name, value, type } = e.target;
if (type === "checkbox") {
if (type === 'checkbox') {
const checked = (e.target as HTMLInputElement).checked;
setFormData((prevFormData) => ({
...prevFormData,
Expand Down Expand Up @@ -204,7 +199,7 @@ const UpdateApplicationPage = (): JSX.Element => {
className="bg-blue-500 hover:bg-blue-700 text-white font-bold py-2 px-4 rounded focus:outline-none focus:shadow-outline"
type="submit"
>
{status === "updating" ? "Updating..." : "Update Application"}
{status === 'updating' ? 'Updating...' : 'Update Application'}
</button>
</form>
</div>
Expand Down
28 changes: 8 additions & 20 deletions server/controllers/applicationsController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ interface StatusCount {
count: string;
}

const getAllApplications = async (req: Request, res: Response, next: NextFunction) => {
const getAllApplications = async (req: Request, res: Response) => {
try {
const userId = req.query.user_id;

Expand Down Expand Up @@ -37,7 +37,7 @@ const getAllApplications = async (req: Request, res: Response, next: NextFunctio
}
};

const getStatuses = async (req: Request, res: Response, next: NextFunction) => {
const getStatuses = async (req: Request, res: Response) => {
try {
const { rows } = await pool.query('SELECT * FROM statuses');
res.json(rows);
Expand All @@ -47,7 +47,7 @@ const getStatuses = async (req: Request, res: Response, next: NextFunction) => {
}
};

const createApplication = async (req: Request, res: Response, next: NextFunction) => {
const createApplication = async (req: Request, res: Response) => {
try {
const {
title,
Expand Down Expand Up @@ -93,11 +93,7 @@ const createApplication = async (req: Request, res: Response, next: NextFunction
}
};

const getApplicationById = async (
req: CustomRequest<{ id: string }>,
res: Response,
next: NextFunction,
) => {
const getApplicationById = async (req: CustomRequest<{ id: string }>, res: Response) => {
const { id } = req.params;
try {
const query = `
Expand Down Expand Up @@ -138,11 +134,7 @@ const getApplicationById = async (
}
};

const updateApplication = async (
req: CustomRequest<{ id: string }>,
res: Response,
next: NextFunction,
) => {
const updateApplication = async (req: CustomRequest<{ id: string }>, res: Response) => {
const { id } = req.params;

if (!req.user) {
Expand Down Expand Up @@ -181,11 +173,7 @@ const updateApplication = async (
}
};

const getAggregatedUserStats = async (
req: CustomRequest<{ userId: string }>,
res: Response,
next: NextFunction,
) => {
const getAggregatedUserStats = async (req: CustomRequest<{ userId: string }>, res: Response) => {
const { userId } = req.params;
if (!req.user || req.user.id !== userId)
return res.status(401).json({ message: 'You are not authorized to retrieve those records' });
Expand Down Expand Up @@ -216,7 +204,7 @@ const getAggregatedUserStats = async (
}
};

const updateNotificationPeriod = async (req: Request, res: Response, next: NextFunction) => {
const updateNotificationPeriod = async (req: Request, res: Response) => {
try {
const { id } = req.params;
const { period } = req.body;
Expand All @@ -234,7 +222,7 @@ const updateNotificationPeriod = async (req: Request, res: Response, next: NextF
}
};

const pauseNotifications = async (req: Request, res: Response, next: NextFunction) => {
const pauseNotifications = async (req: Request, res: Response) => {
try {
const { id } = req.params;
const { pause } = req.body;
Expand Down

0 comments on commit fc44442

Please sign in to comment.