2015-08-10 17:02:10 +02:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
import alt from '../../../../alt';
|
|
|
|
import Q from 'q';
|
|
|
|
|
|
|
|
import PrizeRatingFetcher from '../fetchers/prize_rating_fetcher';
|
|
|
|
|
|
|
|
class PrizeRatingActions {
|
|
|
|
constructor() {
|
|
|
|
this.generateActions(
|
|
|
|
'updatePrizeRatings',
|
2015-08-24 15:33:36 +02:00
|
|
|
'updatePrizeRatingAverage',
|
2015-08-10 17:02:10 +02:00
|
|
|
'updatePrizeRating'
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2015-08-24 15:33:36 +02:00
|
|
|
fetchAverage(pieceId) {
|
2015-08-10 17:02:10 +02:00
|
|
|
return Q.Promise((resolve, reject) => {
|
|
|
|
PrizeRatingFetcher
|
2015-08-24 15:33:36 +02:00
|
|
|
.fetchAverage(pieceId)
|
2015-08-10 17:02:10 +02:00
|
|
|
.then((res) => {
|
2015-08-24 15:33:36 +02:00
|
|
|
this.actions.updatePrizeRatingAverage(res.data);
|
2015-08-10 17:02:10 +02:00
|
|
|
resolve(res);
|
|
|
|
})
|
|
|
|
.catch((err) => {
|
|
|
|
console.logGlobal(err);
|
|
|
|
reject(err);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
fetchOne(pieceId) {
|
|
|
|
return Q.Promise((resolve, reject) => {
|
|
|
|
PrizeRatingFetcher
|
|
|
|
.fetchOne(pieceId)
|
|
|
|
.then((res) => {
|
|
|
|
this.actions.updatePrizeRating(res.rating.rating);
|
|
|
|
resolve(res);
|
|
|
|
})
|
|
|
|
.catch((err) => {
|
|
|
|
reject(err);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
createRating(pieceId, rating) {
|
|
|
|
return Q.Promise((resolve, reject) => {
|
|
|
|
PrizeRatingFetcher
|
|
|
|
.rate(pieceId, rating)
|
|
|
|
.then((res) => {
|
|
|
|
this.actions.updatePrizeRating(res.rating.rating);
|
|
|
|
resolve(res);
|
|
|
|
})
|
|
|
|
.catch((err) => {
|
|
|
|
reject(err);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
updateRating(rating) {
|
|
|
|
this.actions.updatePrizeRating(rating);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export default alt.createActions(PrizeRatingActions);
|