fix delete account

This commit is contained in:
Emily
2024-06-06 15:08:55 +02:00
parent f8a3a5ce68
commit c15e5d966e
8 changed files with 97 additions and 52 deletions

View File

@@ -1,18 +1,21 @@
import { ProjectModel } from "@schema/ProjectSchema";
import { ProjectCountModel } from "@schema/ProjectsCounts";
import { ProjectLimitModel } from "@schema/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 body = await readBody(event);
const projectId = body.project_id;
const project_id = body.project_id;
const userData = getRequestUser(event);
if (!userData?.logged) return setResponseStatus(event, 400, 'NotLogged');
const project = await ProjectModel.findById(projectId);
const project = await ProjectModel.findById(project_id);
if (!project) return setResponseStatus(event, 400, 'Project not exist');
const projects = await ProjectModel.countDocuments({ owner: userData.id });
@@ -22,18 +25,25 @@ export default defineEventHandler(async event => {
await StripeService.deleteCustomer(project.customer_id);
const countDeletation = await ProjectCountModel.deleteOne({ owner: userData.id, _id: projectId });
const limitdeletation = await ProjectLimitModel.deleteOne({ owner: userData.id, _id: projectId });
const projectDeletation = await ProjectModel.deleteOne({ owner: userData.id, _id: projectId });
const projectDeletation = await ProjectModel.deleteOne({ _id: project_id });
const countDeletation = await ProjectCountModel.deleteMany({ project_id });
const limitdeletation = await ProjectLimitModel.deleteMany({ project_id });
const sessionsDeletation = await SessionModel.deleteMany({ project_id });
const notifiesDeletation = await LimitNotifyModel.deleteMany({ project_id });
const aiChatsDeletation = await AiChatModel.deleteMany({ project_id });
const ok = countDeletation.acknowledged && limitdeletation.acknowledged &&
projectDeletation.acknowledged && sessionsDeletation.acknowledged && notifiesDeletation.acknowledged && aiChatsDeletation.acknowledged
const ok = countDeletation.acknowledged && limitdeletation.acknowledged && projectDeletation.acknowledged
return {
ok,
data: [
countDeletation.acknowledged,
limitdeletation.acknowledged,
projectDeletation.acknowledged
projectDeletation.acknowledged,
sessionsDeletation.acknowledged,
notifiesDeletation.acknowledged,
aiChatsDeletation.acknowledged
]
};