Skip to content

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

Open
Griboedoff wants to merge 2 commits intourfu-2017:masterfrom
Griboedoff:master
Open

Дубровин Алексей#16
Griboedoff wants to merge 2 commits intourfu-2017:masterfrom
Griboedoff:master

Conversation

@Griboedoff
Copy link
Copy Markdown

No description provided.

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

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

@honest-hrundel
Copy link
Copy Markdown

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

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

Choose a reason for hiding this comment

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

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

Comment thread index.js
Cart.belongsToMany(Souvenir, { through: 'cart_souvenirs' });
Review.belongsTo(Souvenir);
Review.belongsTo(User);
User.hasOne(Cart);
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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

Comment thread index.js
Review.belongsTo(Souvenir);
Review.belongsTo(User);
User.hasOne(Cart);
User.hasMany(Review);
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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

Comment thread models/cart.js
}
}, {
timestamps: true
});
Copy link
Copy Markdown

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).

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

Choose a reason for hiding this comment

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

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

Comment thread models/souvenir.js
type: DataTypes.INTEGER,
allowNull: true
}
}, {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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

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

Choose a reason for hiding this comment

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

Аналогично

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

Choose a reason for hiding this comment

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

Тоже

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

Choose a reason for hiding this comment

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

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

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

await souvenir.save();
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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

@savichev-igor
Copy link
Copy Markdown

🍪

@honest-hrundel
Copy link
Copy Markdown

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

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