add admin utils

This commit is contained in:
Emily
2024-06-06 03:45:51 +02:00
parent 7e8da6ec06
commit 1c26f6a1d4
3 changed files with 83 additions and 1 deletions

View File

@@ -0,0 +1,15 @@
import { ProjectCountModel } from "@schema/ProjectsCounts";
export default defineEventHandler(async event => {
const userData = getRequestUser(event);
if (!userData?.logged) return;
if (!userData.user.roles.includes('ADMIN')) return;
const { project_id } = getQuery(event);
if (!project_id) return setResponseStatus(event, 400, 'ProjectId is required');
await ProjectCountModel.updateOne({ project_id, events: 0, visits: 0 }, {}, { upsert: true });
return { ok: true };
});