Skip to content

Commit

Permalink
added posting of blood pressure
Browse files Browse the repository at this point in the history
  • Loading branch information
Ronald-pro committed Jul 22, 2024
1 parent 92f3256 commit b712abd
Show file tree
Hide file tree
Showing 2 changed files with 102 additions and 29 deletions.
26 changes: 26 additions & 0 deletions models/n_blood_pressure.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
const sequelize = require("../db_config");
const Sequelize = require("sequelize");
const Joi = require("joi");

const NBloodPressure= sequelize.sequelize.define(
"tbl_nishauri_blood_pressure", {
id: {
type: Sequelize.INTEGER,
primaryKey: true,
autoIncrement: true
},

systolic:Sequelize.DOUBLE,
diastolic:Sequelize.DOUBLE,
pulse_rate:Sequelize.DOUBLE,
notes:Sequelize.STRING,
user_id:Sequelize.INTEGER
}, {
timestamps: true,
paranoid: true,
underscored: true,
freezeTableName: true,
tableName: "tbl_nishauri_blood_pressure"
}
);
exports.NBloodPressure = NBloodPressure;
105 changes: 76 additions & 29 deletions routes/processes/nishauri_new.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ const { NToken } = require("../../models/n_revoke_token");
const { NChatLogs } = require("../../models/n_chat_log");
const { NFAQ } = require("../../models/n_faq");
const { NBmiLog } = require("../../models/n_bmi_log");
const { NBloodPressure } = require("../../models/n_blood_pressure");

generateOtp = function (size) {
const zeros = "0".repeat(size - 1);
Expand Down Expand Up @@ -4572,55 +4573,102 @@ router.post(
where: {
user_id: base64.decode(user_id),
created_at: {
[Op.gte]: new Date(today),
[Op.gte]: new Date(today),
[Op.lt]: new Date(new Date(today).getTime() + 24 * 60 * 60 * 1000)
}
}
}
});
if (existing_bmi) {
const update_bmi = await NBmiLog.update(
{ height: height,
if (existing_bmi) {
const update_bmi = await NBmiLog.update(
{
height: height,
weight: weight,
results: results,
updated_at: today
},
{ where: { user_id: base64.decode(user_id) } }
);

if (update_bmi) {
return res.status(200).json({
success: true,
msg: "BMI results was successfully logged up"
});
} else {
return res.status(200).json({
success: false,
msg: "Error occured while logging BMI results"
});
}
} else {
const new_bmi = await NBmiLog.create({
height: height,
weight: weight,
results: results,
user_id: base64.decode(user_id),
created_at: today,
updated_at: today
},
{ where: { user_id: base64.decode(user_id) } }
);

if (update_bmi) {
return res.status(200).json({
success: true,
msg: "BMI results was successfully logged up"
});
} else {
return res.status(200).json({
success: false,
msg: "Error occured while logging BMI results"
});
if (new_bmi) {
return res.status(200).json({
success: true,
msg: "BMI results was successfully logged"
});
} else {
return res.status(200).json({
success: false,
msg: "Error occured while logging BMI results"
});
}
}
} else {
const new_bmi = await NBmiLog.create({
height: height,
weight: weight,
results: results,
return res.status(404).json({
success: false,
msg: "User not found"
});
}
}
);
router.post(
"/blood_pressure",
passport.authenticate("jwt", { session: false }),
async (req, res) => {
let user_id = req.body.user_id;
let systolic = req.body.systolic;
let diastolic = req.body.diastolic;
let pulse_rate = req.body.pulse_rate;
let notes = req.body.notes;
let today = moment(new Date().toDateString())
.tz("Africa/Nairobi")
.format("YYYY-MM-DD H:M:S");

let user = await NUsers.findOne({
where: {
id: base64.decode(user_id)
}
});

if (user) {
const new_blood_pressure = await NBloodPressure.create({
systolic: systolic,
diastolic: diastolic,
pulse_rate: pulse_rate,
user_id: base64.decode(user_id),
notes: notes,
created_at: today,
updated_at: today
});
if (new_bmi) {
if (new_blood_pressure) {
return res.status(200).json({
success: true,
msg: "BMI results was successfully logged"
msg: "You successfully logged your blood pressure"
});
} else {
return res.status(200).json({
success: false,
msg: "Error occured while logging BMI results"
msg: "Could not logged your blood pressure"
});
}

}

} else {
return res.status(404).json({
success: false,
Expand All @@ -4629,6 +4677,5 @@ router.post(
}
}
);

module.exports = router;
//module.exports = { router, users };

0 comments on commit b712abd

Please sign in to comment.