Firing multiple api calls at once - reactjs

I'm struggling to find the right words to convey what I'm looking for in my research, so I thought I would ask the stackoverflow community. I am looking for best practices to create records in different tables at once.
An example would be, user registration. Say you need to create 6 records for that user when they sign up, which need to connect. By connect I mean in the sense that if a user and team were created on user registration, the userID would need to be included in the team's members array. So the records need to fire in order so the relationship is properly recorded. So user would need to be created first, then the team record so I can add the userID to the team's members. Also note that the user record would need to be updated later on (after the team's record is created) with the teamID under the user's teams.
So as you can see it feels a bit all over the place. Currently I have multiple API calls being fired on user submit. While I have this working using redux, firebase and react — I foresee a lot of potential errors happening and feel as if I am not doing this in the most efficient way. I want to do this correctly and happy to do the research, I'm just not exactly sure what I am looking for. I was hoping for some guides, information, search terms, etc — basically anything to help me understand this concept more throughly if that makes sense.

This is a perfect candidate for GraphQL and a backend that handles it properly. Take KeystoneJS for example. You could do a single create user and handle it all internally via the hooks system. You can also do nested creates / connects all in one mutation and KeystoneJS will take care of all of it for you if there are nested operations. For example you can create object A, then create object B in one mutation. It'll create B, then A, then connect A to B... with no extra work on your end. I just give this as a single example of a tool you can use. Here is an example mutation that Keystone just handles:
mutation CreateUser {
createUser(data: {
username: "test"
organization: {create: {
title: "test"
}}
})
}
Notice organization is created inside of the user mutation.
Yes, I think the best practice is to have your back end, whatever it is, do the work. It will fail if it bumps into an issue and clean itself up. Otherwise, it produces a positive response. I hope this is helpful...
For alternatives, since this is a pretty open ended question... I've also created a nestJS back end. That works great too, but it's a lot less opinionated with fewer built in solutions, so you do a lot more work (but it's more flexible). Any CMS should give you control over this (Strapi seems to be taking off... I just ran into too many bugs with it).

Related

How to structure your flutter/aws-amplify project so that you have a course structure in your app

*I´m new at Flutter/AWS-Amplify so please forgive me in case that's a really basic question
Imagin that I have a course to complete with several.
Course1 with Module 1 to 10, I want to have my app to take into account where each user is in its course and having my UI reflecting those possible states where my user is. (for instance Duolingo tree where you know which learning activities you have finish and which ones you still need to complete)
I have created several tables under my data modeling saved in DataStore, AWS/Amplify, all related to my course.(defining the logical sequence of my course)
Now the point is how to deal with all the possible states where a single user can be and hoe to handle the fact that different users can be at any state of my course...
In my schema.graphql file I´m trying to set authorization rules for my databases but I´m not sure if that´s the way to go.
Thank you very much for the help and time spend to help me.

React/Redux pattern for demoable apps

I've been searching around for a while on this, but as of yet haven't found anyone else trying it. So I'm asking for feedback and critique - both on if this seems reasonable, and if there's a better established pattern for it.
Basically, I want to be able to easily publish a "demo" version of a react/redux app. My specific example is an app I built but that is only useable with our internal database with user information. I can't show that anywhere, because we don't want the information to escape out into the world.
Since all of the model interactions are routed through redux, it occurred to me that I could drop in a new set of actions based upon the URL.
Say the user goes to myawesomeapp.com - they're given the full app, login prompts, security, access to the database.
But an outside party could go to demo.myawesomeapp.com (for example), and get an app that is functionally the same but is wired up to dummy data that isn't saved.
The general pattern that I have would be this:
Vaguely, in actions/index.js
export * from './common_actions';
if (location.href.match(/demo\.myawesomeapp\.com/)) {
export * from './demo_actions';
}
else {
export * from './actions';
}
I don't really like that - it feels brittle and like a hack. But it works! Registered users can use the actual app, and demo users can try it out in a sandbox.
Judicious use of exported constants and values also allow peppering of other flags and data - overlays of text to walk through things, links to sign up for the actual app, etc.
I love this as a concept - with just a few new redux actions, you get a fully sandboxed app to show off with no worry of cross contamination. It's much easier than trying to sanitize all the endpoints.
And even if an action wasn't properly isolated in this manner, the worst that would happen is that they'd get an access denied error from the actual backend since they're not logged in.
But to the world, my questions are -
1) Does this seem like a reasonable thing to do or are there gotchas I'm not considering it?
2) Does this seem like a reasonable way to implement it, or is there a better approach I haven't considered?
I don't like this solution, if i understood you correctly this solution will duplicate your code, which is never a good idea, you'll have to change two different code bases with every little change, needless to say it will duplicate your work, why not just point the demo app to a different database ? or better yet(and it's also industry standard) create a "time trial" role for your users so they can test your app and if they like it, they already have an user account.

Can only add entity kinds/attributes if they already exist in GAE dev server

I am unsure if this is a bug, by design (though I can't see the benefit), or if I am just being dimwitted.
Using Google App Engine development server, v1.9.8, I can only add a datastore entity if another of the same kind already exists. Otherwise the drop-down physically does not show the entity kind.
Further, even on an entity kind that does exist, I can only change attributes (or create them if it's new) if that attribute is not null on at least one of the other existing entities of that kind.
This is annoying, since in order to test things I have to first do:
entityKind(every=Possible, attribute=Set, to=Something, even=If,
i=Dont, yet=Need).put()
Refresh, and then remember to delete this line before refreshing again to avoid duplicating the entry in datastore.
Note though, that if I happen to be testing with only entities that do not use every attribute, I have to keep this dummy one just in case I want the others later.
I must, surely, be missing something here? I can't believe there isn't a way to just create datastore entities without hacking around it like this?
You are talking about creating entities manually using a Dev server. Over the past 4 years of using GAE I wished once or twice that this would be possible, but I never needed this feature. You create entities in your code, and you debug your code if something does not work.
You can (and should) write unit tests to test your code. A proper unit test creates an entity, saves it, reads it, verifies that all the properties are correct, deletes it, verifies that it was deleted. There is no code to cut and paste (or comment/uncomment), and there are no test entities left after testing is completed.
Your mistake is in thinking of the web console as a part of your workflow. It is absolutely not, and not intended to be. It is a vaguely hacked-together tool that allows you to do some basic operations on your data, and nothing else.
Interact with the datastore via code, and leave the web console for simple verifications.

CakePHP Beginner: Advice needed, Everything on a single view or multi part forms

Thanks in advance for any help offered and patience for my current web-coding experience.
Background:
I'm currently attempting to develop an web based application for my family's business. There is a current version of this system I have developed in C#, however I want to get the system web-based and in the process learn cakephp and the MVC pattern.
Current problem:
I'm currently stuck in a controller that's supposed to take care of a PurchaseTicket. This ticket will have an associated customer, line items, totals etc. I've been trying to develop a basic 'add()' function to the controller however I'm having trouble with the following:
I'm creating a view with everything on it: a button for searching customer, a button to add line items, and a save button. Since I'm used to developing desktop applications, I'm thinking that I might be trying to transfer the same logic to web-based. Is this something that would be recommended or do'able?
I'm running into basic problems like 'searching customer'. From the New Ticket page I'm redirecting to the customer controller, searching and then putting result in session variable or posting it back, but as I continue my process with the rest of the required information, I'm ending up with a bit of "spaghetti" code. Should I do a multi part form? If I do I break the visual design of the application.
Right now I ended up instantiating my PurchaseTicket model and putting it in a session variable. I did this to save intermediate data however I'm not sure if instantiating a Model is conforming to cakephp standards or MVC pattern.
I apologize for the length, this is my first post as a member.
Thanks!
Welcome to Stack Overflow!
So it sounds like there's a few questions, all with pretty open-ended answers. I don't know if this will end up an answer as such, but it's more information than I could put in a comment, so here I go:
First and foremost, if you haven't already, I'd recommend doing the CakePHP Blog Tutorial to get familiar with Cake, before diving straight into a conversion of your existing desktop app.
Second, get familiar with CakePHP's bake console. It will save you a LOT of time if you use it to get started on the web version of your app.
I can't stress how important it is to get a decent grasp of MVC and CakePHP on a small project before trying to tackle something substantial.
Third, the UI for web apps is definitely different to desktop apps. In the case of CakePHP, nothing is 'running' permanently on the server. The entire CakePHP framework gets instantiated, and dies, with every single page request to the server. That can be a tricky concept when transitioning from desktop apps, where everything is stored in memory, and instances of objects can exist for as long as you want them to. With desktop apps, it's easier to have a user go and do another task (like searching for a customer), and then send the result back to the calling object, the instance of which will still exist. As you've found out, if you try and mimic this functionality in a web app by storing too much information in sessions, you'll quickly end up with spaghetti code.
You can use AJAX (google it if you don't already know about it) to update parts of a page only, and get a more streamlined UI, which it sounds like something you'll be needing to do. To get a general idea of the possibilities, you might want to take a look at Bamboo Invoice. It's not built with CakePHP, but it's built with CodeIgniter, which is another open source PHP MVC framework. It sounds like Bamboo Invoice has quite a few similar functionalities to what you're describing (an Invoice has line items, totals, a customer, etc), so it might help you to get an idea of how you should structure your interface - and if you want to dig into the source code, how you can achieve some of the things you want to do.
Bamboo Invoice uses Ajax to give the app a feel of 'one view with everything on it', which it sounds like you want.
Fourth, regarding the specific case of your Customer Search situation, storing stuff in a session variable probably isn't the way to go. You may well want to use an autocomplete field, which sends an Ajax request to server after each time a character is entered in the field, and displays the list list of suggestions / matching customers that the server sends back. See an example here: http://jqueryui.com/autocomplete/. Implementing an autocomplete isn't totally straight forward, but there should be plenty of examples and tutorials all over the web.
Lastly, I obviously don't know what your business does, but have you looked into existing software that might work for you, before building your own? There's a lot of great, flexible web-based solutions, at very reasonable prices, for a LOT of the common tasks that businesses have. There might be something that gives you great results for much less time and money than it costs to build your own solution.
Either way, good luck, and enjoy CakePHP!

DNN module sugestions needed, form/reg, pyment, emailing

i need a module that is kind of a cross between a registration module and a form module.
it need to allow for custom form fields to be saved to the DB and work as part of a flow such that once data is entered by the users they click next and see the data to confirm it is correct. at this point they should have the option to edit the data if they notice an error or continue to a payment page.
the payment page needs to have a module that can integrat with payment gateways liek paypal and accept credit cards. once credit card data is entered and the transaction is complete a custom email with a unique userNumber needs to be sent to the user.
i figure im lookign at three separate modules for this typeof work flow. but i hope since this is a standard type of register, pay, email confirm operation there may be a single module i can confugure to meet my needs.
thoughts? suggestions?
Have you looked at DNM RAD by DotNet Mushroom?
http://www.dotnetmushroom.com/DNMRADGeneral/GeneralInformation/WhatisDNMRAD/tabid/2347/Default.aspx
I have not had a use for this yet, but it is a module that I have on my short list in case the need comes up. They do state that they can work with pament gateways.
Good luck.
You might have to be somewhat flexible with your work flow if you want to used 100% canned modules.
FormMaster is a pretty good form solution. You can write to existing database tables, structure SQL tables or just the default is an XML file. It doesn't go through a preview before saving though.
FormMaster Website
Searching snowcovered.com you can certainly find something that can process a payment. That one shouldn't be too difficult.
I'm thinking you may need to sling some code to get the exact experience you are looking for.

Resources