From 301976551a0de8d334883bf04b648fee09ab5fe1 Mon Sep 17 00:00:00 2001 From: Esteban Gonzalez Tamayo <53051438+egonzalezt@users.noreply.github.com> Date: Mon, 16 Oct 2023 13:27:59 -0500 Subject: [PATCH] feat(security): improve app security --- src/database/repositories/serverProperties/index.js | 9 +++++---- .../checkUniqueKeyServerPropertiesCategory.js | 5 ++--- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/database/repositories/serverProperties/index.js b/src/database/repositories/serverProperties/index.js index 742f580..3a4973d 100644 --- a/src/database/repositories/serverProperties/index.js +++ b/src/database/repositories/serverProperties/index.js @@ -2,15 +2,15 @@ const ServerProperties = require('../../schemas/serverProperties'); const ServerPropertiesCategory = require('../../schemas/serverPropertiesCategory'); async function findCategoryByKey(key) { - return ServerPropertiesCategory.findOne({ key }); + return await ServerPropertiesCategory.findOne({ key }); } async function findPropertyByKeyAndCategory(key, category) { - return ServerProperties.findOne({ key, category }); + return await ServerProperties.findOne({ key, category }); } async function findPropertyByKey(key) { - return ServerProperties.findOne({ key }); + return await ServerProperties.findOne({ key }); } @@ -157,5 +157,6 @@ module.exports = { findCategoryByKey, findPropertyByKeyAndCategory, createProperty, - getCategoryById + getCategoryById, + findPropertyByKey }; diff --git a/src/middlewares/checkUniqueKeyServerPropertiesCategory.js b/src/middlewares/checkUniqueKeyServerPropertiesCategory.js index 92b1358..2faed50 100644 --- a/src/middlewares/checkUniqueKeyServerPropertiesCategory.js +++ b/src/middlewares/checkUniqueKeyServerPropertiesCategory.js @@ -1,8 +1,7 @@ -const ServerPropertiesCategory = require('../database/schemas/serverPropertiesCategory'); - +const repository = require("../database/repositories/serverProperties/index") const checkUniqueKeyServerPropertiesCategory = async (req, res, next) => { try { - const existingCategory = await ServerPropertiesCategory.findOne({ key: req.body.key }); + const existingCategory = await repository.findCategoryByKey(req.body.key); if (existingCategory) { return res.status(400).json({ error: 'Category with this key already exists' }); }