diff --git a/server/methods/insert/example.js b/server/methods/insert/example.js new file mode 100644 index 0000000..1bc32d0 --- /dev/null +++ b/server/methods/insert/example.js @@ -0,0 +1,20 @@ +/* +* Methods: Insert - Example +* Example of a method used for inserting into the database. +*/ + +Meteor.methods({ + exampleInsertMethod: function(argument){ + // Check the argument. Assuming an Object type here. + check(argument, Object); + + // Perform the insert. + try { + var exampleId = Example.insert(argument); + return exampleId; + } catch(exception) { + // If an error occurs, return it to the client. + return exception; + } + } +}); diff --git a/server/methods/read/example.js b/server/methods/read/example.js new file mode 100644 index 0000000..1c54af7 --- /dev/null +++ b/server/methods/read/example.js @@ -0,0 +1,22 @@ +/* +* Methods: Read - Example +* Example of a method used for reading from the database. +*/ + +Meteor.methods({ + exampleReadMethod: function(argument){ + // Check the argument. Assuming a String type here. + check(argument, String); + + // Perform the read. + var exampleItem = Example.findOne(argument); + + // If the read fails (no documents found), throw an error. + if (!exampleItem) { + throw new Meteor.Error(500, 'Error 500: Not Found', 'No documents found.'); + } + + // Return either the result or the error. + return exampleItem; + } +}); diff --git a/server/methods/remove/example.js b/server/methods/remove/example.js new file mode 100644 index 0000000..9c8058e --- /dev/null +++ b/server/methods/remove/example.js @@ -0,0 +1,20 @@ +/* +* Methods: Remove - Example +* Example of a method used for removing a document from the database. +*/ + +Meteor.methods({ + exampleRemoveMethod: function(argument){ + // Check the argument. Assuming a String type here. + check(argument, String); + + // Perform the remove. + try { + var exampleId = Example.remove(argument); + return exampleId; + } catch(exception) { + // If an error occurs, return it to the client. + return exception; + } + } +}); diff --git a/server/methods/update/example.js b/server/methods/update/example.js new file mode 100644 index 0000000..a7cacd3 --- /dev/null +++ b/server/methods/update/example.js @@ -0,0 +1,24 @@ +/* +* Methods: Update - Example +* Example of a method used for updating a document in the database. +*/ + +Meteor.methods({ + exampleUpdateMethod: function(argument){ + // Check the argument. Assuming an Object type here. + check(argument, Object); + + // Perform the update. + try { + var exampleId = Example.update(argument._id, { + $set: { + "someKey": argument.someKey + } + }); + return exampleId; + } catch(exception) { + // If an error occurs, return it to the client. + return exception; + } + } +}); diff --git a/server/methods/utility/example.js b/server/methods/utility/example.js new file mode 100644 index 0000000..c012483 --- /dev/null +++ b/server/methods/utility/example.js @@ -0,0 +1,28 @@ +/* +* Methods: Utility - Example +* Example of a method used for performing a function on the server. +*/ + +// Example third-party API stub to call. +// This should be deleted and is only here as an example. +var chipotle = { + getBurrito: function(burrito){ + return burrito; + } +} + +Meteor.methods({ + exampleUtilityMethod: function(argument){ + // Check the argument. Assuming an Object type here. + check(argument, Object); + + // Perform the function. + try { + var apiCall = chipotle.getBurrito("Barbacoa"); + return apiCall; + } catch(exception) { + // If an error occurs, return it to the client. + return exception; + } + } +});