R2R
Posts: 0
Joined: Wed May 07, 2014 7:24 pm

Updating slider (UI element) value in database collection

Hello. I've been able to successfully create a createService, which creates entries (rows) in the "User Feedback" database collection for each page of content in my app (identified by a variable) that is rated on a scale of 1-4 using a slider UI element and a "Submit" button. What I'd like to do is to update the rating (ratingValue column) if the same user rates the same page of content, instead of creating an additional entry (row). I've provided some screenshots of services, mappings, and the database collection. I'm having trouble with the updateService as it is not working. I believe my readService and createService are correct. I've worked on this all day and am not making any progress. I hope someone can help. Thank you.

database collection:

Image

readService:

Image Image Image Image Image

updateService:

Image Image Image Image Image

Events:

Image

Yurii Orishchuk
Posts: 0
Joined: Fri Feb 14, 2014 8:20 am

Updating slider (UI element) value in database collection

Hello.

It seem all ok with your services.

But on your screen "update service test" screen you have an error:

http://prntscr.com/3hgw6c/direct

And a problem in the response is - invalid type for type "object".

As we can see on this screen shot https://d2r1vs3d9006ap.cloudfront.net...

you have only field "acl" with "object" type. But this field in test tab is hiden by scroll. Please show us this field in test mode.

Also please provide us your app public link.

Thanks.

R2R
Posts: 0
Joined: Wed May 07, 2014 7:24 pm

Updating slider (UI element) value in database collection

Hello Yurii. Here's the public link to my app:

http://appery.io/app/view/275b7f4f-d2...

...and the updated screenshot you requested:

Image

Yurii Orishchuk
Posts: 0
Joined: Fri Feb 14, 2014 8:20 am

Updating slider (UI element) value in database collection

Hello.

As i can see you have empty value in "acl" field.

But you should have an object value like empty object = "{}".

So please add to your "acl" field "{}" value.

http://prntscr.com/3iff59/direct

Regards.

R2R
Posts: 0
Joined: Wed May 07, 2014 7:24 pm

Updating slider (UI element) value in database collection

Hi Yurii. I've added to the Request an entry called "acl" as an "Object" with a value of "{}". The test is now successful, but the database still does not update the fields.
First, are my actions on the Submit button correct? That is, I invoke a readService on the button, and if the readService is successful the updateService is invoked; otherwise, the createService is invoked. I also added a simple alert JS to let me know if the readService is a success or failure, and every time I click on the Submit button, the readService shows that it is a failure. Here are the screenshots:

readService failed:

Image

service events:

Image

db not updating:

Image

It seems the service event "createService" works if readService fails because notice that I have multiple entries for the same currentUserID and the same contentID. What I want is for the updateService to replace the ratingValue and comments for the same currentUserID and the same contentID.

The question is, does the readService need to store the object it read in a variable? What happens when a readService is invoked - where is the read information stored and then used in the updateService?

R2R
Posts: 0
Joined: Wed May 07, 2014 7:24 pm

Updating slider (UI element) value in database collection

By the way, it doesn't look like I need a readService, but instead a queryService would be useful to find the objects I need to update if they exist in the DB. However, how do I map multiple variables to a the "where" field? I can only map one or the other and yet I need the "where" field for the request to contain "currentUserID" AND "contentID".

Kateryna Grynko
Posts: 0
Joined: Thu Nov 15, 2012 9:13 am

Updating slider (UI element) value in database collection

Hi,

You can't update data using parameter 'where'. Database records can be updated only one by one. Please post a screenshot of server response from Network tab, when it returns an error.

R2R
Posts: 0
Joined: Wed May 07, 2014 7:24 pm

Updating slider (UI element) value in database collection

Hi Katya - thank you for your response. Please be patient with me, but I'm not sure where the Network tab is. Is this somewhere within the appery.io environment or outside? Is this a function of my browser?

R2R
Posts: 0
Joined: Wed May 07, 2014 7:24 pm

Updating slider (UI element) value in database collection

By the way, Katya, you provided this sample code:

if(localSrorage.getItem("myValue")){
update.execute();
} else{
create.execute();
}

Does this JS go with the button (e.g. btnSubmit), or is this JS for the readService?

R2R
Posts: 0
Joined: Wed May 07, 2014 7:24 pm

Updating slider (UI element) value in database collection

I only have one service check now in the Events section in the Data tab.

readService - Complete - Run JS

...and I added the code you provided and changed to the following:

if(localStorage.getItem("_id")
{
updateService.execute();
}
else
{
createService();
}

Still no luck...

Should I still add additional service checks in the Events tab, in addition to the JS I have above, as I did before? For example:

readService - Success - Invoke service - updateService
readService - Errror - Invoke service - createService

Return to “Issues”