week5-node-express-knex-pg/controllers/subscribers.js

55 lines
1.2 KiB
JavaScript
Raw Permalink Normal View History

2024-10-21 17:09:40 +01:00
import {
getAllSubscribers,
addOneSubscriber,
selectOneSubscriber,
deleteOneSubscriber
} from "../models/subscribers.js";
async function getSubscribers(req, res) {
try {
const results = await getAllSubscribers();
return res.status(200).json(results);
} catch (error) {
console.log(error);
return res.status(500).json(error);
}
}
async function addSubscriber(req, res) {
console.log(req.body);
try {
const results = await addOneSubscriber(req.body);
return res.status(200).json(results);
} catch (error) {
console.log(error);
return res.status(500).json(error);
}
}
async function getSubscriber(req, res) {
console.log(req.params);
try {
const results = await selectOneSubscriber(req.params);
return res.status(200).json(results);
} catch (error) {
console.log(error);
return res.status(500).json(error);
}
}
async function deleteSubscriber(req, res) {
console.log(req.body);
try {
const results = await deleteOneSubscriber(req.body);
return res.status(200).json(results);
} catch (error) {
console.log(error);
return res.status(500).json(error);
}
}
export { getSubscribers, addSubscriber, getSubscriber, deleteSubscriber };