LoopBack Relational Mapping : Events and Invitations - mongodb

I'm trying to model a simple event application.
Basically:
A User can create an Event
A User can invite many Users to an Event
A User can accept/decline an Invitation
A User can retrieve an Event if he's the owner or is participating (accepted Invitation). The difference should somehow be visible in the returned objects
A User can retrieve Event's current accepted/declined Invitations (actually Users, not foreign keys)
A User can remove himself from an Event
To many things to think about so it's all mixed up in my head and I'm losing the whole picture. I don't fully understand how I should implement accept/decline Invitation and how I should retrieve information about current participants. What are the relations behind?
I think I know how to do it with references only, but my front-end is mobile so I don't want to make a lot of requests to get every object by reference after the first fetch...
If someone could lighten me up...
Thanks :)

You should have an invitation model and an event model with the following fields.
Invitation : eventId, userInvited, accepted
An invitation belongs to an event and belongs to a user
Event : your event details, event owner
Then for a user you can do a remote method that gets the events with
Invitation.find({where: {userInvited: user.id}}, include: 'event')
.then((event) => event.id)
And with the event, gets all the users
.then((eventId) => Invitation.find({where: {eventId}}, include: 'user'))
.then((invitations) => invitations.map((invitation) => invitation.toJSON().user))
It's a quick draft of how to achieve what you want.

Related

send calendar invite based on response

I want to create a form using Microsoft Forms to schedule some trainings and I wanted to use Flow to send out the person a calendar invite to the session they choose on the form.
what's the best way to go about doing this ...
You can use the answer on this post here to start the flow and add another action to send an email with the link to the event created. You can also update the event with the person information using something like this.
Images for reference:
1) Create the Flow part that gets the form inputs and convert into events.
2) Get the event created previously and update it with the email addresses from the people so they will receive an email with the invite.

Differentiate between Facebook user and event ID

How can I detect programmatically wether a Facebook ID user over event ID is? Are there any intervals where ID come from? I.e. 10211282278486891 is my user ID, and 1774156412659580 is an event ID. Looking for a fast way, without any web service call.
Search for fields specific for the user - for example, there is no "first_name" field in an event and you do not need extra permission to get that field.
/id?fields=first_name
Another solution that is probably better:
/id?metadata=1
With that API call, you get a "type" field that tells you if it´s a user profile or event.

Friend list through relations

I'm creating a social media app. I'm able to allow the current user to search for a PFUser and add the user to a friendship relation. I'm struggling on accessing the friendship relation and getting all the friends to create a table view right now. Could someone help me with this?
A Relation type in Parse represents just like what it literal meaning is. It's just a relation that contains no data. If you want to access the data inside the relation. You will need to perform query on it like so:
let query = relation.query() // I assume relation is an instance of PFRelation you want
Actually, Parse tutorial provides us a very comprehensive guide and you should check that first: https://parse.com/docs/ios/guide#relations
NOTE: This answer provides alternatives to using Relations to make a Friend System
I have created a friend system in two ways using Parse and both a function of your specific needs.
The first time I implemented a friend system. I had a table of Users and a table of Relationships. The Relationships table stored the usernames (or ObjectIds) of the two users in a relationship and the state of that relationship (friends, request sent, etc). The problem with this is that the queries can be kinda complicated, and if you have a lot of users, this may end up being too slow.
The second option is storing friend information in the User table itself. For each user, you add the columns with they type Array: Friends, RequestSent, and RequestReceived. Anytime a user sends a request they update their own user row and send a message to CloudCode to update the other affected user. Take a look at this example:
User A sends a request to User B:
User A adds user B's name to RequestSent
User A sends a message to cloud code that he/she wants to add user B
CloudCode adds User A's name to User B's RequestReceived
User B wants to accept User A's request
User B adds user A's name to Friends
User B removes user A's name from RequestSent
User B sends a message to CloudCode that he/she wants to accept User A's friend Request
CloudCode adds user A's name to Friends
CloudCode removes user A's name from RequestReceived
With this option, you never perform any server side queries. You only ever perform get operations. The downside to this option is if the logged-in user has thousands of friends/requests, it will take a while to download that information.
Note: The reason you have to use CloudCode is that a User can only change information about him/herself. The other option is to have CloudCode manage all the adding/removing so better checks can be made.
I found with this method that you can sometimes have one user who is listed a a friend in another users row but not their own. Controlling everything from CloudCode could eliminate this kind of error.

Problems of inviting friends through Facebook email

I want my users to invite their friends by sending them Facebook private massage. I am thinking of using send button, but the problem is that each invitation url is different and unique, so if I use send button to do it, I might need to create many send buttons each of which carries an unique href. I think this should work? But ideally, I want users to just select their friends in a multi friend selector and everything's done by just clicking the sending button. Any ideas?
Thanks for any help!
You can generate a unique URL for the message that includes the IDs for all the users the user wants to send the message to. Then, when the recipient accesses the URL and authenticates themselves, you can cross reference the URL and their User ID to what you have in your database.
Without knowing what the message contains, its purpose and what you want to achieve, this is the best approach I can think of.
You won't be able to tell who the message is actually sent to, as Facebook doesn't return the User IDs in the callback, but if you have read_inbox permissions, you should be able to look the User IDs up that way.
i think an better way to approach this is set up an invite system, have an invitation code field in your register.php that you sign into, store that info in user account database and set an number of times it can be used

CQRS and email notification

Reading up on CQRS there is a lot of talk of email notification - i'm wondering where to get the data from. Imagine a senario where one user invites other users to an event. To inform a user that he has been invited to an event, he is sent an email.
The concrete steps might go like this:
A CreateEvent command with an associated collection of users to invite, is received by the server.
A new Meeting aggregate is created and a method InviteUser is called for each user that is to be invited.
Each time a user is invited to an event, a domain event UserWasInvitedToEvent is raised.
An email notification sender picks up the domain event and sends out the notification email.
Now my question is this: Where do I go for information to include in the email?
Say I want to include a description of the event as well as the user's name. Since this is CQRS I can't get it thru my domain model; All the properties of the domain objects are private! Should I then query the read side? Or maybe move email notification to a different service entirely?
In CQRS, you're separating the command from the query side. You will always want to go to the query side in order to get data for a given event handler. The write database is going to be a separate database that contains the data necessary for building up your domain objects and will not be optimized for reads, but for writes.
The domain should register and send an EventCreated event to the event handlers / processors. This could be raised from the constructor of the Meeting aggregate.
The event processing component would pick up the EventCreated event, and update the query database with the data contained in the event (ie, the Id of the event and its name).
The domain could register and send a UserWasInvitedToEvent event to the event processors.
The event processors would pick up the UserWasInvitedToEvent and update the query store with any reporting data necessary.
Another event processing component would also pick up the UserWasInvitedToEvent event. This process could have access to the query database and pull back all of the data necessary for sending the email.
The query database is nothing more than a reporting database, so you could even have a specific table that stores all of the data required for the email in one place.
In order to orchestrate several different events into a single handler (assuming the events might be processed in a different order at different times), you could utilize the concept of a Saga in your messaging bus. NServiceBus is an example of a messaging bus that supports Saga's. See this StackOverflow question as well: NServiceBus Delayed Message Processing.