2022-07-12 23:14:36 +02:00
|
|
|
import { deleteWebsite, getWebsiteById } from 'queries';
|
2020-09-17 20:40:04 +02:00
|
|
|
import { methodNotAllowed, ok, unauthorized } from 'lib/response';
|
2020-09-18 07:52:20 +02:00
|
|
|
import { allowQuery } from 'lib/auth';
|
2022-04-04 09:33:20 +02:00
|
|
|
import { useCors } from 'lib/middleware';
|
2020-09-17 20:40:04 +02:00
|
|
|
|
|
|
|
export default async (req, res) => {
|
2020-09-18 07:52:20 +02:00
|
|
|
const { id } = req.query;
|
2020-09-17 20:40:04 +02:00
|
|
|
|
|
|
|
const websiteId = +id;
|
|
|
|
|
|
|
|
if (req.method === 'GET') {
|
2022-04-04 09:33:20 +02:00
|
|
|
await useCors(req, res);
|
|
|
|
|
2020-09-18 07:52:20 +02:00
|
|
|
if (!(await allowQuery(req))) {
|
|
|
|
return unauthorized(res);
|
2020-09-17 20:40:04 +02:00
|
|
|
}
|
2020-09-18 07:52:20 +02:00
|
|
|
|
|
|
|
const website = await getWebsiteById(websiteId);
|
|
|
|
|
|
|
|
return ok(res, website);
|
2020-09-17 20:40:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (req.method === 'DELETE') {
|
2020-09-18 07:52:20 +02:00
|
|
|
if (!(await allowQuery(req, true))) {
|
|
|
|
return unauthorized(res);
|
2020-09-17 20:40:04 +02:00
|
|
|
}
|
2020-09-18 07:52:20 +02:00
|
|
|
|
|
|
|
await deleteWebsite(websiteId);
|
|
|
|
|
|
|
|
return ok(res);
|
2020-09-17 20:40:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return methodNotAllowed(res);
|
|
|
|
};
|