📈 Open source, privacy-first web analytics — a cookie-less Google Analytics alternative with built-in error tracking and performance monitoring. Self-host it or use our cloud. Get started for free!
TypeScript chartsclickhousedockergdprgoogle-analyticsmetricsmonitoringmysqlnestjsprivacyredisself-hostedselfhostedstatisticstailwindcssweb-analyticswebanalyticswebsite
added some cron jobs
Blue Mouse493d888671b2
diff --git a/src/task-manager/task-manager.service.ts b/src/task-manager/task-manager.service.tsindex 367ed26b9..237ed104d 100644--- a/src/task-manager/task-manager.service.ts+++ b/src/task-manager/task-manager.service.ts@@ -1,6 +1,6 @@import { Injectable } from '@nestjs/common'import { Cron, CronExpression } from '@nestjs/schedule'-import { IsNull, LessThan, In, Not } from 'typeorm'+import { IsNull, LessThan, In, Not, Between } from 'typeorm'import * as bcrypt from 'bcrypt'import * as dayjs from 'dayjs'import * as utc from 'dayjs/plugin/utc'@@ -406,6 +406,44 @@ export class TaskManagerService {}}+ @Cron(CronExpression.EVERY_4_HOURS)+ // @Cron(CronExpression.EVERY_MINUTE)+ async trialReminder(): Promise<void> {+ const users = await this.userService.find({+ where: {+ planCode: PlanCode.trial,+ trialEndDate: Between( // between today & tomorrow+ new Date(),+ new Date(new Date().getTime() + 24 * 60 * 60 * 1000),+ ),+ trialReminderSent: false,+ }+ })++ // TODO:+ // send email reminding user that trial period will end tomorrow+ // set trialReminderSent to true+ }++ @Cron(CronExpression.EVERY_2_HOURS)+ async trialEnd(): Promise<void> {+ const users = await this.userService.find({+ where: {+ planCode: PlanCode.trial,+ trialEndDate: LessThan(new Date()),+ }+ })++ for (let i = 0; i < _size(users); ++i) {+ await this.userService.update(users[i].id, {+ planCode: PlanCode.none,+ trialEndDate: null,+ })++ // TODO: send email notifying user that trial period has ended+ }+ }+@Cron(CronExpression.EVERY_5_MINUTES)// @Cron(CronExpression.EVERY_5_SECONDS)async checkOnlineUsersAlerts(): Promise<void> {diff --git a/src/user/entities/user.entity.ts b/src/user/entities/user.entity.tsindex 72b8b72b8..2cf6cda06 100644--- a/src/user/entities/user.entity.ts+++ b/src/user/entities/user.entity.ts@@ -212,6 +212,9 @@ export class User {@Column({ default: false })isTwoFactorAuthenticationEnabled: boolean+ @Column({ default: false })+ trialReminderSent: boolean+@BeforeUpdate()updateTimestamp() {this.updated = new Date()diff --git a/src/user/user.controller.ts b/src/user/user.controller.tsindex fbc303908..97ef7e45b 100644--- a/src/user/user.controller.ts+++ b/src/user/user.controller.ts@@ -570,6 +570,7 @@ export class UserController {'isTelegramChatIdConfirmed','trialEndDate','cancellationEffectiveDate',+ 'trialReminderSent',])await this.userService.update(id, userToUpdate)