GameController.ts 940 B

123456789101112131415161718192021222324252627282930
  1. import Express = require('express');
  2. import {UserManager} from "../manager/UserManager";
  3. export class GameController {
  4. public static createRoute(r:Express.router) {
  5. r.all("/member/game", GameController.launchGame);
  6. }
  7. public static launchGame(req, res, next) {
  8. let manageUser = new UserManager();
  9. let level = req.query.level;
  10. manageUser.findById(req.session.user._id, function (user) {
  11. //check if access is possible
  12. if (level == null || level == 0 || user.nbAccess < level) {
  13. res.redirect("/member");
  14. } else {
  15. //remove access from the user
  16. user.nbAccess -= level;
  17. manageUser.saveEntity(user);
  18. //add level session
  19. req.session.level = level;
  20. req.session.nbAccess = level;
  21. res.render("Game/game");
  22. }
  23. });
  24. }
  25. }