umami/pages/api/websites/[id]/reset.ts

34 lines
832 B
TypeScript
Raw Normal View History

2022-07-12 23:14:36 +02:00
import { resetWebsite } from 'queries';
2022-08-29 05:20:54 +02:00
import { methodNotAllowed, ok, unauthorized } from 'next-basics';
import { allowQuery } from 'lib/auth';
2022-10-12 22:11:44 +02:00
import { useAuth, useCors } from 'lib/middleware';
import { TYPE_WEBSITE } from 'lib/constants';
2022-11-15 22:21:14 +01:00
import { NextApiRequestQueryBody } from 'interface/api/nextApi';
import { NextApiResponse } from 'next';
2022-11-15 22:21:14 +01:00
export interface WebsiteResetReqeustQuery {
id: string;
}
export default async (
req: NextApiRequestQueryBody<WebsiteResetReqeustQuery>,
res: NextApiResponse,
) => {
2022-10-12 22:11:44 +02:00
await useCors(req, res);
await useAuth(req, res);
2022-10-12 04:37:38 +02:00
const { id: websiteId } = req.query;
if (req.method === 'POST') {
if (!(await allowQuery(req, TYPE_WEBSITE))) {
return unauthorized(res);
}
await resetWebsite(websiteId);
return ok(res);
}
return methodNotAllowed(res);
};