Files
outline/server/commands/documentLoader.ts
T
Tom Moor bf45e97641 chore: Enforce type import consistency (#10968)
* Update types

* fix circular dep

* type imports

* lint type imports and --fix
2025-12-19 23:07:02 -05:00

44 lines
892 B
TypeScript

import { NotFoundError, PaymentRequiredError } from "@server/errors";
import type { User } from "@server/models";
import { Document } from "@server/models";
import { authorize } from "@server/policies";
type Props = {
id: string;
user: User;
includeState?: boolean;
};
export default async function loadDocument({
id,
user,
includeState,
}: Props): Promise<Document> {
const document = await Document.findByPk(id, {
userId: user ? user.id : undefined,
paranoid: false,
includeState,
});
if (!document) {
throw NotFoundError();
}
if (document.deletedAt) {
// don't send data if user cannot restore deleted doc
if (user) {
authorize(user, "restore", document);
}
} else {
if (user) {
authorize(user, "read", document);
}
}
if (document.isTrialImport) {
throw PaymentRequiredError();
}
return document;
}