Skip to content

Commit 54d34ee

Browse files
committed
fix(api): do not return soft-deleted documents in populated ref fields
1 parent 759b694 commit 54d34ee

2 files changed

Lines changed: 12 additions & 2 deletions

File tree

‎apps/public-api/src/controllers/data.controller.js‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -383,7 +383,10 @@ module.exports.getSingleDoc = async (req, res, next) => {
383383
const fields = populateParam.split(',').map(f => f.trim()).filter(Boolean);
384384

385385
fields.forEach(f => {
386-
query = query.populate(f);
386+
query = query.populate({
387+
path: f,
388+
match: includeDeleted ? {} : { isDeleted: { $ne: true } }
389+
});
387390
});
388391
}
389392

‎packages/common/src/utils/queryEngine.js‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,10 +159,17 @@ class QueryEngine {
159159
populate() {
160160
const rawParam = this.queryString.populate || this.queryString.expand;
161161
if (!rawParam) return this;
162+
163+
const includeDeleted = this.queryString.include_deleted === 'true';
164+
const matchCond = includeDeleted ? {} : { isDeleted: { $ne: true } };
165+
162166
const populateParam = Array.isArray(rawParam) ? rawParam.join(',') : String(rawParam);
163167
const fields = populateParam.split(',').map(f => f.trim()).filter(Boolean);
164168
fields.forEach(f => {
165-
this.query = this.query.populate(f);
169+
this.query = this.query.populate({
170+
path: f,
171+
match: matchCond
172+
});
166173
});
167174
return this;
168175
}

0 commit comments

Comments
 (0)