mirror of
https://github.com/docmost/docmost.git
synced 2025-11-14 20:01:09 +10:00
queue trial ended job (#992)
This commit is contained in:
@ -26,6 +26,9 @@ import { DomainService } from '../../../integrations/environment/domain.service'
|
|||||||
import { jsonArrayFrom } from 'kysely/helpers/postgres';
|
import { jsonArrayFrom } from 'kysely/helpers/postgres';
|
||||||
import { addDays } from 'date-fns';
|
import { addDays } from 'date-fns';
|
||||||
import { DISALLOWED_HOSTNAMES, WorkspaceStatus } from '../workspace.constants';
|
import { DISALLOWED_HOSTNAMES, WorkspaceStatus } from '../workspace.constants';
|
||||||
|
import { InjectQueue } from '@nestjs/bullmq';
|
||||||
|
import { QueueJob, QueueName } from '../../../integrations/queue/constants';
|
||||||
|
import { Queue } from 'bullmq';
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class WorkspaceService {
|
export class WorkspaceService {
|
||||||
@ -39,6 +42,7 @@ export class WorkspaceService {
|
|||||||
private environmentService: EnvironmentService,
|
private environmentService: EnvironmentService,
|
||||||
private domainService: DomainService,
|
private domainService: DomainService,
|
||||||
@InjectKysely() private readonly db: KyselyDB,
|
@InjectKysely() private readonly db: KyselyDB,
|
||||||
|
@InjectQueue(QueueName.BILLING_QUEUE) private billingQueue: Queue,
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
async findById(workspaceId: string) {
|
async findById(workspaceId: string) {
|
||||||
@ -91,13 +95,15 @@ export class WorkspaceService {
|
|||||||
createWorkspaceDto: CreateWorkspaceDto,
|
createWorkspaceDto: CreateWorkspaceDto,
|
||||||
trx?: KyselyTransaction,
|
trx?: KyselyTransaction,
|
||||||
) {
|
) {
|
||||||
return await executeTx(
|
let trialEndAt = undefined;
|
||||||
|
|
||||||
|
const createdWorkspace = await executeTx(
|
||||||
this.db,
|
this.db,
|
||||||
async (trx) => {
|
async (trx) => {
|
||||||
let hostname = undefined;
|
let hostname = undefined;
|
||||||
let trialEndAt = undefined;
|
|
||||||
let status = undefined;
|
let status = undefined;
|
||||||
let plan = undefined;
|
let plan = undefined;
|
||||||
|
let billingEmail = undefined;
|
||||||
|
|
||||||
if (this.environmentService.isCloud()) {
|
if (this.environmentService.isCloud()) {
|
||||||
// generate unique hostname
|
// generate unique hostname
|
||||||
@ -110,6 +116,7 @@ export class WorkspaceService {
|
|||||||
);
|
);
|
||||||
status = WorkspaceStatus.Active;
|
status = WorkspaceStatus.Active;
|
||||||
plan = 'standard';
|
plan = 'standard';
|
||||||
|
billingEmail = user.email;
|
||||||
}
|
}
|
||||||
|
|
||||||
// create workspace
|
// create workspace
|
||||||
@ -121,6 +128,7 @@ export class WorkspaceService {
|
|||||||
status,
|
status,
|
||||||
trialEndAt,
|
trialEndAt,
|
||||||
plan,
|
plan,
|
||||||
|
billingEmail,
|
||||||
},
|
},
|
||||||
trx,
|
trx,
|
||||||
);
|
);
|
||||||
@ -195,6 +203,18 @@ export class WorkspaceService {
|
|||||||
},
|
},
|
||||||
trx,
|
trx,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
if (this.environmentService.isCloud() && trialEndAt) {
|
||||||
|
const delay = trialEndAt.getTime() - Date.now();
|
||||||
|
|
||||||
|
await this.billingQueue.add(
|
||||||
|
QueueJob.TRIAL_ENDED,
|
||||||
|
{ workspaceId: createdWorkspace.id },
|
||||||
|
{ delay },
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return createdWorkspace;
|
||||||
}
|
}
|
||||||
|
|
||||||
async addUserToWorkspace(
|
async addUserToWorkspace(
|
||||||
|
|||||||
Submodule apps/server/src/ee updated: bcc0731b6a...2d9bc2b394
@ -14,4 +14,6 @@ export enum QueueJob {
|
|||||||
PAGE_BACKLINKS = 'page-backlinks',
|
PAGE_BACKLINKS = 'page-backlinks',
|
||||||
|
|
||||||
STRIPE_SEATS_SYNC = 'sync-stripe-seats',
|
STRIPE_SEATS_SYNC = 'sync-stripe-seats',
|
||||||
|
|
||||||
|
TRIAL_ENDED = 'trial-ended',
|
||||||
}
|
}
|
||||||
|
|||||||
@ -0,0 +1,46 @@
|
|||||||
|
import { Section, Text, Button } from '@react-email/components';
|
||||||
|
import * as React from 'react';
|
||||||
|
import { button, content, paragraph } from '@docmost/transactional/css/styles';
|
||||||
|
import { MailBody } from '@docmost/transactional/partials/partials';
|
||||||
|
|
||||||
|
interface Props {
|
||||||
|
billingLink: string;
|
||||||
|
workspaceName: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export const TrialEndedEmail = ({ billingLink, workspaceName }: Props) => {
|
||||||
|
return (
|
||||||
|
<MailBody>
|
||||||
|
<Section style={content}>
|
||||||
|
<Text style={paragraph}>Hi there,</Text>
|
||||||
|
<Text style={paragraph}>
|
||||||
|
Your Docmost 7-day free trial for {workspaceName} has come to an end.
|
||||||
|
</Text>
|
||||||
|
<Text style={paragraph}>
|
||||||
|
To continue using Docmost for your wiki and documentation, please
|
||||||
|
upgrade to a premium plan.
|
||||||
|
</Text>
|
||||||
|
</Section>
|
||||||
|
<Section
|
||||||
|
style={{
|
||||||
|
display: 'flex',
|
||||||
|
justifyContent: 'center',
|
||||||
|
alignItems: 'center',
|
||||||
|
paddingLeft: '15px',
|
||||||
|
paddingBottom: '15px',
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<Button href={billingLink} style={button}>
|
||||||
|
Upgrade now
|
||||||
|
</Button>
|
||||||
|
</Section>
|
||||||
|
<Section style={content}>
|
||||||
|
<Text style={paragraph}>
|
||||||
|
PS: If you would like to extend your trial, please reply this email.
|
||||||
|
</Text>
|
||||||
|
</Section>
|
||||||
|
</MailBody>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default TrialEndedEmail;
|
||||||
Reference in New Issue
Block a user