Last active
August 29, 2015 14:08
-
-
Save benbahrenburg/154c9e16180bd04b9a2f to your computer and use it in GitHub Desktop.
NoteEvents - Update Script
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
function update(item, user, request) { | |
var table = tables.getTable('noteEvents'); | |
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.insert(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