Tasks score notes (#8507)

* Added setting and modal for score notes

* Added persistent score notes

* Fixed linting issues and documented new field

* Added max length to task score notes

* Added check for score notes existence

* Combined tasks perferences
This commit is contained in:
Keith Holliday
2017-02-27 14:56:34 -07:00
committed by GitHub
parent 68a042cdb9
commit 93befcebcc
12 changed files with 102 additions and 9 deletions

View File

@@ -23,6 +23,8 @@ import Bluebird from 'bluebird';
import _ from 'lodash';
import logger from '../../libs/logger';
const MAX_SCORE_NOTES_LENGTH = 256;
/**
* @apiDefine TaskNotFound
* @apiError (404) {NotFound} TaskNotFound The specified task could not be found.
@@ -482,6 +484,7 @@ api.updateTask = {
*
* @apiParam {String} taskId The task _id or alias
* @apiParam {String="up","down"} direction The direction for scoring the task
* @apiParam {String} scoreNotes Notes explaining the scoring
*
* @apiExample {json} Example call:
* curl -X "POST" https://habitica.com/api/v3/tasks/test-api-params/score/up
@@ -509,11 +512,15 @@ api.scoreTask = {
if (validationErrors) throw validationErrors;
let user = res.locals.user;
let scoreNotes = req.body.scoreNotes;
if (scoreNotes && scoreNotes.length > MAX_SCORE_NOTES_LENGTH) throw new NotAuthorized(res.t('taskScoreNotesTooLong'));
let {taskId} = req.params;
let task = await Tasks.Task.findByIdOrAlias(taskId, user._id, {userId: user._id});
let direction = req.params.direction;
if (scoreNotes) task.scoreNotes = scoreNotes;
if (!task) throw new NotFound(res.t('taskNotFound'));
if (task.group.approval.required && !task.group.approval.approved) {