2023-03-09 21:42:12 +01:00
|
|
|
import { canDeleteTeamWebsite } from 'lib/auth';
|
|
|
|
import { useAuth } from 'lib/middleware';
|
|
|
|
import { NextApiRequestQueryBody } from 'lib/types';
|
|
|
|
import { NextApiResponse } from 'next';
|
|
|
|
import { methodNotAllowed, ok, unauthorized } from 'next-basics';
|
|
|
|
import { deleteTeamWebsite } from 'queries/admin/teamWebsite';
|
|
|
|
|
2023-04-10 01:04:28 +02:00
|
|
|
export interface TeamWebsitesRequestQuery {
|
2023-03-09 21:42:12 +01:00
|
|
|
id: string;
|
2023-04-10 01:04:28 +02:00
|
|
|
websiteId: string;
|
2023-03-09 21:42:12 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
export default async (
|
2023-04-10 01:04:28 +02:00
|
|
|
req: NextApiRequestQueryBody<TeamWebsitesRequestQuery>,
|
2023-03-09 21:42:12 +01:00
|
|
|
res: NextApiResponse,
|
|
|
|
) => {
|
|
|
|
await useAuth(req, res);
|
|
|
|
|
2023-04-10 01:04:28 +02:00
|
|
|
const { id: teamId, websiteId } = req.query;
|
2023-03-09 21:42:12 +01:00
|
|
|
|
|
|
|
if (req.method === 'DELETE') {
|
2023-04-10 01:04:28 +02:00
|
|
|
if (!(await canDeleteTeamWebsite(req.auth, teamId, websiteId))) {
|
2023-03-09 21:42:12 +01:00
|
|
|
return unauthorized(res);
|
|
|
|
}
|
|
|
|
|
2023-04-14 05:33:21 +02:00
|
|
|
await deleteTeamWebsite(teamId, websiteId);
|
2023-03-09 21:42:12 +01:00
|
|
|
|
2023-04-14 05:33:21 +02:00
|
|
|
return ok(res);
|
2023-03-09 21:42:12 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return methodNotAllowed(res);
|
|
|
|
};
|