update deps, node >= 14, add mariadb and postgres to tests

This commit is contained in:
lesion
2022-07-27 11:23:57 +02:00
parent b54fca0ce8
commit 4ac78db475
10 changed files with 251 additions and 136 deletions

View File

@@ -14,8 +14,7 @@ const collectionController = {
const withFilters = req.query.withFilters
let collections
if (withFilters) {
collections = await Collection.findAll({ include: [Filter] })
collections = await Collection.findAll({ include: [ Filter ] })
} else {
collections = await Collection.findAll()
}
@@ -109,9 +108,14 @@ const collectionController = {
}
// TODO: validation
log.info('Create collection: ' + req.body.name)
const collection = await Collection.create(collectionDetail)
res.json(collection)
log.info(`Create collection: ${req.body.name}`)
try {
const collection = await Collection.create(collectionDetail)
res.json(collection)
} catch (e) {
log.error(`Create collection failed ${e}`)
res.sendStatus(400)
}
},
async remove (req, res) {
@@ -122,7 +126,7 @@ const collectionController = {
await collection.destroy()
res.sendStatus(200)
} catch (e) {
log.error('Remove collection failed:', e)
log.error('Remove collection failed:' + String(e))
res.sendStatus(404)
}
},
@@ -148,9 +152,12 @@ const collectionController = {
async removeFilter (req, res) {
const filter_id = req.params.id
log.info('Remove filter', filter_id)
log.info(`Remove filter ${filter_id}`)
try {
const filter = await Filter.findByPk(filter_id)
if (!filter) {
return res.sendStatus(404)
}
await filter.destroy()
res.sendStatus(200)
} catch (e) {

View File

@@ -391,7 +391,13 @@ const eventController = {
let place
if (body.place_id) {
place = await Place.findByPk(body.place_id)
if (!place) {
return res.status(400).send(`Place not found`)
}
} else {
if (!body.place_name) {
return res.status(400).send(`Place not found`)
}
place = await Place.findOne({ where: Sequelize.where(Sequelize.fn('LOWER', Sequelize.col('name')), Op.eq, body.place_name.trim().toLocaleLowerCase() )})
if (!place) {
if (!body.place_address || !body.place_name) {
@@ -639,11 +645,11 @@ const eventController = {
if (tags && places) {
where[Op.and] = [
{ placeId: places ? places.split(',') : []},
Sequelize.fn('EXISTS', Sequelize.literal(`SELECT 1 FROM event_tags WHERE ${Col('event_tags.eventId')}=event.id AND LOWER(${Col('tagTag')}) in (?)`))
Sequelize.fn('EXISTS', Sequelize.literal(`SELECT 1 FROM event_tags WHERE ${Col('event_tags.eventId')}=${Col('event.id')} AND LOWER(${Col('tagTag')}) in (?)`))
]
replacements.push(tags)
} else if (tags) {
where[Op.and] = Sequelize.fn('EXISTS', Sequelize.literal(`SELECT 1 FROM event_tags WHERE ${Col('event_tags.eventId')}=event.id AND LOWER(${Col('tagTag')}) in (?)`))
where[Op.and] = Sequelize.fn('EXISTS', Sequelize.literal(`SELECT 1 FROM event_tags WHERE ${Col('event_tags.eventId')}=${Col('event.id')} AND LOWER(${Col('tagTag')}) in (?)`))
replacements.push(tags)
} else if (places) {
where.placeId = places.split(',')