Skip to content

Commit ec58b3f

Browse files
Merge pull request #30
chore: added console.errro
2 parents 75c419a + d45c393 commit ec58b3f

2 files changed

Lines changed: 11 additions & 10 deletions

File tree

backend/controllers/data.controller.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ module.exports.insertData = async (req, res) => {
4040
}
4141
}
4242

43-
// Prevnt NoSQL injection
4443
const safeData = sanitize(cleanData);
4544

4645
let docSize = 0;
@@ -66,6 +65,7 @@ module.exports.insertData = async (req, res) => {
6665
console.timeEnd("insert data")
6766
res.status(201).json(result);
6867
} catch (err) {
68+
console.error(err);
6969
res.status(500).json({ error: err.message });
7070
}
7171
};
@@ -92,6 +92,7 @@ module.exports.getAllData = async (req, res) => {
9292
console.timeEnd("getall")
9393
res.json(data);
9494
} catch (err) {
95+
console.error(err);
9596
res.status(500).json({ error: err.message });
9697
}
9798
};
@@ -116,6 +117,7 @@ module.exports.getSingleDoc = async (req, res) => {
116117

117118
res.json(doc);
118119
} catch (err) {
120+
console.error(err);
119121
res.status(500).json({ error: err.message });
120122
}
121123
};
@@ -135,12 +137,12 @@ module.exports.updateSingleData = async (req, res) => {
135137
const connection = await getConnection(project._id);
136138
const Model = getCompiledModel(connection, collectionConfig, project._id, project.resources.db.isExternal);
137139

138-
// Strict Schema Validation
140+
// Schma Validation
139141
const schemaRules = collectionConfig.model;
140142
const updateData = {};
141143
for (const key in incomingData) {
142144
const fieldRule = schemaRules.find(f => f.key === key);
143-
if (!fieldRule) continue; // Unknown fields ko ignore karo
145+
if (!fieldRule) continue;
144146

145147
const value = incomingData[key];
146148
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) => {
157159

158160
res.json({ message: "Updated", data: result });
159161
} catch (err) {
162+
console.error(err);
160163
res.status(500).json({ error: err.message });
161164
}
162165
};
@@ -195,6 +198,7 @@ module.exports.deleteSingleDoc = async (req, res) => {
195198

196199
res.json({ message: "Document deleted", id });
197200
} catch (err) {
201+
console.error(err);
198202
res.status(500).json({ error: err.message });
199203
}
200204
};

backend/controllers/schema.controller.js

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,16 @@ module.exports.checkSchema = async (req, res) => {
1919

2020
res.status(200).json({ message: "Schema exists", collection: collectionConfig });
2121
} catch (err) {
22+
console.error(err);
2223
res.status(500).json({ error: err.message });
2324
}
2425
};
2526

2627
module.exports.createSchema = async (req, res) => {
2728
try {
2829
const { name, fields } = createSchemaApiKeySchema.parse(req.body);
29-
let project = req.project; // From verifyApiKey
30+
let project = req.project;
3031

31-
// Need the full document to call .save(), req.project from cache might be a lean object.
32-
// It's safer to fetch the mongoose model instance to modify it.
3332
const projectId = project._id;
3433
const fullProject = await Project.findById(projectId);
3534

@@ -40,9 +39,7 @@ module.exports.createSchema = async (req, res) => {
4039

4140
if (!fullProject.jwtSecret) fullProject.jwtSecret = uuidv4();
4241

43-
// Convert the incoming API payload (name, type, required) into the UrBackend schema format (key, type, required)
4442
const transformedFields = (fields || []).map(f => {
45-
// Capitalize first letter of type mapping "string" -> "String" requirement
4643
const mappedType = f.type.charAt(0).toUpperCase() + f.type.slice(1).toLowerCase();
4744
return {
4845
key: f.name,
@@ -57,8 +54,7 @@ module.exports.createSchema = async (req, res) => {
5754
// Clear redis cache
5855
await deleteProjectById(projectId.toString());
5956
await setProjectById(projectId.toString(), fullProject);
60-
await deleteProjectByApiKeyCache(fullProject.apiKey); // In case it was cached by hashed key
61-
// NOTE: req.hashedApiKey is available from middleware if we strictly want that.
57+
await deleteProjectByApiKeyCache(fullProject.apiKey);
6258
if (req.hashedApiKey) {
6359
await deleteProjectByApiKeyCache(req.hashedApiKey);
6460
}
@@ -70,6 +66,7 @@ module.exports.createSchema = async (req, res) => {
7066
res.status(201).json({ message: "Schema created successfully", project: projectObj });
7167
} catch (err) {
7268
if (err instanceof z.ZodError) return res.status(400).json({ error: err.errors });
69+
console.error(err);
7370
res.status(500).json({ error: err.message });
7471
}
7572
};

0 commit comments

Comments
 (0)