add export and fix async functions
This commit is contained in:
@@ -8,8 +8,8 @@ const siteModel = new SiteModel();
|
|||||||
*
|
*
|
||||||
* Returns a list of all sites in JSON format.
|
* Returns a list of all sites in JSON format.
|
||||||
*/
|
*/
|
||||||
router.get('/', function(req, res, next) {
|
router.get('/', async function(req, res, next) {
|
||||||
const sites = siteModel.getAllSites();
|
const sites = await siteModel.getAll();
|
||||||
|
|
||||||
res.json(sites);
|
res.json(sites);
|
||||||
});
|
});
|
||||||
@@ -19,10 +19,10 @@ router.get('/', function(req, res, next) {
|
|||||||
*
|
*
|
||||||
* Returns a specific site by its ID in JSON format.
|
* Returns a specific site by its ID in JSON format.
|
||||||
*/
|
*/
|
||||||
router.get('/:id', function(req, res, next) {
|
router.get('/:id', async function(req, res, next) {
|
||||||
const siteId = req.params.id;
|
const siteId = req.params.id;
|
||||||
|
|
||||||
const site = siteModel.getSiteById(siteId);
|
const site = await siteModel.getById(siteId);
|
||||||
|
|
||||||
if (!site) {
|
if (!site) {
|
||||||
return res.status(404).send('Site not found');
|
return res.status(404).send('Site not found');
|
||||||
@@ -43,7 +43,7 @@ router.get('/:id', function(req, res, next) {
|
|||||||
router.post('/add/:domain', function(req, res, next) {
|
router.post('/add/:domain', function(req, res, next) {
|
||||||
const domain = req.params.domain;
|
const domain = req.params.domain;
|
||||||
|
|
||||||
const newSite = siteModel.createSite(domain);
|
const newSite = siteModel.insert(domain);
|
||||||
|
|
||||||
if (!newSite) {
|
if (!newSite) {
|
||||||
return res.status(400).send('Error creating site');
|
return res.status(400).send('Error creating site');
|
||||||
@@ -65,3 +65,6 @@ router.post('/add/:domain', function(req, res, next) {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
// TODO: Implement delete functionality
|
// TODO: Implement delete functionality
|
||||||
|
|
||||||
|
|
||||||
|
module.exports = router;
|
||||||
Reference in New Issue
Block a user