This is a migrated thread and some comments may be shown as answers.

Can you use Cloud Code to validate data using queries?

3 Answers 45 Views
General Discussion
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Brad
Top achievements
Rank 1
Brad asked on 24 Sep 2013, 08:20 PM
The built in cloud code seems to validate some format and range type scenarios but is there a way to query the database to see if a value already exists or if you need to retrieve a value from another content type?  Can you check for something like an existing username or email address?  If you need to check a value from another Content type to you have to use External HTTP requests?

Something like the following uses the built in validation but  I would like to add the ability to query the database to check for existing values.

Everlive.Events.beforeCreate(function(request, context, done) {
    var email = request.data.Email;
    var isValid = email && Everlive.Validation.validateEmail(email);
     
    if (!isValid) {
        Everlive.Response.setErrorResult('The "Email" field must be a valid email address.', 131, 500);
    }
     
    done();
});

Thanks,
Brad

3 Answers, 1 is accepted

Sort by
0
Lyubomir Dokov
Telerik team
answered on 25 Sep 2013, 12:10 PM
Hello Brad,

For now you have to use external HTTP calls to get data from another content type. In the future we plan to introduce the JavaScript SDK in the cloud code, so it will be much easier to work with data.

Here is an example of how to construct the URL for the external HTTP request, so that it is not hard-coded:
var parameters = Everlive.Parameters;
var apiKey = parameters.apiKey;
var masterKey = parameters.masterKey;
var baseUrl = parameters.apiBaseUrl;
var apiVersion = parameters.apiVersion;
var url = baseUrl + "/v" + apiVersion + "/" + apiKey + "/" + "MyContentType";



Regards,
Lyubomir Dokov
Telerik

Big news for mobile app and .NET developers! Hear about it at our Release Keynote. Thursday, September 26th, 11AM EDT
Do you enjoy Icenium? Vote for it in Windows IT Pro Community Choice Awards as Best Cloud Computing Product or Service (Category 5).
Looking for tips & tricks directly from the Icenium team? Check out our blog!
Share feedback and vote for features on our Feedback Portal.
0
Brad
Top achievements
Rank 1
answered on 25 Sep 2013, 12:32 PM
Thanks for the cross content type example!

If you are working within the same content type like Users, is there a more integrated way of querying data like checking for an existing username without having to resort to External HTTP requests?

Thanks,
Brad
0
Accepted
Lyubomir Dokov
Telerik team
answered on 27 Sep 2013, 04:37 PM
Hi Brad,

No, currently there is no way to do that without external calls.


Regards,
Lyubomir Dokov
Telerik

Do you enjoy Icenium? Vote for it in Windows IT Pro Community Choice Awards as Best Cloud Computing Product or Service (Category 5).
Looking for tips & tricks directly from the Icenium team? Check out our blog!
Share feedback and vote for features on our Feedback Portal.
Tags
General Discussion
Asked by
Brad
Top achievements
Rank 1
Answers by
Lyubomir Dokov
Telerik team
Brad
Top achievements
Rank 1
Share this question
or