Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added assets/tick.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions firebase.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"functions": {
"predeploy": [
"npm --prefix \"$RESOURCE_DIR\" run lint"
]
],
"source": "functions"
}
}
163 changes: 163 additions & 0 deletions functions/dist/index.dev.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,163 @@
"use strict";

var functions = require('firebase-functions');

var admin = require('firebase-admin');

admin.initializeApp();
var fcm = admin.messaging();
var msgData;
exports.adminOrderTrigger = functions.firestore.document('confirmedOrders/{id}').onCreate(function _callee(snapshot, context) {
var tokens, _snap;

return regeneratorRuntime.async(function _callee$(_context) {
while (1) {
switch (_context.prev = _context.next) {
case 0:
tokens = [];
_context.next = 3;
return regeneratorRuntime.awrap(admin.firestore().collection('userInfo').where('isAdmin', '==', true).get());

case 3:
_snap = _context.sent;

_snap.forEach(function (k) {
tokens.push(k.data().token.toString());
});

return _context.abrupt("return", fcm.sendToDevice(tokens, {
notification: {
title: 'New Order',
body: 'New order has been placed',
clickAction: 'FLUTTER_NOTIFICATION_CLICK'
}
}));

case 6:
case "end":
return _context.stop();
}
}
});
});
exports.adminBookingTrigger = functions.firestore.document('BookingDetails/{id}').onCreate(function _callee2(snapshot, context) {
var tokens, _snap;

return regeneratorRuntime.async(function _callee2$(_context2) {
while (1) {
switch (_context2.prev = _context2.next) {
case 0:
tokens = [];
_context2.next = 3;
return regeneratorRuntime.awrap(admin.firestore().collection('userInfo').where('isAdmin', '==', true).get());

case 3:
_snap = _context2.sent;

_snap.forEach(function (k) {
tokens.push(k.data().token.toString());
});

return _context2.abrupt("return", fcm.sendToDevice(tokens, {
notification: {
title: 'New Booking',
body: 'New booking request sent',
clickAction: 'FLUTTER_NOTIFICATION_CLICK'
}
}));

case 6:
case "end":
return _context2.stop();
}
}
});
});
exports.confirmNotification = functions.firestore.document('confirmedOrders/{id}').onUpdate(function _callee3(snapshot, context) {
var token, rejected, confirmed;
return regeneratorRuntime.async(function _callee3$(_context3) {
while (1) {
switch (_context3.prev = _context3.next) {
case 0:
token = snapshot.after.data().token;
rejected = snapshot.after.data().isRejected;
confirmed = snapshot.after.data().isConfirmed;

if (!(confirmed === true)) {
_context3.next = 7;
break;
}

return _context3.abrupt("return", fcm.sendToDevice(token, {
notification: {
title: 'Order Confirmation',
body: 'Your order has been confirmed',
clickAction: 'FLUTTER_NOTIFICATION_CLICK'
}
}));

case 7:
if (!(rejected === true)) {
_context3.next = 9;
break;
}

return _context3.abrupt("return", fcm.sendToDevice(token, {
notification: {
title: 'Order rejected',
body: 'Your order has been rejected',
clickAction: 'FLUTTER_NOTIFICATION_CLICK'
}
}));

case 9:
case "end":
return _context3.stop();
}
}
});
});
exports.BookingNotification = functions.firestore.document('BookingDetails/{id}').onUpdate(function _callee4(snapshot, context) {
var token, isConfirmed, isRejected;
return regeneratorRuntime.async(function _callee4$(_context4) {
while (1) {
switch (_context4.prev = _context4.next) {
case 0:
token = snapshot.after.data().token;
isConfirmed = snapshot.after.data().isConfirmed;
isRejected = snapshot.after.data().isRejected;

if (!(isConfirmed === true)) {
_context4.next = 7;
break;
}

return _context4.abrupt("return", fcm.sendToDevice(token, {
notification: {
title: 'Booking Confirmation',
body: 'Your Booking has been confirmed',
clickAction: 'FLUTTER_NOTIFICATION_CLICK'
}
}));

case 7:
if (!(isRejected === true)) {
_context4.next = 9;
break;
}

return _context4.abrupt("return", fcm.sendToDevice(token, {
notification: {
title: 'Booking Rejection',
body: 'Your Booking has been rejected',
clickAction: 'FLUTTER_NOTIFICATION_CLICK'
}
}));

case 9:
case "end":
return _context4.stop();
}
}
});
});
90 changes: 55 additions & 35 deletions functions/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,13 @@ const fcm = admin.messaging();

var msgData;

// exports.offerTrigger = functions.firestore.document('confirmedOrders/{id}').onCreate((snapshot, context) => {
// msgData = snapshot.data();

// return fcm.sendToTopic('confirmedOrders', {
// notification: {title: snapshot.data().name, body: 'order has been placed',clickAction: 'FLUTTER_NOTIFICATION_CLICK'}
// });

// });

