How do I get the id of a newly created resource in a Joosy.Form.attach callback? - joosy

I have the following in my joosy page:
#afterLoad ->
#form = Joosy.Form.attach #rawForm,
resource: #data.presentation
success: (data) =>
#navigate '/presentations'
But instead of navigating to /presentations, I want to navigate to the newly created presentation. How can I get the id for the newly created object? It doesn't appear to be in the data param.

The newly created id will be in the data parameter as long as it's returned in the json for the resource being created. In my case, I needed to edit the default app/views/presentations/show.json.jbuilder to add the :id field.

Related

Cannot Return null for non-nullable type: 'String' within Parent (Error while adding a new field in the Schema)

While using a Lambda function to update using the mutation in GraphQL, the data gets updated but on subscribing it the data shows up as NULL. This Issue happens only when i make a change in the schema by adding a new Field / Column. This issue does not happen when i don't make any changes in the existing schema.
Subscription error after adding new Field to an existing schema
Note: We are using amplify
when i make a change in the schema by adding a new Field / Column and I use a Lambda function to update data using the mutation in GraphQL, the data gets updated and on subscribing it the updated new data must show.
if we try adding a new field to the schema and try updating the new field using a Backend Lambda function using mutation. the new field gets updated. Now Try getting the updated data using Subscription / Query from any Frontend/ Amplify. I think there is a problem with the resolver which is sending the data as NULL.Schema where new field address added
Same issue here: after digging a bit, turns out you need to query all the fields required by the subscription in the mutation that triggers the subscription. (in your case the mutation executed from the lambda function)
Ex: assuming you have a subscription with the following form:
subscription MySubscription {
onSomethingDone {
field1
..
fieldN
}
}
Then you would need to make sure that the mutation in your lambda function queries all fields from field1 to fieldN, i.e with the form :
mutation MyMutation {
createSomething {
field1
..
fieldN
}
}
Hope this helps

api platform - Create post requests with nested resources

