|
|
|
@ -24,22 +24,8 @@ const User = syzoj.model('user');
|
|
|
|
|
let db = syzoj.db; |
|
|
|
|
|
|
|
|
|
let model = db.define('rating_history', { |
|
|
|
|
rating_calculation_id: { |
|
|
|
|
type: Sequelize.INTEGER, |
|
|
|
|
primaryKey: true, |
|
|
|
|
references: { |
|
|
|
|
model: 'rating_calculation', |
|
|
|
|
key: 'id' |
|
|
|
|
} |
|
|
|
|
}, |
|
|
|
|
user_id: { |
|
|
|
|
type: Sequelize.INTEGER, |
|
|
|
|
primaryKey: true, |
|
|
|
|
references: { |
|
|
|
|
model: 'user', |
|
|
|
|
key: 'id' |
|
|
|
|
} |
|
|
|
|
}, |
|
|
|
|
rating_calculation_id: { type: Sequelize.INTEGER, primaryKey: true }, |
|
|
|
|
user_id: { type: Sequelize.INTEGER, primaryKey: true }, |
|
|
|
|
rating_after: { type: Sequelize.INTEGER }, |
|
|
|
|
}, { |
|
|
|
|
timestamps: false, |
|
|
|
@ -57,15 +43,11 @@ let model = db.define('rating_history', {
|
|
|
|
|
let Model = require('./common'); |
|
|
|
|
class RatingHistory extends Model { |
|
|
|
|
static async create(rating_calculation_id, user_id, rating) { |
|
|
|
|
const newRecord = await RatingHistory.model.create({ |
|
|
|
|
return RatingHistory.fromRecord(RatingHistory.model.build({ |
|
|
|
|
rating_calculation_id: rating_calculation_id, |
|
|
|
|
user_id: user_id, |
|
|
|
|
rating_after: rating |
|
|
|
|
}); |
|
|
|
|
await newRecord.loadRelationShips(); |
|
|
|
|
newRecord.user.rating = rating; |
|
|
|
|
await newRecord.user.save(); |
|
|
|
|
return newRecord; |
|
|
|
|
})); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
async loadRelationships() { |
|
|
|
|