2020-08-07 11:27:12 +02:00
|
|
|
import { getWebsites, updateWebsite } from 'lib/db';
|
2020-07-28 08:52:14 +02:00
|
|
|
import { useAuth } from 'lib/middleware';
|
|
|
|
|
|
|
|
export default async (req, res) => {
|
|
|
|
await useAuth(req, res);
|
|
|
|
|
|
|
|
const { user_id } = req.auth;
|
2020-08-07 11:27:12 +02:00
|
|
|
const { website_id } = req.body;
|
2020-07-28 08:52:14 +02:00
|
|
|
|
2020-08-07 11:27:12 +02:00
|
|
|
if (req.method === 'GET') {
|
|
|
|
const websites = await getWebsites(user_id);
|
2020-07-28 08:52:14 +02:00
|
|
|
|
2020-08-07 11:27:12 +02:00
|
|
|
return res.status(200).json(websites);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (req.method === 'POST') {
|
|
|
|
if (website_id) {
|
|
|
|
const { name, domain } = req.body;
|
|
|
|
const website = await updateWebsite(website_id, { name, domain });
|
|
|
|
|
|
|
|
return res.status(200).json(website);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return res.status(405).end();
|
2020-07-28 08:52:14 +02:00
|
|
|
};
|