Skip to content
Browse files

added destroyFilesByUser and findCustom

  • Loading branch information...
1 parent 1874bb4 commit af07af6173133d9fb141625f634fb634f09e8ca4 @Leveton committed Jun 25, 2012
Showing with 26 additions and 7 deletions.
  1. +26 −7 lib/Parse.js
View
33 lib/Parse.js
@@ -30,17 +30,26 @@ Parse.prototype = {
parseRequest.call(this, 'GET', '/1/' + className, { where: JSON.stringify(query) }, callback);
}
},
+
+ // get objects from classes that you create
+ findCustom: function (className, query, callback) {
+ if (typeof query === 'string') {
+ parseRequest.call(this, 'GET', '/1/classes' + className + '/' + query, null, callback);
+ } else {
+ parseRequest.call(this, 'GET', '/1/classes' + className, { where: JSON.stringify(query) }, callback);
+ }
+ },
// get a user from the Parse's special User class. See https://parse.com/questions/why-does-querying-for-a-user-create-a-second-user-class
getUser: function (userName, passWord, callback) {
parseRequest.call(this, 'GET', '/1/login/?username=' + userName + '&password=' + passWord, null, callback);
},
// get an object belonging to a certain User
- getFileByUser: function(userId, callback) {
+ getFileByUser: function(userId, className, callback) {
queryString = 'where={"user":' + '"' + userId + '"' + '}'
encodedString = encodeURIComponent(queryString);
- parseRequest.call(this, 'GET', '/1/classes/contracts?' + encodedString, null, callback)
+ parseRequest.call(this, 'GET', '/1/classes/' + className + '?' + encodedString, null, callback)
},
// insert an object into Parse
@@ -49,28 +58,38 @@ Parse.prototype = {
},
// update an object in the class store
- update: function (className, objectId, object, callback) {
- parseRequest.call(this, 'PUT', '/1/classes/' + className + '/' + objectId, object, callback);
+ update: function (className, objectId, data, objectToUpdate, dataBody, callback) {
+ objectToUpdate = objectToUpdate;
+ dataBody = dataBody;
+ data = { objectToUpdate: dataBody }
+ parseRequest.call(this, 'PUT', '/1/classes/' + className + '/' + objectId, data, callback);
},
- // update a User's email address
+ // update a User object's email address
updateUserEmail: function(objectId, data, callback) {
data = { email: data }
parseRequest.call(this, 'PUT', '/1/users/' + objectId, data, callback)
},
- // update a User's username
+ // update a User object's username*
updateUserName: function(objectId, data, callback) {
data = { username: data }
parseRequest.call(this, 'PUT', '/1/users/' + objectId, data, callback)
},
- // reset a User's password
+ // reset a User object's password
passwordReset: function (data, callback) {
data = { email: data }
parseRequest.call(this, 'POST', '/1/requestPasswordReset/', data, callback)
},
+ // because deleteFile does not remove objects from db, this hack replaces the username so that it doesn't show up in collections by user-predicate
+ destroyFilesByUser: function (objectId, className, username, data, callback) {
+ userObjectIdKey = userObjectIdKey; //the key for your user's objectId
+ data = { userObjectIdKey: data }
+ parseRequest.call(this, 'PUT', '/1/classes/' + className + '/' + objectId, data, callback)
+ },
+
// delete a file. Note: file still shows up on the parse databrowser, but attempting to access it will result in a 401
deleteFile: function (fileName, callback) {
parseRequest.call(this, 'DELETE', '/1/files/' + fileName, null, callback)

0 comments on commit af07af6

Please sign in to comment.
Something went wrong with that request. Please try again.