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();
if (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]);

View File

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