mirror of
https://github.com/Litlyx/litlyx
synced 2025-12-11 00:08:37 +01:00
fix payment service + appsumo + ui
This commit is contained in:
@@ -1,17 +1,13 @@
|
||||
import { getPlanFromId, PREMIUM_PLAN } from "@data/PREMIUM";
|
||||
import { canTryAppsumoCode, checkAppsumoCode, useAppsumoCode, useTryAppsumoCode } from "~/server/services/AppsumoService";
|
||||
import { PaymentServiceHelper } from "~/server/services/PaymentServiceHelper";
|
||||
import { PremiumModel } from "~/shared/schema/PremiumSchema";
|
||||
|
||||
|
||||
function getPlanToActivate(current_plan_id: number) {
|
||||
if (current_plan_id === PREMIUM_PLAN.FREE.ID) {
|
||||
return PREMIUM_PLAN.APPSUMO_INCUBATION;
|
||||
}
|
||||
// if (current_plan_id === PREMIUM_PLAN.INCUBATION.ID) {
|
||||
// return PREMIUM_PLAN.APPSUMO_ACCELERATION;
|
||||
// }
|
||||
// if (current_plan_id === PREMIUM_PLAN.ACCELERATION.ID) {
|
||||
// return PREMIUM_PLAN.APPSUMO_GROWTH;
|
||||
// }
|
||||
if (current_plan_id === PREMIUM_PLAN.APPSUMO_INCUBATION.ID) {
|
||||
return PREMIUM_PLAN.APPSUMO_ACCELERATION;
|
||||
}
|
||||
@@ -38,13 +34,18 @@ export default defineEventHandler(async event => {
|
||||
const valid = await checkAppsumoCode(code);
|
||||
if (!valid) return setResponseStatus(event, 400, 'Code not valid');
|
||||
|
||||
// const currentPlan = getPlanFromId(project.premium_type);
|
||||
// if (!currentPlan) return setResponseStatus(event, 400, 'Current plan not found');
|
||||
// const planToActivate = getPlanToActivate(currentPlan.ID);
|
||||
// if (!planToActivate) return setResponseStatus(event, 400, 'Cannot use code on current plan');
|
||||
const currentPremiumData = await PremiumModel.findOne({ user_id: user.id });
|
||||
if (!currentPremiumData) return setResponseStatus(event, 400, 'Error finding user');
|
||||
|
||||
// await StripeService.createSubscription(project.customer_id, planToActivate.ID);
|
||||
const currentPlan = getPlanFromId(currentPremiumData.premium_type);
|
||||
if (!currentPlan) return setResponseStatus(event, 400, 'Current plan not found');
|
||||
|
||||
// await useAppsumoCode(pid, code);
|
||||
const planToActivate = getPlanToActivate(currentPlan.ID);
|
||||
if (!planToActivate) return setResponseStatus(event, 400, 'Cannot use code on current plan');
|
||||
|
||||
const sub = await PaymentServiceHelper.create_subscription(user.id, planToActivate.TAG);
|
||||
console.log(sub);
|
||||
|
||||
await useAppsumoCode(pid, code);
|
||||
|
||||
});
|
||||
@@ -15,6 +15,8 @@ import { TeamMemberModel } from "~/shared/schema/TeamMemberSchema";
|
||||
import { PasswordModel } from "~/shared/schema/PasswordSchema";
|
||||
import { PremiumModel } from "~/shared/schema/PremiumSchema";
|
||||
import { PaymentServiceHelper } from "~/server/services/PaymentServiceHelper";
|
||||
import { VisitModel } from "~/shared/schema/metrics/VisitSchema";
|
||||
import { EventModel } from "~/shared/schema/metrics/EventSchema";
|
||||
|
||||
export default defineEventHandler(async event => {
|
||||
|
||||
@@ -24,9 +26,8 @@ export default defineEventHandler(async event => {
|
||||
const projects = await ProjectModel.find({ owner: userData.id });
|
||||
|
||||
const premium = await PremiumModel.findOne({ user_id: userData.id });
|
||||
if (!premium) return;
|
||||
|
||||
if (premium.premium_type > 0) return setResponseStatus(event, 400, 'Cannot delete an account with a premium project');
|
||||
if (premium && premium.premium_type > 0) return setResponseStatus(event, 400, 'Cannot delete an account with a premium project');
|
||||
|
||||
const membersDeletation = await TeamMemberModel.deleteMany({ user_id: userData.id });
|
||||
const membersEmailDeletation = await TeamMemberModel.deleteMany({ email: userData.user.email });
|
||||
@@ -36,24 +37,31 @@ export default defineEventHandler(async event => {
|
||||
const limitdeletation = await UserLimitModel.deleteMany({ user_id: userData.id });
|
||||
const notifiesDeletation = await LimitNotifyModel.deleteMany({ user_id: userData.id });
|
||||
|
||||
await PaymentServiceHelper.delete_customer(premium.customer_id);
|
||||
if (premium) PaymentServiceHelper.delete_customer(premium.customer_id);
|
||||
|
||||
|
||||
for (const project of projects) {
|
||||
const project_id = project._id;
|
||||
|
||||
const projectDeletation = await ProjectModel.deleteOne({ _id: project_id });
|
||||
const userSettingsDeletation = await UserSettingsModel.deleteOne({ project_id });
|
||||
const countDeletation = await ProjectCountModel.deleteMany({ project_id });
|
||||
const sessionsDeletation = await SessionModel.deleteMany({ project_id });
|
||||
const aiChatsDeletation = await AiChatModel.deleteMany({ project_id });
|
||||
|
||||
const sessionsDeletation = SessionModel.deleteMany({ project_id });
|
||||
const visitsDeletation = VisitModel.deleteMany({ project_id });
|
||||
const eventsDeletation = EventModel.deleteMany({ project_id });
|
||||
|
||||
const aiChatsDeletation = AiChatModel.deleteMany({ project_id });
|
||||
|
||||
//Shields
|
||||
const addressBlacklistDeletation = await AddressBlacklistModel.deleteMany({ project_id });
|
||||
const botTrafficOptionsDeletation = await BotTrafficOptionModel.deleteMany({ project_id });
|
||||
const countryBlacklistDeletation = await CountryBlacklistModel.deleteMany({ project_id });
|
||||
const domainWhitelistDeletation = await DomainWhitelistModel.deleteMany({ project_id });
|
||||
|
||||
const addressBlacklistDeletation = AddressBlacklistModel.deleteMany({ project_id });
|
||||
const botTrafficOptionsDeletation = BotTrafficOptionModel.deleteMany({ project_id });
|
||||
const countryBlacklistDeletation = CountryBlacklistModel.deleteMany({ project_id });
|
||||
const domainWhitelistDeletation = DomainWhitelistModel.deleteMany({ project_id });
|
||||
|
||||
}
|
||||
|
||||
const premiumDeletation = await PremiumModel.deleteOne({ user_id: userData.id });
|
||||
const userDeletation = await UserModel.deleteOne({ _id: userData.id });
|
||||
|
||||
return { ok: true };
|
||||
|
||||
Reference in New Issue
Block a user