fix: Attributes lost creating template on server (#7049)

This commit is contained in:
Tom Moor
2024-06-15 22:06:37 -04:00
committed by GitHub
parent eb1882eb96
commit 379d2cb788
3 changed files with 40 additions and 1 deletions

View File

@@ -1,6 +1,7 @@
import { Transaction } from "sequelize";
import { Optional } from "utility-types";
import { Document, Event, User } from "@server/models";
import { ProsemirrorHelper } from "@server/models/helpers/ProsemirrorHelper";
import { TextHelper } from "@server/models/helpers/TextHelper";
type Props = Optional<
@@ -58,6 +59,12 @@ export default async function documentCreator({
}: Props): Promise<Document> {
const templateId = templateDocument ? templateDocument.id : undefined;
if (state && templateDocument) {
throw new Error(
"State cannot be set when creating a document from a template"
);
}
if (urlId) {
const existing = await Document.unscoped().findOne({
attributes: ["id"],
@@ -103,6 +110,12 @@ export default async function documentCreator({
ip,
transaction
),
content: templateDocument
? ProsemirrorHelper.replaceTemplateVariables(
templateDocument.content,
user
)
: undefined,
state,
},
{