Skip to content

Add character limit to sketch name on the back end #568 #1529

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions server/controllers/project.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,15 @@ export function updateProject(req, res) {
$set: req.body
},
{
new: true
new: true,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For findOneByIdAndUpdate, you have to explicitly run the mongoose validators. I hate it.

runValidators: true
}
)
.populate('user', 'username')
.exec((updateProjectErr, updatedProject) => {
if (updateProjectErr) {
console.log(updateProjectErr);
res.json({ success: false });
res.status(400).json({ success: false });
return;
}
if (req.body.files && updatedProject.files.length !== req.body.files.length) {
Expand All @@ -50,7 +51,7 @@ export function updateProject(req, res) {
updatedProject.save((innerErr, savedProject) => {
if (innerErr) {
console.log(innerErr);
res.json({ success: false });
res.status(400).json({ success: false });
return;
}
res.json(savedProject);
Expand Down
2 changes: 1 addition & 1 deletion server/controllers/project.controller/createProject.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export default function createProject(req, res) {
projectValues = Object.assign(projectValues, req.body);

function sendFailure() {
res.json({ success: false });
res.status(400).json({ success: false });
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Decided to change this to 400 over 422 because it was more general? It would be really nice to get more granular with the error codes but since this function was called to handle different errors I thought 400 would be more appropriate.

}

function populateUserData(newProject) {
Expand Down
2 changes: 1 addition & 1 deletion server/models/project.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ fileSchema.set('toJSON', {

const projectSchema = new Schema(
{
name: { type: String, default: "Hello p5.js, it's the server" },
name: { type: String, default: "Hello p5.js, it's the server", maxlength: 128 },
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The limit on the front-end is actually 128 characters!

user: { type: Schema.Types.ObjectId, ref: 'User' },
serveSecure: { type: Boolean, default: false },
files: { type: [fileSchema] },
Expand Down