-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
18ef6bf
commit 83dfa33
Showing
28 changed files
with
11,066 additions
and
85 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,3 @@ | ||
node_modules/ | ||
node_modules/ | ||
variables.env | ||
variables-production.env |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
const mongoose = require('mongoose'); | ||
const Review = mongoose.model('Review'); | ||
|
||
exports.addReview = async (req, res) => { | ||
req.body.author = req.user._id; | ||
req.body.store = req.params.id; | ||
const newReview = new Review(req.body); | ||
await newReview.save(); | ||
req.flash('success', 'Revivew Saved!'); | ||
res.redirect('back'); | ||
}; |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
const nodemailer = require('nodemailer'); | ||
const pug = require('pug'); | ||
const juice = require('juice'); | ||
const htmlToText = require('html-to-text'); | ||
const promisify = require('es6-promisify'); | ||
|
||
const transport = nodemailer.createTransport({ | ||
host: process.env.MAIL_HOST, | ||
port: process.env.MAIL_PORT, | ||
auth: { | ||
user: process.env.MAIL_USER, | ||
pass: process.env.MAIL_PASS | ||
} | ||
}); | ||
|
||
const generateHTML = (filename, options = {}) => { | ||
const html = pug.renderFile(`${__dirname}/../views/email/${filename}.pug`, options); | ||
const inlined = juice(html); | ||
return inlined; | ||
}; | ||
|
||
exports.send = async (options) => { | ||
const html = generateHTML(options.filename, options); | ||
const text = htmlToText.fromString(html); | ||
|
||
const mailOptions = { | ||
from: `Wes Bos <[email protected]>`, | ||
to: options.user.email, | ||
subject: options.subject, | ||
html, | ||
text | ||
}; | ||
const sendMail = promisify(transport.sendMail, transport); | ||
return sendMail(mailOptions); | ||
}; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
const mongoose = require('mongoose'); | ||
mongoose.Promise = global.Promise; | ||
|
||
const reviewSchema = new mongoose.Schema({ | ||
created: { | ||
type: Date, | ||
default: Date.now | ||
}, | ||
author: { | ||
type: mongoose.Schema.ObjectId, | ||
ref: 'User', | ||
required: 'You must supply an author!' | ||
}, | ||
store: { | ||
type: mongoose.Schema.ObjectId, | ||
ref: 'Store', | ||
required: 'You must supply a store!' | ||
}, | ||
text: { | ||
type: String, | ||
required: 'Your review must have text!' | ||
}, | ||
rating: { | ||
type: Number, | ||
min: 1, | ||
max: 5 | ||
} | ||
}); | ||
|
||
function autopopulate(next) { | ||
this.populate('author'); | ||
next(); | ||
} | ||
|
||
reviewSchema.pre('find', autopopulate); | ||
reviewSchema.pre('findOne', autopopulate); | ||
|
||
module.exports = mongoose.model('Review', reviewSchema); |
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
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
Oops, something went wrong.