Updated expandObjectIds function in utils.js to exclude specific fields from expansion, ensuring proper handling of object IDs. Added console.log for debugging filter clauses in getFilter function.
All checks were successful
farmcontrol/farmcontrol-api/pipeline/head This commit looks good
All checks were successful
farmcontrol/farmcontrol-api/pipeline/head This commit looks good
This commit is contained in:
parent
11ff82a9af
commit
3dd80b7790
@ -1037,6 +1037,7 @@ function flatternObjectIds(object) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function expandObjectIds(input) {
|
function expandObjectIds(input) {
|
||||||
|
const excludedFields = ['createdAt', 'updatedAt', 'name', '_id'];
|
||||||
// Helper to check if a value is an ObjectId or a 24-char hex string
|
// Helper to check if a value is an ObjectId or a 24-char hex string
|
||||||
function isObjectId(val) {
|
function isObjectId(val) {
|
||||||
// Check for MongoDB ObjectId instance
|
// Check for MongoDB ObjectId instance
|
||||||
@ -1053,8 +1054,8 @@ function expandObjectIds(input) {
|
|||||||
} else if (value && typeof value === 'object' && !(value instanceof mongoose.Types.ObjectId)) {
|
} else if (value && typeof value === 'object' && !(value instanceof mongoose.Types.ObjectId)) {
|
||||||
var result = {};
|
var result = {};
|
||||||
for (const [key, val] of Object.entries(value)) {
|
for (const [key, val] of Object.entries(value)) {
|
||||||
if (key === '_id') {
|
if (excludedFields.includes(key)) {
|
||||||
// Do not expand keys that are already named _id
|
// Do not expand keys that are excluded
|
||||||
result[key] = val.toString();
|
result[key] = val.toString();
|
||||||
} else if (isObjectId(val)) {
|
} else if (isObjectId(val)) {
|
||||||
result[key] = { _id: val };
|
result[key] = { _id: val };
|
||||||
@ -1108,6 +1109,7 @@ function getFilter(query, allowedFilters, parse = true) {
|
|||||||
clauses.push(parse ? parseFilter(key, value) : { [key]: value });
|
clauses.push(parse ? parseFilter(key, value) : { [key]: value });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
console.log('clauses', clauses);
|
||||||
return mergeFilterClauses(clauses);
|
return mergeFilterClauses(clauses);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user