-
-
Notifications
You must be signed in to change notification settings - Fork 251
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #616 from bigcapitalhq/one-click-demo-account
feat(ee): One-click demo account
- Loading branch information
Showing
53 changed files
with
1,311 additions
and
29 deletions.
There are no files selected for viewing
87 changes: 87 additions & 0 deletions
87
packages/server/src/api/controllers/OneClickDemo/OneClickDemoController.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
import { Router, Request, Response, NextFunction } from 'express'; | ||
import { Service, Inject } from 'typedi'; | ||
import { body } from 'express-validator'; | ||
import asyncMiddleware from '@/api/middleware/asyncMiddleware'; | ||
import BaseController from '@/api/controllers/BaseController'; | ||
import { OneClickDemoApplication } from '@/services/OneClickDemo/OneClickDemoApplication'; | ||
import config from '@/config'; | ||
@Service() | ||
export class OneClickDemoController extends BaseController { | ||
@Inject() | ||
private oneClickDemoApp: OneClickDemoApplication; | ||
|
||
/** | ||
* Router constructor method. | ||
*/ | ||
router() { | ||
const router = Router(); | ||
|
||
// Protects the endpoints if the feature is not enabled. | ||
const protectMiddleware = ( | ||
req: Request, | ||
res: Response, | ||
next: NextFunction | ||
) => { | ||
// Add your protection logic here | ||
if (config.oneClickDemoAccounts) { | ||
next(); | ||
} else { | ||
res.status(403).send({ message: 'Forbidden' }); | ||
} | ||
}; | ||
router.post( | ||
'/one_click', | ||
protectMiddleware, | ||
asyncMiddleware(this.oneClickDemo.bind(this)) | ||
); | ||
router.post( | ||
'/one_click_signin', | ||
[body('demo_id').exists()], | ||
this.validationResult, | ||
protectMiddleware, | ||
asyncMiddleware(this.oneClickSignIn.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); | ||
} | ||
} | ||
|
||
/** | ||
* Sign-in to one-click demo account. | ||
* @param {Request} req | ||
* @param {Response} res | ||
* @param {NextFunction} next | ||
*/ | ||
private async oneClickSignIn( | ||
req: Request, | ||
res: Response, | ||
next: NextFunction | ||
) { | ||
const { demoId } = this.matchedBodyData(req); | ||
|
||
try { | ||
const data = await this.oneClickDemoApp.autoSignIn(demoId); | ||
|
||
return res.status(200).send(data); | ||
} catch (error) { | ||
next(error); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.