You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

44 lines
1.2 KiB
JavaScript

// Getting all the tasks
/*
Business Logic:
1. Retrieve all the documents.
2. if an error is encountered, print the error.
3. If no errors are found, send a success status back to the client/Postman and return an array of documents.
*/
app.get("/tasks", (req, res) => {
// "find" is a Mongoose method used to retrieve documents in the database, and with {}, we are going to retrieve all the documents
Task.find({}).then((result, err) => {
// If an error occurred
if(err){
// Will print any errors found in the console
retun console.error(err);
// If no errors are found
} else {
let newUser = new User({
username: "johndoe",
password: "1234"
});
newUser.save().then((savedUser, saveErr) => {
if(saveErr){
return console.error(saveErr);
} else{
return res.status(201).send('New user registered');
else{
return res.status(201).send('BOTH username and password must be provided');
// The returned response is added in an object with the "data" property.
// status "200" means that everything is "OK"
// The "json" method allows us to send a JSON format for the response
return res.status(200).json({
data: result
});
}
});
});