feat: Initial payment implementation
This commit is contained in:
52
packages/backend/src/models/payment-plan.ee.ts
Normal file
52
packages/backend/src/models/payment-plan.ee.ts
Normal file
@@ -0,0 +1,52 @@
|
||||
import Base from './base';
|
||||
import User from './user';
|
||||
|
||||
class PaymentPlan extends Base {
|
||||
id!: string;
|
||||
name!: string;
|
||||
taskCount: number;
|
||||
userId!: string;
|
||||
stripeCustomerId!: string;
|
||||
stripeSubscriptionId!: string;
|
||||
currentPeriodStartedAt!: string;
|
||||
currentPeriodEndsAt!: string;
|
||||
|
||||
static tableName = 'payment_plans';
|
||||
|
||||
static jsonSchema = {
|
||||
type: 'object',
|
||||
required: [
|
||||
'name',
|
||||
'taskCount',
|
||||
'userId',
|
||||
'stripeCustomerId',
|
||||
'stripeSubscriptionId',
|
||||
'currentPeriodStartedAt',
|
||||
'currentPeriodEndsAt',
|
||||
],
|
||||
|
||||
properties: {
|
||||
id: { type: 'string', format: 'uuid' },
|
||||
name: { type: 'string' },
|
||||
taskCount: { type: 'integer' },
|
||||
userId: { type: 'string', format: 'uuid' },
|
||||
stripeCustomerId: { type: 'string' },
|
||||
stripeSubscriptionId: { type: 'string' },
|
||||
currentPeriodStartedAt: { type: 'string' },
|
||||
currentPeriodEndsAt: { type: 'string' },
|
||||
},
|
||||
};
|
||||
|
||||
static relationMappings = () => ({
|
||||
user: {
|
||||
relation: Base.BelongsToOneRelation,
|
||||
modelClass: User,
|
||||
join: {
|
||||
from: 'payment_plans.user_id',
|
||||
to: 'users.id',
|
||||
},
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
export default PaymentPlan;
|
36
packages/backend/src/models/usage-data.ee.ts
Normal file
36
packages/backend/src/models/usage-data.ee.ts
Normal file
@@ -0,0 +1,36 @@
|
||||
import Base from './base';
|
||||
import User from './user';
|
||||
|
||||
class UsageData extends Base {
|
||||
id!: string;
|
||||
userId!: string;
|
||||
consumedTaskCount!: number;
|
||||
nextResetAt!: string;
|
||||
|
||||
static tableName = 'usage_data';
|
||||
|
||||
static jsonSchema = {
|
||||
type: 'object',
|
||||
required: ['userId', 'consumedTaskCount', 'nextResetAt'],
|
||||
|
||||
properties: {
|
||||
id: { type: 'string', format: 'uuid' },
|
||||
userId: { type: 'string', format: 'uuid' },
|
||||
consumedTaskCount: { type: 'integer' },
|
||||
nextResetAt: { type: 'string' },
|
||||
},
|
||||
};
|
||||
|
||||
static relationMappings = () => ({
|
||||
user: {
|
||||
relation: Base.BelongsToOneRelation,
|
||||
modelClass: User,
|
||||
join: {
|
||||
from: 'payment_plans.user_id',
|
||||
to: 'users.id',
|
||||
},
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
export default UsageData;
|
@@ -6,6 +6,7 @@ import Step from './step';
|
||||
import Execution from './execution';
|
||||
import bcrypt from 'bcrypt';
|
||||
import crypto from 'crypto';
|
||||
import PaymentPlan from './payment-plan.ee';
|
||||
|
||||
class User extends Base {
|
||||
id!: string;
|
||||
@@ -19,6 +20,7 @@ class User extends Base {
|
||||
flows?: Flow[];
|
||||
steps?: Step[];
|
||||
executions?: Execution[];
|
||||
paymentPlan?: PaymentPlan;
|
||||
|
||||
static tableName = 'users';
|
||||
|
||||
@@ -76,6 +78,14 @@ class User extends Base {
|
||||
to: 'executions.flow_id',
|
||||
},
|
||||
},
|
||||
paymentPlan: {
|
||||
relation: Base.HasOneRelation,
|
||||
modelClass: PaymentPlan,
|
||||
join: {
|
||||
from: 'payment_plans.user_id',
|
||||
to: 'users.id',
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
login(password: string) {
|
||||
|
Reference in New Issue
Block a user