Skip to content

Instantly share code, notes, and snippets.

@samilamti
Created March 30, 2013 18:01
Show Gist options
  • Save samilamti/5277690 to your computer and use it in GitHub Desktop.
Save samilamti/5277690 to your computer and use it in GitHub Desktop.
Inserts - or updates - a Ninja entity of the ninja table.
function insert(item, user, request) {
item.LastSeen = new Date();
item.UserId = user.userId;
item.GroupName = item.GroupName.toUpperCase();
var ninjasTable = tables.getTable("ninja");
ninjasTable.where({ UserId: user.userId }).read({
success: function(results) {
if (results.length > 0) {
var existingNinja = results[0];
existingNinja.NickName = item.NickName;
existingNinja.GroupName = item.GroupName;
existingNinja.Latitude = item.Latitude;
existingNinja.Longitude = item.Longitude;
existingNinja.LocationName = item.LocationName;
existingNinja.LastSeen = item.LastSeen;
ninjasTable.update(existingNinja);
request.respond(statusCodes.OK);
}
else
{
request.execute();
}
}
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment