Skip to content

Commit

Permalink
updated point curve
Browse files Browse the repository at this point in the history
  • Loading branch information
Freeassassin committed Sep 6, 2023
1 parent 0012ace commit 2a5354a
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 8 deletions.
13 changes: 6 additions & 7 deletions server/src/services/ScuntTeamServices.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 });
}
Expand All @@ -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(
Expand All @@ -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) => {
Expand All @@ -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,
},
],
},
Expand Down
2 changes: 1 addition & 1 deletion server/test/services/ScuntTeamServices.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand Down

0 comments on commit 2a5354a

Please sign in to comment.