Skip to content

Commit

Permalink
Update pg
Browse files Browse the repository at this point in the history
  • Loading branch information
sonsoleslp committed May 1, 2022
1 parent 9a6d020 commit aa06921
Show file tree
Hide file tree
Showing 8 changed files with 10,552 additions and 319 deletions.
20 changes: 15 additions & 5 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ const compression = require("compression");
dotenv.config();
const api = require("./routes/api");
const index = require("./routes/index"),

app = express();// View engine setup
// To compress all routes

// To compress all routes
app.use(compression());
// Security headers, commented because it fails with CSP
// TODO, study options and configure accordingly
Expand All @@ -45,6 +45,8 @@ app.use(logger("dev"));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({"extended": true}));
app.use(cookieParser());
app.use(express.static(path.join(__dirname, "public")));

app.use(i18n({
"translationsPath": path.join(__dirname, "i18n"),
"siteLangs": ["en", "es"],
Expand Down Expand Up @@ -80,22 +82,30 @@ const sessionStore = new SequelizeStore({
});

const sessionMiddleware = session({
"secret": "Escape Room",
"secret": process.env.SECRET || "Escape Room",
"store": sessionStore,
"resave": false,
"cookie": {"path": "/", "httpOnly": true, "secure": app.get("env") === "production" && !process.env.HEROKU, "maxAge": null},
"cookie": {
"path": "/",
"httpOnly": true,
"secure": app.get("env") === "production" && !process.env.HEROKU,
"maxAge": null
},
"saveUninitialized": false
});


app.sessionMiddleware = sessionMiddleware;

app.use(sessionMiddleware);

app.use(methodOverride("_method", {
"methods": [
"POST",
"GET"
]
}));
app.use(express.static(path.join(__dirname, "public")));


app.use(partials());
require("./helpers/locals")(app);
Expand Down
15 changes: 10 additions & 5 deletions controllers/analytics_controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -345,8 +345,10 @@ exports.puzzleStats = async (req, res, next) => {
try {
escapeRoom.puzzles = await getERPuzzles(escapeRoom.id);
escapeRoom.turnos = await getERTurnos(escapeRoom.id);
await models.team.findAll(queries.team.teamComplete(escapeRoom.id, turnId, "order")).
map((team) => {
const teamList = await models.team.findAll(queries.team.teamComplete(escapeRoom.id, turnId, "order"));

if (teamList) {
teamList.map((team) => {
const {turno, startTime} = team;
const actualStartTime = turno.startTime || startTime;
const retosSuperados = getRetosSuperadosIdTime(team.retos, actualStartTime);
Expand All @@ -363,6 +365,7 @@ exports.puzzleStats = async (req, res, next) => {

return {"id": team.id, retosSuperados};
});
}
const retosNoSuperados = groupByTeamRetos(await models.team.findAll(queries.team.teamRetosNoSuperados(escapeRoom.id, turnId)), true);

for (const t in retosNoSuperados) {
Expand Down Expand Up @@ -434,8 +437,10 @@ exports.histogram = async (req, res, next) => {
try {
escapeRoom.puzzles = await getERPuzzles(escapeRoom.id);
escapeRoom.turnos = await getERTurnos(escapeRoom.id);
await models.team.findAll(queries.team.teamComplete(escapeRoom.id, turnId)).
map((team) => {
const teamList = await models.team.findAll(queries.team.teamComplete(escapeRoom.id, turnId));

if (teamList) {
teamList.map((team) => {
const {turno, startTime} = team;
const actualStartTime = turno.startTime || startTime;
const retosSuperados = getRetosSuperadosIdTime(team.retos, actualStartTime);
Expand All @@ -451,7 +456,7 @@ exports.histogram = async (req, res, next) => {
}
return {"id": team.id, retosSuperados};
});

}
res.render("escapeRooms/analytics/histogram", {"escapeRoom": req.escapeRoom, "puzzles": result, turnId});
} catch (e) {
console.error(e);
Expand Down
1 change: 1 addition & 0 deletions helpers/sockets.js
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,7 @@ exports.checkPuzzle = async (escapeRoomId, teamId, userId, puzzleOrderMinus, sol
}
const {body} = await checkPuzzle(solution, puzzle, team.turno.escapeRoom, [team], {"id": userId}, i18n, true);
const {code, correctAnswer, participation, authentication, msg, erState} = body;

puzzleChecked(teamId, code, correctAnswer, solution, puzzleOrderMinus, participation, authentication, erState, msg, i18n.escapeRoom.api.participation[participation]);
} catch (e) {
console.error(e);
Expand Down
3 changes: 1 addition & 2 deletions helpers/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,7 @@ exports.playInterface = async (name, req, res, next) => {
await exports.automaticallySetAttendance(team, req.session.user.id, req.escapeRoom.automaticAttendance);
const hints = await models.requestedHint.findAll({"where": {"teamId": team.id, "success": true}, "include": [{"model": models.hint, "include": [{"model": models.puzzle, "attributes": ["order"]}]}], "order": [["createdAt", "ASC"]]});


res.render("escapeRooms/play/play", {"escapeRoom": req.escapeRoom, "hostName": process.env.APP_NAME ? `https://${process.env.APP_NAME}` : "http://localhost:3000", cloudinary, "teams": [], team, token, "userId": req.session.user.id, "turnoId": team.turno.id, "teamId": team.id, "isStudent": true, "hints": hints || [], "endPoint": name, "layout": false, });
res.render("escapeRooms/play/play", {"escapeRoom": req.escapeRoom, "hostName": process.env.APP_NAME ? `https://${process.env.APP_NAME}` : "http://localhost:3000", cloudinary, "teams": [], team, token, "userId": req.session.user.id, "turnoId": team.turno.id, "teamId": team.id, "isStudent": true, "hints": hints || [], "endPoint": name, "layout": false });
} catch (err) {
next(err);
}
Expand Down
3 changes: 1 addition & 2 deletions io.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ const {checkAccess, getInfoFromSocket, socketAuthenticate, sendInitialInfo, init
const {getAuthMessageAndCode, NOT_A_PARTICIPANT, NOK} = require("./helpers/apiCodes");

exports.createServer = (server, sessionMiddleware) => {

const io = new Server(server,{"perMessageDeflate": false, "allowEIO3": true });
const io = new Server(server, {"perMessageDeflate": false, "allowEIO3": true });

io.use(function (socket, next) {
sessionMiddleware(socket.request, socket.request.res, next);
Expand Down
36 changes: 19 additions & 17 deletions models/index.js
Original file line number Diff line number Diff line change
@@ -1,54 +1,56 @@
const path = require("path");

// Load ORM
const Sequelize = require("sequelize");
const url = process.env.DATABASE_URL || "sqlite:escapeRoom.sqlite";
const { Sequelize } = require("sequelize");

const url = process.env.DATABASE_URL;

const sequelize = new Sequelize(url);// Import the definition of the Escape Room Table from escapeRoom.js

sequelize.import(path.join(__dirname, "escapeRoom"));

require(path.join(__dirname, "escapeRoom"))(sequelize, Sequelize.DataTypes);

// Session
sequelize.import(path.join(__dirname, "session"));
require(path.join(__dirname, "session"))(sequelize, Sequelize.DataTypes);

// Import the definition of the Turns Table from turno.js
sequelize.import(path.join(__dirname, "turno"));
require(path.join(__dirname, "turno"))(sequelize, Sequelize.DataTypes);

// Import the definition of the Attachment Table from attachment.js
sequelize.import(path.join(__dirname, "attachment"));
require(path.join(__dirname, "attachment"))(sequelize, Sequelize.DataTypes);

// Import the definition of the User Table from user.js
sequelize.import(path.join(__dirname, "user"));
require(path.join(__dirname, "user"))(sequelize, Sequelize.DataTypes);

// Import the definition of the User Table from puzzle.js (Retos)
sequelize.import(path.join(__dirname, "puzzle"));
require(path.join(__dirname, "puzzle"))(sequelize, Sequelize.DataTypes);

// Import the definition of the User Table from hint.js (Pistas)
sequelize.import(path.join(__dirname, "hint"));
require(path.join(__dirname, "hint"))(sequelize, Sequelize.DataTypes);

// Import the definition of the Team Table from team.js
sequelize.import(path.join(__dirname, "team"));
require(path.join(__dirname, "team"))(sequelize, Sequelize.DataTypes);

// Import the definition of the Attachment Table from attachment.js
sequelize.import(path.join(__dirname, "hintApp"));
require(path.join(__dirname, "hintApp"))(sequelize, Sequelize.DataTypes);

// Import the definition of the Participants Table from participants.js
sequelize.import(path.join(__dirname, "participants"));
require(path.join(__dirname, "participants"))(sequelize, Sequelize.DataTypes);

// Import the definition of the Requested Hints Table from requestedHint.js
sequelize.import(path.join(__dirname, "requestedHint"));
require(path.join(__dirname, "requestedHint"))(sequelize, Sequelize.DataTypes);

// Import the definition of the Asset Table from attachment.js
sequelize.import(path.join(__dirname, "asset"));
require(path.join(__dirname, "asset"))(sequelize, Sequelize.DataTypes);

// Import the definition of the App Table from app.js
sequelize.import(path.join(__dirname, "app"));
require(path.join(__dirname, "app"))(sequelize, Sequelize.DataTypes);

// Import the definition of the Resource Table from app.js
sequelize.import(path.join(__dirname, "resource"));
require(path.join(__dirname, "resource"))(sequelize, Sequelize.DataTypes);

// Import the definition of the RetosSuperados Table from retosSuperados.js
sequelize.import(path.join(__dirname, "retosSuperados"));
require(path.join(__dirname, "retosSuperados"))(sequelize, Sequelize.DataTypes);


// Relation between models
Expand Down
Loading

0 comments on commit aa06921

Please sign in to comment.