This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const validate = require('../BaseRequest'); | |
module.exports = (request, response, next) => { | |
return validate(request, response, next, { | |
'name': 'required|string|max:255', | |
'email': 'required|string|max:255' | |
}); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const _ = require('lodash'); | |
const Validator = require('validatorjs'); | |
module.exports = (request, response, next, rules) => { | |
const validation = new Validator(request.body, rules); | |
if (validation.fails()) { | |
const errors = {}; | |
_.each(validation.errors.errors, (error, key) => { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const ProfileRequest = require('./app/Requests/ProfileRequest'); | |
app.post("/profile/:id", ProfileRequest, (request, response) => { | |
const user = await User.findById(request.params.id); | |
if (!user) return response.status(404).send({ message: "User not found" }); | |
user.name = request.body.name; | |
user.email = request.body.email; | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const _ = require('lodash'); | |
const Validator = require('validatorjs'); | |
module.exports = (request, response, next) => { | |
const validation = new Validator(request.body, { | |
'name': 'required|string|min:3|max:255', | |
'email': 'required|string|max:255' | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const items = [ | |
{name: "Item 1", price: 20, in_stock: true}, | |
{name: "Item 2", price: 40, in_stock: true}, | |
{name: "Item 3", price: 40, in_stock: false}, | |
]; | |
const inStockItems = items => items.filter(item => item.in_stock); | |
const total = items => { | |
let total = 0; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const items = [ | |
{name: "Item 1", price: 20, in_stock: true}, | |
{name: "Item 2", price: 40, in_stock: true}, | |
{name: "Item 3", price: 40, in_stock: false}, | |
]; | |
function inStockItems(items) { | |
const inStockItems = []; | |
for (let i = 0; i < items.length; i++) { | |
if (items[i].in_stock) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const items = [ | |
{name: "Item 1", price: 20, in_stock: true}, | |
{name: "Item 2", price: 40, in_stock: true}, | |
{name: "Item 3", price: 40, in_stock: false}, | |
]; | |
const inStockItems = []; | |
for (let i = 0; i < items.length; i++) { | |
if (items[i].in_stock) | |
inStockItems.push(items[i]); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const minAge = 18; | |
const eligibility = minAge => age => age >= minAge; | |
const check = eligibility(minAge); | |
check(20) // returns true; | |
check(16) // returns false; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const minAge = 18; | |
function eligibility(age, minAge) { | |
return age >= minAge; | |
} | |
eligibility(18, minAge); // true | |
eligibility(16, minAge); // false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const minAge = 18; | |
function eligibility(age) { | |
return age >= minAge; | |
} | |
eligibility(18); // true | |
eligibility(16); // false | |
eligibility(18); // true |