Skip to content

Commit

Permalink
Refactor tag creation and cover image property
Browse files Browse the repository at this point in the history
name
  • Loading branch information
thebkht committed Nov 4, 2023
1 parent 8608010 commit d176977
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 12 deletions.
15 changes: 4 additions & 11 deletions app/api/post/[postid]/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,13 @@ async function insertTag(tags: any, postid: any) {
},
});
if (!tagExists) {
await postgres.tag.create({
const tagId = await postgres.tag.create({
data: {
name: tag.value.replace(/\s+/g, "-").toLowerCase(),
},
select: { id: true }
});
}
const tagId = await postgres.tag.findFirst({
where: {
name: tag.value.replace(/\s+/g, "-").toLowerCase(),
},
select: {
id: true,
},
});
if (tagId) {

await postgres.postTag.create({
data: {
tagId: tagId.id,
Expand Down Expand Up @@ -127,6 +119,7 @@ export async function PATCH(
},
});
}

await insertTag(tags, postid);

return new Response(null, { status: 200 });
Expand Down
4 changes: 3 additions & 1 deletion components/editor/post-editor-form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -91,13 +91,15 @@ const defaultValues: Partial<PostFormValues> = {
title: props.post?.title,
content: props.post?.content,
visibility: props.post?.visibility,
coverImage: props.post?.coverimage || '',
coverImage: props.post?.cover || '',
url: props.post?.url,
subtitle: props.post?.subtitle,
tags: props.post?.tags?.map((tag: any) => ({
value: tag.tag?.name,
})),
}

console.log(defaultValues)

const form = useForm<PostFormValues>({
resolver: zodResolver(postFormSchema),
Expand Down

0 comments on commit d176977

Please sign in to comment.