forked from parse-community/parse-server-example
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinventory.js
More file actions
63 lines (52 loc) · 2 KB
/
Copy pathinventory.js
File metadata and controls
63 lines (52 loc) · 2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
var Parse = require('parse/node');
Parse.initialize("Sup3rS0da");
Parse.serverURL = 'http://supernatural-sodas-parse.herokuapp.com/parse';
Parse.masterKey = 'frfnieurnfddc4rf34fe';
Parse.databaseUri = 'mongodb://heroku_wlwgjx3v:p1kehucb5fepar9dd1var490lu@ds113650.mlab.com:13650/heroku_wlwgjx3v';
////////////// SODAS //////////////////////
//Creates the class of sodas
var SupernaturalSoda = Parse.Object.extend("SupernaturalSoda");
// Creates the new soda
function SodaFactory(attributes) {
var supernaturalSoda = new SupernaturalSoda();
for (attribute in attributes) {
supernaturalSoda.set(attribute, attributes[attribute]);
}
// Sets attributes of the new soda
supernaturalSoda.save(null, {
success: function(supernaturalSoda) {
// Execute any logic that should take place after the object is saved.
console.log(supernaturalSoda);
},
error: function(supernaturalSoda, error) {
// Execute any logic that should take place if the save fails.
// error is a Parse.Error with an error code and message.
console.log('Failed to create new object, with error code: ' + error.message);
}
});
}
// Example of a new flavour
var newFlavour = {sodaName: "Banana", sodaQuantity: 16}
var newSoda = SodaFactory(newFlavour)
//////////// GET IT BACK //////////
// function SodaInventory()
// var SupernaturalSoda = Parse.Object.extend("SupernaturalSoda");
// var query = new Parse.Query(SupernaturalSoda);
// query.get("3zfG4OOtMG", {
// success: function(supernaturalSoda) {
// // The object was retrieved successfully
// console.log(supernaturalSoda.get("sodaQuantity"))
// },
// error: function(object, error) {
// // The object was not retrieved succesffully
// console.log("Error: " + error.code + " " + error.message);
// }
// });
// Parse.Object.fetchAll([object1, object2, ...], {
// success: function(list) {
// // All the objects were fetched.
// },
// error: function(error) {
// // An error occurred while fetching one of the objects.
// },
// });