diff --git a/backend/assets/images/functions/convertCurrency.png b/backend/assets/images/functions/convertCurrency.png new file mode 100644 index 0000000..9211c69 Binary files /dev/null and b/backend/assets/images/functions/convertCurrency.png differ diff --git a/backend/controllers/functions.js b/backend/controllers/functions.js index 27d654f..7a1985d 100644 --- a/backend/controllers/functions.js +++ b/backend/controllers/functions.js @@ -3,22 +3,36 @@ const { serverError } = require('../assets/config/errors'); const Functions = require('../models/functions'); const Categories = require('../models/categories'); const functionToExecute = require('../assets/functions/functionObject'); +const Sequelize = require('sequelize'); + +function helperQueryNumber(value, defaultValue) { + if (value && !isNaN(value)) return parseInt(value); + return defaultValue; +} exports.getFunctions = (req, res, next) => { - // TODO: Trier et chercher par catégories - let page = 1; - let limit = 10; - if (req.query.page && !isNaN(req.query.page)) { - page = parseInt(req.query.page); - } - if (req.query.limit && !isNaN(req.query.limit)) { - limit = parseInt(req.query.limit); - } + const page = helperQueryNumber(req.query.page, 1); + const limit = helperQueryNumber(req.query.limit, 10); + const categoryId = helperQueryNumber(req.query.categoryId, 0); + let search = req.query.search; + try { search = search.toLowerCase(); } catch {} const offset = (page - 1) * limit; Functions.findAndCountAll({ limit, offset, - where: { isOnline: 1 }, + where: { + isOnline: 1, + // Trie par catégorie + ... (categoryId !== 0) && { categorieId: categoryId }, + // Recherche + ... (search != undefined) && { + [Sequelize.Op.or]: [ + { title: Sequelize.where(Sequelize.fn('LOWER', Sequelize.col('title')), 'LIKE', `%${search}%`) }, + { slug: Sequelize.where(Sequelize.fn('LOWER', Sequelize.col('slug')), 'LIKE', `%${search}%`) }, + { description: Sequelize.where(Sequelize.fn('LOWER', Sequelize.col('description')), 'LIKE', `%${search}%`) } + ] + } + }, include: [ { model: Categories, attributes: ["name", "color"] } ] diff --git a/frontend/components/FunctionCard/FunctionCard.css b/frontend/components/FunctionCard/FunctionCard.css index 20f8a0d..5196dbb 100644 --- a/frontend/components/FunctionCard/FunctionCard.css +++ b/frontend/components/FunctionCard/FunctionCard.css @@ -55,4 +55,5 @@ border-radius: 0.5em; padding: 0.5em; margin-right: 20px; + font-size: 16.4px; } \ No newline at end of file