Calendar enpoint for listing all events. TODO add date-filtering.

This commit is contained in:
2019-03-02 22:45:16 +01:00
parent 417ec775ff
commit bd62e76b0d
3 changed files with 9 additions and 32 deletions

View File

@@ -1,47 +1,16 @@
const Adventure = require('../db/models').adventure;
// const { Adventure } = require('../db/sequelize')
const Op = require('sequelize').Op;
module.exports = {
location(req, res) {
return Adventure
.findAll({
where: { [Op.not]: { locationName: null } }
})
.then(adventure => res.status(200).send(adventure))
.catch(error => res.status(400).send(error))
},
list(req, res) {
return Adventure
.findAll({
attributes: ['id', 'title', 'subtext', 'dateStart', 'dateEnd', 'locationName']
attributes: ['id', 'title', 'dateStart', 'dateEnd', 'locationName']
})
.then(adventure => res.status(200).send(adventure))
.catch(error => res.status(400).send(error))
},
get(req, res) {
return Adventure
.findById(req.params.id)
.then(adventure => res.status(200).send(adventure))
.catch(error => res.status(400).send(error));
},
// get form elements
create(req, res) {
console.log('adventure', Adventure)
return Adventure
.create({
title: req.body.title,
subtext: req.body.subtext,
dateStart: req.body.dateStart,
dateEnd: req.body.dateEnd,
locationName: req.body.locationName
})
.then(adventure => res.status(201).send(adventure))
.catch(error => res.status(400).send(error))
}
};

View File

@@ -1,9 +1,11 @@
const Adventure = require('./adventure');
const Calendar = require('./calendar');
const Location = require('./location');
const Image = require('./image');
module.exports = {
Adventure,
Calendar,
Location,
Image
}

View File

@@ -1,4 +1,5 @@
const adventureController = require('../controllers').Adventure;
const calendarController = require('../controllers').Calendar;
const locationController = require('../controllers').Location;
const imageController = require('../controllers').Image;
@@ -14,6 +15,11 @@ module.exports = (app) => {
app.get('/api/adventure/location', adventureController.location);
app.get('/api/adventure/:id', adventureController.get);
app.post('/api/upload/', adventureController.uploadHandler);
// Dates
app.get('/api/dates', calendarController.list)
// Location (map)
app.get('/api/location', locationController.list)