Skip to content

Commit

Permalink
Review fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Christina committed Mar 22, 2020
1 parent bbfe6e2 commit 56f94ba
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 40 deletions.
38 changes: 21 additions & 17 deletions src/api/controllers/UserController.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,21 +35,24 @@ module.exports = {
changePassword: (req, res) => {},

getProfile: (req, res) => {
User.findOne({ _id: req.params.userId })
.exec()
.then(user => {
user = sanitizeUser(user);
res.status(200).json({ user });
})
.catch(err => {
console.error(`Error during user find():\n${err}`);
res.status(500).send();
});
if (req.params.user_id === req.userData.userId) {
User.findOne({ _id: req.params.user_id })
.exec()
.then(user => {
user = sanitizeUser(user);
res.status(200).json({ user });
})
.catch(err => {
console.error(`Error during user find():\n${err}`);
res.status(500).send();
});
} else {
res.status(401).send();
}
},

getSelfProfile: (req, res, next) => {
req.params.userId = req.userData.userId;
next();
getSelfProfile: (req, res) => {
res.redirect(`/users/${req.userData.userId}/profile`);
},

login: (req, res) => {
Expand Down Expand Up @@ -110,18 +113,19 @@ module.exports = {
if (err.name === "ValidationError") {
if (err.errors.email) {
if (err.errors.email.kind === "regexp") {
res.status(500).json({ error: "Invalid email address" });
res.status(400).json({ error: "Invalid email address" });
} else if (err.errors.email.kind === "unique") {
res.status(500).json({ error: "Email already exists" });
res.status(400).json({ error: "Email already exists" });
}
}

if (err.errors.username) {
if (err.errors.username.kind === "unique") {
res.status(500).json({ error: "Username already exists" });
res.status(400).json({ error: "Username already exists" });
}
}
res.status(500).json(err);
console.error(err);
res.status(500).send();
} else {
console.error(`Error during user save():\n${err}`);
res.status(500).json(err);
Expand Down
7 changes: 4 additions & 3 deletions src/api/models/ActionModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const mongo = require("mongoose");
const ActionSchema = new mongo.Schema({
name: { type: String, required: true },
description: { type: String },
type: { type: [mongo.Schema.Types.ObjectId] },
categories: { type: [mongo.Schema.Types.ObjectId] },
location: {
type: {
type: String,
Expand All @@ -15,10 +15,11 @@ const ActionSchema = new mongo.Schema({
required: true
}
},
date: { type: Date },
date: { type: Date, required: true },
photo: { type: String },
organizer: {
_id: { type: mongo.Schema.Types.ObjectId },
required: true,
organizerId: { type: mongo.Schema.Types.ObjectId },
isTeam: { type: Boolean }
},
attendees: { type: [mongo.Schema.Types.ObjectId] }
Expand Down
2 changes: 1 addition & 1 deletion src/api/models/TeamModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const TeamSchema = new mongo.Schema({
name: { type: String, required: true },
description: { type: String },
logo: { type: String },
owner: { type: mongo.Schema.Types.ObjectId },
owner: { type: mongo.Schema.Types.ObjectId, required: true },
members: { type: [mongo.Schema.Types.ObjectId] },
categories: { type: [String] }
});
Expand Down
16 changes: 4 additions & 12 deletions src/api/routes/action.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,28 +45,20 @@ router.post(

/* Attendants */

router.post(
"/:action_id/attendees/:user_id",
checkAuth,
ActionUserController.addAttendant
);
router.post("/:action_id/attend", checkAuth, ActionUserController.addAttendant);

router.delete(
"/:action_id/attendees/:user_id",
"/:action_id/attend",
checkAuth,
ActionUserController.removeAttendant
);

/* Saved Actions */

router.post(
"/:action_id/saved/:user_id",
checkAuth,
ActionUserController.addSavedAction
);
router.post("/:action_id/save", checkAuth, ActionUserController.addSavedAction);

router.delete(
"/:action_id/saved/:user_id",
"/:action_id/save",
checkAuth,
ActionUserController.removeSavedAction
);
Expand Down
2 changes: 1 addition & 1 deletion src/api/routes/contact.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ const router = express.Router();

const ContactFormController = require("../controllers/ContactFormController");

router.post("/", ContactFormController.contact);
router.post("/submit", ContactFormController.contact);

module.exports = router;
7 changes: 1 addition & 6 deletions src/api/routes/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,7 @@ const UserController = require("../controllers/UserController");

/* User Profile */

router.get(
"/me/profile",
checkAuth,
UserController.getSelfProfile,
UserController.getProfile
);
router.get("/me/profile", checkAuth, UserController.getSelfProfile);

router.patch("/me/profile", checkAuth, UserController.updateProfile);

Expand Down

0 comments on commit 56f94ba

Please sign in to comment.