mirror of
https://github.com/sudoxnym/habitica-self-host.git
synced 2026-07-31 19:20:25 +00:00
Move deprecated API back to deprecated
This commit is contained in:
parent
e86c994076
commit
4919cd22b5
2 changed files with 34 additions and 39 deletions
|
|
@ -113,42 +113,6 @@ router.get '/user/tasks', auth, (req, res) ->
|
|||
|
||||
res.json 200, tasks
|
||||
|
||||
###
|
||||
This is called form deprecated.coffee's score function, and the req.headers are setup properly to handle the login
|
||||
###
|
||||
scoreTask = (req, res, next) ->
|
||||
auth req, res, ->
|
||||
{taskId, direction} = req.params
|
||||
{title, service, icon} = req.body
|
||||
|
||||
# Send error responses for improper API call
|
||||
return res.send(500, ':taskId required') unless taskId
|
||||
return res.send(500, ":direction must be 'up' or 'down'") unless direction in ['up','down']
|
||||
|
||||
model = req.getModel()
|
||||
{user, userObj} = req
|
||||
|
||||
model.ref('_user', user)
|
||||
|
||||
# Create task if doesn't exist
|
||||
# TODO add service & icon to task
|
||||
unless model.get("_user.tasks.#{taskId}")
|
||||
model.refList "_habitList", "_user.tasks", "_user.habitIds"
|
||||
model.at('_habitList').push
|
||||
id: taskId
|
||||
type: 'habit'
|
||||
text: (title || taskId)
|
||||
value: 0
|
||||
up: true
|
||||
down: true
|
||||
notes: "This task was created by a third-party service. Feel free to edit, it won't harm the connection to that service. Additionally, multiple services may piggy-back off this task."
|
||||
|
||||
delta = scoring.score(model, taskId, direction)
|
||||
result = model.get ('_user.stats')
|
||||
result.delta = delta
|
||||
res.send(result)
|
||||
router.post '/user/tasks/:taskId/:direction', scoreTask
|
||||
|
||||
module.exports = router
|
||||
module.exports.scoreTask = scoreTask # export so deprecated can call it
|
||||
module.exports.auth = auth # export so deprecated can call it
|
||||
|
||||
|
|
|
|||
|
|
@ -15,10 +15,41 @@ router.get '/:uid/down/:score?', (req, res) -> res.send(500, deprecatedMessage)
|
|||
router.post '/users/:uid/tasks/:taskId/:direction', (req, res) -> res.send(500, deprecatedMessage)
|
||||
|
||||
# Redirect to new API
|
||||
router.post '/v1/users/:uid/tasks/:taskId/:direction', (req, res, next) ->
|
||||
initDeprecated = (req, res, next) ->
|
||||
req.headers['x-api-user'] = req.params.uid
|
||||
req.headers['x-api-key'] = req.body.apiToken
|
||||
api.scoreTask(req, res, next)
|
||||
next()
|
||||
|
||||
router.post '/v1/users/:uid/tasks/:taskId/:direction', initDeprecated, api.auth, (req, res) ->
|
||||
{taskId, direction} = req.params
|
||||
{title, service, icon} = req.body
|
||||
|
||||
# Send error responses for improper API call
|
||||
return res.send(500, ':taskId required') unless taskId
|
||||
return res.send(500, ":direction must be 'up' or 'down'") unless direction in ['up','down']
|
||||
|
||||
model = req.getModel()
|
||||
{user, userObj} = req
|
||||
|
||||
model.ref('_user', user)
|
||||
|
||||
# Create task if doesn't exist
|
||||
# TODO add service & icon to task
|
||||
unless model.get("_user.tasks.#{taskId}")
|
||||
model.refList "_habitList", "_user.tasks", "_user.habitIds"
|
||||
model.at('_habitList').push
|
||||
id: taskId
|
||||
type: 'habit'
|
||||
text: (title || taskId)
|
||||
value: 0
|
||||
up: true
|
||||
down: true
|
||||
notes: "This task was created by a third-party service. Feel free to edit, it won't harm the connection to that service. Additionally, multiple services may piggy-back off this task."
|
||||
|
||||
delta = scoring.score(model, taskId, direction)
|
||||
result = model.get ('_user.stats')
|
||||
result.delta = delta
|
||||
res.send(result)
|
||||
|
||||
router.get '/v1/users/:uid/calendar.ics', (req, res) ->
|
||||
#return next() #disable for now
|
||||
|
|
|
|||
Loading…
Reference in a new issue