app.get('/feeds', async (req, res) => {
res.json(await db.select('*').from('feeds').orderBy('created_at'));
-})
+});
+
+app.delete('/feeds/:feed_id', async (req, res) => {
+ if(req.query.key !== process.env.ADMIN_KEY) {
+ res.sendStatus(400).end();
+ return;
+ }
+
+ await db('feeds').delete().where({ id: req.params.feed_id });
+ await db('feed_entry').delete().where({ feed_id: req.params.feed_id });
+
+ res.json(await db.select('*').from('feeds').orderBy('created_at'));
+});
app.listen(process.env.API_PORT, () => {
console.log(`Listening on port ${process.env.API_PORT}`);