Jump to content

appery.io database query "where" values match


Recommended Posts

hello there!!i m building an app for the elections..in this app i ve build a rest service that takes data(votes,etc) from a .js file of another website,and presents them to some fields.the problem is that.on that js file,the creators provide only "party_id" and not "party_name" which is contained in another .js file.i copied the id's and the names to my database.and now i want that:when the first js file gives the "Party_id",to search the database and provide me the "party_name"..what i want to do is to compare the values given from the rest service and the database collection and to return the correct name.

i tried this code:

 

var objectId = value;

//Debug information that you can see in browser console.console.log("objectId = " + objectId);var whereObject = {"kwdikos": objectId};return JSON.stringify(whereObject);

 

as shown here,it returns all the database array!!

http://imageshack.com/a/img673/9877/EkpHcb.png but as it seems,it returns it without comparing..i mean,i want it when the id sent is 2,to return ND,and when id_sent is 1,to return PASOK.it just displays all the database array without criteria match!i tried to do it by using IF statement,but it didnt let me do it!!

the correct results should be these:http://imagizer.imageshack.us/a/img537/7291/d2mTx9.png

 

thanks for your time guys!!!

Link to post
Share on other sites

You didn't show enough code to suggest what the problem might be, you need to at least show the actual code that is getting the results.This is just a personal project or something, right? This isn't for an actual election?

Link to post
Share on other sites

its my personal project for the actual elections..its not an official one of course!i m trying to make it for me,and if it works correctly to share it with family and friends!i m building it using appery.io platform. i m including screenshots of all states of the app so maybe you could figure out the problem!

please please take a look!! i ve made a storage and a model as here: http://imageshack.com/a/img910/3508/WcqssY.jpg and http://imageshack.com/a/img912/6391/RdQ0QZ.jpg then i created 3 services.first,a rest which takes data from the .js file,stores everything on local storage. secondly i created a rest service which takes data from the local storage and queries the database. http://imageshack.com/a/img911/4687/jq0eYa.jpg (before send mapping) the data are displayed like this. http://imageshack.com/a/img905/9840/iiSCct.png and the query is displayed like this:(red color for the right response) http://imagizer.imageshack.us/a/img537/7291/d2mTx9.png

as shown here:https://imageshack.com/i/exUJgy7Pjthanks so so much for your time!! i wish you can help me!

Link to post
Share on other sites

I'm not familiar with appery.io, I've never used it. Considering that, it's hard for me to guess what the problem might be without seeing some of the other code that it's running. For example, if it's returning incorrect results then I would want to see the code that gets those results to work backwards and figure out the reason.

Link to post
Share on other sites

there is an option to save the whole app as an eclipse project!can i send you this??i think that i have some ideas about where the problem might be!

 

here is the eclipse project..

 

on ekloges+2014 (5).zipekloges_2014assetswwwa_athinas.jsi think that in line 97 it starts the restful service mapping..

from_name": "restservice1",            "from_type": "SERVICE_RESPONSE",            "to_name": "A_Athinas",            "to_type": "UI",            "mappings": [            {                "source": "$['body']['party'][i]",                "target": "$['mobilegrid_95']"            },            {                "source": "$['body']['party'][i]['PARTY_ID']",                "target": "$['mobilegrid_95']['mobilelabel_126:text']"

so i think that problem begins on line 130.

 Apperyio.mappings["A_Athinas_restservice1_onbeforesend_mapping_0"] = {        "homeScreen": "A_Athinas",        "directions": []    };    Apperyio.mappings["A_Athinas_restservice2_onsuccess_mapping_0"] = {        "homeScreen": "A_Athinas",        "directions": [        {            "from_name": "restservice2",            "from_type": "SERVICE_RESPONSE",            "to_name": "A_Athinas",            "to_type": "UI",            "mappings": [            {                "source": "$['body'][i]",                "target": "$['mobilegrid_172']"            },            {                "source": "$['body'][i]['onoma']",                "target": "$['mobilegrid_172']['mobilelabel_177:text']"            },            {                "source": "$['body'][i]['kwdikos']",                "target": "$['mobilegrid_172']['mobilelabel_178:text']"            }

i think that it should create the criteria there..but it doesnt..

 

if you have some time,take a look..thank you so so so much for the help and your time!!i m really greatefull!!

Edited by karavidas
Link to post
Share on other sites

really thanks for your time even if you arent going to be able to help me more!!thanks a lot for trying to help!i have to dig more i think!one last thing!the guys there told me to :

  1. create a generic rest service.
  2. In this generic service implementation: 2.1. Get first level object. 2.2. Get needed information from first level object. 2.3. Query DB with filter by info from 2.2.(use for this goal query/list service). 2.4. Receive result from 2.3. And put it into result object.(your result object should have all needed information). 2.5. Populate service response settings with correct response parameters. 2.6. Return this object like service response.

so if you know any tutorial that will lead me to get the objects and needed info from custom javascript code,please,please let me know!!again,thank you so much!!

Edited by karavidas
Link to post
Share on other sites

If you have something like 2 arrays of objects, and you want to find the objects that exist in both arrays, that's called an intersection. You should be able to find several algorithms for finding the intersection between 2 arrays, although you'll need to tweak them a little bit if you're looking for an object property (like ID) instead of just comparing the values.

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...