all repos — caroster @ 3095e0573ccb511d048f34f1d369bcc2c996e7b9

[Octree] Group carpool to your event https://caroster.io

🐛 Fix travel alerts
Tim Izzo tim@octree.ch
Tue, 20 Feb 2024 10:27:49 +0100
commit

3095e0573ccb511d048f34f1d369bcc2c996e7b9

parent

ca949321c8556677f2659c1202eb180ce88137a7

1 files changed, 8 insertions(+), 11 deletions(-)

jump to
M backend/src/api/trip-alert/services/trip-alert.tsbackend/src/api/trip-alert/services/trip-alert.ts

@@ -9,17 +9,6 @@ export default factories.createCoreService(

"api::trip-alert.trip-alert", ({ strapi }) => ({ async sendTripAlerts(eventId: string, travel) { - if (!travel.meeting_latitude || !travel.meeting_longitude) { - strapi.log.warn( - `Can't send trip alert for travel ${travel.id}. No coordinates found.` - ); - return; - } - - const travelCoordinates: Coordinates = [ - travel.meeting_latitude, - travel.meeting_longitude, - ]; const eventTripAlerts = await strapi.entityService.findMany( "api::trip-alert.trip-alert", {

@@ -34,12 +23,19 @@ const filteredTripAlerts = eventTripAlerts.filter((tripAlert) => {

// If alert has no geographical info, send alert on each new trip if (!tripAlert.latitude || !tripAlert.longitude || !tripAlert.radius) return true; + // If travel has no geographical info, send alert to all + else if (!travel.meeting_latitude || !travel.meeting_longitude) + return true; // Else, check if new travel is in alert area const alertCoordinates: Coordinates = [ tripAlert.latitude, tripAlert.longitude, ]; + const travelCoordinates: Coordinates = [ + travel.meeting_latitude, + travel.meeting_longitude, + ]; const distance = calculateHaversineDistance( travelCoordinates, alertCoordinates

@@ -56,6 +52,7 @@ data: {

type: "NewTrip", event: eventId, user: tripAlert.user.id, + payload: { travel }, }, }); });