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
2 changes: 1 addition & 1 deletion api/database/database.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const mongoose = require('mongoose'),
models = require('./models'),
config = require('./config/database')

mongoose.connect(config.database, { useNewUrlParser: true })
mongoose.connect(config.database, { useNewUrlParser: true , useFindAndModify: false })

module.exports = {
db: mongoose,
Expand Down
41 changes: 12 additions & 29 deletions api/server/routes/reviews.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,21 +21,6 @@ module.exports = (fastify, opts, next) => {
reply.send(data)
})

// Get all reviews for a video
// fastify.get('/', { schema: opts.schemas.list }, async (req, reply) => {
// Review.find({}, (err, reviews) => {
// let reviewMap = {}
//
// reviews.forEach((review) => {
// if (!reviewMap[review.videoUrl]) reviewMap[review.videoUrl] = []
// reviewMap[review.videoUrl].push(review)
// })
//
// reply.send(reviewMap)
// })
// })


// Get reviews by videoUrl
fastify.get('/:videoUrl', { schema: opts.schemas.get }, async (req, reply) => {
if (!req.params.videoUrl) {
Expand All @@ -57,17 +42,17 @@ module.exports = (fastify, opts, next) => {
})
})

// Get a review by reviewId
fastify.get('/reviews/:reviewId', { schema: opts.schemas.get }, async (req, reply) => {
if (!req.params.reviewId) {
// Get a review by reviewId for a videoURL
fastify.get('/:videoUrl/:reviewId', { schema: opts.schemas.get }, async (req, reply) => {
if (!req.params.videoUrl) {
req.log.info('redirect on reviews')
reply.redirect(opts.prefix ? opts.prefix : '/')
return
}

req.log.info('request for a reiview : ' + req.params.reviewId)
req.log.info('request for a review : ' + req.params.reviewId + ' on a videoURL' + req.params.videoUrl)

const data = await Review.find({reviewId: req.params._id}, (err, reviews) => {
const data = await Review.find({_id: req.params.reviewId}, (err, reviews) => {
let reviewMap = {}

reviews.forEach((review) => {
Expand All @@ -80,20 +65,18 @@ module.exports = (fastify, opts, next) => {
})

// Create new review
fastify.post('/:videoUrl', { schema: opts.schemas.add }, async (req, reply) => {
fastify.post('/', { schema: opts.schemas.add }, async (req, reply) => {
let review = new Review(req.body.review)
const err = await review.save((err) => { return !!err })

reply.send({ err })
})

// // Increment vote of a review
// fastify.post('/:reviewId', { schema: opts.schemas.add }, async (req, reply) => {
// let review = new Review(req.body.review)
// review.save((err) => {
// reply.send({ err: !!err })
// })
// })
// Increment vote of a review
fastify.post('/:reviewId', async (req, reply) => {
const data = await Review.findByIdAndUpdate(req.params.reviewId , {$inc: {vote: req.body.review.vote}})
req.log.info(' ====== data.vote: ' + data.vote+ " ========")

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

You need to use single-quotes only to comply with standard JS

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

ok Thanks ;)

reply.send( data)
})

next()
}