55 lines
1.2 KiB
JavaScript
55 lines
1.2 KiB
JavaScript
|
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 };
|