fix: improve document meta logic

This commit is contained in:
David Nguyen
2024-01-03 20:10:50 +11:00
parent b8a45dd5e3
commit 6be119ac95
2 changed files with 10 additions and 0 deletions

View File

@ -8,6 +8,7 @@ export type CreateDocumentMetaOptions = {
message: string; message: string;
timezone: string; timezone: string;
dateFormat: string; dateFormat: string;
userId: number;
}; };
export const upsertDocumentMeta = async ({ export const upsertDocumentMeta = async ({
@ -16,7 +17,15 @@ export const upsertDocumentMeta = async ({
timezone, timezone,
dateFormat, dateFormat,
documentId, documentId,
userId,
}: CreateDocumentMetaOptions) => { }: CreateDocumentMetaOptions) => {
await prisma.document.findFirstOrThrow({
where: {
id: documentId,
userId,
},
});
return await prisma.documentMeta.upsert({ return await prisma.documentMeta.upsert({
where: { where: {
documentId, documentId,

View File

@ -188,6 +188,7 @@ export const documentRouter = router({
message: meta.message, message: meta.message,
dateFormat: meta.dateFormat, dateFormat: meta.dateFormat,
timezone: meta.timezone, timezone: meta.timezone,
userId: ctx.user.id,
}); });
} }