initial commit

This commit is contained in:
Hunter Johnston
2023-02-04 11:44:27 -05:00
commit b15148ca19
31 changed files with 2560 additions and 0 deletions

View File

@@ -0,0 +1,49 @@
import type { Actions, PageServerLoad } from "./$types"
import { prisma } from "$lib/server/prisma"
import { error, fail } from "@sveltejs/kit"
export const load: PageServerLoad = async ({ params }) => {
const getArticle = async () => {
const article = await prisma.article.findUnique({
where: {
id: Number(params.articleId),
},
})
if (!article) {
throw error(404, "Article not found")
}
return article
}
return {
article: getArticle(),
}
}
export const actions: Actions = {
updateArticle: async ({ request, params }) => {
const { title, content } = Object.fromEntries(await request.formData()) as {
title: string
content: string
}
try {
await prisma.article.update({
where: {
id: Number(params.articleId),
},
data: {
title,
content,
},
})
} catch (err) {
console.error(err)
return fail(500, { message: "Could not update article" })
}
return {
status: 200,
}
},
}