Browse Source

Merge branch 'development' of github.com:naresh97/ssr-tracing-backend into development

pull/5/head
Nareshkumar Rao 3 years ago
parent
commit
a77d456b7a
  1. 6
      src/routes/LoginRoute.js
  2. 44
      src/routes/TelegramWebhookRoute.js

6
src/routes/LoginRoute.js

@ -7,10 +7,9 @@ function LoginRoute(req, res) {
authUser(telegramResponse, (success, msg) => {
if (success) {
// User is already logged in
if(req.session.user == telegramResponse.id){
res.send({authorized: success});
if (req.session.user == telegramResponse.id) {
res.send({ authorized: success });
return;
}
@ -34,7 +33,6 @@ function LoginRoute(req, res) {
res.status(401).send({ authorized: success, message: msg });
}
});
}
function authUser(telegramResponse, done) {

44
src/routes/TelegramWebhookRoute.js

@ -22,6 +22,7 @@ function TelegramWebhookRoute(req, res) {
});
}
}
});
}
catch(e){
console.log("Could not get Telegram Message");
@ -30,7 +31,7 @@ function TelegramWebhookRoute(req, res) {
res.send();
res.send();
}
function informContacts(telegramID, doneCallback=()=>{}){
@ -64,25 +65,30 @@ function informContacts(telegramID, doneCallback=()=>{}){
}
function userInfected(telegramID, doneCallback) {
User.findOne({
where: {
telegram: telegramID,
},
}).then((user) => {
if (!user) {
done({saved: false});
} else {
user.isInfected = true;
user.save().then(result => {
if(result){
doneCallback({saved: true});
}
}).catch(err=>{doneCallback({saved: false})});
}
User.findOne({
where: {
telegram: telegramID,
},
})
.then((user) => {
if (!user) {
done({ saved: false });
} else {
user.isInfected = true;
user
.save()
.then((result) => {
if (result) {
doneCallback({ saved: true });
}
})
.catch((err) => {
doneCallback({ saved: false });
});
}
})
.catch(err=>{
doneCallback({saved: false});
.catch((err) => {
doneCallback({ saved: false });
});
}

Loading…
Cancel
Save