2022-11-19 03:49:58 +01:00
|
|
|
import { NextApiRequestQueryBody } from 'interface/api/nextApi';
|
2021-08-10 23:03:55 +02:00
|
|
|
import { allowQuery } from 'lib/auth';
|
2022-11-19 03:49:58 +01:00
|
|
|
import { UmamiApi } from 'lib/constants';
|
2022-10-12 22:11:44 +02:00
|
|
|
import { useAuth, useCors } from 'lib/middleware';
|
2022-11-15 22:21:14 +01:00
|
|
|
import { NextApiResponse } from 'next';
|
2022-11-19 03:49:58 +01:00
|
|
|
import { methodNotAllowed, ok, unauthorized } from 'next-basics';
|
|
|
|
import { resetWebsite } from 'queries';
|
2021-08-10 23:03:55 +02:00
|
|
|
|
2022-11-18 07:46:05 +01:00
|
|
|
export interface WebsiteResetRequestQuery {
|
2022-11-15 22:21:14 +01:00
|
|
|
id: string;
|
|
|
|
}
|
|
|
|
|
|
|
|
export default async (
|
2022-11-18 07:46:05 +01:00
|
|
|
req: NextApiRequestQueryBody<WebsiteResetRequestQuery>,
|
2022-11-15 22:21:14 +01:00
|
|
|
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;
|
2021-08-10 23:03:55 +02:00
|
|
|
|
|
|
|
if (req.method === 'POST') {
|
2022-11-19 03:49:58 +01:00
|
|
|
if (!(await allowQuery(req, UmamiApi.AuthType.Website))) {
|
2021-08-10 23:03:55 +02:00
|
|
|
return unauthorized(res);
|
|
|
|
}
|
|
|
|
|
|
|
|
await resetWebsite(websiteId);
|
|
|
|
|
|
|
|
return ok(res);
|
|
|
|
}
|
|
|
|
|
|
|
|
return methodNotAllowed(res);
|
|
|
|
};
|