Merge pull request #1280 from jeremyjackson89/master
Single object queries to use include and keys
This commit is contained in:
@@ -2393,4 +2393,44 @@ describe('Parse.Query testing', () => {
|
|||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('include for specific object', function(done){
|
||||||
|
var child = new Parse.Object('Child');
|
||||||
|
var parent = new Parse.Object('Parent');
|
||||||
|
child.set('foo', 'bar');
|
||||||
|
parent.set('child', child);
|
||||||
|
Parse.Object.saveAll([child, parent], function(response){
|
||||||
|
var savedParent = response[1];
|
||||||
|
var parentQuery = new Parse.Query('Parent');
|
||||||
|
parentQuery.include('child');
|
||||||
|
parentQuery.get(savedParent.id, {
|
||||||
|
success: function(parentObj) {
|
||||||
|
var childPointer = parentObj.get('child');
|
||||||
|
ok(childPointer);
|
||||||
|
equal(childPointer.get('foo'), 'bar');
|
||||||
|
done();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('select keys for specific object', function(done){
|
||||||
|
var Foobar = new Parse.Object('Foobar');
|
||||||
|
Foobar.set('foo', 'bar');
|
||||||
|
Foobar.set('fizz', 'buzz');
|
||||||
|
Foobar.save({
|
||||||
|
success: function(savedFoobar){
|
||||||
|
var foobarQuery = new Parse.Query('Foobar');
|
||||||
|
foobarQuery.select('fizz');
|
||||||
|
foobarQuery.get(savedFoobar.id,{
|
||||||
|
success: function(foobarObj){
|
||||||
|
equal(foobarObj.get('fizz'), 'buzz');
|
||||||
|
equal(foobarObj.get('foo'), undefined);
|
||||||
|
done();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
})
|
||||||
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -4,6 +4,8 @@ import rest from '../rest';
|
|||||||
|
|
||||||
import url from 'url';
|
import url from 'url';
|
||||||
|
|
||||||
|
const ALLOWED_GET_QUERY_KEYS = ['keys', 'include'];
|
||||||
|
|
||||||
export class ClassesRouter extends PromiseRouter {
|
export class ClassesRouter extends PromiseRouter {
|
||||||
|
|
||||||
handleFind(req) {
|
handleFind(req) {
|
||||||
@@ -59,7 +61,23 @@ export class ClassesRouter extends PromiseRouter {
|
|||||||
|
|
||||||
// Returns a promise for a {response} object.
|
// Returns a promise for a {response} object.
|
||||||
handleGet(req) {
|
handleGet(req) {
|
||||||
return rest.find(req.config, req.auth, req.params.className, {objectId: req.params.objectId})
|
let body = Object.assign(req.body, ClassesRouter.JSONFromQuery(req.query));
|
||||||
|
let options = {};
|
||||||
|
|
||||||
|
for (let key of Object.keys(body)) {
|
||||||
|
if (ALLOWED_GET_QUERY_KEYS.indexOf(key) === -1) {
|
||||||
|
throw new Parse.Error(Parse.Error.INVALID_QUERY, 'Improper encode of parameter');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (typeof body.keys == 'string') {
|
||||||
|
options.keys = body.keys;
|
||||||
|
}
|
||||||
|
if (body.include) {
|
||||||
|
options.include = String(body.include);
|
||||||
|
}
|
||||||
|
|
||||||
|
return rest.find(req.config, req.auth, req.params.className, {objectId: req.params.objectId}, options)
|
||||||
.then((response) => {
|
.then((response) => {
|
||||||
if (!response.results || response.results.length == 0) {
|
if (!response.results || response.results.length == 0) {
|
||||||
throw new Parse.Error(Parse.Error.OBJECT_NOT_FOUND, 'Object not found.');
|
throw new Parse.Error(Parse.Error.OBJECT_NOT_FOUND, 'Object not found.');
|
||||||
|
|||||||
Reference in New Issue
Block a user