Skip to content

Instantly share code, notes, and snippets.

@benbahrenburg
Last active August 29, 2015 14:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save benbahrenburg/c34911f0a14315f881ea to your computer and use it in GitHub Desktop.
Save benbahrenburg/c34911f0a14315f881ea to your computer and use it in GitHub Desktop.
Note Table - Insert Script
function insert(item, user, request) {
var table = tables.getTable('notes');
table.where({
id: item.id,
userId : user.userId
}).read({
success: upsertItem
});
function upsertItem(items) {
item.userId = user.userId;
if (items.length === 0) {
request.execute();
} else {
table.update(item, {
success: function(e) {
request.respond(statusCodes.OK, e)
}
});
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment