Merge branch 'bluewave-labs:master' into backend-completion
This commit is contained in:
13 files changed
+240
-53
No files matched your search
@@ -56,7 +56,11 @@ const registerController = async (req, res, next) => {
|
||||
service: SERVICE_NAME,
|
||||
userId: newUser._id,
|
||||
});
|
||||
const token = issueToken(newUser._doc);
|
||||
|
||||
const userForToken = { ...newUser._doc };
|
||||
delete userForToken.profileImage;
|
||||
|
||||
const token = issueToken(userForToken);
|
||||
|
||||
// Sending email to user with pre defined template
|
||||
const template = registerTemplate("https://www.bluewavelabs.ca");
|
||||
@@ -70,7 +74,7 @@ const registerController = async (req, res, next) => {
|
||||
return res.status(200).json({
|
||||
success: true,
|
||||
msg: successMessages.AUTH_CREATE_USER,
|
||||
data: token,
|
||||
data: { user: newUser, token: token },
|
||||
});
|
||||
} catch (error) {
|
||||
error.service = SERVICE_NAME;
|
||||
@@ -109,7 +113,7 @@ const loginController = async (req, res, next) => {
|
||||
return res.status(200).json({
|
||||
success: true,
|
||||
msg: successMessages.AUTH_LOGIN_USER,
|
||||
data: token,
|
||||
data: { user: userWithoutPassword, token: token },
|
||||
});
|
||||
} catch (error) {
|
||||
error.status = 500;
|
||||
|
||||
@@ -88,9 +88,16 @@ const getUserByEmail = async (req, res) => {
|
||||
|
||||
const updateUser = async (req, res) => {
|
||||
const candidateUserId = req.params.userId;
|
||||
const candidateUser = req.body;
|
||||
|
||||
try {
|
||||
const candidateUser = { ...req.body };
|
||||
if (req.file) {
|
||||
candidateUser.profileImage = {
|
||||
data: req.file.buffer,
|
||||
contentType: req.file.mimetype,
|
||||
};
|
||||
}
|
||||
|
||||
const updatedUser = await UserModel.findByIdAndUpdate(
|
||||
candidateUserId,
|
||||
candidateUser,
|
||||
|
||||
@@ -31,4 +31,33 @@ const CheckSchema = mongoose.Schema(
|
||||
}
|
||||
);
|
||||
|
||||
/**
|
||||
* When a check is created, we should update the stauts of the associated monitor
|
||||
* if it has changed. Monitor starts with default status: true
|
||||
* @param {function} next - Callback to proceed to the next middleware.
|
||||
*/
|
||||
|
||||
CheckSchema.pre("save", async function (next) {
|
||||
try {
|
||||
const monitor = await mongoose.model("Monitor").findById(this.monitorId);
|
||||
if (monitor && monitor.status !== this.status) {
|
||||
if (monitor.status === true && this.status === false) {
|
||||
// TODO issue alert
|
||||
console.log("Monitor went down");
|
||||
}
|
||||
|
||||
if (monitor.status === false && this.status === true) {
|
||||
// TODO issue alert
|
||||
console.log("Monitor went up");
|
||||
}
|
||||
monitor.status = this.status;
|
||||
await monitor.save();
|
||||
}
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
} finally {
|
||||
next();
|
||||
}
|
||||
});
|
||||
|
||||
module.exports = mongoose.model("Check", CheckSchema);
|
||||
@@ -14,6 +14,10 @@ const MonitorSchema = mongoose.Schema(
|
||||
description: {
|
||||
type: String,
|
||||
},
|
||||
status: {
|
||||
type: Boolean,
|
||||
default: true,
|
||||
},
|
||||
type: {
|
||||
type: String,
|
||||
required: true,
|
||||
|
||||
@@ -17,7 +17,12 @@ const {
|
||||
//Auth routes
|
||||
router.post("/register", upload.single("profileImage"), registerController);
|
||||
router.post("/login", loginController);
|
||||
router.post("/user/:userId", verifyJWT, userEditController);
|
||||
router.post(
|
||||
"/user/:userId",
|
||||
upload.single("profileImage"),
|
||||
verifyJWT,
|
||||
userEditController
|
||||
);
|
||||
router.get("/users/admin", checkAdminController);
|
||||
router.delete("/user/:userId", verifyJWT, deleteUserController);
|
||||
|
||||
|
||||
@@ -25,7 +25,7 @@ const editUserParamValidation = joi.object({
|
||||
const editUserBodyValidation = joi.object({
|
||||
firstname: joi.string(),
|
||||
lastname: joi.string(),
|
||||
profilePicUrl: joi.string(),
|
||||
profileImage: joi.any(),
|
||||
role: joi.string(),
|
||||
});
|
||||
|
||||
|
||||
Reference in new issue
Block a user