-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'dev' into CHE-113/story/Profiles-Improvements
- Loading branch information
Showing
60 changed files
with
1,438 additions
and
835 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
-- DROP EXISTING TABLES | ||
DROP TABLE IF EXISTS follow_ups; | ||
DROP TABLE IF EXISTS applications; | ||
DROP TABLE IF EXISTS jobs; | ||
DROP TABLE IF EXISTS statuses; | ||
DROP TABLE IF EXISTS follow_up_types; | ||
|
||
-- CREATE JOBS TABLE | ||
CREATE TABLE jobs ( | ||
id SERIAL PRIMARY KEY, | ||
title VARCHAR(255) NOT NULL, | ||
company VARCHAR(255) NOT NULL, | ||
location VARCHAR(255), | ||
description TEXT, | ||
url VARCHAR(255), | ||
created_at TIMESTAMPTZ DEFAULT NOW() | ||
); | ||
|
||
-- CREATE STATUSES TABLE | ||
CREATE TABLE statuses ( | ||
id SERIAL PRIMARY KEY, | ||
name VARCHAR(255) NOT NULL | ||
); | ||
|
||
-- INSERT DEFAULT STATUSES | ||
INSERT INTO statuses (name) VALUES | ||
('Applied'), | ||
('Phone Screen'), | ||
('Interviewing'), | ||
('Offer Received'), | ||
('Rejected'), | ||
('Withdrawn'); | ||
|
||
-- CREATE FOLLOW-UP TYPES TABLE | ||
CREATE TABLE follow_up_types ( | ||
id SERIAL PRIMARY KEY, | ||
name VARCHAR(255) NOT NULL | ||
); | ||
|
||
-- INSERT DEFAULT FOLLOW-UP TYPES | ||
INSERT INTO follow_up_types (name) VALUES | ||
('After Apply'), | ||
('After Phone Screen'), | ||
('After Interview'), | ||
('After Technical Interview'), | ||
('After Offer Received'), | ||
('After Rejection'), | ||
('After Withdrawal'); | ||
|
||
-- CREATE APPLICATIONS TABLE | ||
CREATE TABLE applications ( | ||
id SERIAL PRIMARY KEY, | ||
job_id INT NOT NULL, | ||
status_id INT NOT NULL, | ||
user_id VARCHAR(255) NOT NULL, | ||
quick_apply BOOLEAN NOT NULL, | ||
date_applied TIMESTAMPTZ DEFAULT NOW(), | ||
general_notes TEXT, | ||
last_updated TIMESTAMPTZ DEFAULT NOW(), | ||
notification_period INT DEFAULT 3, | ||
notifications_paused BOOLEAN DEFAULT FALSE, | ||
FOREIGN KEY (job_id) REFERENCES jobs(id), | ||
FOREIGN KEY (status_id) REFERENCES statuses(id) | ||
); | ||
|
||
-- CREATE FOLLOW-UPS TABLE | ||
CREATE TABLE follow_ups ( | ||
id SERIAL PRIMARY KEY, | ||
application_id INT NOT NULL, | ||
follow_up_date TIMESTAMPTZ DEFAULT NOW(), | ||
follow_up_type_id INT NOT NULL, | ||
notes TEXT, | ||
FOREIGN KEY (application_id) REFERENCES applications(id), | ||
FOREIGN KEY (follow_up_type_id) REFERENCES follow_up_types(id) | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import getAllAlumniData from './getAllAlumniData/getAllAumniData'; | ||
|
||
export { getAllAlumniData }; |
45 changes: 45 additions & 0 deletions
45
server/controllers/applicationController/createApplication/createApplication.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import { Request, Response } from 'express'; | ||
import { pool } from '../../../config/sql-db'; | ||
|
||
const createApplication = async (req: Request, res: Response) => { | ||
try { | ||
const { | ||
title, | ||
company, | ||
location, | ||
description, | ||
url, | ||
status_id, | ||
quick_apply, | ||
date_applied, | ||
general_notes, | ||
user_id, | ||
} = req.body; | ||
|
||
const appliedDate = new Date(date_applied).toISOString(); | ||
|
||
const jobQuery = ` | ||
INSERT INTO jobs (title, company, location, description, url) | ||
VALUES ($1, $2, $3, $4, $5) | ||
RETURNING id | ||
`; | ||
const jobValues = [title, company, location, description, url]; | ||
const jobResult = await pool.query(jobQuery, jobValues); | ||
const job_id = jobResult.rows[0].id; | ||
|
||
const applicationQuery = ` | ||
INSERT INTO applications (job_id, status_id, user_id, quick_apply, date_applied, general_notes, last_updated) | ||
VALUES ($1, $2, $3, $4, $5, $6, NOW()) | ||
RETURNING id | ||
`; | ||
const applicationValues = [job_id, status_id, user_id, quick_apply, appliedDate, general_notes]; | ||
const applicationResult = await pool.query(applicationQuery, applicationValues); | ||
|
||
res.status(201).json({ id: applicationResult.rows[0].id }); | ||
} catch (error) { | ||
console.error('Error creating application:', error); | ||
res.status(500).json({ message: 'Internal server error' }); | ||
} | ||
}; | ||
|
||
export default createApplication; |
40 changes: 40 additions & 0 deletions
40
server/controllers/applicationController/getAggregateUserStats/getAggregateUserStats.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import { Request, Response } from 'express'; | ||
import { pool } from '../../../config/sql-db'; | ||
|
||
interface StatusCount { | ||
status: string; | ||
count: string; | ||
} | ||
|
||
const getAggregatedUserStats = async (req: Request, 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' }); | ||
try { | ||
const applicationsByStatusQuery = ` | ||
SELECT statuses.name AS status, COUNT(*) AS count | ||
FROM applications | ||
JOIN statuses ON applications.status_id = statuses.id | ||
WHERE applications.user_id = $1 | ||
GROUP BY statuses.name | ||
`; | ||
const applicationsByStatusResult = await pool.query<StatusCount>(applicationsByStatusQuery, [ | ||
userId, | ||
]); | ||
|
||
const totalApplications = applicationsByStatusResult.rows.reduce( | ||
(sum: number, row: StatusCount) => sum + parseInt(row.count, 10), | ||
0, | ||
); | ||
|
||
res.json({ | ||
totalApplications, | ||
applicationsByStatus: applicationsByStatusResult.rows, | ||
}); | ||
} catch (error) { | ||
console.error('Error fetching aggregated data:', error); | ||
res.status(500).send('Internal server error'); | ||
} | ||
}; | ||
|
||
export default getAggregatedUserStats; |
50 changes: 50 additions & 0 deletions
50
server/controllers/applicationController/getAllApplications/getAllApplications.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import { Request, Response } from 'express'; | ||
import { pool } from '../../../config/sql-db'; | ||
|
||
const getAllApplications = async (req: Request, res: Response) => { | ||
try { | ||
const { userId, status, date } = req.query; | ||
|
||
let query = ` | ||
SELECT | ||
applications.id, | ||
jobs.company, | ||
jobs.title, | ||
statuses.name AS status, | ||
applications.general_notes, | ||
applications.date_applied, | ||
applications.last_updated, | ||
applications.notification_period, | ||
applications.notifications_paused | ||
FROM | ||
applications | ||
INNER JOIN jobs ON applications.job_id = jobs.id | ||
INNER JOIN statuses ON applications.status_id = statuses.id | ||
WHERE | ||
applications.user_id = $1 | ||
`; | ||
|
||
const queryParams = [userId]; | ||
let paramIndex = 2; | ||
|
||
if (status) { | ||
query += ` AND statuses.name != $${paramIndex}`; | ||
queryParams.push(status); | ||
paramIndex += 1; | ||
} | ||
|
||
if (date) { | ||
query += ` AND applications.date_applied >= $${paramIndex}`; | ||
queryParams.push(date); | ||
} | ||
|
||
const { rows } = await pool.query(query, queryParams); | ||
|
||
res.json(rows); | ||
} catch (error) { | ||
console.error('Error fetching job applications:', error); | ||
res.status(500).json({ message: 'Internal server error' }); | ||
} | ||
}; | ||
|
||
export default getAllApplications; |
45 changes: 45 additions & 0 deletions
45
server/controllers/applicationController/getApplicationById/getApplicationById.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import { Request, Response } from 'express'; | ||
import { pool } from '../../../config/sql-db'; | ||
|
||
const getApplicationById = async (req: Request, res: Response) => { | ||
const { id } = req.params; | ||
try { | ||
const query = ` | ||
SELECT | ||
applications.id, | ||
jobs.title, | ||
jobs.company, | ||
jobs.location, | ||
jobs.description, | ||
jobs.url, | ||
statuses.id AS status_id, | ||
statuses.name AS status, | ||
applications.quick_apply, | ||
applications.date_applied, | ||
applications.general_notes, | ||
applications.job_id, | ||
applications.user_id | ||
FROM | ||
applications | ||
INNER JOIN jobs ON applications.job_id = jobs.id | ||
INNER JOIN statuses ON applications.status_id = statuses.id | ||
WHERE | ||
applications.id = $1 | ||
`; | ||
const { rows } = await pool.query(query, [id]); | ||
|
||
if (rows.length === 0) { | ||
return res.status(404).json({ message: 'Application not found' }); | ||
} | ||
|
||
if (!req.user || req.user.id !== rows[0].user_id) | ||
return res.status(401).json({ message: 'You are not authorized to retrieve those records' }); | ||
|
||
res.json(rows[0]); | ||
} catch (error) { | ||
console.error('Error fetching application by id:', error); | ||
res.status(500).json({ message: 'Internal server error' }); | ||
} | ||
}; | ||
|
||
export default getApplicationById; |
14 changes: 14 additions & 0 deletions
14
server/controllers/applicationController/getStatuses/getStatuses.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { Request, Response } from 'express'; | ||
import { pool } from '../../../config/sql-db'; | ||
|
||
const getStatuses = async (req: Request, res: Response) => { | ||
try { | ||
const { rows } = await pool.query('SELECT * FROM statuses'); | ||
res.json(rows); | ||
} catch (error) { | ||
console.error('Error fetching statuses:', error); | ||
res.status(500).json({ message: 'Internal server error' }); | ||
} | ||
}; | ||
|
||
export default getStatuses; |
Oops, something went wrong.