rewrite & api: add reroll api route POST /api/v1/user/reroll. pretty bad
interface on client for now since I can't get the UI to update, have to refresh. will revisit. routes/api.coffee => routes/api.js
This commit is contained in:
@@ -21,8 +21,8 @@ api = module.exports
|
||||
------------------------------------------------------------------------
|
||||
####
|
||||
|
||||
NO_TOKEN_OR_UID = err: "You must include a token and uid (user id) in your request"
|
||||
NO_USER_FOUND = err: "No user found."
|
||||
NO_TOKEN_OR_UID = {err: "You must include a token and uid (user id) in your request"}
|
||||
NO_USER_FOUND = {err: "No user found."}
|
||||
|
||||
###
|
||||
beforeEach auth interceptor
|
||||
@@ -379,6 +379,19 @@ api.revive = (req, res, next) ->
|
||||
return res.json(500,{err}) if err
|
||||
res.json 200, saved
|
||||
|
||||
api.reroll = (req, res, next) ->
|
||||
{user} = res.locals
|
||||
if user.balance < 1
|
||||
return res.json 401, {err: "Not enough tokens."}
|
||||
user.balance -= 1
|
||||
_.each user.tasks, (task) ->
|
||||
user.tasks[task.id].value = 0 unless task.type is 'reward'
|
||||
true
|
||||
user.stats.hp = 50
|
||||
user.save (err, saved) ->
|
||||
return res.json(500, {err}) if err
|
||||
res.json 200, saved
|
||||
|
||||
###
|
||||
------------------------------------------------------------------------
|
||||
Party
|
||||
@@ -460,6 +473,8 @@ api.batchUpdate = (req, res, next) ->
|
||||
api.revive(req, res)
|
||||
when "clear-completed"
|
||||
api.clearCompleted(req, res)
|
||||
when "reroll"
|
||||
api.reroll(req, res)
|
||||
else cb()
|
||||
|
||||
# Setup the array of functions we're going to call in parallel with async
|
||||
|
||||
@@ -30,17 +30,6 @@ module.exports.app = (appExports, model) ->
|
||||
panelLabel: "Checkout"
|
||||
token: token
|
||||
|
||||
###
|
||||
Buy Reroll Button
|
||||
###
|
||||
appExports.buyReroll = ->
|
||||
misc.batchTxn model, (uObj, paths, batch) ->
|
||||
uObj.balance -= 1; paths['balance'] =1
|
||||
_.each uObj.tasks, (task) ->
|
||||
batch.set("tasks.#{task.id}.value", 0) unless task.type is 'reward'
|
||||
true
|
||||
$('#reroll-modal').modal('hide')
|
||||
|
||||
module.exports.routes = (expressApp) ->
|
||||
###
|
||||
Setup Stripe response when posting payment
|
||||
|
||||
Reference in New Issue
Block a user