diff --git a/src/routes/blog.js b/src/routes/blog.js index 34274f0..a301309 100644 --- a/src/routes/blog.js +++ b/src/routes/blog.js @@ -82,7 +82,7 @@ export const blogRoutes = (fastify, _, done) => { const [{ total }] = await db.select({ total: sql`COUNT(*)` }).from(articlesTable).where(clause); - + response.send({ success: true, articles: results, @@ -152,7 +152,7 @@ export const blogRoutes = (fastify, _, done) => { email: req.body.email, site_id: req.body.site_id, source: req.body.source - }).returning(); + }); if (inserted.rowCount != 1) { reply.status(400).send({ diff --git a/src/utils/email.js b/src/utils/email.js index fda0ff3..5051614 100644 --- a/src/utils/email.js +++ b/src/utils/email.js @@ -13,7 +13,7 @@ export async function sendFreebie(recipient, blog_id) { const [blog] = await db.select().from(sites).where(eq(sites.id, blog_id)); if (!blog) throw new Error("Invalid site"); - if (!blog.use_freebie) return; + if (!blog.use_freebie || !blog.freebie_url) return; const sender = { email: "mailtrap@demomailtrap.com", @@ -32,6 +32,5 @@ export async function sendFreebie(recipient, blog_id) { to: recipients, subject: `Your freebie from ${blog.name}`, text: `Thank you for subscribing to ${blog.name}! Your freebie is linked below.\n ${blog.freebie_url}`, - }) - .then(console.log, console.error); + }).catch(console.error); }