mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-19 07:37:25 +01:00
Habits: store one history entry per day (#10442)
* initial refactor * add scoredUp and scoredDown values for habits history entries, one entry per habit per day * fix lint and add initial migration * update old test * remove scoreNotes * dry run for migration * migration fixes * update migration and remove old test * fix * add challenges migration (read only) * fix challenges migration * handle custom day start * update tasks in migration * scoring: support cds * add new test
This commit is contained in:
@@ -25,8 +25,6 @@ import logger from '../../libs/logger';
|
||||
import moment from 'moment';
|
||||
import apiError from '../../libs/apiError';
|
||||
|
||||
const MAX_SCORE_NOTES_LENGTH = 256;
|
||||
|
||||
function canNotEditTasks (group, user, assignedUserId) {
|
||||
let isNotGroupLeader = group.leader !== user._id;
|
||||
let isManager = Boolean(group.managers[user._id]);
|
||||
@@ -530,7 +528,6 @@ api.updateTask = {
|
||||
*
|
||||
* @apiParam (Path) {String} taskId The task _id or alias
|
||||
* @apiParam (Path) {String="up","down"} direction The direction for scoring the task
|
||||
* @apiParam (Body) {String} scoreNotes Notes explaining the scoring
|
||||
*
|
||||
* @apiExample {json} Example call:
|
||||
* curl -X "POST" https://habitica.com/api/v3/tasks/test-api-params/score/up
|
||||
@@ -556,18 +553,14 @@ api.scoreTask = {
|
||||
async handler (req, res) {
|
||||
req.checkParams('direction', res.t('directionUpDown')).notEmpty().isIn(['up', 'down']);
|
||||
|
||||
let validationErrors = req.validationErrors();
|
||||
const validationErrors = req.validationErrors();
|
||||
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;
|
||||
const user = res.locals.user;
|
||||
const {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;
|
||||
const task = await Tasks.Task.findByIdOrAlias(taskId, user._id, {userId: user._id});
|
||||
const direction = req.params.direction;
|
||||
|
||||
if (!task) throw new NotFound(res.t('taskNotFound'));
|
||||
|
||||
@@ -679,13 +672,13 @@ api.scoreTask = {
|
||||
if (task.challenge && task.challenge.id && task.challenge.taskId && !task.challenge.broken && task.type !== 'reward') {
|
||||
// Wrapping everything in a try/catch block because if an error occurs using `await` it MUST NOT bubble up because the request has already been handled
|
||||
try {
|
||||
let chalTask = await Tasks.Task.findOne({
|
||||
const chalTask = await Tasks.Task.findOne({
|
||||
_id: task.challenge.taskId,
|
||||
}).exec();
|
||||
|
||||
if (!chalTask) return;
|
||||
|
||||
await chalTask.scoreChallengeTask(delta);
|
||||
await chalTask.scoreChallengeTask(delta, direction);
|
||||
} catch (e) {
|
||||
logger.error(e);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user