mirror of
				https://github.com/KevinMidboe/leifsbackend.git
				synced 2025-10-29 17:50: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 Image = require('../db/models').image; | ||||||
|  |  | ||||||
| const Op = require('sequelize').Op; | const Op = require('sequelize').Op; | ||||||
|  | const moment = require('moment'); | ||||||
|  | const SORT_OPTIONS = ['asc', 'desc'] | ||||||
|  |  | ||||||
| function location(req, res) { | function location(req, res) { | ||||||
|   return Adventure |   return Adventure | ||||||
| @@ -54,11 +56,14 @@ function createLocation(req, res) { | |||||||
| function create(req, res) { | function create(req, res) { | ||||||
|   console.log('Received req body for create:', req.body) |   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({ |   Adventure.create({ | ||||||
|     title: req.body.title, |     title: req.body.title, | ||||||
|     subtext: req.body.subtext, |     subtext: req.body.subtext, | ||||||
|     dateStart: req.body.dateStart, |     dateStart: dateStart, | ||||||
|     dateEnd: req.body.dateEnd, |     dateEnd: dateEnd, | ||||||
|     locationName: req.body.locationName, |     locationName: req.body.locationName, | ||||||
|   }, {}) |   }, {}) | ||||||
|   .then(() => createLocation(req, res)) |   .then(() => createLocation(req, res)) | ||||||
|   | |||||||
| @@ -1,7 +1,8 @@ | |||||||
| const Image = require('../db/models').image; | const Image = require('../db/models').image; | ||||||
|  |  | ||||||
| const path = require("path"); | const path = require("path"); | ||||||
|  |  | ||||||
|  | const SORT_OPTIONS = ['asc', 'desc'] | ||||||
|  |  | ||||||
| module.exports = { | module.exports = { | ||||||
|  |  | ||||||
|   all(req, res) { |   all(req, res) { | ||||||
| @@ -13,11 +14,17 @@ module.exports = { | |||||||
|   }, |   }, | ||||||
|  |  | ||||||
|   list(req, res) { |   list(req, res) { | ||||||
|  |     let sortOption = SORT_OPTIONS[0]; | ||||||
|  |  | ||||||
|  |     if (req.query.sort && SORT_OPTIONS.includes(req.query.sort)) { | ||||||
|  |       sortOption = req.query.sort; | ||||||
|  |     } | ||||||
|  |  | ||||||
|     return Image |     return Image | ||||||
|       .findAll({ |       .findAll({ | ||||||
|         where: { 'adventure_id': req.params.adventureId }, |         where: { 'adventure_id': req.params.adventureId }, | ||||||
|         order: [ |         order: [ | ||||||
|           ['album_order', 'ASC'], |           ['album_order', sortOption], | ||||||
|         ] |         ] | ||||||
|       }) |       }) | ||||||
|       .then(images => res.status(200).send(images)) |       .then(images => res.status(200).send(images)) | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user