Skip to content

Conversation

@Griboedoff
Copy link

No description provided.

@honest-hrundel honest-hrundel changed the title master Дубровин Алексей Apr 23, 2018
@honest-hrundel
Copy link

🍏 Пройден линтинг и базовые тесты

@honest-hrundel
Copy link

🍏 Пройден линтинг и базовые тесты

// Ваши relations между моделями :)
Cart.belongsTo(User);
Cart.belongsToMany(Souvenir, { through: 'cart_souvenirs' });
Review.belongsTo(Souvenir);

Choose a reason for hiding this comment

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

Souvenir.hasMany(Review) достаточно

Cart.belongsToMany(Souvenir, { through: 'cart_souvenirs' });
Review.belongsTo(Souvenir);
Review.belongsTo(User);
User.hasOne(Cart);

Choose a reason for hiding this comment

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

Уже есть Cart.belongsTo(User)

Review.belongsTo(Souvenir);
Review.belongsTo(User);
User.hasOne(Cart);
User.hasMany(Review);

Choose a reason for hiding this comment

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

Также с Review.belongsTo(User)

}
}, {
timestamps: true
});

Choose a reason for hiding this comment

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

Нет необходимости явным образом определять что либо в этой модели.
id, createdAt, updatedAt проставляются неявно Sequelize'ом.
userId также появится засчёт связи Cart.belongsTo(User).

module.exports = (sequelize, DataTypes) => {
// Ваша модель страны
return sequelize.define('country', {
id: {

Choose a reason for hiding this comment

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

Аналогично про id

type: DataTypes.INTEGER,
allowNull: true
}
}, {

Choose a reason for hiding this comment

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

Всё также, много лишних явных объявлений

module.exports = (sequelize, DataTypes) => {
// Ваша модель тэга
return sequelize.define('tag', {
id: {

Choose a reason for hiding this comment

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

Аналогично

module.exports = (sequelize, DataTypes) => {
// Ваша модель юзера
return sequelize.define('user', {
id: {

Choose a reason for hiding this comment

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

Тоже

// подстрока substring. Поиск должен быть регистронезависимым.
return this.Souvenir.findAll({
where: {
name: { [Sequelize.Op.contains]: substring }

Choose a reason for hiding this comment

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

ilike или iRegexp для регистронезависимого поиска

souvenir.rating = ratings.reduce((a, b) => a + b, 0) / ratings.length;

await souvenir.save();
}

Choose a reason for hiding this comment

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

Оберни в транзакцию

@savichev-igor
Copy link

🍪

@honest-hrundel
Copy link

🍏 Пройден линтинг и базовые тесты

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

Labels

None yet

Development

Successfully merging this pull request may close these issues.

4 participants