Skip to content

Commit

Permalink
Minor fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
sonsoleslp committed Aug 24, 2020
1 parent 8c44fb5 commit 021aabc
Show file tree
Hide file tree
Showing 10 changed files with 85 additions and 64 deletions.
2 changes: 1 addition & 1 deletion controllers/play_controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ exports.writeMessage = async (req, res) => {
const {escapeRoom} = req;
const turnos = await models.turno.findAll({"where": {"escapeRoomId": escapeRoom.id}, "order": [["date", "ASC NULLS LAST"]]});
const participants = await models.user.findAll(queries.user.participantsWithTurnoAndTeam(escapeRoom.id, undefined, "name"));
const teams = await models.team.findAll(queries.team.teamComplete(escapeRoom.id, undefined, "name"));
const teams = await models.team.findAll(queries.team.teamComplete(escapeRoom.id, undefined, "name", true));
const {turnId} = req.query;

console.log(turnId);
Expand Down
110 changes: 58 additions & 52 deletions helpers/sockets.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ exports.socketAuthenticate = async ({request, handshake}) => {
* Check team connected
*/
exports.isTeamConnected = (teamId) => {
console.log({teamId});
if (!teamId) {
return false;
}
Expand All @@ -121,8 +122,10 @@ exports.isTeamConnected = (teamId) => {
}
}
}
} catch(e){
}finally {return false;}
return false;
} catch (e) {
return false;
}
};

/**
Expand All @@ -133,18 +136,19 @@ exports.isTeamConnectedWaiting = (teamId) => {
return false;
}
try {
const room = global.io.sockets.adapter.rooms[`teamId_waiting_${teamId}`];

const room = global.io.sockets.adapter.rooms[`teamId_waiting_${teamId}`];

if (room) {
for (const socketId in room.sockets) {
if (global.io.sockets.connected[socketId]) {
return true;
if (room) {
for (const socketId in room.sockets) {
if (global.io.sockets.connected[socketId]) {
return true;
}
}
}
return false;
} catch (e) {
return false;
}
} catch(e){
}finally {return false;}
};

/**
Expand All @@ -155,22 +159,23 @@ exports.isParticipantTurnConnected = (userId, turnId) => {
return false;
}
try {
const room = global.io.sockets.adapter.rooms[`turnId_${turnId}`];

const room = global.io.sockets.adapter.rooms[`turnId_${turnId}`];

if (room) {
for (const socketId in room.sockets) {
if (global.io.sockets.connected[socketId]) {
const {id} = global.io.sockets.connected[socketId].handshake;
if (room) {
for (const socketId in room.sockets) {
if (global.io.sockets.connected[socketId]) {
const {id} = global.io.sockets.connected[socketId].handshake;

if (id === userId) {
return true;
if (id === userId) {
return true;
}
}
}
}
return false;
} catch (e) {
return false;
}
} catch(e){
}finally {return false;}
};

/**
Expand All @@ -181,22 +186,23 @@ exports.isParticipantTeamConnected = (participantId, teamId) => {
return false;
}
try {
const room = global.io.sockets.adapter.rooms[`teamId_${teamId}`];

const room = global.io.sockets.adapter.rooms[`teamId_${teamId}`];

if (room) {
for (const socketId in room.sockets) {
if (global.io.sockets.connected[socketId]) {
const {userId} = global.io.sockets.connected[socketId].handshake;
if (room) {
for (const socketId in room.sockets) {
if (global.io.sockets.connected[socketId]) {
const {userId} = global.io.sockets.connected[socketId].handshake;

if (participantId === userId) {
return true;
if (participantId === userId) {
return true;
}
}
}
}
return false;
} catch (e) {
return false;
}
} catch(e){
}finally {return false;}
};

/**
Expand All @@ -207,22 +213,23 @@ exports.isParticipantTeamConnectedWaiting = (participantId, teamId) => {
return false;
}
try {
const room = global.io.sockets.adapter.rooms[`teamId_waiting_${teamId}`];

const room = global.io.sockets.adapter.rooms[`teamId_waiting_${teamId}`];

if (room) {
for (const socketId in room.sockets) {
if (global.io.sockets.connected[socketId]) {
const {userId} = global.io.sockets.connected[socketId].handshake;
if (room) {
for (const socketId in room.sockets) {
if (global.io.sockets.connected[socketId]) {
const {userId} = global.io.sockets.connected[socketId].handshake;

if (participantId === userId) {
return true;
if (participantId === userId) {
return true;
}
}
}
}
return false;
} catch (e) {
return false;
}
} catch(e){
}finally {return false;}
};


Expand All @@ -235,23 +242,22 @@ exports.getConnectedMembers = (teamId) => {
return [];
}
try {
const room = global.io.sockets.adapter.rooms[`teamId_${teamId}`];
const connectedMembers = new Set();

const room = global.io.sockets.adapter.rooms[`teamId_${teamId}`];
const connectedMembers = new Set();

if (room) {
for (const socketId in room.sockets) {
if (global.io.sockets.connected[socketId]) {
const {username} = global.io.sockets.connected[socketId].handshake;
if (room) {
for (const socketId in room.sockets) {
if (global.io.sockets.connected[socketId]) {
const {username} = global.io.sockets.connected[socketId].handshake;

connectedMembers.add(username);
connectedMembers.add(username);
}
}
}
return Array.from(connectedMembers);
} catch (e) {
return [];
}
return Array.from(connectedMembers);
} catch(e){
return []
}
};

/**
Expand Down
2 changes: 2 additions & 0 deletions i18n/es.json
Original file line number Diff line number Diff line change
Expand Up @@ -916,6 +916,8 @@
"place": "Lugar",
"activateTurnos": "Administrar los turnos de la escape room",
"areYouSureStop": "¿Seguro que deseas detener este turno?",
"areYouSureStartScheduledFor": "¿Seguro que deseas comenzar el turno programado para",
"areYouSureStopScheduledFor": "¿Seguro que deseas detener el turno programado para",
"areYouSureStart": "¿Seguro que deseas comenzar este turno?",
"activateTurnosBC": "Administrar turnos",
"status": "Estado",
Expand Down
3 changes: 1 addition & 2 deletions public/stylesheets/messages.sass
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
color: $textpurple
vertical-align: middle
font-family: Lato

#msg
width: 100%
resize: none
Expand All @@ -29,4 +28,4 @@
-webkit-text-fill-color: white !important
select
font-family: Lato !important
padding: 0px 10px
padding: 0px 27px 0px 10px
1 change: 1 addition & 0 deletions public/stylesheets/showStudent.sass
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
flex: 1
.editor img
max-width: 100%
height: auto
.desc
font-family: Lato, sans-serif
.members
Expand Down
5 changes: 3 additions & 2 deletions public/stylesheets/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -2336,7 +2336,7 @@ body .daterangepicker {

#mainSection .main.messages select {
font-family: Lato !important;
padding: 0px 10px; }
padding: 0px 27px 0px 10px; }

#mainSection .main.participants .flex-table-wrapper {
margin: 10px 0px;
Expand Down Expand Up @@ -2997,7 +2997,8 @@ body .daterangepicker {
#mainSection .main.showStudent .flex .flex-er-info {
flex: 1; }
#mainSection .main.showStudent .editor img {
max-width: 100%; }
max-width: 100%;
height: auto; }
#mainSection .main.showStudent .desc {
font-family: Lato, sans-serif; }
#mainSection .main.showStudent .members {
Expand Down
7 changes: 5 additions & 2 deletions queries/team.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
const Sequelize = require("sequelize");
const {models} = require("../models");

exports.teamComplete = (escapeRoomId, turnId, order) => {
exports.teamComplete = (escapeRoomId, turnId, order, waiting = false) => {
const where = {
// "attributes": [],
"where": {"startTime": {[Sequelize.Op.ne]: null}},
"where": {},
"include": [
{
"model": models.turno,
Expand Down Expand Up @@ -51,6 +51,9 @@ exports.teamComplete = (escapeRoomId, turnId, order) => {
]
};

if (!waiting) {
where.where.startTime = {[Sequelize.Op.ne]: null};
}
if (turnId) {
where.include[0].where.id = turnId;
}
Expand Down
4 changes: 2 additions & 2 deletions test/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ exports.publicRoutes = (escapeRoomId, userId, puzzleId, turnoId) => [
"route": `/escapeRooms/${escapeRoomId}/play`,
"statusCode": 302
},
/* {
/* {
"route": `/escapeRooms/${escapeRoomId}/project`,
"statusCode": 302
}, */
Expand Down Expand Up @@ -490,7 +490,7 @@ exports.studentRoutes = (escapeRoomId, userId, puzzleId, turnoId) => [
"route": `/escapeRooms/${escapeRoomId}/play`,
"statusCode": 302
},
/* {
/* {
"route": `/escapeRooms/${escapeRoomId}/project`,
"statusCode": 403
}, */
Expand Down
13 changes: 11 additions & 2 deletions test/routes.test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/* eslint-disable no-undef */
/* eslint-disable require-await */
/* eslint-disable no-loop-func */
const request = require("supertest");
const session = require("supertest-session");
const {execSync} = require("child_process");
Expand Down Expand Up @@ -27,8 +28,16 @@ let authenticatedSession = null;
let testSession = null;

