mirror of
https://github.com/outline/outline.git
synced 2026-04-24 11:20:11 -05:00
feat: Add query parameter to collections.list (#8595)
This commit is contained in:
@@ -702,7 +702,7 @@ router.post(
|
||||
pagination(),
|
||||
transaction(),
|
||||
async (ctx: APIContext<T.CollectionsListReq>) => {
|
||||
const { includeListOnly, statusFilter } = ctx.input.body;
|
||||
const { includeListOnly, query, statusFilter } = ctx.input.body;
|
||||
const { user } = ctx.state.auth;
|
||||
const { transaction } = ctx.state;
|
||||
const collectionIds = await user.collectionIds({ transaction });
|
||||
@@ -728,6 +728,12 @@ router.post(
|
||||
where[Op.and].push({ id: collectionIds });
|
||||
}
|
||||
|
||||
if (query) {
|
||||
where[Op.and].push(
|
||||
Sequelize.literal(`unaccent(LOWER(name)) like unaccent(LOWER(:query))`)
|
||||
);
|
||||
}
|
||||
|
||||
const statusQuery = [];
|
||||
if (statusFilter?.includes(CollectionStatusFilter.Archived)) {
|
||||
statusQuery.push({
|
||||
@@ -743,6 +749,8 @@ router.post(
|
||||
});
|
||||
}
|
||||
|
||||
const replacements = { query: `%${query}%` };
|
||||
|
||||
const [collections, total] = await Promise.all([
|
||||
Collection.scope(
|
||||
statusFilter?.includes(CollectionStatusFilter.Archived)
|
||||
@@ -757,6 +765,7 @@ router.post(
|
||||
}
|
||||
).findAll({
|
||||
where,
|
||||
replacements,
|
||||
order: [
|
||||
Sequelize.literal('"collection"."index" collate "C"'),
|
||||
["updatedAt", "DESC"],
|
||||
@@ -765,7 +774,12 @@ router.post(
|
||||
limit: ctx.state.pagination.limit,
|
||||
transaction,
|
||||
}),
|
||||
Collection.count({ where, transaction }),
|
||||
Collection.count({
|
||||
where,
|
||||
// @ts-expect-error Types are incorrect for count
|
||||
replacements,
|
||||
transaction,
|
||||
}),
|
||||
]);
|
||||
|
||||
const nullIndex = collections.findIndex(
|
||||
|
||||
@@ -178,6 +178,9 @@ export type CollectionsUpdateReq = z.infer<typeof CollectionsUpdateSchema>;
|
||||
export const CollectionsListSchema = BaseSchema.extend({
|
||||
body: z.object({
|
||||
includeListOnly: z.boolean().default(false),
|
||||
|
||||
query: z.string().optional(),
|
||||
|
||||
/** Collection statuses to include in results */
|
||||
statusFilter: z.nativeEnum(CollectionStatusFilter).array().optional(),
|
||||
}),
|
||||
|
||||
Reference in New Issue
Block a user