Skip to content
Open
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
3 changes: 2 additions & 1 deletion config/custom-environment-variables.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{
"jwtPrivateKey": "vidly_jwtPrivateKey"
"jwtPrivateKey": "vidly_jwtPrivateKey",
"db": "vidly_db"
}
3 changes: 2 additions & 1 deletion config/test.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"jwtPrivateKey": "1234",
"db": "mongodb://localhost/vidly_tests"
"db": "mongodb://localhost/vidly_tests",
"requiresAuth": true
}
6 changes: 3 additions & 3 deletions models/customer.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@ const Customer = mongoose.model('Customer', new mongoose.Schema({
}));

function validateCustomer(customer) {
const schema = {
const schema = Joi.object({
name: Joi.string().min(5).max(50).required(),
phone: Joi.string().min(5).max(50).required(),
isGold: Joi.boolean()
};
});

return Joi.validate(customer, schema);
return schema.validate(customer);
}

exports.Customer = Customer;
Expand Down
6 changes: 3 additions & 3 deletions models/genre.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ const genreSchema = new mongoose.Schema({
const Genre = mongoose.model('Genre', genreSchema);

function validateGenre(genre) {
const schema = {
const schema = Joi.object({
name: Joi.string().min(5).max(50).required()
};
});

return Joi.validate(genre, schema);
return schema.validate(genre);
}

exports.genreSchema = genreSchema;
Expand Down
10 changes: 7 additions & 3 deletions models/movie.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,22 @@ const Movie = mongoose.model('Movies', new mongoose.Schema({
required: true,
min: 0,
max: 255
},
publishedDate: {
type: Date,
default: Date.now(),
}
}));

function validateMovie(movie) {
const schema = {
const schema = Joi.object({
title: Joi.string().min(5).max(50).required(),
genreId: Joi.objectId().required(),
numberInStock: Joi.number().min(0).required(),
dailyRentalRate: Joi.number().min(0).required()
};
});

return Joi.validate(movie, schema);
return schema.validate(movie);
}

exports.Movie = Movie;
Expand Down
6 changes: 3 additions & 3 deletions models/rental.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,12 @@ rentalSchema.methods.return = function() {
const Rental = mongoose.model('Rental', rentalSchema);

function validateRental(rental) {
const schema = {
const schema = Joi.object({
customerId: Joi.objectId().required(),
movieId: Joi.objectId().required()
};
});

return Joi.validate(rental, schema);
return schema.validate(rental);
}

exports.Rental = Rental;
Expand Down
6 changes: 3 additions & 3 deletions models/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ userSchema.methods.generateAuthToken = function() {
const User = mongoose.model("User", userSchema);

function validateUser(user) {
const schema = {
const schema = Joi.object({
name: Joi.string()
.min(2)
.max(50)
Expand All @@ -56,9 +56,9 @@ function validateUser(user) {
.min(5)
.max(255)
.required()
};
});

return Joi.validate(user, schema);
return schema.validate(user);
}

exports.User = User;
Expand Down
Loading