place controller

This commit is contained in:
lesion
2022-05-31 15:27:46 +02:00
parent a8c760c7f7
commit 8be335cd55

View File

@@ -1,7 +1,9 @@
const dayjs = require('dayjs') const dayjs = require('dayjs')
const Place = require('../models/place') const Place = require('../models/place')
const Event = require('../models/event')
const eventController = require('./event') const eventController = require('./event')
const log = require('../../log')
const { Op, where, col, fn } = require('sequelize')
module.exports = { module.exports = {
async getEvents (req, res) { async getEvents (req, res) {
@@ -15,5 +17,27 @@ module.exports = {
const events = await eventController._select({ start, places: `${place.id}`, show_recurrent: true}) const events = await eventController._select({ start, places: `${place.id}`, show_recurrent: true})
return res.json({ events, place }) return res.json({ events, place })
} },
async updatePlace (req, res) {
const place = await Place.findByPk(req.body.id)
await place.update(req.body)
res.json(place)
},
async get (req, res) {
const search = req.query.search
const places = await Place.findAll({
where: {
[Op.or]: [
{ name: where(fn('LOWER', col('name')), 'LIKE', '%' + search + '%') },
{ address: where(fn('LOWER', col('address')), 'LIKE', '%' + search + '%') },
]
}
})
return res.json(places)
}
} }