-
Notifications
You must be signed in to change notification settings - Fork 0
/
controller.js
49 lines (41 loc) · 1.18 KB
/
controller.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
const cloudant = require("./cloudant");
const db = cloudant.db.use('yourinitials-tasks');
module.exports.getTasks = async (req, res) => {
const tasks = await db.find({ selector: {} });
res.render('todo.ejs', { todoTasks: tasks.docs });
};
module.exports.createTask = async (req, res) => {
// @TODO: insert new item into tasks db
res.redirect("/");
};
module.exports.getTask = async (req, res) => {
const id = req.params.id;
let tasks; // @TODO: get existing task by id
res.render("todoEdit.ejs", { todoTask: tasks.docs[0] });
};
module.exports.editTask = async (req, res) => {
const id = req.params.id;
try {
let result; // @TODO: get existing task by id
if (!result.docs.length) {
return res.status(404).end();
}
// @TODO: update existing task with new content
res.redirect("/");
} catch (err) {
res.send(500, err);
}
};
module.exports.removeTask = async (req, res) => {
const id = req.params.id;
try {
let result; // @TODO: get existing task by id
if (!result.docs.length) {
return res.status(404).end();
}
// @TODO: delete existing task
res.redirect("/");
} catch (err) {
return res.send(500, err);
}
};