mirror of
https://github.com/KevinMidboe/leifsbackend.git
synced 2025-10-29 09:40:20 +00:00
Now handles parsing dates from dd-mm-yyyy option over to utc. Also added sort query option for asc or desc for adventures.
This commit is contained in:
@@ -3,6 +3,8 @@ const Location = require('../db/models').location;
|
||||
const Image = require('../db/models').image;
|
||||
|
||||
const Op = require('sequelize').Op;
|
||||
const moment = require('moment');
|
||||
const SORT_OPTIONS = ['asc', 'desc']
|
||||
|
||||
function location(req, res) {
|
||||
return Adventure
|
||||
@@ -54,11 +56,14 @@ function createLocation(req, res) {
|
||||
function create(req, res) {
|
||||
console.log('Received req body for create:', req.body)
|
||||
|
||||
const dateStart = moment.utc(req.body.dateStart, 'DD-MM-YYYY');
|
||||
const dateEnd = moment.utc(req.body.dateEnd, 'DD-MM-YYYY');
|
||||
|
||||
Adventure.create({
|
||||
title: req.body.title,
|
||||
subtext: req.body.subtext,
|
||||
dateStart: req.body.dateStart,
|
||||
dateEnd: req.body.dateEnd,
|
||||
dateStart: dateStart,
|
||||
dateEnd: dateEnd,
|
||||
locationName: req.body.locationName,
|
||||
}, {})
|
||||
.then(() => createLocation(req, res))
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
const Image = require('../db/models').image;
|
||||
|
||||
const path = require("path");
|
||||
|
||||
const SORT_OPTIONS = ['asc', 'desc']
|
||||
|
||||
module.exports = {
|
||||
|
||||
all(req, res) {
|
||||
@@ -13,11 +14,17 @@ module.exports = {
|
||||
},
|
||||
|
||||
list(req, res) {
|
||||
let sortOption = SORT_OPTIONS[0];
|
||||
|
||||
if (req.query.sort && SORT_OPTIONS.includes(req.query.sort)) {
|
||||
sortOption = req.query.sort;
|
||||
}
|
||||
|
||||
return Image
|
||||
.findAll({
|
||||
where: { 'adventure_id': req.params.adventureId },
|
||||
order: [
|
||||
['album_order', 'ASC'],
|
||||
['album_order', sortOption],
|
||||
]
|
||||
})
|
||||
.then(images => res.status(200).send(images))
|
||||
|
||||
Reference in New Issue
Block a user