mirror of
https://github.com/KevinMidboe/leifsbackend.git
synced 2025-10-29 17:50:20 +00:00
Calendar enpoint for listing all events. TODO add date-filtering.
This commit is contained in:
@@ -1,47 +1,16 @@
|
|||||||
const Adventure = require('../db/models').adventure;
|
const Adventure = require('../db/models').adventure;
|
||||||
// const { Adventure } = require('../db/sequelize')
|
|
||||||
|
|
||||||
const Op = require('sequelize').Op;
|
const Op = require('sequelize').Op;
|
||||||
|
|
||||||
module.exports = {
|
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) {
|
list(req, res) {
|
||||||
return Adventure
|
return Adventure
|
||||||
.findAll({
|
.findAll({
|
||||||
attributes: ['id', 'title', 'subtext', 'dateStart', 'dateEnd', 'locationName']
|
attributes: ['id', 'title', 'dateStart', 'dateEnd', 'locationName']
|
||||||
})
|
})
|
||||||
.then(adventure => res.status(200).send(adventure))
|
.then(adventure => res.status(200).send(adventure))
|
||||||
.catch(error => res.status(400).send(error))
|
.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))
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
@@ -1,9 +1,11 @@
|
|||||||
const Adventure = require('./adventure');
|
const Adventure = require('./adventure');
|
||||||
|
const Calendar = require('./calendar');
|
||||||
const Location = require('./location');
|
const Location = require('./location');
|
||||||
const Image = require('./image');
|
const Image = require('./image');
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
Adventure,
|
Adventure,
|
||||||
|
Calendar,
|
||||||
Location,
|
Location,
|
||||||
Image
|
Image
|
||||||
}
|
}
|
||||||
@@ -1,4 +1,5 @@
|
|||||||
const adventureController = require('../controllers').Adventure;
|
const adventureController = require('../controllers').Adventure;
|
||||||
|
const calendarController = require('../controllers').Calendar;
|
||||||
const locationController = require('../controllers').Location;
|
const locationController = require('../controllers').Location;
|
||||||
const imageController = require('../controllers').Image;
|
const imageController = require('../controllers').Image;
|
||||||
|
|
||||||
@@ -14,6 +15,11 @@ module.exports = (app) => {
|
|||||||
app.get('/api/adventure/location', adventureController.location);
|
app.get('/api/adventure/location', adventureController.location);
|
||||||
app.get('/api/adventure/:id', adventureController.get);
|
app.get('/api/adventure/:id', adventureController.get);
|
||||||
|
|
||||||
|
app.post('/api/upload/', adventureController.uploadHandler);
|
||||||
|
|
||||||
|
// Dates
|
||||||
|
app.get('/api/dates', calendarController.list)
|
||||||
|
|
||||||
// Location (map)
|
// Location (map)
|
||||||
app.get('/api/location', locationController.list)
|
app.get('/api/location', locationController.list)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user