I'm new to symfony and the api platform and I want to develop an api with specific routes.
I'm looking to do is create a post query with nested resources to add relationships between tables.
example: I have 3 tables (users, periods, articles). I need to create a post request to add a new post with the following structure:
URL: api/:userid/:period/item
:userID = user ID
:period = Period name
name = element name
This request must create a new article in my "articles" table by adding the identifier, the name of the period and the name of the article entered as a parameter.
So my question is how do I pass multiple parameters in my path and save them in the database using the api platform?
Thanks in advance !
You can use custom routes with API platform, which allow you to create a route that correspond to a custom query => but you need to have these data before setting them in your Api platform path.
First of all, I would use the query builder to create the query you need get the data you need, then you can use your method directly in your entity (more here https://api-platform.com/docs/core/controllers/).
You can set the route you want inside of the path of the route and set the different arguments you need like this:
'path' => '/books/{id}/publication'
here id is your argument coming from your repository function.

ExtJS4 - Cross-store model deletion: Removing a model from a store by creating a model and setting it's ID

I am building a web application and I have a Grid Panel A who has Store A that uses a Model A. When the user clicks a certain entry E with an ID and clicks the delete button, what I want to happen is to get Store B then remove the entry with the same ID as the selected entry E.
Basically, what I'm trying to do is some sort of "cross-store" model deletion. The model from Store A gets selected, but the entry from Store B gets deleted.
Here's what I've done so far:
var userStore = Ext.getStore('borrowerListStore'); //this is Store B
var model = Ext.ModelManager.create({
}, 'myAppLicationName.model.borrowerList'); //this is Model B
model.set("ID", personID); //person id here is the ID of Entry E selected earlier
Ext.getBody().mask('Starting Client Delete...');
userStore.remove(model); //I remove the model from the store
//then I sync the store
userStore.sync({
success: function(batch){
Ext.getBody().unmask();
console.log('delete user details success');
},
failure: function(batch){
Ext.getBody().unmask();
console.log('delete user details failure');
}
});
However, I am stuck on the masking screen.
I also tried loading the store first as such before I remove then sync the store:
userStore.load({
callback: function() {
userStore.remove(model);
}
});
However, I still got stuck on the loading screen.
Is there any way to do a cross-store model deletion based on a model property? I know that I can get Store B then iterate through the models and then remove the one whose ID matches the ID of what the user selected. My issue with that is if I have a lot of records in my store, it would take a lot of time to search through those.
Okay I'm an idiot.
I did something like:
userStore.getProxy().extraParams = {
selectedUserID: personID
};
and I had a if-else handling part in the php if selectedUserID was passed, I'd query the database using that in my Where clause so I'd end up with 1 entry.

How to replace relationship field type object IDs with names / titles in KeystoneJS list CSV download / export?

In Keystone admin list view the handy download link exports all list items in a CSV file, however, if some of the fields are of Relationship type, the exported CSV contains Mongo ObjectIDs instead of nmeaningful strings (name, title, etc) which would be useful.
How can one force the ObjectIDs to be mapped / replaced by another field?
Keystone has an undocumented feature that allows you to create your own custom CSV export function. This feature was added back in April (see KeystoneJS Issue #278).
All you need to do is add a method to the schema called toCSV. Keystone will inject any of the following dependencies when specified as arguments to this method.
- req (current express request object)
- user (currently authenticated user)
- row (default row data, as generated without custom toCSV())
- callback (invokes async mode, must be provided last)
You could, for example, use the Mongoose Model.Populate method to replace the Object Ids of any relationship field with whatever data you want.
Assume you have a Post list with an author field of Types.Relationship to another list (let's say User) which has a name field. You could replace the author Object Id with the author's name (from the User list) by doing the following.
Post.schema.methods.toCSV = function(callback) {
var post = this,
rtn = this.toJSON();
this.populate('author', function() {
rtn.author = post.author.name; // <-- author now has data from User list
callback(null, rtn);
});
};
.toCSV() will be called for every document returned with the Model as the context. When used asynchronously (as above) you should return a JSON representation of the new CSV data by passing it as the second argument of the callback. When using it synchronously simply return the updated JSON object.

Overload of actions in the controller

Is it possible to do an overload of the actions in the controller? I haven't found any info about it and when I tried, I got this error:
The current request for action 'Create' on controller type 'InterviewController' is >ambiguous between the following action methods:
System.Web.Mvc.ViewResult Create() on type >MvcApplication4.MvcApplication4.InterviewController
System.Web.Mvc.ViewResult Create(Int32) on type >MvcApplication4.MvcApplication4.InterviewController
I've tried to do this on another way and I also get a new error that I can't fix. In fact, I created a new action (called create_client instead of create)
I need 2 ways of creating an "opportunite".
I just call the action, and I receive an empty formular in which I just have to insert data.
From a client's page, I must create an "opportunite" with the client that's already completed when the form is displayed to the user. (there is a need of productivity, the user must perform actions as fast as possible).
In the table "opportunite", I've got a column called "FK_opp_client", which is equal to the column "idClient" from the client's table.
I don't get how I can do the second way.
I've created a new action in the controller.
'
' GET: /Opportunite/Create_client
Function Create_client(idclient) As ViewResult
'Dim FK_Client = (From e In db.client
'Where(e.idClient = idclient)
' Select e.nomCompteClient).ToString()
'ViewBag.FK_client = New SelectList(db.client, "idClient", "nomCompteClient", idclient)
Dim opportunite As opportunite = db.opportunite.Single(Function(o) o.idOpportunite = 5)
opportunite.FK_Client = idclient
ViewBag.FK_Client = New SelectList(db.client, "idClient", "nomCompteClient", opportunite.FK_Client)
Return View(opportunite)
End Function
I've tried a few things to get what I wanted, the last one was to copy what was done in the "Edit" action, but for an empty rank. (so I created an empty rank in my DB). I don't think it was a good idea (imagine someone wants to update the DB where idOpportunite = 5...)
Any better ideas?
If you want to keep those two methods under the same name, you will have to implement an ActionSelectionAttribute to decorate them, or use them with different verbs (for example POST and PUT). Please read more details on action method selection process here (old but still true).
Different approach might be making your parameter optional and make action to check if it has been passed or not (through nullable type).