fix dashboard premium tables

This commit is contained in:
Emily
2025-04-05 16:32:38 +02:00
parent 70c15238a0
commit 10d4a9f1bc
24 changed files with 341 additions and 370 deletions

View File

@@ -1,14 +1,12 @@
import { ProjectModel } from "@schema/project/ProjectSchema";
import { ProjectCountModel } from "@schema/project/ProjectsCounts";
import { ProjectLimitModel } from "@schema/project/ProjectsLimits";
import { SessionModel } from "@schema/metrics/SessionSchema";
import { LimitNotifyModel } from "@schema/broker/LimitNotifySchema";
import StripeService from '~/server/services/StripeService';
import { AiChatModel } from "@schema/ai/AiChatSchema";
export default defineEventHandler(async event => {
const data = await getRequestDataOld(event, { requireSchema: false, allowGuests: false, allowLitlyx: false });
const data = await getRequestData(event, [], []);
if (!data) return;
const { project, user, project_id } = data;
@@ -16,15 +14,9 @@ export default defineEventHandler(async event => {
const projects = await ProjectModel.countDocuments({ owner: user.id });
if (projects == 1) return setResponseStatus(event, 400, 'Cannot delete last project');
if (project.premium === true) return setResponseStatus(event, 400, 'Cannot delete premium project');
if (project.customer_id) {
await StripeService.deleteCustomer(project.customer_id);
}
const projectDeletation = ProjectModel.deleteOne({ _id: project_id });
const countDeletation = ProjectCountModel.deleteMany({ project_id });
const limitdeletation = ProjectLimitModel.deleteMany({ project_id });
const sessionsDeletation = SessionModel.deleteMany({ project_id });
const notifiesDeletation = LimitNotifyModel.deleteMany({ project_id });
const aiChatsDeletation = AiChatModel.deleteMany({ project_id });
@@ -32,7 +24,6 @@ export default defineEventHandler(async event => {
const results = await Promise.all([
projectDeletation,
countDeletation,
limitdeletation,
sessionsDeletation,
notifiesDeletation,
aiChatsDeletation