mirror of
https://github.com/Litlyx/litlyx
synced 2025-12-11 00:08:37 +01:00
fix dashboard + payments
This commit is contained in:
@@ -1,6 +1,5 @@
|
||||
import { ProjectModel, TProject } from "@schema/project/ProjectSchema";
|
||||
import { ProjectCountModel } from "@schema/project/ProjectsCounts";
|
||||
import StripeService from '~/server/services/StripeService';
|
||||
|
||||
export default defineEventHandler(async event => {
|
||||
|
||||
@@ -19,57 +18,11 @@ export default defineEventHandler(async event => {
|
||||
const existingUserProjects = await ProjectModel.countDocuments({ owner: userData.id });
|
||||
if (existingUserProjects >= maxProjects) return setResponseStatus(event, 400, 'Already have max number of projects');
|
||||
|
||||
if (StripeService.isDisabled()) {
|
||||
const project = await ProjectModel.create({ owner: userData.id, name: newProjectName });
|
||||
|
||||
const project = await ProjectModel.create({
|
||||
owner: userData.id,
|
||||
name: newProjectName,
|
||||
premium: false,
|
||||
premium_type: 0,
|
||||
customer_id: 'DISABLED_MODE',
|
||||
subscription_id: "DISABLED_MODE",
|
||||
premium_expire_at: new Date(3000, 1, 1)
|
||||
});
|
||||
await ProjectCountModel.create({ project_id: project._id, events: 0, visits: 0, sessions: 0 });
|
||||
|
||||
|
||||
await ProjectCountModel.create({
|
||||
project_id: project._id,
|
||||
events: 0,
|
||||
visits: 0,
|
||||
sessions: 0
|
||||
});
|
||||
|
||||
return project.toJSON() as TProject;
|
||||
|
||||
} else {
|
||||
|
||||
const customer = await StripeService.createCustomer(userData.user.email);
|
||||
if (!customer) return setResponseStatus(event, 400, 'Error creating customer');
|
||||
|
||||
const subscription = await StripeService.createFreeSubscription(customer.id);
|
||||
if (!subscription) return setResponseStatus(event, 400, 'Error creating subscription');
|
||||
|
||||
const project = await ProjectModel.create({
|
||||
owner: userData.id,
|
||||
name: newProjectName,
|
||||
premium: false,
|
||||
premium_type: 0,
|
||||
customer_id: customer.id,
|
||||
subscription_id: subscription.id,
|
||||
premium_expire_at: subscription.current_period_end * 1000
|
||||
});
|
||||
|
||||
|
||||
await ProjectCountModel.create({
|
||||
project_id: project._id,
|
||||
events: 0,
|
||||
visits: 0,
|
||||
sessions: 0
|
||||
});
|
||||
|
||||
return project.toJSON() as TProject;
|
||||
|
||||
}
|
||||
return project.toJSON() as TProject;
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import { UserLimitModel } from "@schema/UserLimitSchema";
|
||||
import StripeService from '~/server/services/StripeService';
|
||||
import { PremiumModel } from "~/shared/schema/PremiumSchema";
|
||||
|
||||
export default defineEventHandler(async event => {
|
||||
@@ -22,14 +21,12 @@ export default defineEventHandler(async event => {
|
||||
billing_expire_at: userLimits.billing_expire_at,
|
||||
limit: userLimits.limit,
|
||||
count: userLimits.events + userLimits.visits,
|
||||
subscription_status: StripeService.isDisabled() ? 'Disabled mode' : ('One time payment')
|
||||
subscription_status: 'One time'
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
const subscription = await StripeService.getSubscription(premium.subscription_id);
|
||||
|
||||
const userLimits = await UserLimitModel.findOne({ user_id: data.user.id });
|
||||
if (!userLimits) return setResponseStatus(event, 400, 'User limits not found');
|
||||
|
||||
@@ -41,7 +38,7 @@ export default defineEventHandler(async event => {
|
||||
billing_expire_at: userLimits.billing_expire_at,
|
||||
limit: userLimits.limit,
|
||||
count: userLimits.events + userLimits.visits,
|
||||
subscription_status: StripeService.isDisabled() ? 'Disabled mode' : (subscription?.status ?? '?')
|
||||
subscription_status: ''
|
||||
}
|
||||
|
||||
return result;
|
||||
|
||||
Reference in New Issue
Block a user