Merge branch 'api-v3' into sabrecat/v3-payments
This commit is contained in:
@@ -72,7 +72,7 @@ api.getTag = {
|
||||
let validationErrors = req.validationErrors();
|
||||
if (validationErrors) throw validationErrors;
|
||||
|
||||
let tag = user.tags.id(req.params.tagId);
|
||||
let tag = _.find(user.tags, {id: req.params.tagId});
|
||||
if (!tag) throw new NotFound(res.t('tagNotFound'));
|
||||
res.respond(200, tag);
|
||||
},
|
||||
@@ -102,13 +102,13 @@ api.updateTag = {
|
||||
let validationErrors = req.validationErrors();
|
||||
if (validationErrors) throw validationErrors;
|
||||
|
||||
let tag = user.tags.id(tagId);
|
||||
let tag = _.find(user.tags, {id: tagId});
|
||||
if (!tag) throw new NotFound(res.t('tagNotFound'));
|
||||
|
||||
_.merge(tag, Tag.sanitize(req.body));
|
||||
|
||||
let savedUser = await user.save();
|
||||
res.respond(200, savedUser.tags.id(tagId));
|
||||
res.respond(200, _.find(savedUser.tags, {id: tagId}));
|
||||
},
|
||||
};
|
||||
|
||||
@@ -134,7 +134,7 @@ api.deleteTag = {
|
||||
let validationErrors = req.validationErrors();
|
||||
if (validationErrors) throw validationErrors;
|
||||
|
||||
let tag = user.tags.id(req.params.tagId);
|
||||
let tag = _.find(user.tags, {id: req.params.tagId});
|
||||
if (!tag) throw new NotFound(res.t('tagNotFound'));
|
||||
tag.remove();
|
||||
|
||||
@@ -143,7 +143,7 @@ api.deleteTag = {
|
||||
userId: user._id,
|
||||
}, {
|
||||
$pull: {
|
||||
tags: tag._id,
|
||||
tags: tag.id,
|
||||
},
|
||||
}, {multi: true}).exec();
|
||||
|
||||
|
||||
@@ -518,7 +518,7 @@ api.addChecklistItem = {
|
||||
|
||||
if (task.type !== 'daily' && task.type !== 'todo') throw new BadRequest(res.t('checklistOnlyDailyTodo'));
|
||||
|
||||
task.checklist.push(Tasks.Task.sanitizeChecklist(req.body)); // TODO why not allow to supply _id on creation?
|
||||
task.checklist.push(Tasks.Task.sanitizeChecklist(req.body));
|
||||
let savedTask = await task.save();
|
||||
|
||||
res.respond(200, savedTask);
|
||||
@@ -558,7 +558,7 @@ api.scoreCheckListItem = {
|
||||
if (!task) throw new NotFound(res.t('taskNotFound'));
|
||||
if (task.type !== 'daily' && task.type !== 'todo') throw new BadRequest(res.t('checklistOnlyDailyTodo'));
|
||||
|
||||
let item = _.find(task.checklist, {_id: req.params.itemId});
|
||||
let item = _.find(task.checklist, {id: req.params.itemId});
|
||||
|
||||
if (!item) throw new NotFound(res.t('checklistItemNotFound'));
|
||||
item.completed = !item.completed;
|
||||
@@ -608,7 +608,7 @@ api.updateChecklistItem = {
|
||||
}
|
||||
if (task.type !== 'daily' && task.type !== 'todo') throw new BadRequest(res.t('checklistOnlyDailyTodo'));
|
||||
|
||||
let item = _.find(task.checklist, {_id: req.params.itemId});
|
||||
let item = _.find(task.checklist, {id: req.params.itemId});
|
||||
if (!item) throw new NotFound(res.t('checklistItemNotFound'));
|
||||
|
||||
_.merge(item, Tasks.Task.sanitizeChecklist(req.body));
|
||||
@@ -659,7 +659,7 @@ api.removeChecklistItem = {
|
||||
}
|
||||
if (task.type !== 'daily' && task.type !== 'todo') throw new BadRequest(res.t('checklistOnlyDailyTodo'));
|
||||
|
||||
let hasItem = removeFromArray(task.checklist, { _id: req.params.itemId });
|
||||
let hasItem = removeFromArray(task.checklist, { id: req.params.itemId });
|
||||
if (!hasItem) throw new NotFound(res.t('checklistItemNotFound'));
|
||||
|
||||
let savedTask = await task.save();
|
||||
@@ -687,7 +687,7 @@ api.addTagToTask = {
|
||||
let user = res.locals.user;
|
||||
|
||||
req.checkParams('taskId', res.t('taskIdRequired')).notEmpty().isUUID();
|
||||
let userTags = user.tags.map(tag => tag._id);
|
||||
let userTags = user.tags.map(tag => tag.id);
|
||||
req.checkParams('tagId', res.t('tagIdRequired')).notEmpty().isUUID().isIn(userTags);
|
||||
|
||||
let validationErrors = req.validationErrors();
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import locals from '../../middlewares/api-v3/locals';
|
||||
import _ from 'lodash';
|
||||
import Remarkable from 'remarkable';
|
||||
import markdownIt from 'markdown-it';
|
||||
|
||||
const md = new Remarkable({
|
||||
const md = markdownIt({
|
||||
html: true,
|
||||
});
|
||||
|
||||
|
||||
@@ -1,9 +1,17 @@
|
||||
import mongoose from 'mongoose';
|
||||
import baseModel from '../libs/api-v3/baseModel';
|
||||
import { v4 as uuid } from 'uuid';
|
||||
import validator from 'validator';
|
||||
|
||||
let Schema = mongoose.Schema;
|
||||
|
||||
export let schema = new Schema({
|
||||
_id: false, // use id not _id
|
||||
id: {
|
||||
type: String,
|
||||
default: uuid,
|
||||
validate: [validator.isUUID, 'Invalid uuid.'],
|
||||
},
|
||||
name: {type: String, required: true},
|
||||
challenge: {type: String},
|
||||
}, {
|
||||
@@ -12,7 +20,7 @@ export let schema = new Schema({
|
||||
});
|
||||
|
||||
schema.plugin(baseModel, {
|
||||
noSet: ['_id', 'challenge'],
|
||||
noSet: ['_id', 'id', 'challenge'],
|
||||
});
|
||||
|
||||
export let model = mongoose.model('Tag', schema);
|
||||
|
||||
@@ -45,7 +45,8 @@ export let TaskSchema = new Schema({
|
||||
},
|
||||
|
||||
reminders: [{
|
||||
_id: {type: String, validate: [validator.isUUID, 'Invalid uuid.'], default: shared.uuid, required: true},
|
||||
_id: false,
|
||||
id: {type: String, validate: [validator.isUUID, 'Invalid uuid.'], default: shared.uuid, required: true},
|
||||
startDate: {type: Date, required: true},
|
||||
time: {type: Date, required: true},
|
||||
}],
|
||||
@@ -67,15 +68,15 @@ TaskSchema.plugin(baseModel, {
|
||||
timestamps: true,
|
||||
});
|
||||
|
||||
// Sanitize checklist objects (disallowing _id)
|
||||
// Sanitize checklist objects (disallowing id)
|
||||
TaskSchema.statics.sanitizeChecklist = function sanitizeChecklist (checklistObj) {
|
||||
delete checklistObj._id;
|
||||
delete checklistObj.id;
|
||||
return checklistObj;
|
||||
};
|
||||
|
||||
// Sanitize reminder objects (disallowing id)
|
||||
TaskSchema.statics.sanitizeReminder = function sanitizeReminder (reminderObj) {
|
||||
delete reminderObj.id; // TODO convert to _id?
|
||||
delete reminderObj.id;
|
||||
return reminderObj;
|
||||
};
|
||||
|
||||
@@ -159,8 +160,9 @@ let dailyTodoSchema = () => {
|
||||
collapseChecklist: {type: Boolean, default: false},
|
||||
checklist: [{
|
||||
completed: {type: Boolean, default: false},
|
||||
text: {type: String, required: true},
|
||||
_id: {type: String, default: shared.uuid, validate: [validator.isUUID, 'Invalid uuid.']},
|
||||
text: {type: String, required: false, default: ''}, // required:false because it can be empty on creation
|
||||
_id: false,
|
||||
id: {type: String, default: shared.uuid, validate: [validator.isUUID, 'Invalid uuid.']},
|
||||
}],
|
||||
};
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user