Skip to content

Commit 700a80a

Browse files
committed
feat(core): enable schema-less flexibility by setting strict:false and allowing validation passthrough
1 parent ebdd3a2 commit 700a80a

2 files changed

Lines changed: 6 additions & 4 deletions

File tree

packages/common/src/utils/injectModel.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ function buildMongooseSchema(fieldsArray) {
6464
fieldsArray.forEach(field => {
6565
schemaDef[field.key] = buildFieldDef(field);
6666
});
67-
return new mongoose.Schema(schemaDef, { timestamps: true });
67+
return new mongoose.Schema(schemaDef, { timestamps: true, strict: false });
6868
}
6969

7070

packages/common/src/utils/validateData.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,13 +61,15 @@ function validateField(value, field) {
6161
// Validate incoming data against schema rules
6262
// Returns { error } or { cleanData }
6363
function validateData(incomingData, schemaRules) {
64-
const cleanData = {};
64+
const cleanData = { ...incomingData }; // Start with all data
6565
for (const field of schemaRules) {
6666
const value = incomingData[field.key];
6767

6868
const error = validateField(value, field);
6969
if (error) return { error };
7070

71+
// Ensure defined fields are present if required (handled by validateField)
72+
// cleanData already has it, but we can be explicit
7173
if (value !== undefined) {
7274
cleanData[field.key] = value;
7375
}
@@ -77,10 +79,10 @@ function validateData(incomingData, schemaRules) {
7779

7880
// Validate partial update data (non-required fields can be missing)
7981
function validateUpdateData(incomingData, schemaRules) {
80-
const updateData = {};
82+
const updateData = { ...incomingData }; // Start with all data
8183
for (const key in incomingData) {
8284
const fieldRule = schemaRules.find(f => f.key === key);
83-
if (!fieldRule) continue;
85+
if (!fieldRule) continue; // Allow extra fields
8486

8587
const value = incomingData[key];
8688
// For updates, don't enforce 'required' — only validate type

0 commit comments

Comments
 (0)