From d45c393e2607064baac5c9ff4c40435a0ec9b079 Mon Sep 17 00:00:00 2001 From: yash-pouranik Date: Mon, 2 Mar 2026 22:20:05 +0530 Subject: [PATCH] chore: added console.errro --- backend/controllers/data.controller.js | 10 +++++++--- backend/controllers/schema.controller.js | 11 ++++------- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/backend/controllers/data.controller.js b/backend/controllers/data.controller.js index 50ee2ec47..22a635d5e 100644 --- a/backend/controllers/data.controller.js +++ b/backend/controllers/data.controller.js @@ -40,7 +40,6 @@ module.exports.insertData = async (req, res) => { } } - // Prevnt NoSQL injection const safeData = sanitize(cleanData); let docSize = 0; @@ -66,6 +65,7 @@ module.exports.insertData = async (req, res) => { console.timeEnd("insert data") res.status(201).json(result); } catch (err) { + console.error(err); res.status(500).json({ error: err.message }); } }; @@ -92,6 +92,7 @@ module.exports.getAllData = async (req, res) => { console.timeEnd("getall") res.json(data); } catch (err) { + console.error(err); res.status(500).json({ error: err.message }); } }; @@ -116,6 +117,7 @@ module.exports.getSingleDoc = async (req, res) => { res.json(doc); } catch (err) { + console.error(err); res.status(500).json({ error: err.message }); } }; @@ -135,12 +137,12 @@ module.exports.updateSingleData = async (req, res) => { const connection = await getConnection(project._id); const Model = getCompiledModel(connection, collectionConfig, project._id, project.resources.db.isExternal); - // Strict Schema Validation + // Schma Validation const schemaRules = collectionConfig.model; const updateData = {}; for (const key in incomingData) { const fieldRule = schemaRules.find(f => f.key === key); - if (!fieldRule) continue; // Unknown fields ko ignore karo + if (!fieldRule) continue; const value = incomingData[key]; if (fieldRule.type === 'Number' && typeof value !== 'number') return res.status(400).json({ error: `Field '${key}' must be a Number.` }); @@ -157,6 +159,7 @@ module.exports.updateSingleData = async (req, res) => { res.json({ message: "Updated", data: result }); } catch (err) { + console.error(err); res.status(500).json({ error: err.message }); } }; @@ -195,6 +198,7 @@ module.exports.deleteSingleDoc = async (req, res) => { res.json({ message: "Document deleted", id }); } catch (err) { + console.error(err); res.status(500).json({ error: err.message }); } }; \ No newline at end of file diff --git a/backend/controllers/schema.controller.js b/backend/controllers/schema.controller.js index 07e02dd98..9ba31580c 100644 --- a/backend/controllers/schema.controller.js +++ b/backend/controllers/schema.controller.js @@ -19,6 +19,7 @@ module.exports.checkSchema = async (req, res) => { res.status(200).json({ message: "Schema exists", collection: collectionConfig }); } catch (err) { + console.error(err); res.status(500).json({ error: err.message }); } }; @@ -26,10 +27,8 @@ module.exports.checkSchema = async (req, res) => { module.exports.createSchema = async (req, res) => { try { const { name, fields } = createSchemaApiKeySchema.parse(req.body); - let project = req.project; // From verifyApiKey + let project = req.project; - // Need the full document to call .save(), req.project from cache might be a lean object. - // It's safer to fetch the mongoose model instance to modify it. const projectId = project._id; const fullProject = await Project.findById(projectId); @@ -40,9 +39,7 @@ module.exports.createSchema = async (req, res) => { if (!fullProject.jwtSecret) fullProject.jwtSecret = uuidv4(); - // Convert the incoming API payload (name, type, required) into the UrBackend schema format (key, type, required) const transformedFields = (fields || []).map(f => { - // Capitalize first letter of type mapping "string" -> "String" requirement const mappedType = f.type.charAt(0).toUpperCase() + f.type.slice(1).toLowerCase(); return { key: f.name, @@ -57,8 +54,7 @@ module.exports.createSchema = async (req, res) => { // Clear redis cache await deleteProjectById(projectId.toString()); await setProjectById(projectId.toString(), fullProject); - await deleteProjectByApiKeyCache(fullProject.apiKey); // In case it was cached by hashed key - // NOTE: req.hashedApiKey is available from middleware if we strictly want that. + await deleteProjectByApiKeyCache(fullProject.apiKey); if (req.hashedApiKey) { await deleteProjectByApiKeyCache(req.hashedApiKey); } @@ -70,6 +66,7 @@ module.exports.createSchema = async (req, res) => { res.status(201).json({ message: "Schema created successfully", project: projectObj }); } catch (err) { if (err instanceof z.ZodError) return res.status(400).json({ error: err.errors }); + console.error(err); res.status(500).json({ error: err.message }); } };