mirror of
https://github.com/outline/outline.git
synced 2026-11-28 16:19:46 +03:00
share query options
This commit is contained in:
1 parent
f014cc91d4
commit
dc7f712558
1 file changed
+36
-53
@@ -1,6 +1,6 @@
|
||||
import Router from "koa-router";
|
||||
import isUndefined from "lodash/isUndefined";
|
||||
import { Op, WhereOptions } from "sequelize";
|
||||
import { FindOptions, Op, WhereOptions } from "sequelize";
|
||||
import { NotFoundError } from "@server/errors";
|
||||
import auth from "@server/middlewares/authentication";
|
||||
import validate from "@server/middlewares/validate";
|
||||
@@ -116,64 +116,47 @@ router.post(
|
||||
|
||||
const collectionIds = await user.collectionIds();
|
||||
|
||||
const options: FindOptions = {
|
||||
where,
|
||||
include: [
|
||||
{
|
||||
model: Document,
|
||||
required: true,
|
||||
paranoid: true,
|
||||
as: "document",
|
||||
where: {
|
||||
collectionId: collectionIds,
|
||||
},
|
||||
include: [
|
||||
{
|
||||
model: Collection.scope({
|
||||
method: ["withMembership", user.id],
|
||||
}),
|
||||
as: "collection",
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
model: User,
|
||||
required: true,
|
||||
as: "user",
|
||||
},
|
||||
{
|
||||
model: Team,
|
||||
required: true,
|
||||
as: "team",
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
const [shares, total] = await Promise.all([
|
||||
Share.findAll({
|
||||
where,
|
||||
...options,
|
||||
order: [[sort, direction]],
|
||||
include: [
|
||||
{
|
||||
model: Document,
|
||||
required: true,
|
||||
paranoid: true,
|
||||
as: "document",
|
||||
where: {
|
||||
collectionId: collectionIds,
|
||||
},
|
||||
include: [
|
||||
{
|
||||
model: Collection.scope({
|
||||
method: ["withMembership", user.id],
|
||||
}),
|
||||
as: "collection",
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
model: User,
|
||||
required: true,
|
||||
as: "user",
|
||||
},
|
||||
{
|
||||
model: Team,
|
||||
required: true,
|
||||
as: "team",
|
||||
},
|
||||
],
|
||||
offset: ctx.state.pagination.offset,
|
||||
limit: ctx.state.pagination.limit,
|
||||
}),
|
||||
Share.count({
|
||||
where,
|
||||
include: [
|
||||
{
|
||||
model: Document,
|
||||
required: true,
|
||||
paranoid: true,
|
||||
as: "document",
|
||||
where: {
|
||||
collectionId: collectionIds,
|
||||
},
|
||||
include: [
|
||||
{
|
||||
model: Collection.scope({
|
||||
method: ["withMembership", user.id],
|
||||
}),
|
||||
as: "collection",
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
}),
|
||||
Share.count(options),
|
||||
]);
|
||||
|
||||
ctx.body = {
|
||||
|
||||
Reference in new issue
Block a user