From 4602003ca72884a485521012f3dae237ae962080 Mon Sep 17 00:00:00 2001 From: Ronald-pro <36841157+Ronald-pro@users.noreply.github.com> Date: Tue, 16 Jul 2024 11:27:51 +0300 Subject: [PATCH] added profile completion check on login --- models/n_patient_obs.js | 4 +++- routes/processes/nishauri_new.js | 37 +++++++++++++++++++++++++++++--- 2 files changed, 37 insertions(+), 4 deletions(-) diff --git a/models/n_patient_obs.js b/models/n_patient_obs.js index 84befdf..199aa7e 100644 --- a/models/n_patient_obs.js +++ b/models/n_patient_obs.js @@ -12,7 +12,9 @@ const NpatientObs = sequelize.sequelize.define( lab_data:Sequelize.JSON, patient_ob:Sequelize.JSON, - user_id:Sequelize.INTEGER + user_id:Sequelize.INTEGER, + height:Sequelize.DOUBLE, + weight:Sequelize.DOUBLE }, { timestamps: true, paranoid: true, diff --git a/routes/processes/nishauri_new.js b/routes/processes/nishauri_new.js index 681d77a..03da618 100644 --- a/routes/processes/nishauri_new.js +++ b/routes/processes/nishauri_new.js @@ -298,9 +298,26 @@ router.post("/signin", async (req, res) => { let refreshToken = crypto.randomBytes(64).toString("hex"); + // check for if profile is up to date + async function isProfileComplete(userId) { + let userProfile = await NUserProfile.findOne({ where: { user_id: userId } }); + + if (!userProfile) return 0; + + const { f_name, l_name, gender, dob } = userProfile; + if (!f_name || !l_name || !gender || !dob) { + return 0; + } else { + return 1; + } + } + //console.log(check_username.password); if (check_username) { + let userId = check_username.id; + let profile_complete = await isProfileComplete(userId); + var password_hash = check_username.password; //console.log(password_hash); const verified = bcrypt.compareSync(password_1, password_hash); @@ -326,7 +343,8 @@ router.post("/signin", async (req, res) => { token: token, refreshToken: refreshToken, phone_no: check_username.msisdn, - account_verified: check_username.is_active + account_verified: check_username.is_active, + profile_complete: `${profile_complete}` }; return res.status(200).json({ @@ -372,7 +390,8 @@ router.post("/signin", async (req, res) => { token: token, refreshToken: refreshToken, phone_no: check_username.msisdn, - account_verified: check_username.is_active + account_verified: check_username.is_active, + profile_complete: `${profile_complete}` }; // Trigger data retrieval from getVLResults function @@ -4496,7 +4515,7 @@ router.get( const user_id = req.query.user_id; const user_consent = await NUsers.findOne({ - attributes: ['chatbot_consent', 'chatbot_consent_date'], + attributes: ["chatbot_consent", "chatbot_consent_date"], where: { id: base64.decode(user_id) } @@ -4527,6 +4546,18 @@ router.get( } ); +router.post( + "/post_bmi", + passport.authenticate("jwt", { session: false }), + async (req, res) => { + let user_id = req.body.user_id; + let height = req.body.height; + let weight = req.body.weight; + let today = moment(new Date().toDateString()) + .tz("Africa/Nairobi") + .format("YYYY-MM-DD H:M:S"); + } +); module.exports = router; //module.exports = { router, users };