Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Дубровин Алексей #16

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

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

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

@@ -21,6 +21,15 @@ const Cart = sequelize.import('models/cart');
const User = sequelize.import('models/user');

// Ваши 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).

@@ -1,5 +1,18 @@
'use strict';

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.

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

@@ -1,5 +1,18 @@
'use strict';

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.

Аналогично

@@ -1,5 +1,18 @@
'use strict';

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 для регистронезависимого поиска

const ratings = await this.Review.findAll({ where: { souvenirId } }).then(r => r.rating);
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