mirror of
https://github.com/sudoxnym/habitica-self-host.git
synced 2026-07-17 03:22:14 +00:00
Merge branch 'develop' of github.com:lefnire/habitrpg into develop
This commit is contained in:
commit
795aac8fcb
2 changed files with 36 additions and 2 deletions
|
|
@ -60,7 +60,7 @@ validateTask = (req, res, next) ->
|
|||
newTask = { type, text, notes, value, up, down, completed } = req.body
|
||||
|
||||
# If we're updating, get the task from the user
|
||||
if req.method is 'PUT'
|
||||
if req.method is 'PUT' or req.method is 'DELETE'
|
||||
task = req.userObj?.tasks[req.params.id]
|
||||
return res.json 400, err: "No task found." if !task || _.isEmpty(task)
|
||||
# Strip for now
|
||||
|
|
@ -90,6 +90,15 @@ router.put '/user/task/:id', auth, validateTask, (req, res) ->
|
|||
|
||||
res.json 200, req.task
|
||||
|
||||
router.delete '/user/task/:id', auth, validateTask, (req, res) ->
|
||||
taskIds = req.user.get "#{req.task.type}Ids"
|
||||
|
||||
req.user.del "tasks.#{req.task.id}"
|
||||
# Remove one id from array of typeIds
|
||||
req.user.remove "#{req.task.type}Ids", taskIds.indexOf(req.task.id), 1
|
||||
|
||||
res.send 204
|
||||
|
||||
router.post '/user/task', auth, validateTask, (req, res) ->
|
||||
task = req.task
|
||||
type = task.type
|
||||
|
|
@ -156,4 +165,3 @@ router.post '/user/tasks/:taskId/:direction', auth, scoreTask
|
|||
module.exports = router
|
||||
module.exports.auth = auth
|
||||
module.exports.scoreTask = scoreTask # export so deprecated can call it
|
||||
|
||||
|
|
|
|||
|
|
@ -245,3 +245,29 @@ describe 'API', ->
|
|||
# Ensure that the two sets are equal
|
||||
expect(_.difference(_.pluck(res.body,'id'), _.pluck(tasks,'id')).length).to.equal 0
|
||||
done()
|
||||
|
||||
it 'DELETE /api/v1/user/task/:id', (done) ->
|
||||
tid = currentUser.habitIds[2]
|
||||
request.del("#{baseURL}/user/task/#{tid}")
|
||||
.set('Accept', 'application/json')
|
||||
.set('X-API-User', currentUser.id)
|
||||
.set('X-API-Key', currentUser.apiToken)
|
||||
.end (res) ->
|
||||
expect(res.body.err).to.be undefined
|
||||
expect(res.statusCode).to.be 204
|
||||
query = model.query('users').withIdAndToken(currentUser.id, currentUser.apiToken)
|
||||
query.fetch (err, user) ->
|
||||
expect(user.get('habitIds').indexOf(tid)).to.be -1
|
||||
expect(user.get("tasks.#{tid}")).to.be undefined
|
||||
done()
|
||||
|
||||
it 'DELETE /api/v1/user/task/:id (no task found)', (done) ->
|
||||
tid = "adsfasdfjunkshouldntbeatask"
|
||||
request.del("#{baseURL}/user/task/#{tid}")
|
||||
.set('Accept', 'application/json')
|
||||
.set('X-API-User', currentUser.id)
|
||||
.set('X-API-Key', currentUser.apiToken)
|
||||
.end (res) ->
|
||||
expect(res.statusCode).to.be 400
|
||||
expect(res.body.err).to.be 'No task found.'
|
||||
done()
|
||||
|
|
|
|||
Loading…
Reference in a new issue