Guest bulk questions - social-tables

We’re trying to get an understanding of the guest bulk api endpoints, and have some questions we need to get clarified.
Can you please provide examples to the guest bulk import? Does a batch update return the social tables internal guest id?
How do we add gender to a guest in the bulk import in order to use them in the auto seating function?
How do we add tags on guests in the guest bulk api?
The guest bulk import create method seem to support custom id on each guest, are there any requirements on how we build these ids?

For a POST to /4.0/guestlists/{guestlist_id}/guests/_bulk to create guests, a sample body with tags could be:
{
action: "CREATE",
guests: [
{"first_name": "Test", "last_name": "One", "tags": ["VIP", "Donor"]},
{"first_name": "Test", "last_name": "Two"}
]
}
A bulk update request will not return any data, but if you fetch the guestlist after your update, you will have all the guests' data including internal guest id.
Gender is not a supported property by default for guests at this time. If you wish, you may add it as a property by creating it as a Custom Field on guests after import.
See code sample for importing guests with tags.
The bulk endpoint does indeed support user-generated guest ids. There are no requirements for these ids, but you are responsible for guaranteeing uniqueness among the ids.

Related

Checking Whether Table Data Exists, Updating / Inserting Into Two Tables & Posting End Outcome

I am working on my cron system which gathers informaiton via an API call. For most, it has been fairly straight forward, but now I am faced with multiple difficulties, as the API call is dependant on who is making the API request. It runs through each users API Key and certain information will be visible/hidden to them and visaversa to the public.
There are teams, and users are part of teams. A user can stealth their move, however all information will be showed to them and their team, however this will not be visible to their oponent, however both teams share the same id and have access tothe same informaiton, just one can see more of it than the other.
Defendants Point Of View
"attacks": {
"12345`": {
"timestamp": 1645345234,
"attacker_id": "",
"attacker_team_id": "",
"defender_id": 321,
"defender_team_id": 1,
"stealthed": 1
}
}
Attackers Point Of View
"attacks": {
"12345`": {
"timestamp": 1645345234,
"attacker_id": 123,
"attacker_team_id": 2
"defender_id": 321,
"defender_team_id": 1,
"stealthed": 1,
"boosters": {
"fair_fight": 3,
"retaliation": 1,
"group_attack": 1
}
}
}
So, if the defendant's API key is first used, id 12345 will already be in the team_attacks table but will not include the attacker_id and attacker_team_id. For each insert there after, I need to check to see whether the new insert's ID already exist and has any additional information to add to the row.
Here is the part of my code that loops through the API and obtains the data, it loops through all the attacks per API Key;
else if ($category === "attacks") {
$database = new Database();
foreach($data as $attack_id => $info) {
$database->query('INSERT INTO team_attacks (attack_id, attacker_id, attacker_team_id, defender_id, defender_team_id) VALUES (:attack_id, :attacker_id, :attacker_team_id, :defender_id, :defender_team_id)');
$database->bind(':attack_id', $attack_id);
$database->bind(':attacker_id', $info["attacker_id"]);
$database->bind(':attacker_team_id', $info["attacker_team_id"]);
$database->bind(':defender_id', $info["defender_id"]);
$database->bind(':defender_team_id', $info["defender_team_id"]);
$database->execute();
}
}
I have also been submitting to the news table, and typically I have simply been submitting X new entries have been added or whatnot, however I haven't a clue if there is a way to check during the above if any new entries and any updated entries to produce two news feeds:
2 attacks have bee updated.
49 new attack information added.
For this part, I was simply counting how many is in the array, but this only works for the first ever upload, I know I cannot simply count the array length on future inserts which require additional checks.
If The attack_id Does NOT Already Exist I also need to submit the boosters into another table, for this I was adding them to an array during the above loop and then looping through them to submit those, but this also depends on the above, not simply attempting to upload for each one without any checks. Boosters will share the attack_id.
With over 1,000 teams who will potentially have at least one members join my site, I need to be as efficient as this as possible. The API will give the last 100 attacks per call and I want this to be within my cron which collects any new data every 30 seconds, so I need to sort through potentially 100,000.
In SQL, you can check conditions when inserting new data using merge:
https://en.wikipedia.org/wiki/Merge_(SQL)
Depending on the database you are using, the name and syntax of the command might be different. Common names for the command are also upsert and replace.
But: If you are seeking for high performance and almost-realtimeness, consider using a cache holding critical aggregated data instead of doing the aggregation 100'000 times per minute.
This may or may not be the "answer" you're looking for. The question(s) imply use of a single table for both teams. It's worth considering one table per team for writes to avoid write contention altogether. The two data sets could be combined at query time in order to return "team" results via the API. At scale, you could have another process calculating and storing combined team results in an API-specific cache table that serves the API request.

How to get Customer object's customerID from metadata in Stripe Payment Intent

