@@ -367,12 +367,13 @@ router.post('documents.restore', auth(), async ctx => {
|
||||
});
|
||||
|
||||
router.post('documents.search', auth(), pagination(), async ctx => {
|
||||
const { query } = ctx.body;
|
||||
const { query, includeArchived } = ctx.body;
|
||||
const { offset, limit } = ctx.state.pagination;
|
||||
ctx.assertPresent(query, 'query is required');
|
||||
|
||||
const user = ctx.state.user;
|
||||
const results = await Document.searchForUser(user, query, {
|
||||
includeArchived: includeArchived === 'true',
|
||||
offset,
|
||||
limit,
|
||||
});
|
||||
|
||||
@@ -464,6 +464,29 @@ describe('#documents.search', async () => {
|
||||
expect(body.data.length).toEqual(0);
|
||||
});
|
||||
|
||||
it('should return archived documents if chosen', async () => {
|
||||
const { user } = await seed();
|
||||
const document = await buildDocument({
|
||||
title: 'search term',
|
||||
text: 'search term',
|
||||
teamId: user.teamId,
|
||||
});
|
||||
await document.archive(user.id);
|
||||
|
||||
const res = await server.post('/api/documents.search', {
|
||||
body: {
|
||||
token: user.getJwtToken(),
|
||||
query: 'search term',
|
||||
includeArchived: 'true',
|
||||
},
|
||||
});
|
||||
const body = await res.json();
|
||||
|
||||
expect(res.status).toEqual(200);
|
||||
expect(body.data.length).toEqual(1);
|
||||
expect(body.data[0].document.text).toEqual('search term');
|
||||
});
|
||||
|
||||
it('should not return documents in private collections not a member of', async () => {
|
||||
const { user } = await seed();
|
||||
const collection = await buildCollection({ private: true });
|
||||
|
||||
@@ -224,7 +224,7 @@ Document.searchForUser = async (
|
||||
FROM documents
|
||||
WHERE "searchVector" @@ to_tsquery('english', :query) AND
|
||||
"collectionId" IN(:collectionIds) AND
|
||||
"archivedAt" IS NULL AND
|
||||
${options.includeArchived ? '' : '"archivedAt" IS NULL AND'}
|
||||
"deletedAt" IS NULL AND
|
||||
("publishedAt" IS NOT NULL OR "createdById" = '${user.id}')
|
||||
ORDER BY
|
||||
|
||||
@@ -250,11 +250,13 @@ export default function Pricing() {
|
||||
|
||||
<Method method="documents.search" label="Search documents">
|
||||
<Description>
|
||||
This methods allows you to search all of your documents with
|
||||
keywords.
|
||||
This methods allows you to search your teams documents with
|
||||
keywords. Search results will be restricted to those accessible by
|
||||
the current access token.
|
||||
</Description>
|
||||
<Arguments>
|
||||
<Argument id="query" description="Search query" required />
|
||||
<Argument id="includeArchived" description="Boolean" />
|
||||
</Arguments>
|
||||
</Method>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user