Permalink
Browse files

update ch7 text to new ES.Next and versions

  • Loading branch information...
azat-co committed Nov 12, 2017
1 parent 669abbf commit 35840c173da8322c1fefc036b7008f30b5bf1c9c
@@ -5,5 +5,6 @@
"mongoskin",
"truthy",
"truthyness"
]
],
"cSpell.language": "en,en-US"
}

Large diffs are not rendered by default.

Oops, something went wrong.
@@ -1,5 +1,5 @@
var TWITTER_CONSUMER_KEY = process.env.TWITTER_CONSUMER_KEY || 'ABC'
var TWITTER_CONSUMER_SECRET = process.env.TWITTER_CONSUMER_SECRET || 'XYZXYZ'
const TWITTER_CONSUMER_KEY = process.env.TWITTER_CONSUMER_KEY || 'ABC'
const TWITTER_CONSUMER_SECRET = process.env.TWITTER_CONSUMER_SECRET || 'XYZXYZ'

const express = require('express')
const routes = require('./routes')
@@ -82,7 +82,11 @@ app.use((req, res, next) => {

// Authorization
const authorize = function (req, res, next) {
if (req.session && req.session.admin) { return next() } else { return res.send(401) }
if (req.session && req.session.admin) {
return next()
} else {
return res.send(401)
}
}

// Pages and routes
@@ -1,10 +1,12 @@
var mongoose = require('mongoose');
const mongoose = require('mongoose')

var articleSchema = new mongoose.Schema({
const articleSchema = new mongoose.Schema({
title: {
type: String,
required: true,
validate: [function(value) {return value.length<=120}, 'Title is too long (120 max)'],
validate: [function (value) {
return value.length <= 120
}, 'Title is too long (120 max)'],
default: 'New Post'
},
text: String,
@@ -14,13 +16,16 @@ var articleSchema = new mongoose.Schema({
},
slug: {
type: String,
set: function(value){return value.toLowerCase().replace(' ', '-')}
set: function (value) {
return value.toLowerCase().replace(' ', '-')
}
}
});
})

articleSchema.static({
list: function(callback){
this.find({}, null, {sort: {_id:-1}}, callback);
list: function (callback) {
this.find({}, null, {sort: {_id: -1}}, callback)
}
})
module.exports = mongoose.model('Article', articleSchema);

module.exports = mongoose.model('Article', articleSchema)
@@ -1,2 +1,2 @@
exports.Article = require('./article');
exports.User = require('./user');
exports.Article = require('./article')
exports.User = require('./user')
@@ -1,13 +1,14 @@
var mongoose = require('mongoose');
const mongoose = require('mongoose')

var userSchema = new mongoose.Schema({
const userSchema = new mongoose.Schema({
email: {
type: String,
required: true,
set: function(value) {return value.trim().toLowerCase()},
set: function (value) { return value.trim().toLowerCase() },
validate: [
function(email) {
return (email.match(/[a-z0-9!#$%&'*+\/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+\/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?/i) != null)},
function (email) {
return (email.match(/[a-z0-9!#$%&'*+\/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+\/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?/i) != null)
},
'Invalid email'
]
},
@@ -16,6 +17,6 @@ var userSchema = new mongoose.Schema({
type: Boolean,
default: false
}
});
})

module.exports = mongoose.model('User', userSchema);
module.exports = mongoose.model('User', userSchema)
@@ -4,7 +4,7 @@ mongoose.Promise = global.Promise
const Book = mongoose.model('Book', { name: String })

const practicalNodeBook = new Book({ name: 'Practical Node.js' })
practicalNodeBook.save(function (err, results) {
practicalNodeBook.save((err, results) => {
if (err) {
console.error(err)
process.exit(1)

0 comments on commit 35840c1

Please sign in to comment.