Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

/api/close-ticket now works #17

Merged
merged 1 commit into from Apr 13, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
33 changes: 33 additions & 0 deletions index.js
Expand Up @@ -256,4 +256,37 @@ app.post('/api/unclaim-ticket', (req, res) => {
});
});

/**
* Closes the requesting user's claimed ticket if it is claimed by them
* {
* id: integer
* }
*/
app.post('/api/close-ticket', (req, res) => {
if (!req.isAuthenticated()) {
res.sendStatus(403);
return;
}
if (req.user.role !== "Mentor" && req.user.role !== "Organizer") {
res.sendStatus(403);
return;
}
if(req.body.id == undefined) {
res.sendStatus(400);
return;
}
connection.query("UPDATE tickets SET status = 'Closed' WHERE mentor_id = ? AND id = ? AND status = 'Claimed'", [req.user.id, req.body.id], (err, result) => {
if (err) {
res.sendStatus(500);
return;
}
if (result.affectedRows === 1) {
res.json({unclaimed: true});
}
else {
res.json({unclaimed: false});
}
});
});

app.listen(port, () => console.log(`App is listening on port ${port}`));
2 changes: 1 addition & 1 deletion mysql-debug/init_db.sql
Expand Up @@ -22,7 +22,7 @@ CREATE TABLE `tickets`
`hacker_id` INT NOT NULL,
`mentor_id` INT,
`submit_time` datetime NOT NULL,
`status` ENUM('Open', 'Claimed', 'Complete'),
`status` ENUM('Open', 'Claimed', 'Closed'),
`location` VARCHAR(255) NOT NULL,
`tags` SET('ANDROID', 'IOS', 'JAVA', 'JAVASCRIPT'),
`message` VARCHAR(255) NOT NULL
Expand Down
2 changes: 1 addition & 1 deletion mysql/init_db.sql
Expand Up @@ -22,7 +22,7 @@ CREATE TABLE `tickets`
`hacker_id` INT NOT NULL,
`mentor_id` INT,
`submit_time` datetime NOT NULL,
`status` ENUM('Open', 'Claimed', 'Complete'),
`status` ENUM('Open', 'Claimed', 'Closed'),
`location` VARCHAR(255) NOT NULL,
`tags` SET('ANDROID', 'IOS', 'JAVA', 'JAVASCRIPT'),
`message` VARCHAR(255) NOT NULL
Expand Down