How Should I check if someone is in a certain location when Database Updates - node.js

I'm currently trying to build something similar to Amber Alerts where whenever a database table is updated, I check if users are in a certain area.
For example, let's say a user makes a report that they found a wallet at their current location. The database is updated where a new row is created with the latitude and longitude of that report location, and then I want to check which users are in a 5 mile radius of that lat-long.
I have every user's phone number but that's about it. I am successfully able to get the location of the report (my frontend provides that in the request data to the backend) but I'm unsure on how to get the location of other users.
How would I do this?
I am using Node JS for my backend and React Native for my frontend.
Thanks!

Related

When is the ideal time to store user session data for e-commerce platforms such as products viewed?

We have a an ecommerce platform where we need to store user session data in a database such as products viewed and products liked. When is the right time to call an API to store this data?
I don't want to call an API every time they open a new product.
I've experimented with DOM methods such as visibilitychange but on our website, every product is opened in a new tab so it's not ideal.
Should we use some background scripts such as service workers?

Best way to track how many times a user has logged in

I'm looking for advice on tracking user logins on my site. I had built a counter that increments on logins but it increments for all users not just one user. I only need it to increment when a specific user logs in. The purpose is to have a welcome message display the first time a user logs into the site. My site is built using ReactJs for the front end and NodeJs for the back. So far I tried using a state with a count set at 0 and then when the login function is run update the count by one. This works but it isn't relative to a user, just to the login function itself. Any advice?

Is it possible to check if anyone has a certain browser link open and if not execute a function?

I am making a web app that involves the creation of several rooms (users create them). These rooms are then stored on an array on the server. Using react router each of these rooms are given their own unique url /roomCodeGoesHere. I want to periodically check the rooms to see if anyone is in it(I guess in this case has the browser open?) and if there is no one in it, to have the room be deleted from the array.
Is there any way I can go about doing this? (the only ways I can think of seem hacky and are probably not good practice)
You can monitor the user count within your server array (via put request or websocket on mount/unmount), and if the room empties conditionally delete it within the controller. A room should by default start with 1 occupancy since it needs a creator. If you don't want to delete the room right away, then do the same thing but create a setTimeout that conditionally clears itself unless someone new enters.
This chat app I made deletes a room at 0 users using the above method:
http://astral-chat-app.herokuapp.com/

How to locally store user information when he is using facebook messenger chatbot?

I followed facebook's documentation and set up my messenger bot. It works fine when it's just me who's using it, but I don't know how to create variables and store information in them locally so that I can have individual information about each user.
For eg. If I ask them to type their phone number, how/where should I save it, so that it isn't overwritten if a new user comes and inputs his number (which happens, if the variable is declared globally), and I can also use it later.
I used Node JS and followed the steps they mentioned in the documentation.
You have node js server as a backend which can communicate to a (mysql/sqlite) database.
Fb provides senderId with each request and also there is another graph API for getting user's other information like Name, Age, Gender, profile pic link etc
https://graph.facebook.com/v2.6/SENDER_ID?access_token=YOUR_TOKEN
You can have a table in your (mysql/sqlite) database where you can store senderId as a unique key and other information including phone number (which you are getting by asking user) in other columns.
Here's the documentation link for public profile API.

nest api - cryptic error message when creating client with product data write permissions

I'm attempting to create a google nest client to write electricity monitor data to the Nest for display in the energy history plot, but although I'm able to create a test client with thermostat read permissions, when I attempt to create a new client with product data write permissions I get an error message saying "scopes.justification exceeds required maximum length of 140". I don't see any fields with more than 140 characters and an email to the Nest team has been unanswered for several days.
I should say I'm leaving the OAuth redirect field blank because I'm still trying to learn exactly how OAuth is meant to work and if the redirect is a site I need to write and host or what, but it appears to be optional and one can edit client details later or use a PIN so doesn't seem that's the issue, but I could be wrong.
Anyone had this issue or able to provide some tips?

Resources