[#1529] Send status codes, run validator
This commit is contained in:
parent
766a160a5f
commit
76bcf9cb09
3 changed files with 6 additions and 6 deletions
|
@ -30,14 +30,15 @@ export function updateProject(req, res) {
|
||||||
$set: req.body
|
$set: req.body
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
new: true
|
new: true,
|
||||||
|
runValidators: true
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
.populate('user', 'username')
|
.populate('user', 'username')
|
||||||
.exec((updateProjectErr, updatedProject) => {
|
.exec((updateProjectErr, updatedProject) => {
|
||||||
if (updateProjectErr) {
|
if (updateProjectErr) {
|
||||||
console.log(updateProjectErr);
|
console.log(updateProjectErr);
|
||||||
res.json({ success: false });
|
res.status(400).json({ success: false });
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (req.body.files && updatedProject.files.length !== req.body.files.length) {
|
if (req.body.files && updatedProject.files.length !== req.body.files.length) {
|
||||||
|
@ -50,7 +51,7 @@ export function updateProject(req, res) {
|
||||||
updatedProject.save((innerErr, savedProject) => {
|
updatedProject.save((innerErr, savedProject) => {
|
||||||
if (innerErr) {
|
if (innerErr) {
|
||||||
console.log(innerErr);
|
console.log(innerErr);
|
||||||
res.json({ success: false });
|
res.status(400).json({ success: false });
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
res.json(savedProject);
|
res.json(savedProject);
|
||||||
|
|
|
@ -8,9 +8,8 @@ export default function createProject(req, res) {
|
||||||
|
|
||||||
projectValues = Object.assign(projectValues, req.body);
|
projectValues = Object.assign(projectValues, req.body);
|
||||||
|
|
||||||
// TODO: Error handling to match spec
|
|
||||||
function sendFailure() {
|
function sendFailure() {
|
||||||
res.status(422).json({ success: false });
|
res.status(400).json({ success: false });
|
||||||
}
|
}
|
||||||
|
|
||||||
function populateUserData(newProject) {
|
function populateUserData(newProject) {
|
||||||
|
|
|
@ -29,7 +29,7 @@ fileSchema.set('toJSON', {
|
||||||
|
|
||||||
const projectSchema = new Schema(
|
const projectSchema = new Schema(
|
||||||
{
|
{
|
||||||
name: { type: String, default: "Hello p5.js, it's the server", maxlength: 256 },
|
name: { type: String, default: "Hello p5.js, it's the server", maxlength: 128 },
|
||||||
user: { type: Schema.Types.ObjectId, ref: 'User' },
|
user: { type: Schema.Types.ObjectId, ref: 'User' },
|
||||||
serveSecure: { type: Boolean, default: false },
|
serveSecure: { type: Boolean, default: false },
|
||||||
files: { type: [fileSchema] },
|
files: { type: [fileSchema] },
|
||||||
|
|
Loading…
Reference in a new issue