implementing new payment system + rewrite deploy scripts

This commit is contained in:
Emily
2025-03-28 16:57:57 +01:00
parent 7658dbe85c
commit 7e093251fa
14 changed files with 265 additions and 124 deletions

View File

@@ -0,0 +1,22 @@
import { model, Schema, Types } from 'mongoose';
export type TPremium = {
user_id: Schema.Types.ObjectId,
premium_type: number,
customer_id: string,
subscription_id: string,
expire_at: number,
created_at: Date,
}
const PremiumSchema = new Schema<TPremium>({
user_id: { type: Types.ObjectId, unique: true, index: 1 },
customer_id: { type: String },
premium_type: { type: Number },
subscription_id: { type: String },
expire_at: { type: Number },
created_at: { type: Date, default: () => Date.now() }
})
export const PremiumModel = model<TPremium>('premiums', PremiumSchema);

View File

@@ -0,0 +1,26 @@
import { model, Schema, Types } from 'mongoose';
export type TUserLimit = {
_id: Schema.Types.ObjectId,
user_id: Schema.Types.ObjectId,
events: number,
visits: number,
ai_messages: number,
limit: number,
ai_limit: number,
billing_expire_at: Date,
billing_start_at: Date,
}
const UserLimitSchema = new Schema<TUserLimit>({
user_id: { type: Types.ObjectId, index: true, unique: true },
events: { type: Number, required: true, default: 0 },
visits: { type: Number, required: true, default: 0 },
ai_messages: { type: Number, required: true, default: 0 },
limit: { type: Number, required: true },
ai_limit: { type: Number, required: true },
billing_start_at: { type: Date, required: true },
billing_expire_at: { type: Date, required: true },
});
export const UserLimitModel = model<TUserLimit>('user_limits', UserLimitSchema);

View File

@@ -7,14 +7,6 @@ export type TUser = {
locale: string,
picture: string,
created_at: Date,
google_tokens?: {
refresh_token?: string;
expiry_date?: number;
access_token?: string;
token_type?: string;
id_token?: string;
scope?: string;
}
}
const UserSchema = new Schema<TUser>({
@@ -22,15 +14,7 @@ const UserSchema = new Schema<TUser>({
name: String,
given_name: String,
locale: String,
picture: String,
google_tokens: {
refresh_token: String,
expiry_date: Number,
access_token: String,
token_type: String,
id_token: String,
scope: String
},
picture: String,
created_at: { type: Date, default: () => Date.now() }
})

View File

@@ -4,22 +4,12 @@ export type TProject = {
_id: Schema.Types.ObjectId,
owner: Schema.Types.ObjectId,
name: string,
premium: boolean,
premium_type: number,
customer_id: string,
subscription_id: string,
premium_expire_at: Date,
created_at: Date
}
const ProjectSchema = new Schema<TProject>({
owner: { type: Types.ObjectId, index: 1 },
name: { type: String, required: true },
premium: { type: Boolean, default: false },
premium_type: { type: Number, default: 0 },
customer_id: { type: String, required: true },
subscription_id: { type: String, required: true },
premium_expire_at: { type: Date, required: true },
created_at: { type: Date, default: () => Date.now() },
})