adjustments for docker image

This commit is contained in:
Emily
2024-06-27 23:46:37 +02:00
parent 9db55bbbe2
commit 237dccad8f
2 changed files with 16 additions and 2 deletions

View File

@@ -35,19 +35,21 @@ async function addSubscriptionToProject(project_id: string, plan: PREMIUM_DATA,
async function onPaymentFailed(event: Event.InvoicePaymentFailedEvent) {
//TODO: Send emails
if (event.data.object.attempt_count > 1) {
const customer_id = event.data.object.customer as string;
const project = await ProjectModel.findOne({ customer_id });
if (!project) return { error: 'CUSTOMER NOT EXIST' }
const allSubscriptions = await StripeService.getAllSubscriptions(customer_id);
if (!allSubscriptions) return;
for (const subscription of allSubscriptions.data) {
await StripeService.deleteSubscription(subscription.id);
}
const freeSub = await StripeService.createFreeSubscription(customer_id);
if (!freeSub) return;
await addSubscriptionToProject(
project._id.toString(),
@@ -75,7 +77,8 @@ async function onPaymentSuccess(event: Event.InvoicePaidEvent) {
const subscription_id = event.data.object.subscription as string;
const allSubscriptions = await StripeService.getAllSubscriptions(customer_id);
if (!allSubscriptions) return;
const currentSubscription = allSubscriptions.data.find(e => e.id === subscription_id);
if (!currentSubscription) return { error: 'SUBSCRIPTION NOT EXIST' }

View File

@@ -1,5 +1,6 @@
import { ProjectModel, TProject } from "@schema/ProjectSchema";
import { ProjectCountModel } from "@schema/ProjectsCounts";
import { ProjectLimitModel } from "@schema/ProjectsLimits";
import { UserSettingsModel } from "@schema/UserSettings";
import StripeService from '~/server/services/StripeService';
@@ -41,6 +42,16 @@ export default defineEventHandler(async event => {
visits: 0
});
await ProjectLimitModel.updateOne({ project_id: project._id }, {
events: 0,
visits: 0,
ai_messages: 0,
limit: 10_000_000,
ai_limit: 1_000_000,
billing_start_at: Date.now(),
billing_expire_at: new Date(3000, 1, 1)
}, { upsert: true })
return project.toJSON() as TProject;
} else {