fix: Types on overridden findByPk methods (#5908)

This commit is contained in:
Tom Moor
2023-10-01 15:02:56 -04:00
committed by GitHub
parent e2a6d828a9
commit 41a6f77998
6 changed files with 59 additions and 16 deletions

View File

@@ -1,5 +1,6 @@
import invariant from "invariant";
import { Transaction } from "sequelize";
import { ValidationError } from "@server/errors";
import { traceFunction } from "@server/logging/tracing";
import { User, Document, Collection, Pin, Event } from "@server/models";
import pinDestroyer from "./pinDestroyer";
@@ -50,7 +51,10 @@ async function documentMover({
}
if (document.template) {
invariant(collectionId, "collectionId should exist");
if (!document.collectionId) {
throw ValidationError("Templates must be in a collection");
}
document.collectionId = collectionId;
document.parentDocumentId = null;
document.lastModifiedById = user.id;
@@ -142,7 +146,8 @@ async function documentMover({
}).findByPk(collectionId, {
transaction,
});
invariant(newCollection, "collection should exist");
invariant(newCollection, "Collection not found");
result.collections.push(newCollection);
await Document.update(