Skip to content

Conversation

@weresquirrel
Copy link
Contributor

No description provided.

Copy link
Contributor

@jalada jalada left a comment

Choose a reason for hiding this comment

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

This is looking good! A few bits and pieces here, see what you think.

'use strict';

module.exports = {
up: (queryInterface, Sequelize) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Oh hello 4 space tabs!

We don't have a documented convention, but the rest of the code is 2 spaces for tabs.

Text: {
defaultValue: false,
allowNull: false,
type: Sequelize.STRING
Copy link
Contributor

Choose a reason for hiding this comment

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

What does this translate down to in PostgreSQL? Is it a VARCHAR? Because if so, this will have a 255 character limit.

const Review = sequelize.define('Review', {
BookId: DataTypes.INTEGER,
UserId: DataTypes.INTEGER,
Rating: DataTypes.INTEGER,
Copy link
Contributor

Choose a reason for hiding this comment

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

We should validate that this is between the 2 numbers we accept. (1 to 5?)


const router = Router();

const Op = Sequelize.Op;
Copy link
Contributor

Choose a reason for hiding this comment

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

You could also change the import line above to something like import { Op }, Sequelize from 'sequelize;`. I think...

book = await Book.findByPk(req.params.id);
reviews = await Review.findAll({where: {BookId: {[Op.eq]: book.id}}});
if(reviews.length > 0) {
rating = reviews.reduce((a, review) => a + review.Rating,0) / reviews.length;
Copy link
Contributor

Choose a reason for hiding this comment

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

This code feels like something best placed in the Book or Review model instead, what do you think?

if(reviews.length > 0) {
rating = reviews.reduce((a, review) => a + review.Rating,0) / reviews.length;
}
// res.json(book);
Copy link
Contributor

Choose a reason for hiding this comment

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

It's OK to delete this :)

}));

// Get a single book by ID.
// TODO: Should render HTML, not return JSON.
Copy link
Contributor

Choose a reason for hiding this comment

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

This TODO can be removed; it's rendering HTML now!

const review = await req.user.createReview({BookId, Text, Rating});


// const loan = await req.user.createLoan({BookId, dueDate});
Copy link
Contributor

Choose a reason for hiding this comment

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

What's this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants