Skip to content

Commit

Permalink
added chatbot consent/revoke flag
Browse files Browse the repository at this point in the history
  • Loading branch information
Ronald-pro committed Jul 9, 2024
1 parent 345918a commit 76b4359
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 3 deletions.
4 changes: 3 additions & 1 deletion models/n_users.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ const NUsers = sequelize.sequelize.define(
profile_otp_date:Sequelize.DATEONLY,
profile_status: Sequelize.STRING,
refresh_token: Sequelize.STRING,
app_version: Sequelize.STRING
app_version: Sequelize.STRING,
chatbot_consent: Sequelize.STRING,
chatbot_consent_date: Sequelize.DATE

}, {
timestamps: true,
Expand Down
62 changes: 60 additions & 2 deletions routes/processes/nishauri_new.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,11 @@ router.post("/signup", async (req, res) => {
});

const log_login_attempt = await NUsers.update(
{ refresh_token: refreshToken, last_login: today, app_version: app_version },
{
refresh_token: refreshToken,
last_login: today,
app_version: app_version
},
{ where: { id: new_user.id } }
);

Expand Down Expand Up @@ -345,7 +349,11 @@ router.post("/signin", async (req, res) => {

try {
const log_login = await NUsers.update(
{ last_login: today, refresh_token: refreshToken, app_version: app_version },
{
last_login: today,
refresh_token: refreshToken,
app_version: app_version
},
{ where: { id: check_username.id } }
);
const token = jwt.sign(
Expand Down Expand Up @@ -4430,6 +4438,56 @@ const termsAndConditions = {
router.get("/terms_conditions", (req, res) => {
res.json(termsAndConditions);
});
router.post(
"/chat_consent",
passport.authenticate("jwt", { session: false }),
async (req, res) => {
let user_id = req.body.user_id;
let today = moment(new Date().toDateString())
.tz("Africa/Nairobi")
.format("YYYY-MM-DD H:M:S");

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

if (user_consent.chatbot_consent === "1") {
const consent = await NUsers.update(
{ chatbot_consent_date: today, chatbot_consent: "0" },
{ where: { id: base64.decode(user_id) } }
);
if (consent) {
return res.status(200).json({
success: true,
msg: "Consent was successfully revoked"
});
} else {
return res.status(200).json({
success: false,
msg: "An error occurred, could not consent"
});
}
} else {
const new_consent = await NUsers.update(
{ chatbot_consent_date: today, chatbot_consent: "1" },
{ where: { id: base64.decode(user_id) } }
);
if (new_consent) {
return res.status(200).json({
success: true,
msg: "Consent was successfull"
});
} else {
return res.status(200).json({
success: false,
msg: "An error occurred, could not consent"
});
}
}
}
);

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

0 comments on commit 76b4359

Please sign in to comment.