@moneypot/hub 1.22.1 → 1.22.2

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.
@@ -8,9 +8,16 @@ export async function dbCreateLiability(pgClient, { lockedBankrollId, casinoId,
8
8
  VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9)
9
9
  RETURNING *
10
10
  ),
11
+ -- Sub-statements share one snapshot, so the sum can't see the
12
+ -- inserted row; its payout is added separately.
11
13
  bankroll_update AS (
12
14
  UPDATE hub.bankroll
13
- SET liability = liability + $8
15
+ SET liability = $8 + (
16
+ SELECT COALESCE(SUM(max_payout), 0)
17
+ FROM hub.liability
18
+ WHERE bankroll_id = $1
19
+ AND resolved_at IS NULL
20
+ )
14
21
  WHERE id = $1
15
22
  )
16
23
  SELECT * FROM inserted
@@ -40,10 +47,18 @@ export async function dbResolveLiabilityByRef(pgClient, { refType, refId, locked
40
47
  WHERE ref_type = $1
41
48
  AND ref_id = $2
42
49
  AND resolved_at IS NULL
43
- RETURNING bankroll_id, max_payout
50
+ RETURNING id, bankroll_id
44
51
  )
52
+ -- The sum reads the statement's snapshot, where the resolved row is
53
+ -- still active, so it is excluded by id.
45
54
  UPDATE hub.bankroll
46
- SET liability = liability - resolved.max_payout
55
+ SET liability = (
56
+ SELECT COALESCE(SUM(l.max_payout), 0)
57
+ FROM hub.liability l
58
+ WHERE l.bankroll_id = resolved.bankroll_id
59
+ AND l.resolved_at IS NULL
60
+ AND l.id <> resolved.id
61
+ )
47
62
  FROM resolved
48
63
  WHERE hub.bankroll.id = resolved.bankroll_id
49
64
  `,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@moneypot/hub",
3
- "version": "1.22.1",
3
+ "version": "1.22.2",
4
4
  "author": "moneypot.com",
5
5
  "homepage": "https://moneypot.com/hub",
6
6
  "keywords": [