Open kmehant opened 4 years ago
@kmehant We should not only record the timestamp and routes but what we want is basically the activity of the user let say a user "X" is creating a post so what he will do:
- Send POST request to /post
- With some data So it should store the activity like: userId, postId, timeStamp, so that we when we render in the client side then from there on clicking a particular activity an admin can navigate to that post.
Also, we should not call the middleware on GET requests as we are not interested in what the user is exploring on the platform but we are interested in what actions he/she is performing on the platform.
@Rupeshiya Thank you for the review I had this doubt, I guess I spoke about the data model in the issue for your approval 🥺☹️ before implementing it. For get requests thing, I haven't used the middleware yet, we can include this middleware to any route we wish to use.
@Rupeshiya @vaibhavdaren @devesh-verma Please 🙏🙏 I guess it would be easy if we can discuss on the design, approach correctly and the outcomes so that we all will be on the same page ✌️ and intention.
HASH ---> (KEY, HASH_VALUE)
|
(USER) | (RANDOM)
(ROUTE)
|
IS THIS UNIQUE?
KEY HASH ID_OF_OBJECT_RETURNED
HASH ---> TIMESTAMP ---> ROUTE --> (UUID_mogo_id)
|
(per_user)
@kmehant Also please add the API to fetch those user activity data from DB.
Also will it work in case of comment, because in that case we want postId as well as commentId??
@Rupeshiya Yes, it should work!
based on the response as I can see postid
and commentid
keys in the response object already. So we can use them.
@Rupeshiya Can you suggest API endpoints so that I can move forward
@Rupeshiya Can you suggest API endpoints so that I can move forward
Yeah, let it be /user/:id/activity (here id is the userId as we want to fetch for each user by their id)
@kmehant ETA?
Signed-off-by: K mehant 411843@student.nitandhra.ac.in
Context
This pull request adds an express middleware that can be used to track user activity and store them in a Mongo database.
Design
Taking several points from @vaibhavdaren and @Rupeshiya, I have come with this approach in designing the middleware
get
are recorded as below data models into Redis cacheData model on Redis: A Redis List for cache
Data model on Mongo:
method
request methodroute
name of the routeid
Mongodb`s _id or object id (taken from the response)collection type
: Type of the collection where we can use ourid
to fetch data such ascreated at
and others.partially closes #148