feat: Start trial period on cloud

This commit is contained in:
Faruk AYDIN
2023-03-19 01:24:41 +03:00
parent b1138dbf05
commit 722c39590f
4 changed files with 35 additions and 0 deletions

View File

@@ -1,4 +1,6 @@
import { QueryContext, ModelOptions } from 'objection';
import moment from 'moment';
import appConfig from '../config/app';
import Base from './base';
import Connection from './connection';
import Flow from './flow';
@@ -17,6 +19,7 @@ class User extends Base {
role: string;
resetPasswordToken: string;
resetPasswordTokenSentAt: string;
trialExpiryDate: string;
connections?: Connection[];
flows?: Flow[];
steps?: Step[];
@@ -133,9 +136,17 @@ class User extends Base {
this.password = await bcrypt.hash(this.password, 10);
}
async startTrialPeriod() {
this.trialExpiryDate = moment().add(30, 'days').calendar();
}
async $beforeInsert(queryContext: QueryContext) {
await super.$beforeInsert(queryContext);
await this.generateHash();
if (appConfig.isCloud) {
await this.startTrialPeriod();
}
}
async $beforeUpdate(opt: ModelOptions, queryContext: QueryContext) {