Skip to content

Commit

Permalink
Merge pull request #709 from OneCommunityGlobal/revert-708-development
Browse files Browse the repository at this point in the history
Revert "Backend Release to Main [1.34]"
  • Loading branch information
one-community authored Jan 18, 2024
2 parents c4dca06 + 41228eb commit 08e29b6
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 75 deletions.
27 changes: 0 additions & 27 deletions src/controllers/bmdashboard/bmNewLessonController.js

This file was deleted.

30 changes: 15 additions & 15 deletions src/controllers/userProfileController.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ const moment = require('moment-timezone');

const mongoose = require('mongoose');
const bcrypt = require('bcryptjs');
const fetch = require('node-fetch');
const fetch = require("node-fetch");

const moment_ = require('moment');
const jwt = require('jsonwebtoken');
Expand Down Expand Up @@ -111,6 +111,7 @@ const userProfileController = function (UserProfile) {
};

const postUserProfile = async function (req, res) {

if (!await hasPermission(req.body.requestor, 'postUserProfile')) {
res.status(403).send('You are not authorized to create new users');
return;
Expand Down Expand Up @@ -141,12 +142,12 @@ const userProfileController = function (UserProfile) {
// In dev environment, if newly created user is Owner or Administrator, make fetch request to Beta login route with actualEmail and actual Password
if (process.env.dbName === 'hgnData_dev') {
if (req.body.role === 'Owner' || req.body.role === 'Administrator') {
const email = req.body.actualEmail;
const password = req.body.actualPassword;
const url = 'https://hgn-rest-beta.azurewebsites.net/api/';
const email = req.body.actualEmail
const password = req.body.actualPassword
const url = "https://hgn-rest-beta.azurewebsites.net/api/"
try {
// Log in to Beta login route using provided credentials
const response = await fetch(`${url}login`, {
const response = await fetch(url + 'login', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
Expand Down Expand Up @@ -275,6 +276,14 @@ const userProfileController = function (UserProfile) {
return;
}

const canEditTeamCode = req.body.requestor.role === 'Owner'
|| req.body.requestor.role === 'Administrator'
|| req.body.requestor.permissions?.frontPermissions.includes('editTeamCode');

if (!canEditTeamCode) {
res.status(403).send('You are not authorized to edit team code.');
return;
}

if (req.body.role === 'Owner' && !await hasPermission(req.body.requestor, 'addDeleteEditOwners')) {
res.status(403).send('You are not authorized to update this user');
Expand All @@ -298,15 +307,6 @@ const userProfileController = function (UserProfile) {
}
}

const canEditTeamCode = req.body.requestor.role === 'Owner'
|| req.body.requestor.role === 'Administrator'
|| req.body.requestor.permissions?.frontPermissions.includes('editTeamCode');

if (!canEditTeamCode && record.teamCode !== req.body.teamCode) {
res.status(403).send('You are not authorized to edit team code.');
return;
}

const originalinfringements = record.infringements
? record.infringements
: [];
Expand Down Expand Up @@ -890,7 +890,7 @@ const userProfileController = function (UserProfile) {
const currentRefreshToken = jwt.sign(jwtPayload, JWT_SECRET);
res.status(200).send({ refreshToken: currentRefreshToken });
};

return {
postUserProfile,
getUserProfiles,
Expand Down
5 changes: 5 additions & 0 deletions src/models/bmdashboard/buildingInventoryItem.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ const smallItemBaseSchema = mongoose.Schema({
// TODO: can stockAvailable default be a function?
stockAvailable: { type: Number, default: 0 }, // available = bought - (used + wasted/destroyed)
purchaseRecord: [{
_id: false, // do not add _id field to subdocument
date: { type: Date, default: Date.now() },
requestedBy: { type: mongoose.SchemaTypes.ObjectId, ref: 'userProfile' },
quantity: { type: Number, required: true, default: 1 }, // default 1 for tool or equipment purchases
Expand All @@ -25,6 +26,7 @@ const smallItemBaseSchema = mongoose.Schema({
status: { type: String, default: 'Pending', enum: ['Approved', 'Pending', 'Rejected'] },
}],
updateRecord: [{
_id: false,
date: { type: Date, required: true },
createdBy: { type: mongoose.SchemaTypes.ObjectId, ref: 'userProfile' },
quantityUsed: { type: Number, required: true },
Expand All @@ -47,6 +49,7 @@ const largeItemBaseSchema = mongoose.Schema({
rentalDueDate: { type: Date, required: () => this.purchaseStatus === 'Rental' },
imageUrl: String,
purchaseRecord: [{
_id: false, // do not add _id field to subdocument
date: { type: Date, default: Date.now() },
requestedBy: { type: mongoose.SchemaTypes.ObjectId, ref: 'userProfile' },
priority: { type: String, enum: ['Low', 'Medium', 'High'], required: true },
Expand All @@ -55,11 +58,13 @@ const largeItemBaseSchema = mongoose.Schema({
status: { type: String, default: 'Pending', enum: ['Approved', 'Pending', 'Rejected'] },
}],
updateRecord: [{ // track tool condition updates
_id: false,
date: { type: Date, default: Date.now() },
createdBy: { type: mongoose.SchemaTypes.ObjectId, ref: 'userProfile' },
condition: { type: String, enum: ['Good', 'Needs Repair', 'Out of Order'] },
}],
logRecord: [{ // track tool daily check in/out and responsible user
_id: false,
date: { type: Date, default: Date.now() },
createdBy: { type: mongoose.SchemaTypes.ObjectId, ref: 'userProfile' },
responsibleUser: { type: mongoose.SchemaTypes.ObjectId, ref: 'userProfile' },
Expand Down
2 changes: 2 additions & 0 deletions src/models/bmdashboard/buildingMaterial.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ const buildingMaterial = new Schema({
stockWasted: { type: Number, default: 0 }, // total amount of item wasted/ruined/lost in the project
stockAvailable: { type: Number, default: 0 }, // bought - (used + wasted)
purchaseRecord: [{
_id: false, // do not add _id field to subdocument
date: { type: Date, default: Date.now() },
requestedBy: { type: mongoose.SchemaTypes.ObjectId, ref: 'userProfile' },
quantity: { type: Number, required: true },
Expand All @@ -18,6 +19,7 @@ const buildingMaterial = new Schema({
status: { type: String, default: 'Pending', enum: ['Approved', 'Pending', 'Rejected'] },
}],
updateRecord: [{
_id: false,
date: { type: Date, required: true },
createdBy: { type: mongoose.SchemaTypes.ObjectId, ref: 'userProfile' },
quantityUsed: { type: Number, required: true },
Expand Down
14 changes: 0 additions & 14 deletions src/models/bmdashboard/buildingNewLesson.js

This file was deleted.

15 changes: 0 additions & 15 deletions src/routes/bmdashboard/bmNewLessonRouter.js

This file was deleted.

5 changes: 1 addition & 4 deletions src/startup/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ const mouseoverText = require('../models/mouseoverText');
// const inventoryItemMaterial = require('../models/inventoryItemMaterial');
const mapLocations = require('../models/mapLocation');
const buildingProject = require('../models/bmdashboard/buildingProject');
const buildingNewLesson = require('../models/bmdashboard/buildingNewLesson');
// const buildingMaterial = require('../models/bmdashboard/buildingMaterial');
const {
invTypeBase,
Expand Down Expand Up @@ -79,7 +78,6 @@ const mapLocationRouter = require('../routes/mapLocationsRouter')(mapLocations);
const bmLoginRouter = require('../routes/bmdashboard/bmLoginRouter')();
const bmMaterialsRouter = require('../routes/bmdashboard/bmMaterialsRouter')(buildingMaterial);
const bmProjectRouter = require('../routes/bmdashboard/bmProjectRouter')(buildingProject);
const bmNewLessonRouter = require('../routes/bmdashboard/bmNewLessonRouter')(buildingNewLesson);
const bmConsumablesRouter = require('../routes/bmdashboard/bmConsumablesRouter')(buildingConsumable);
const bmInventoryTypeRouter = require('../routes/bmdashboard/bmInventoryTypeRouter')(invTypeBase, materialType, consumableType, reusableType, toolType, equipmentType);
const bmToolRouter = require('../routes/bmdashboard/bmToolRouter')(buildingTool);
Expand Down Expand Up @@ -118,8 +116,7 @@ module.exports = function (app) {
app.use('/api/bm', bmLoginRouter);
app.use('/api/bm', bmMaterialsRouter);
app.use('/api/bm', bmProjectRouter);
app.use('/api/bm', bmNewLessonRouter);
app.use('/api/bm', bmInventoryTypeRouter);
app.use('/api/bm', bmToolRouter);
app.use('/api/bm', bmConsumablesRouter);
};
};

0 comments on commit 08e29b6

Please sign in to comment.