Skip to content

Commit 23de46d

Browse files
chore: remove goal from a player only if they have scored it (#24)
1 parent 159a910 commit 23de46d

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

deployment.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
"appId": 8,
33
"appInbox": "0xa2a5d72B29C9Ccdc2c6594Bf9eD92cBd5A3bAf58",
44
"chainId": 69420
5-
}
5+
}

src/stackr/transitions.ts

+11
Original file line numberDiff line numberDiff line change
@@ -326,6 +326,17 @@ const removeGoal: STF<League, GoalRequest> = {
326326
if (match.scores[teamId] === 0) {
327327
throw new Error("NO_GOALS_TO_REMOVE");
328328
}
329+
const correspondingGoalIdx = state.logs.findIndex(
330+
(l) =>
331+
l.matchId === matchId &&
332+
l.playerId === playerId &&
333+
l.action === LogAction.GOAL
334+
);
335+
336+
if (correspondingGoalIdx === -1) {
337+
throw new Error("NO_GOALS_TO_REMOVE");
338+
}
339+
329340
match.scores[teamId] -= 1;
330341
state.logs.push({
331342
playerId,

0 commit comments

Comments
 (0)