Skip to content

Commit

Permalink
getting current mentors works
Browse files Browse the repository at this point in the history
  • Loading branch information
JMKassman committed Apr 14, 2019
1 parent c85aa2f commit 44c4f3d
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
14 changes: 14 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -432,4 +432,18 @@ app.post('/api/checkout-mentor', (req, res) => {
});
});

app.get('/api/get-current-mentors', (req, res) => {
if (!req.isAuthenticated()) {
res.sendStatus(403);
return;
}
connection.query("SELECT users.name, users.email, mentors.skills, (SELECT COUNT(status) > 0 FROM tickets WHERE mentor_id = 2 AND status LIKE 'Claimed') AS status, mentors.start_time, TIMEDIFF(NOW(), mentors.start_time) AS elapsed_time FROM mentors INNER JOIN users ON mentors.mentor_id=users.id WHERE mentors.status = 'In'", (err, rows) => {
if (err) {
res.sendStatus(500);
return;
}
res.json(rows);
});
});

app.listen(port, () => console.log(`App is listening on port ${port}`));
5 changes: 3 additions & 2 deletions mysql-debug/init_db.sql
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ CREATE TABLE `tickets`
CREATE TABLE `mentors`
(
`mentor_id` INT NOT NULL,
`skills` VARCHAR(255) NOT NULL,
`status` ENUM('In', 'Out'),
`start_time` datetime NULL,
`end_time` datetime NULL,
Expand All @@ -49,8 +50,8 @@ VALUES("josh", "jkass", "jkass@example.com", "$2b$10$LjlSBAAWIN4WPRWwKgK9OOmaZrD
("vikas", "vtati", "vtat@example.com", "$2b$10$glzKke.feNFNLAbXTB67gOKaEGRQG5mXwKVEiRVb3JCH8tHqT/7T2", 'Mentor'),
("chris", "crose", "crose@example.com", "$2b$10$0tCQV/l1oTRbRl5lCi5gOOsvF/XelBA1yBFvChbsOz1OKLOKA7oc6", 'Organizer');

INSERT INTO mentors (mentor_id, status)
VALUES((SELECT id FROM users WHERE email="vtat@example.com"), 'OUT');
INSERT INTO mentors (mentor_id, skills, status)
VALUES((SELECT id FROM users WHERE email="vtat@example.com"), 'lol no', 'OUT');

INSERT INTO tickets (hacker_id, submit_time, status, location, tags, message)
VALUES((SELECT id FROM users WHERE email="jkass@example.com"), "2019-04-11 10:15:34", "Open", "880b", '', "Please Help ASAP");
Expand Down
1 change: 1 addition & 0 deletions mysql/init_db.sql
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ CREATE TABLE `tickets`
CREATE TABLE `mentors`
(
`mentor_id` INT NOT NULL,
`skills` VARCHAR(255) NOT NULL,
`status` ENUM('In', 'Out'),
`start_time` datetime NULL,
`end_time` datetime NULL,
Expand Down

0 comments on commit 44c4f3d

Please sign in to comment.