Last active
February 3, 2017 22:13
-
-
Save sahin/3b4c09cff2b090ddb5791bceaba5175d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
async function parseFind(className, identifyingValue, identifyingKey = 'id') { | |
const ParseObject = Parse.Object.extend(className); | |
const query = new Parse.Query(ParseObject); | |
query.equalTo(identifyingKey, identifyingValue); | |
const result = await query.first();; | |
return result; | |
} | |
async function parseSave(className, objectAttributes) { | |
const ParseObject = Parse.Object.extend(className); | |
const object = new ParseObject(); | |
object.set(objectAttributes); | |
await object.save(); | |
} | |
async function parseCreateOrUpdate(className, objectAttributes, identifyingKey = 'id') { | |
const identifyingValue = objectAttributes[identifyingKey]; | |
const foundObject = await parseFind(className, identifyingValue, identifyingKey); | |
console.log({ foundObject }); | |
if (foundObject) { | |
foundObject.set(objectAttributes); | |
await foundObject.save(); | |
return; | |
} | |
await parseSave(className, objectAttributes); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment