diff --git a/server/src/services/ScuntTeamServices.js b/server/src/services/ScuntTeamServices.js index ef314306..50e5e96e 100644 --- a/server/src/services/ScuntTeamServices.js +++ b/server/src/services/ScuntTeamServices.js @@ -71,9 +71,9 @@ const ScuntTeamServices = { ); // finds the rank of the team (i.e., index in teams array) - const teamPosition = teams?.findIndex((t) => teamNumber === t.number) + 1; + const teamPosition = teams?.findIndex((t) => teamNumber === t.number); - return (teamPosition / teams.length) * totalPoints; + return (teamPosition / teams.length + 1.0) * totalPoints; } catch (error) { throw new Error('UNABLE_TO_CALCULATE_POINTS', { cause: error }); } @@ -87,8 +87,7 @@ const ScuntTeamServices = { * @returns {ScuntTeam , Leadur} */ async bribeTransaction(teamNumber, points, user) { - const curvedPoints = await this.calculatePoints(teamNumber, points); - if (!user.scuntJudgeBribePoints || curvedPoints > user.scuntJudgeBribePoints) + if (!user.scuntJudgeBribePoints || points > user.scuntJudgeBribePoints) throw new Error('NOT_ENOUGH_BRIBE_POINTS'); await ScuntGameSettingsModel.findOne({}).then( @@ -103,7 +102,7 @@ const ScuntTeamServices = { const leadur = await LeadurModel.findByIdAndUpdate( user.id, - { $set: { scuntJudgeBribePoints: user.scuntJudgeBribePoints - curvedPoints } }, + { $set: { scuntJudgeBribePoints: user.scuntJudgeBribePoints - points } }, { upsert: false, returnDocument: 'after' }, ).then( (leadur) => { @@ -118,12 +117,12 @@ const ScuntTeamServices = { return ScuntTeamModel.findOneAndUpdate( { number: teamNumber }, { - $inc: { points: curvedPoints }, + $inc: { points }, $push: { transactions: [ { name: `${points.toString()} points bribe from ${user.firstName} ${user.lastName}`, - points: curvedPoints, + points, }, ], }, diff --git a/server/test/services/ScuntTeamServices.test.js b/server/test/services/ScuntTeamServices.test.js index c5519867..eeb9c54b 100644 --- a/server/test/services/ScuntTeamServices.test.js +++ b/server/test/services/ScuntTeamServices.test.js @@ -416,7 +416,7 @@ describe('ScuntTeamServices', () => { await ScuntTeamServices.addTransaction(4, 1, 20); await ScuntTeamServices.addTransaction(4, 1, 10); const points = await ScuntTeamServices.checkTransaction(4, 1); - assert.equal(points, 14); + assert.equal(points, 31); }); it('.checkTransaction()\t\t|\tCheck a transaction (INVALID TEAM NUMBER)', async () => {