feat: Implement getTrialStatus graphQL query

This commit is contained in:
Faruk AYDIN
2023-04-07 22:55:18 +02:00
parent 3bfc428dfe
commit c4dc0509c2
5 changed files with 53 additions and 13 deletions

View File

@@ -126,19 +126,6 @@ class User extends Base {
},
});
get inTrial() {
if (!this.trialExpiryDate) {
return false;
}
const expiryDate = DateTime.fromJSDate(
this.trialExpiryDate as unknown as Date
);
const now = DateTime.now();
return now < expiryDate;
}
login(password: string) {
return bcrypt.compare(password, this.password);
}
@@ -178,6 +165,29 @@ class User extends Base {
this.trialExpiryDate = DateTime.now().plus({ days: 30 }).toISODate();
}
async inTrial() {
if (!appConfig.isCloud) {
return false;
}
if (!this.trialExpiryDate) {
return false;
}
const subscription = await this.$relatedQuery('currentSubscription');
if (subscription?.isActive) {
return false;
}
const expiryDate = DateTime.fromJSDate(
this.trialExpiryDate as unknown as Date
);
const now = DateTime.now();
return now < expiryDate;
}
async $beforeInsert(queryContext: QueryContext) {
await super.$beforeInsert(queryContext);
await this.generateHash();