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) {
|
||||
const excludedFields = ['createdAt', 'updatedAt', 'name', '_id'];
|
||||
// Helper to check if a value is an ObjectId or a 24-char hex string
|
||||
function isObjectId(val) {
|
||||
// Check for MongoDB ObjectId instance
|
||||
@ -1053,8 +1054,8 @@ function expandObjectIds(input) {
|
||||
} else if (value && typeof value === 'object' && !(value instanceof mongoose.Types.ObjectId)) {
|
||||
var result = {};
|
||||
for (const [key, val] of Object.entries(value)) {
|
||||
if (key === '_id') {
|
||||
// Do not expand keys that are already named _id
|
||||
if (excludedFields.includes(key)) {
|
||||
// Do not expand keys that are excluded
|
||||
result[key] = val.toString();
|
||||
} else if (isObjectId(val)) {
|
||||
result[key] = { _id: val };
|
||||
@ -1108,6 +1109,7 @@ function getFilter(query, allowedFilters, parse = true) {
|
||||
clauses.push(parse ? parseFilter(key, value) : { [key]: value });
|
||||
}
|
||||
}
|
||||
console.log('clauses', clauses);
|
||||
return mergeFilterClauses(clauses);
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user