Skip to content

Commit

Permalink
added getsos & sos collection..
Browse files Browse the repository at this point in the history
  • Loading branch information
nik-gautam committed Jan 29, 2020
1 parent b878bbb commit 927e610
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 2 deletions.
24 changes: 22 additions & 2 deletions controllers/users.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const Pusher = require('pusher')
const Pusher = require('pusher');
const fetch = require('node-fetch');

const User = require('../models/user');
const Sos = require('../models/sos');
Expand Down Expand Up @@ -91,6 +92,10 @@ exports.postEmergencyList = (req, res, next) => {

exports.getSos = (req, res, next) => {
let id = req.query.uid;
let lat = req.query.lat;
let long = req.query.long;
let max = req.query.max

Location.find({
uid: id
}, (err, loc) => {
Expand All @@ -108,8 +113,23 @@ exports.getSos = (req, res, next) => {
});

result.save().then(resultt => {
fetch(`https://still-lake-87096.herokuapp.com/loc/nearby?long=${long}&lat=${lat}`).then(response => {
for (let i = 0; i <= max; i++) {
pusher.trigger('nearby-channel', response.result[i].uid, {
"sos": true,
"uid": result.uid
});
}
}).catch(err => {
res.status(404).json({
success: false,
err
});
})

pusher.trigger('sos-channel', req.query.uid, {
"sos": true
"sos": true,
"uid": result.uid
});
res.json({
success: true,
Expand Down
5 changes: 5 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"express": "~4.16.1",
"mongoose": "^5.8.9",
"morgan": "~1.9.1",
"node-fetch": "^2.6.0",
"pusher": "^3.0.0"
}
}

0 comments on commit 927e610

Please sign in to comment.