beforeAll(() => {
try{execSync(`npx sequelize db:drop --url ${dbName}`);}catch(e){}
try{execSync(`npx sequelize db:create --url ${dbName}`);}catch(e){}
try {
execSync(`npx sequelize db:drop --url ${dbName}`);
} catch (e) {
console.log("Test db could not be deleted");
}
try {
execSync(`npx sequelize db:create --url ${dbName}`);
} catch (e) {
console.log("Test db could not be created");
}
execSync(`npx sequelize db:migrate --url ${dbName}`);
execSync(`npx sequelize db:seed:all --url ${dbName}`);
});
Expand Down
2 changes: 1 addition & 1 deletion views/turnos/_indexActivate.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
<%}%>
<%if (turno.status !== "finished"){%>
<div class="overlay-wrapper">
<button class="turno-btn" onclick="overlayTrigger('activate-<%=turno.id%>')" style="color:var(--<%= turno.status === "active"? "lightred" : "brightgreen"%>);" >
<button class="turno-btn" onclick="overlayTrigger('activate-<%=turno.id%>')" style="color:var(--<%= turno.status === "active"? "lightred" : "brightgreen"%>);" title="<%=i18n.turno[turno.status === 'active' ? 'stop' : 'start']%>" >
<span class="material-icons"><%= turno.status === "active"? "stop" : "play_arrow"%></span>
</button>
<div class="overlay-trigger" data-id="activate-<%=turno.id%>">
Expand Down

0 comments on commit 021aabc

Please sign in to comment.