Skip to content

Commit

Permalink
added notif in cab sharing
Browse files Browse the repository at this point in the history
  • Loading branch information
Kunalpal215 committed Jun 27, 2023
1 parent 21532e6 commit 4cb4ebe
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 17 deletions.
40 changes: 29 additions & 11 deletions api/javascript/controllers/campusTravelController.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,13 @@ exports.getTravelPosts = async (req, res) => {

exports.deleteTravelPost = async (req, res) => {
try {
console.log("FSJDFJKSDFJK");
const id = req.query.travelPostId;
let travelPost = await TravelPostModel.findById(id);
console.log(travelPost);
console.log(req.body);
console.log(travelPost["email"]);
console.log("here");
if (travelPost["email"] !== req.body.email) {
res.json({ "success": false, "message": "Email doesn't match" });
return;
Expand Down Expand Up @@ -155,6 +160,18 @@ exports.getTravelPostChatReplies = async (req, res) => {
}
}


async function sendPostReplyNotif(req,res,title,replier,replierOutlook){
req.body = {
category: "CAB SHARING",
model: "",
header: title,
body: `${replier} replied to your recent Travel Post on OneStop 🙌. Click to see!!`,
sendTo: replierOutlook
}
await sendToDevice(req,res);
}

exports.postReplyChat = async (req, res) => {
try {
console.log(req.body);
Expand All @@ -167,18 +184,19 @@ exports.postReplyChat = async (req, res) => {
// console.log(travelChat);
TravelPostModel.findOne({ chatId: id }).then((travelPost) => {
console.log(travelPost["travelDateTime"]);
if(true){ // when other people writes a message
sendMailForTravelPostReply(data["name"],travelPost["email"],travelPost["name"],travelPost["from"],travelPost["to"],travelPost["travelDateTime"]);
req.body.notif={};
req.body.notif.category = "travel";
req.body.notif.model = "maybeJsonValue";
req.body.notif.header = "Cab sharing reply";
req.body.notif.body = `You have got reply from ${data["name"]} 🙌`;
//ADD here chat reply body
req.body.sendTo = travelPost.email;
sendPostReplyNotif(req,res,"Cab sharing reply",data["name"],travelPost.email);
//if(true){ // when other people writes a message
//sendMailForTravelPostReply(data["name"],travelPost["email"],travelPost["name"],travelPost["from"],travelPost["to"],travelPost["travelDateTime"]);
// req.body.notif={};
// req.body.notif.category = "travel";
// req.body.notif.model = "maybeJsonValue";
// req.body.notif.header = "Cab sharing reply";
// req.body.notif.body = `You have got reply from ${data["name"]} 🙌`;
// //ADD here chat reply body
// req.body.sendTo = travelPost.email;
// ADD send to email here
sendToDevice(req,res);
}
//sendToDevice(req,res);
//}
});
res.json({ "success": true });
}
Expand Down
4 changes: 2 additions & 2 deletions api/javascript/controllers/lostAndFoundControllers.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ exports.deleteLostAll = async (req, res) => {
async function sendLostNotif(req,res,title){
req.body = {
category: "LOST",
model: "hello",
model: "",
header: title,
body: "An item has been lost"
}
Expand Down Expand Up @@ -290,7 +290,7 @@ exports.claimFoundItem = async (req, res) => {
async function sendFoundNotif(req,res,title){
req.body = {
category: "FOUND",
model: "hello",
model: "",
header: title,
body: "An item was found"
}
Expand Down
5 changes: 1 addition & 4 deletions api/javascript/controllers/notificationController.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,6 @@ exports.sendToDevice = async (req, res) => {
}

let user = await userModel.findOne({ outlookEmail: req.body.sendTo });

const token = user["deviceIDs"][0];
// this only allows one device at a time so either loop through or send to only one device per user which is better

const payload = {
data: {
Expand All @@ -42,8 +39,8 @@ exports.sendToDevice = async (req, res) => {
timeToLive: 60 * 60 * 24
};


let userNotifTokens = await userNotifTokenModel.find({userid: user._id});
console.log(userNotifTokens);
userNotifTokens.forEach((userNotifToken) => firebase.messaging().sendToDevice(userNotifToken.deviceToken, payload, options));
};

Expand Down

0 comments on commit 4cb4ebe

Please sign in to comment.