fix: Templatize no longer works, closes #6067

This commit is contained in:
Tom Moor
2023-10-25 20:29:36 -04:00
parent f063bef968
commit 2fcf9149b5
2 changed files with 40 additions and 25 deletions

View File

@@ -23,7 +23,7 @@ function DocumentTemplatizeDialog({ documentId }: Props) {
const template = await document?.templatize(); const template = await document?.templatize();
if (template) { if (template) {
history.push(documentPath(template)); history.push(documentPath(template));
toast.message(t("Template created, go ahead and customize it")); toast.success(t("Template created, go ahead and customize it"));
} }
}, [document, history, t]); }, [document, history, t]);

View File

@@ -885,16 +885,21 @@ router.post(
auth({ member: true }), auth({ member: true }),
rateLimiter(RateLimiterStrategy.TwentyFivePerMinute), rateLimiter(RateLimiterStrategy.TwentyFivePerMinute),
validate(T.DocumentsTemplatizeSchema), validate(T.DocumentsTemplatizeSchema),
transaction(),
async (ctx: APIContext<T.DocumentsTemplatizeReq>) => { async (ctx: APIContext<T.DocumentsTemplatizeReq>) => {
const { id } = ctx.input.body; const { id } = ctx.input.body;
const { user } = ctx.state.auth; const { user } = ctx.state.auth;
const { transaction } = ctx.state;
const original = await Document.findByPk(id, { const original = await Document.findByPk(id, {
userId: user.id, userId: user.id,
transaction,
}); });
authorize(user, "update", original); authorize(user, "update", original);
const document = await Document.create({ const document = await Document.create(
{
editorVersion: original.editorVersion, editorVersion: original.editorVersion,
collectionId: original.collectionId, collectionId: original.collectionId,
teamId: original.teamId, teamId: original.teamId,
@@ -906,8 +911,13 @@ router.post(
emoji: original.emoji, emoji: original.emoji,
title: original.title, title: original.title,
text: original.text, text: original.text,
}); },
await Event.create({ {
transaction,
}
);
await Event.create(
{
name: "documents.create", name: "documents.create",
documentId: document.id, documentId: document.id,
collectionId: document.collectionId, collectionId: document.collectionId,
@@ -918,13 +928,18 @@ router.post(
template: true, template: true,
}, },
ip: ctx.request.ip, ip: ctx.request.ip,
}); },
{
transaction,
}
);
// reload to get all of the data needed to present (user, collection etc) // reload to get all of the data needed to present (user, collection etc)
const reloaded = await Document.findByPk(document.id, { const reloaded = await Document.findByPk(document.id, {
userId: user.id, userId: user.id,
rejectOnEmpty: true, transaction,
}); });
invariant(reloaded, "document not found");
ctx.body = { ctx.body = {
data: await presentDocument(reloaded), data: await presentDocument(reloaded),