mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-16 04:40:32 +00:00
feat(ee): one-click demo account
This commit is contained in:
@@ -0,0 +1,41 @@
|
||||
import { Router, Request, Response, NextFunction } from 'express';
|
||||
import { Service, Inject } from 'typedi';
|
||||
import asyncMiddleware from '@/api/middleware/asyncMiddleware';
|
||||
import BaseController from '@/api/controllers/BaseController';
|
||||
import { OneClickDemoApplication } from '@/services/OneClickDemo/OneClickDemoApplication';
|
||||
|
||||
@Service()
|
||||
export class OneClickDemoController extends BaseController {
|
||||
@Inject()
|
||||
private oneClickDemoApp: OneClickDemoApplication;
|
||||
|
||||
/**
|
||||
* Router constructor method.
|
||||
*/
|
||||
router() {
|
||||
const router = Router();
|
||||
|
||||
router.post('/one_click', asyncMiddleware(this.oneClickDemo.bind(this)));
|
||||
|
||||
return router;
|
||||
}
|
||||
|
||||
/**
|
||||
* One-click demo application.
|
||||
* @param {Request} req -
|
||||
* @param {Response} res -
|
||||
* @param {NextFunction} next -
|
||||
*/
|
||||
private async oneClickDemo(req: Request, res: Response, next: NextFunction) {
|
||||
try {
|
||||
const data = await this.oneClickDemoApp.createOneClick();
|
||||
|
||||
return res.status(200).send({
|
||||
data,
|
||||
message: 'The one-click demo has been created successfully.',
|
||||
});
|
||||
} catch (error) {
|
||||
next(error);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -7,7 +7,6 @@ export interface IRegisterDTO {
|
||||
lastName: string;
|
||||
email: string;
|
||||
password: string;
|
||||
organizationName: string;
|
||||
}
|
||||
|
||||
export interface ILoginDTO {
|
||||
|
||||
@@ -0,0 +1,57 @@
|
||||
import { Inject, Service } from 'typedi';
|
||||
import { faker } from '@faker-js/faker';
|
||||
import AuthenticationApplication from '../Authentication/AuthApplication';
|
||||
import OrganizationService from '../Organization/OrganizationService';
|
||||
import { IAuthSignInPOJO } from '@/interfaces';
|
||||
|
||||
@Service()
|
||||
export class CreateOneClickDemo {
|
||||
@Inject()
|
||||
private authApp: AuthenticationApplication;
|
||||
|
||||
@Inject()
|
||||
private organizationService: OrganizationService;
|
||||
|
||||
/**
|
||||
* Creates one-click demo account.
|
||||
* @returns {Promise<ICreateOneClickDemoPOJO>}
|
||||
*/
|
||||
async createOneClickDemo(): Promise<ICreateOneClickDemoPOJO> {
|
||||
const firstName = faker.person.firstName();
|
||||
const lastName = faker.person.lastName();
|
||||
const email = faker.internet.email();
|
||||
const password = '123123123';
|
||||
|
||||
await this.authApp.signUp({ firstName, lastName, email, password });
|
||||
|
||||
//
|
||||
const signedIn = await this.authApp.signIn(email, password);
|
||||
const tenantId = signedIn.tenant.id;
|
||||
|
||||
const buildJob = await this.organizationService.buildRunJob(
|
||||
tenantId,
|
||||
{
|
||||
name: 'BIGCAPITAL, INC',
|
||||
base_currency: 'USD',
|
||||
location: 'US',
|
||||
language: 'en',
|
||||
fiscal_year: 'march',
|
||||
timezone: 'US/Central',
|
||||
},
|
||||
signedIn.user
|
||||
);
|
||||
return { email, signedIn, buildJob };
|
||||
}
|
||||
|
||||
/**
|
||||
* Sign-in automicatlly using the demo id one creating an account finish.
|
||||
* @param {string} oneClickDemoId -
|
||||
*/
|
||||
async autoSignIn(oneClickDemoId: string) {}
|
||||
}
|
||||
|
||||
interface ICreateOneClickDemoPOJO {
|
||||
email: string;
|
||||
signedIn: IAuthSignInPOJO;
|
||||
buildJob: any;
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
import { Inject, Service } from "typedi";
|
||||
import { CreateOneClickDemo } from "./CreateOneClickDemo";
|
||||
|
||||
|
||||
@Service()
|
||||
export class OneClickDemoApplication {
|
||||
|
||||
@Inject()
|
||||
private createOneClickDemoService: CreateOneClickDemo;
|
||||
|
||||
public createOneClick() {
|
||||
return this.createOneClickDemoService.createOneClickDemo();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user