@meith/groups 0.21.2 → 0.22.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/promotion.ts +5 -3
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@meith/groups",
3
- "version": "0.21.2",
3
+ "version": "0.22.0",
4
4
  "license": "MIT",
5
5
  "repository": {
6
6
  "type": "git",
package/src/promotion.ts CHANGED
@@ -62,8 +62,8 @@ export function evaluatePromotions(
62
62
  now: Date = new Date(),
63
63
  ): PromotionOutcome[] {
64
64
  const protectedIds = new Set(guards.protectedGroupIds)
65
- const rankOf = (groupId: number | null): number =>
66
- groupId === null ? 0 : (guards.rank?.get(groupId) ?? 0)
65
+ const rankOf = (groupId: number | null): number | undefined =>
66
+ groupId === null ? undefined : guards.rank?.get(groupId)
67
67
 
68
68
  const active = [...rules]
69
69
  .filter((r) => r.enabled)
@@ -79,7 +79,9 @@ export function evaluatePromotions(
79
79
 
80
80
  if (user.primaryGroupId === rule.toPrimaryGroupId) break
81
81
 
82
- if (rankOf(rule.toPrimaryGroupId) < rankOf(user.primaryGroupId)) break
82
+ const to = rankOf(rule.toPrimaryGroupId)
83
+ const from = rankOf(user.primaryGroupId)
84
+ if (to !== undefined && from !== undefined && to < from) break
83
85
 
84
86
  outcomes.push({
85
87
  userId: user.userId,