Skip to content

Instantly share code, notes, and snippets.

@marshallbrekka
Created December 10, 2014 00:59
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 marshallbrekka/01f5ee927f96ba99388e to your computer and use it in GitHub Desktop.
Save marshallbrekka/01f5ee927f96ba99388e to your computer and use it in GitHub Desktop.
Mobile App Account Model
var fakeIds = 555;
var proxyAccounts = {
active: true,
apr: 15.99,
balance: 2254.86,
lastUpdated : 1372910701811,
id: 1,
minimum: 35,
name: "JetBlue Card Orig",
number: "1000",
type: "credits",
siteId : 10
}];
var accounts = new PersistentSpec("accounts/1/accounts", {
seq : true,
proxy : {
get : function(opts, promise) {
promise.resolve({"_control" : {result : "ok"}, response : proxyAccounts});
},
add: function(opts, promise) {
var id = ++fakeIds;
opts.id = id;
proxyAccounts.push(opts);
promise.resolve({"_control": { result: "ok" }, response: id });
},
update: function(opts, promise) {
promise.resolve({"_control" : {result : "ok"}});
},
remove: function(opts, promise) {
proxyAccounts = _.filter(proxyAccounts, function(account) {
return account.id !== opts.id;
});
promise.resolve({"_control" : {result : "ok"}});
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment