Support for filter by parent document (#6850)
* Backend support for filter by parent document * parentDocumentId -> documentId
This commit is contained in:
@@ -40,6 +40,8 @@ type SearchOptions = {
|
||||
dateFilter?: DateFilter;
|
||||
/** Status of the documents to return */
|
||||
statusFilter?: StatusFilter[];
|
||||
/** Limit results to a list of documents. */
|
||||
documentIds?: string[];
|
||||
/** Limit results to a list of users that collaborated on the document. */
|
||||
collaboratorIds?: string[];
|
||||
/** The minimum number of words to be returned in the contextual snippet */
|
||||
@@ -367,6 +369,12 @@ export default class SearchHelper {
|
||||
});
|
||||
}
|
||||
|
||||
if (options.documentIds) {
|
||||
where[Op.and].push({
|
||||
id: options.documentIds,
|
||||
});
|
||||
}
|
||||
|
||||
const statusQuery = [];
|
||||
if (options.statusFilter?.includes(StatusFilter.Published)) {
|
||||
statusQuery.push({
|
||||
|
||||
@@ -785,6 +785,7 @@ router.post(
|
||||
const {
|
||||
query,
|
||||
collectionId,
|
||||
documentId,
|
||||
userId,
|
||||
dateFilter,
|
||||
statusFilter = [],
|
||||
@@ -853,6 +854,18 @@ router.post(
|
||||
authorize(user, "readDocument", collection);
|
||||
}
|
||||
|
||||
let documentIds = undefined;
|
||||
if (documentId) {
|
||||
const document = await Document.findByPk(documentId, {
|
||||
userId: user.id,
|
||||
});
|
||||
authorize(user, "read", document);
|
||||
documentIds = [
|
||||
documentId,
|
||||
...(await document.findAllChildDocumentIds()),
|
||||
];
|
||||
}
|
||||
|
||||
let collaboratorIds = undefined;
|
||||
|
||||
if (userId) {
|
||||
@@ -862,6 +875,7 @@ router.post(
|
||||
response = await SearchHelper.searchForUser(user, query, {
|
||||
collaboratorIds,
|
||||
collectionId,
|
||||
documentIds,
|
||||
dateFilter,
|
||||
statusFilter,
|
||||
offset,
|
||||
|
||||
@@ -153,6 +153,9 @@ export const DocumentsSearchSchema = BaseSchema.extend({
|
||||
/** Filter results based on user */
|
||||
userId: z.string().uuid().optional(),
|
||||
|
||||
/** Filter results based on content within a document and it's children */
|
||||
documentId: z.string().uuid().optional(),
|
||||
|
||||
/**
|
||||
* Whether to include archived documents in results
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user