@@ -4,15 +4,21 @@ let UserVotingPermissions = function(Config, db, user, post) {
44
55 this . hasEnoughPostsToUpvote = async function ( ) {
66 let allowed = user . postcount >= Config . minPostToUpvote ( ) ;
7- if ( ! allowed ) throw { 'reason' : 'notEnoughPosts' } ;
7+ if ( ! allowed ) throw {
8+ 'reason' : 'notEnoughPosts' ,
9+ 'params' : [ Config . minPostToUpvote ( ) ]
10+ } ;
811 } ;
912
1013 this . isOldEnoughToUpvote = async function ( ) {
1114 let now = new Date ( ) ;
1215 let xDaysAgo = now . getTime ( ) - Config . minDaysToUpvote ( ) * 24 * 60 * 60 * 1000 ;
1316
1417 let allowed = user . joindate < xDaysAgo ;
15- if ( ! allowed ) throw { 'reason' : 'notOldEnough' } ;
18+ if ( ! allowed ) throw {
19+ 'reason' : 'notOldEnough' ,
20+ 'params' : [ Config . minDaysToUpvote ( ) ]
21+ } ;
1622 } ;
1723
1824 this . hasVotedTooManyPostsInThread = async function ( ) {
@@ -24,7 +30,10 @@ let UserVotingPermissions = function(Config, db, user, post) {
2430 throw err ;
2531 }
2632 let allowed = userVotesInThread < Config . maxVotesPerUserInThread ( ) ;
27- if ( ! allowed ) throw { 'reason' : 'tooManyVotesInThread' } ;
33+ if ( ! allowed ) throw {
34+ 'reason' : 'tooManyVotesInThread' ,
35+ 'params' : [ Config . maxVotesPerUserInThread ( ) ]
36+ } ;
2837 } ;
2938
3039 this . hasVotedAuthorTooManyTimesThisMonth = async function ( ) {
@@ -36,7 +45,10 @@ let UserVotingPermissions = function(Config, db, user, post) {
3645 throw err ;
3746 }
3847 let allowed = votesToAuthor < Config . maxVotesToSameUserInMonth ( ) ;
39- if ( ! allowed ) throw { 'reason' : 'tooManyVotesToSameUserThisMonth' } ;
48+ if ( ! allowed ) throw {
49+ 'reason' : 'tooManyVotesToSameUserThisMonth' ,
50+ 'params' : [ Config . maxVotesToSameUserInMonth ( ) ]
51+ } ;
4052 } ;
4153
4254 this . hasVotedTooManyTimesToday = async function ( ) {
@@ -48,25 +60,37 @@ let UserVotingPermissions = function(Config, db, user, post) {
4860 throw err ;
4961 }
5062 let allowed = votes < Config . maxVotesPerUser ( user . reputation ) ;
51- if ( ! allowed ) throw { 'reason' : 'tooManyVotesToday' } ;
63+ if ( ! allowed ) throw {
64+ 'reason' : 'tooManyVotesToday' ,
65+ 'params' : [ Config . maxVotesPerUser ( user . reputation ) ]
66+ } ;
5267 } ;
5368
5469 this . hasEnoughPostsToDownvote = async function ( ) {
5570 let allowed = user . postcount >= Config . minPostToDownvote ( ) ;
56- if ( ! allowed ) throw { 'reason' : 'notEnoughPosts' } ;
71+ if ( ! allowed ) throw {
72+ 'reason' : 'notEnoughPosts' ,
73+ 'params' : [ Config . minPostToDownvote ( ) ]
74+ } ;
5775 } ;
5876
5977 this . isOldEnoughToDownvote = async function ( ) {
6078 let now = new Date ( ) ;
6179 let xDaysAgo = now . getTime ( ) - Config . minDaysToDownvote ( ) * 24 * 60 * 60 * 1000 ;
6280
6381 let allowed = user . joindate < xDaysAgo ;
64- if ( ! allowed ) throw { 'reason' : 'notOldEnough' } ;
82+ if ( ! allowed ) throw {
83+ 'reason' : 'notOldEnough' ,
84+ 'params' : [ Config . minDaysToDownvote ( ) ]
85+ } ;
6586 } ;
6687
6788 this . hasEnoughReputationToDownvote = async function ( ) {
6889 let allowed = user . reputation >= Config . minReputationToDownvote ( ) ;
69- if ( ! allowed ) throw { 'reason' : 'notEnoughReputation' } ;
90+ if ( ! allowed ) throw {
91+ 'reason' : 'notEnoughReputation' ,
92+ 'params' : [ Config . minReputationToDownvote ( ) ]
93+ } ;
7094 } ;
7195
7296 this . votingAllowedInCategory = async function ( ) {
@@ -81,7 +105,10 @@ let UserVotingPermissions = function(Config, db, user, post) {
81105
82106 let now = new Date ( ) ;
83107 let postAgeDays = ( now - post . timestamp ) / 24 / 60 / 60 / 1000 ;
84- if ( postAgeDays > Config . getMaxPostAgeDays ( ) ) throw { 'reason' : 'postTooOld' } ;
108+ if ( postAgeDays > Config . getMaxPostAgeDays ( ) ) throw {
109+ 'reason' : 'postTooOld' ,
110+ 'params' : [ Config . getMaxPostAgeDays ( ) ]
111+ } ;
85112 } ;
86113
87114 this . hasDownvotedTooManyTimesToday = async function ( ) {
@@ -95,7 +122,10 @@ let UserVotingPermissions = function(Config, db, user, post) {
95122 throw err ;
96123 }
97124 let allowed = downvotes < Config . maxDownvotesPerDay ( ) ;
98- if ( ! allowed ) throw { 'reason' : 'tooManyDownvotesToday' } ;
125+ if ( ! allowed ) throw {
126+ 'reason' : 'tooManyDownvotesToday' ,
127+ 'params' : [ Config . maxDownvotesPerDay ( ) ]
128+ } ;
99129 } ;
100130
101131 async function countVotesInThread ( userId , threadId ) {
0 commit comments