umami/pages/api/teams/[id]/websites/[websiteId].ts

33 lines
835 B
TypeScript
Raw Normal View History

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 {
id: string;
2023-04-10 01:04:28 +02:00
websiteId: string;
}
export default async (
2023-04-10 01:04:28 +02:00
req: NextApiRequestQueryBody<TeamWebsitesRequestQuery>,
res: NextApiResponse,
) => {
await useAuth(req, res);
2023-04-10 01:04:28 +02:00
const { id: teamId, websiteId } = req.query;
if (req.method === 'DELETE') {
2023-04-10 01:04:28 +02:00
if (!(await canDeleteTeamWebsite(req.auth, teamId, websiteId))) {
return unauthorized(res);
}
2023-04-14 05:33:21 +02:00
await deleteTeamWebsite(teamId, websiteId);
2023-04-14 05:33:21 +02:00
return ok(res);
}
return methodNotAllowed(res);
};