Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
["doSign Up"] () {
console.log(this.state)
publicClient.query(
q.Create(q.Class("users"), {
credentials : {
password : this.state.password
},
// permissions : {
// read : q.Select("ref", q.Get(q.Ref("classes/users/self")))
// }
data : {
login : this.state.login
}
})).then(() => publicClient.query(
q.Login(q.Match(q.Index("users_by_login"), this.state.login), {
password : this.state.password
}))).then((key) => {
saveTokens(key.secret);
this.authorized(true);
});
q.Do(
q.Update(q.Select("ref", q.Var("item")), {
data : {
for_sale : false
}
}),
"item removed from sale"
),
// Check the credit balance of the purchasing player to ensure
// they have available funds.
q.If(q.LT(q.Var("buyerBalance"), q.Var("itemPrice")),
"purchase failed: insufficient funds",
// All clear! Preconditions passed.
q.Do(
// Write a purchase record.
q.Create(q.Class("purchases"), {
data : {
item : q.Select("ref", q.Var("item")),
price : q.Var("itemPrice"),
buyer : q.Select("ref", q.Var("buyer")),
seller : q.Select("ref", q.Var("seller"))
}
}),
// Update the balances of the selling player and the purchasing player.
q.Update(q.Select("ref", q.Var("buyer")), {
data : {
credits : q.Subtract(q.Var("buyerBalance"), q.Var("itemPrice"))
}
}),
q.Update(q.Select("ref", q.Var("seller")), {
data : {
credits : q.Add(q.Select(["data", "credits"], q.Var("seller")), q.Var("itemPrice"))