-
Notifications
You must be signed in to change notification settings - Fork 447
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
339 additions
and
271 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
module.exports = { | ||
HOST: "us-cdbr-iron-east-02.cleardb.net", | ||
USER: "b7e24378878xxx", | ||
PASSWORD: "0200exxx", | ||
DB: "heroku_7643ec736354xxx" | ||
}; | ||
HOST: "localhost", | ||
USER: "root", | ||
PASSWORD: "123456", | ||
DB: "testdb" | ||
}; |
This file was deleted.
Oops, something went wrong.
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,130 @@ | ||
const Tutorial = require("../models/tutorial.model.js"); | ||
|
||
// Create and Save a new Tutorial | ||
exports.create = (req, res) => { | ||
// Validate request | ||
if (!req.body) { | ||
res.status(400).send({ | ||
message: "Content can not be empty!" | ||
}); | ||
} | ||
|
||
// Create a Tutorial | ||
const tutorial = new Tutorial({ | ||
title: req.body.title, | ||
description: req.body.description, | ||
published: req.body.published || false | ||
}); | ||
|
||
// Save Tutorial in the database | ||
Tutorial.create(tutorial, (err, data) => { | ||
if (err) | ||
res.status(500).send({ | ||
message: | ||
err.message || "Some error occurred while creating the Tutorial." | ||
}); | ||
else res.send(data); | ||
}); | ||
}; | ||
|
||
// Retrieve all Tutorials from the database (with condition). | ||
exports.findAll = (req, res) => { | ||
const title = req.query.title; | ||
|
||
Tutorial.getAll(title, (err, data) => { | ||
if (err) | ||
res.status(500).send({ | ||
message: | ||
err.message || "Some error occurred while retrieving tutorials." | ||
}); | ||
else res.send(data); | ||
}); | ||
}; | ||
|
||
// Find a single Tutorial by Id | ||
exports.findOne = (req, res) => { | ||
Tutorial.findById(req.params.id, (err, data) => { | ||
if (err) { | ||
if (err.kind === "not_found") { | ||
res.status(404).send({ | ||
message: `Not found Tutorial with id ${req.params.id}.` | ||
}); | ||
} else { | ||
res.status(500).send({ | ||
message: "Error retrieving Tutorial with id " + req.params.id | ||
}); | ||
} | ||
} else res.send(data); | ||
}); | ||
}; | ||
|
||
// find all published Tutorials | ||
exports.findAllPublished = (req, res) => { | ||
Tutorial.getAllPublished((err, data) => { | ||
if (err) | ||
res.status(500).send({ | ||
message: | ||
err.message || "Some error occurred while retrieving tutorials." | ||
}); | ||
else res.send(data); | ||
}); | ||
}; | ||
|
||
// Update a Tutorial identified by the id in the request | ||
exports.update = (req, res) => { | ||
// Validate Request | ||
if (!req.body) { | ||
res.status(400).send({ | ||
message: "Content can not be empty!" | ||
}); | ||
} | ||
|
||
console.log(req.body); | ||
|
||
Tutorial.updateById( | ||
req.params.id, | ||
new Tutorial(req.body), | ||
(err, data) => { | ||
if (err) { | ||
if (err.kind === "not_found") { | ||
res.status(404).send({ | ||
message: `Not found Tutorial with id ${req.params.id}.` | ||
}); | ||
} else { | ||
res.status(500).send({ | ||
message: "Error updating Tutorial with id " + req.params.id | ||
}); | ||
} | ||
} else res.send(data); | ||
} | ||
); | ||
}; | ||
|
||
// Delete a Tutorial with the specified id in the request | ||
exports.delete = (req, res) => { | ||
Tutorial.remove(req.params.id, (err, data) => { | ||
if (err) { | ||
if (err.kind === "not_found") { | ||
res.status(404).send({ | ||
message: `Not found Tutorial with id ${req.params.id}.` | ||
}); | ||
} else { | ||
res.status(500).send({ | ||
message: "Could not delete Tutorial with id " + req.params.id | ||
}); | ||
} | ||
} else res.send({ message: `Tutorial was deleted successfully!` }); | ||
}); | ||
}; | ||
|
||
// Delete all Tutorials from the database. | ||
exports.deleteAll = (req, res) => { | ||
Tutorial.removeAll((err, data) => { | ||
if (err) | ||
res.status(500).send({ | ||
message: | ||
err.message || "Some error occurred while removing all tutorials." | ||
}); | ||
else res.send({ message: `All Tutorials were deleted successfully!` }); | ||
}); | ||
}; |
Oops, something went wrong.