Improved search filtering (#940)
* Filter search by collectionId
* Improve spec, remove recursive import
* Add userId filter for documents.search
* 💚
* Search filter UI
* WIP UI
* Date filtering
Prevent dupe menu
* Refactor
* button
* Added year option, improved hover states
* Add new indexes
* Remove manual string interpolation in SQL construction
* Move dateFilter validation to controller
* Fixes: Double query when changing filter
Fixes: Visual jump between filters in dropdown
* Add option to clear filters
* More clearly define dropdowns in dark mode
* Checkbox -> Checkmark
This commit is contained in:
@ -378,13 +378,37 @@ router.post('documents.restore', auth(), async ctx => {
|
||||
});
|
||||
|
||||
router.post('documents.search', auth(), pagination(), async ctx => {
|
||||
const { query, includeArchived } = ctx.body;
|
||||
const { query, includeArchived, collectionId, userId, dateFilter } = ctx.body;
|
||||
const { offset, limit } = ctx.state.pagination;
|
||||
const user = ctx.state.user;
|
||||
ctx.assertPresent(query, 'query is required');
|
||||
|
||||
const user = ctx.state.user;
|
||||
if (collectionId) {
|
||||
ctx.assertUuid(collectionId, 'collectionId must be a UUID');
|
||||
|
||||
const collection = await Collection.findById(collectionId);
|
||||
authorize(user, 'read', collection);
|
||||
}
|
||||
|
||||
let collaboratorIds = undefined;
|
||||
if (userId) {
|
||||
ctx.assertUuid(userId, 'userId must be a UUID');
|
||||
collaboratorIds = [userId];
|
||||
}
|
||||
|
||||
if (dateFilter) {
|
||||
ctx.assertIn(
|
||||
dateFilter,
|
||||
['day', 'week', 'month', 'year'],
|
||||
'dateFilter must be one of day,week,month,year'
|
||||
);
|
||||
}
|
||||
|
||||
const results = await Document.searchForUser(user, query, {
|
||||
includeArchived: includeArchived === 'true',
|
||||
collaboratorIds,
|
||||
collectionId,
|
||||
dateFilter,
|
||||
offset,
|
||||
limit,
|
||||
});
|
||||
|
Reference in New Issue
Block a user