chore: Remove over-usage of invariant (#3719)
This commit is contained in:
@@ -1,5 +1,4 @@
|
||||
import { yDocToProsemirrorJSON } from "@getoutline/y-prosemirror";
|
||||
import invariant from "invariant";
|
||||
import { uniq } from "lodash";
|
||||
import { Node } from "prosemirror-model";
|
||||
import * as Y from "yjs";
|
||||
@@ -25,9 +24,9 @@ export default async function documentCollaborativeUpdater({
|
||||
of: Document,
|
||||
level: transaction.LOCK.UPDATE,
|
||||
},
|
||||
rejectOnEmpty: true,
|
||||
paranoid: false,
|
||||
});
|
||||
invariant(document, "document not found");
|
||||
|
||||
const state = Y.encodeStateAsUpdate(ydoc);
|
||||
const node = Node.fromJSON(schema, yDocToProsemirrorJSON(ydoc, "default"));
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
import invariant from "invariant";
|
||||
import { Transaction } from "sequelize";
|
||||
import { Document, Event, User } from "@server/models";
|
||||
|
||||
@@ -105,14 +104,12 @@ export default async function documentCreator({
|
||||
// reload to get all of the data needed to present (user, collection etc)
|
||||
// we need to specify publishedAt to bypass default scope that only returns
|
||||
// published documents
|
||||
const doc = await Document.findOne({
|
||||
return await Document.findOne({
|
||||
where: {
|
||||
id: document.id,
|
||||
publishedAt: document.publishedAt,
|
||||
},
|
||||
rejectOnEmpty: true,
|
||||
transaction,
|
||||
});
|
||||
invariant(doc, "Document must exist");
|
||||
|
||||
return doc;
|
||||
}
|
||||
|
||||
@@ -149,8 +149,7 @@ export default async function loadDocument({
|
||||
}
|
||||
|
||||
// It is possible to disable sharing at the team level so we must check
|
||||
const team = await Team.findByPk(document.teamId);
|
||||
invariant(team, "team not found");
|
||||
const team = await Team.findByPk(document.teamId, { rejectOnEmpty: true });
|
||||
|
||||
if (!team.sharing) {
|
||||
throw AuthorizationError();
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
import invariant from "invariant";
|
||||
import { uniqBy } from "lodash";
|
||||
import { Role } from "@shared/types";
|
||||
import InviteEmail from "@server/emails/templates/InviteEmail";
|
||||
@@ -25,8 +24,7 @@ export default async function userInviter({
|
||||
sent: Invite[];
|
||||
users: User[];
|
||||
}> {
|
||||
const team = await Team.findByPk(user.teamId);
|
||||
invariant(team, "team not found");
|
||||
const team = await Team.findByPk(user.teamId, { rejectOnEmpty: true });
|
||||
|
||||
// filter out empties and obvious non-emails
|
||||
const compactedInvites = invites.filter(
|
||||
|
||||
Reference in New Issue
Block a user