Skip to content

Commit

Permalink
Merge pull request #777 from OneCommunityGlobal/development
Browse files Browse the repository at this point in the history
Backend Release to Main [1.50]
  • Loading branch information
one-community authored Mar 1, 2024
2 parents dfcec86 + 795dac5 commit 5eb0786
Show file tree
Hide file tree
Showing 7 changed files with 83 additions and 15 deletions.
29 changes: 29 additions & 0 deletions src/controllers/bmdashboard/bmIssueController.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
const mongoose = require('mongoose');

const bmIssueController = function (BuildingIssue) {
const bmGetIssue = async (req, res) => {
try {
BuildingIssue
.find()
.populate()
.then(result => res.status(200).send(result))
.catch(error => res.status(500).send(error));
} catch (err) {
res.json(err);
}
};

const bmPostIssue = async (req, res) => {
try {
const newIssue = BuildingIssue.create(req.body)
.then(result => res.status(201).send(result))
.catch(error => res.status(500).send(error));
} catch (err) {
res.json(err);
}
};

return { bmGetIssue, bmPostIssue };
};

module.exports = bmIssueController;
1 change: 1 addition & 0 deletions src/controllers/userProfileController.js
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,7 @@ const userProfileController = function (UserProfile) {
up.bioPosted = req.body.bioPosted || 'default';
up.isFirstTimelog = true;
up.actualEmail = req.body.actualEmail;
up.isVisible = !['Administrator', 'Mentor', 'Owner'].includes(req.body.role);

up.save()
.then(() => {
Expand Down
17 changes: 17 additions & 0 deletions src/models/bmdashboard/buildingIssue.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
const mongoose = require('mongoose');

const { Schema } = mongoose;

const buildingIssue = new Schema({
createdDate: { type: Date, required: true, default: Date.now() },
issueDate: { type: String, required: true },
createdBy: { type: mongoose.SchemaTypes.ObjectId, ref: 'userProfile', required: true },
staffInvolved: [{ type: mongoose.SchemaTypes.ObjectId, ref: 'userProfile' }],
issueTitle: [{ type: String, required: true, maxLength: 50 }],
issueText: [{ type: String, required: true, maxLength: 500 }],
imageUrl: [{ type: String }],
// not sure if we still need related lesson here:
// relatedLesson: { type: mongoose.SchemaTypes.ObjectId, ref: 'buildingNewLesson', required: true },
});

module.exports = mongoose.model('buildingIssue', buildingIssue, 'buildingIssues');
13 changes: 13 additions & 0 deletions src/routes/bmdashboard/bmIssueRouter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
const express = require('express');

const routes = function (buildingIssue) {
const IssueRouter = express.Router();
const controller = require('../../controllers/bmdashboard/bmIssueController')(buildingIssue);

IssueRouter.route('/issues')
.get(controller.bmGetIssue);
IssueRouter.route('/issue/add')
.post(controller.bmPostIssue);
return IssueRouter;
};
module.exports = routes;
5 changes: 5 additions & 0 deletions src/startup/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ const permissionChangeLog = require('../models/permissionChangeLog');
const mapLocations = require('../models/mapLocation');
const buildingProject = require('../models/bmdashboard/buildingProject');
const buildingNewLesson = require('../models/bmdashboard/buildingNewLesson');
const buildingIssue = require('../models/bmdashboard/buildingIssue');
const {
invTypeBase,
materialType,
Expand Down Expand Up @@ -123,6 +124,9 @@ const bmInventoryTypeRouter = require('../routes/bmdashboard/bmInventoryTypeRout
const bmToolRouter = require('../routes/bmdashboard/bmToolRouter')(
buildingTool,
);
const bmIssueRouter = require('../routes/bmdashboard/bmIssueRouter')(
buildingIssue,
);

module.exports = function (app) {
app.use('/api', forgotPwdRouter);
Expand Down Expand Up @@ -165,4 +169,5 @@ module.exports = function (app) {
app.use('/api/bm', bmToolRouter);
app.use('/api/bm', bmConsumablesRouter);
app.use('/api', timeOffRequestRouter);
app.use('api', bmIssueRouter);
};
23 changes: 11 additions & 12 deletions src/websockets/TimerService/clientsHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ export const action = {
FORCED_PAUSE: 'FORCED_PAUSE',
ACK_FORCED: 'ACK_FORCED',
START_CHIME: 'START_CHIME',
HEARTBEAT: 'ping',
};

const MAX_HOURS = 5;
Expand Down Expand Up @@ -170,22 +171,21 @@ export const handleMessage = async (msg, clients, userId) => {
const client = clients.get(userId);
let resp = null;

const req = msg.toString();
switch (req) {
switch (msg) {
case action.START_TIMER:
startTimer(client);
break;
case req.match(/SET_GOAL=/i)?.input:
setGoal(client, req);
case msg.match(/SET_GOAL=/i)?.input:
setGoal(client, msg);
break;
case req.match(/ADD_TO_GOAL=/i)?.input:
addGoal(client, req);
case msg.match(/ADD_TO_GOAL=/i)?.input:
addGoal(client, msg);
break;
case req.match(/REMOVE_FROM_GOAL=/i)?.input:
removeGoal(client, req);
case msg.match(/REMOVE_FROM_GOAL=/i)?.input:
removeGoal(client, msg);
break;
case req.match(/START_CHIME=/i)?.input:
startChime(client, req);
case msg.match(/START_CHIME=/i)?.input:
startChime(client, msg);
break;
case action.PAUSE_TIMER:
pauseTimer(client);
Expand All @@ -202,11 +202,10 @@ export const handleMessage = async (msg, clients, userId) => {
case action.STOP_TIMER:
stopTimer(client);
break;

default:
resp = {
...client,
error: `Unknown operation ${req}, please use one of ${action}`,
error: `Unknown operation ${msg}, please use one from { ${Object.values(action).join(', ')} }`,
};
break;
}
Expand Down
10 changes: 7 additions & 3 deletions src/websockets/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,12 @@ export default async (expServer) => {
* And we broadcast the response to all the clients that are connected to the same user.
*/
ws.on("message", async (data) => {
const resp = await handleMessage(data, clients, userId);
const msg = data.toString();
if (msg === action.HEARTBEAT) {
ws.send(JSON.stringify({ heartbeat: "pong" }));
return;
}
const resp = await handleMessage(msg, clients, userId);
broadcastToSameUser(connections, userId, resp);
});

Expand All @@ -121,7 +126,6 @@ export default async (expServer) => {
});

// For each new connection we start a time interval of 1min to check if the connection is alive.
// change to 1min before push
const interval = setInterval(() => {
wss.clients.forEach((ws) => {
if (ws.isAlive === false) {
Expand All @@ -130,7 +134,7 @@ export default async (expServer) => {
ws.isAlive = false;
ws.ping();
});
}, 10000);
}, 60000);

wss.on('close', () => {
clearInterval(interval);
Expand Down

0 comments on commit 5eb0786

Please sign in to comment.