exports.adminOrderTrigger = functions.firestore.document('confirmedOrders/{id}').onCreate((snapshot, context) => {
var tokens = [
'd7cf7_GgXCg:APA91bF-HqKMwlAfTsy3dRv_LVuvxkDbiBOWkBMWHweu6X8wvq_9Zw7x8ws2qSepPOk1dypxySmiv-6ct72Pbzwu6nOejFCcTEy17-_k8EmvOEMvcS2BGP-ToNAqsfF9m_EbPG4jdlhu',
'dtG7Gozeq5M:APA91bHAblBNNNJnPn9EY0DWqVLbTnT8jvZNctTDxLVI9QkYU7T0BJP_U8j_pjdRu0LYeNGYtDUHzPN22cmB1cT0z95Z1Y8NDHsJD8wuWHfPax68nwYa4OmgG4Ky6i5KjaHca7-AnWdc'

];
exports.adminOrderTrigger = functions.firestore.document('confirmedOrders/{id}').onCreate(async (snapshot, context) => {
var tokens = [];
const _snap = await admin.firestore().collection('userInfo').where('isAdmin', '==', true).get();
_snap.forEach((k) => {
tokens.push(k.data().token.toString());
})
return fcm.sendToDevice(tokens, {
notification: {
title: 'New Order',
Expand All @@ -33,11 +25,12 @@ exports.adminOrderTrigger = functions.firestore.document('confirmedOrders/{id}')
});


exports.adminBookingTrigger = functions.firestore.document('BookingDetails/{id}').onCreate((snapshot, context) => {
var tokens = [
'dtG7Gozeq5M:APA91bHAblBNNNJnPn9EY0DWqVLbTnT8jvZNctTDxLVI9QkYU7T0BJP_U8j_pjdRu0LYeNGYtDUHzPN22cmB1cT0z95Z1Y8NDHsJD8wuWHfPax68nwYa4OmgG4Ky6i5KjaHca7-AnWdc',
'd7cf7_GgXCg:APA91bF-HqKMwlAfTsy3dRv_LVuvxkDbiBOWkBMWHweu6X8wvq_9Zw7x8ws2qSepPOk1dypxySmiv-6ct72Pbzwu6nOejFCcTEy17-_k8EmvOEMvcS2BGP-ToNAqsfF9m_EbPG4jdlhu'
];
exports.adminBookingTrigger = functions.firestore.document('BookingDetails/{id}').onCreate(async (snapshot, context) => {
var tokens = [];
const _snap = await admin.firestore().collection('userInfo').where('isAdmin', '==', true).get();
_snap.forEach((k) => {
tokens.push(k.data().token.toString());
})
return fcm.sendToDevice(tokens, {
notification: {
title: 'New Booking',
Expand All @@ -47,25 +40,52 @@ exports.adminBookingTrigger = functions.firestore.document('BookingDetails/{id}'
})
});

exports.confirmNotification = functions.firestore.document('confirmedOrders/{id}').onUpdate((snapshot, context) => {
exports.confirmNotification = functions.firestore.document('confirmedOrders/{id}').onUpdate(async(snapshot, context) => {
var token = snapshot.after.data().token;
return fcm.sendToDevice(token, {
notification: {
title: 'Order Confirmation',
body: 'Your order has been confirmed',
clickAction: 'FLUTTER_NOTIFICATION_CLICK'
}
})
var rejected = snapshot.after.data().isRejected;
var confirmed = snapshot.after.data().isConfirmed;

if(confirmed === true) {
return fcm.sendToDevice(token, {
notification: {
title: 'Order Confirmation',
body: 'Your order has been confirmed',
clickAction: 'FLUTTER_NOTIFICATION_CLICK'
}
});
} else if(rejected === true) {
return fcm.sendToDevice(token, {
notification: {
title: 'Order rejected',
body: 'Your order has been rejected',
clickAction: 'FLUTTER_NOTIFICATION_CLICK'
}
});
}

});


exports.BookingNotification = functions.firestore.document('BookingDetails/{id}').onUpdate((snapshot, context) => {
exports.BookingNotification = functions.firestore.document('BookingDetails/{id}').onUpdate(async(snapshot, context) => {
var token = snapshot.after.data().token;
return fcm.sendToDevice(token, {
notification: {
title: 'Booking Confirmation',
body: 'Your Booking has been confirmed',
clickAction: 'FLUTTER_NOTIFICATION_CLICK'
}
})
var isConfirmed = snapshot.after.data().isConfirmed;
var isRejected = snapshot.after.data().isRejected;
if(isConfirmed === true) {
return fcm.sendToDevice(token, {
notification: {
title: 'Booking Confirmation',
body: 'Your Booking has been confirmed',
clickAction: 'FLUTTER_NOTIFICATION_CLICK'
}
});
} else if(isRejected === true) {
return fcm.sendToDevice(token, {
notification: {
title: 'Booking Rejection',
body: 'Your Booking has been rejected',
clickAction: 'FLUTTER_NOTIFICATION_CLICK'
}
});
}
});

Loading