diff --git a/src/routes/blog.js b/src/routes/blog.js index d1a4aee..f5fed13 100644 --- a/src/routes/blog.js +++ b/src/routes/blog.js @@ -91,10 +91,11 @@ export const blogRoutes = (fastify, _, done) => { }, required: ["id"] } - } + }, + preValidation: authMiddlewareFn }, async (req, reply) => { const [article] = await db.select(getTableColumns(articles)).from(articles).leftJoin(sites, eq(sites.id, articles.site_id)).where(eq(sites.user_id, req.session.user_id)); - + if (!article) { reply.status(404).send({ success: false, @@ -104,7 +105,7 @@ export const blogRoutes = (fastify, _, done) => { } if (Object.keys(req.body).length > 1) { - await db.update(articles).set(JSON.parse(JSON.stringify({ ...req.body, id: undefined }))).where(eq(articles.id, req.body.id)).limit(1); + await db.update(articles).set(JSON.parse(JSON.stringify({ ...req.body, id: undefined }))).where(eq(articles.id, req.body.id)); } reply.send({ success: true