I am trying to implement stripe payment intent API in golang.
Is there any way I can get customerID from metadata inside of the Customer object?
For example, I create new customer object and insert uuid as metadata. This uuid comes from my database.
// create new customer object
customerParams := &stripe.CustomerParams{
Description: stripe.String("Go Stripe Developer"),
Email: stripe.String("gostripe#stripe.com"),
Phone: stripe.String("1111111111"),
}
customerParams.AddMetadata("uuid", "123")
I do this because in case something happens to my database and customerID is gone, I can retrieve the data such as purchase history from UUID if I can access to metadata inside of the Customer object.
Or at least, I want to set Customer parameter deleted: true, but if there is no customerID record in my database, I cannnot access to the stripe's Customer object since the object can be accessible only from customerID itself according to API docs.
Since I noticed I can insert metadata, if there is some way I can access to Customer object using that metadata, that would save my life.
Any advice is appreciated!
The solution: you can use the List Customers API by email and do an additional filter match with uuid from metadata (in your code), so you can retrieve the customer detail.

Implementing custom user permissions in GraphQL and Hasura

I am creating a webapp that allows users to communicate in several different rooms and am hoping that I can use GraphQL and Hasura for this project. There will be admins which can create/delete rooms (wow-room, lol-Room, pubg-room), create/delete users, and create/delete permissions (admin, wow, lol, pubg) along with assigning roles to users. Users will be able to see any the rooms which they have the permisions to.
The problem is, I want to be sure that only the admins can create/delete these rooms/users/permisions and that only the correct users can see these rooms. Is there a way I can get Hasura to check the permissions of the given user and return the appropriate data? I believe that I need to write a custom resolver but am not sure how that is done or if it is the correct solution.
While Hasura can handle dynamic roles (you can use the API to create new roles and new permission rules on the fly) with Hasura, I think in this case that's not required.
The problem is, I want to be sure that only the admins can
create/delete these rooms/users/permisions and that only the correct
users can see these rooms. Is there a way I can get Hasura to check
the permissions of the given user and return the appropriate data?
Hasura allows you to set a permission rule that traverse relationships which makes this possible. Check out the article-collaborators example in the Hasura docs.
Assuming that your models are rooms, users and room_users and you have the relationships set up so that room.users returns the list of users for a particular room, the permission for a user role on the rooms table can be expressed as follows:
Allow SELECT on a row in rooms if
rooms.users.id: _eq: x-hasura-user-id
This translates to: if a room's users list contains atleast one user_id that is equal to x-hasura-user-id then grant access to that room.
I've set this up on a heroku app: https://multiple-roles-hasura.herokuapp.com/console/api-explorer
Try the following queries out in GraphiQL:
Set the headers to:
x-hasura-role: user
x-hasura-user-id: 1
Run the following query:
query {
rooms {
id
name
}
}
You'll see that the response only contains the rooms that user1 has access to
Switch x-hasura-user-id through different values 1, 2, 3, 4, 5, 6 and you'll see different results for the same query. Basically the right rooms that the only the current user has access to.
Checkout the models and the permissions for the models on:
User & Room mappings: https://multiple-roles-hasura.herokuapp.com/console/data/schema/public/tables/room_users/browse
Room permissions: https://multiple-roles-hasura.herokuapp.com/console/data/schema/public/tables/rooms/permissions

Sequelize - Incorporate stores into retailers after obtaining the latter

I'm really new to Sequelize and I find the Docs confusing especially for my case since I already had a Postgres DB set up and used sequelize-auto to create all the models from the existing DB.
Now I have the following:
Retailers
Stores
Stores have a FK in retailer_id since Retailers have several Stores, but a single Store belongs to a single Retailer.
I want to retrieve from my Node API a JSON with the following format:
[{
id:"1",
name: "RetailerName",
stores: [{
id: "1",
name: "StoreName",
...
}]
}]
I was thinking of getting all of the retailers, iterate through them and getting all stores based on the "current" retailer id and adding them to retailers, replying that.
However this is not possible without a promise of some sort and since there are better tools to achieve this with sequelize I would like to know how to do this!
Use sequelize's associations (One-To-Many in this particular case)

How to design the schema for an author/user model in mongodb

I have looked through most of the mongodb schema design articles on mongo's website and most of the questions here on SO. There is still one use case which I haven't figured out. When looking at these tutorials, they usually reference the article comments problem and the products/categories problem. I want to figure out how to model the one to many relationship (author to posts) when querying a list of posts. Here are the example schemas:
Users: {
_id: ObjectID
Name: String
Email: String
}
Posts: {
_id: ObjectID
user_id: ObjectID
body: String
comments: [
body: String
]
}
Now, lets say you want to run a query for the latest 10 posts. A pretty simple query, but now you have posts with the possibility of each one having a unique ObjectID pointing to the user. Now, how should you accomplish getting the name and email of each user for a post.
Should you create an array of the user ObjectID's from the posts query and then run the query db.users.find({ _id: {$in: PostsUserIDArray}}); After that would you use your application logic to match the right user information to the correct post?
Should you keep a copy of the data in posts. I.E. keep the user ID, name, and email in the posts table. Then just have a hook when a user updates this information to update all the information in posts.
An option which myself or my friend have not thought of.
I appreciate all help as I try to wrap my head around mongo data modeling.
For a few videos I have seen from MongoDB creators, they advocate the second solution. If your user have more data than just a name and email and if you display only name and email when displaying apost, then it's not really bad to store it in the post. Thus you don't have to perform others queries when querying for posts. And since a user doesn't normally change his name every day, it's more effective to run an update to all posts once he changes his name than perform other queries to retrieve informations when displaying posts.
Edit : link to a video http://lacantine.ubicast.eu/videos/3-mongodb-deployment-strategies/