new queryParamToBool helper

This commit is contained in:
lesion 2023-06-18 22:17:11 +02:00
parent 892f560634
commit d7f1dd686c
No known key found for this signature in database
GPG key ID: 352918250B012177
2 changed files with 5 additions and 4 deletions

View file

@ -2,13 +2,13 @@ const { Collection, Filter, Event, Tag, Place } = require('../models/models')
const log = require('../../log')
const { DateTime } = require('luxon')
const { col: Col } = require('../../helpers')
const { col: Col, queryParamToBool } = require('../../helpers')
const { Op, Sequelize } = require('sequelize')
const collectionController = {
async getAll (req, res) {
const withFilters = req.query.withFilters
const withFilters = queryParamToBool(req.query.withFilters)
let collections
if (withFilters) {
collections = await Collection.findAll({ include: [ Filter ] })

View file

@ -295,8 +295,9 @@ module.exports = {
}
},
queryParamToBool (value) {
return ((value+'').toLowerCase() === 'true')
queryParamToBool (value, defaultValue) {
if (typeof value === 'undefined') return defaultValue
return (String(value).toLowerCase() === 'true')
}
}