@moneypot/hub 1.12.0-dev.6 → 1.12.1

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.
@@ -136,17 +136,21 @@ export async function setTransferCursor(pgClient, { cursor, casinoId, }) {
136
136
  export async function upsertUser(pgClient, { uname, casinoId, mpUserId, }) {
137
137
  const user = await pgClient
138
138
  .query(`
139
- WITH ins AS (
140
- INSERT INTO hub.user (casino_id, mp_user_id, uname)
141
- VALUES ($1, $2, $3)
142
- ON CONFLICT (casino_id, mp_user_id) DO NOTHING
143
- RETURNING *
144
- )
145
- SELECT * FROM ins
146
- UNION ALL
147
- SELECT * FROM hub.user
148
- WHERE casino_id = $1 AND mp_user_id = $2
149
- LIMIT 1;
139
+ WITH upsert AS (
140
+ INSERT INTO hub.user (casino_id, mp_user_id, uname)
141
+ VALUES ($1, $2, $3)
142
+ ON CONFLICT (casino_id, mp_user_id) DO UPDATE
143
+ SET uname = EXCLUDED.uname
144
+ WHERE hub.user.uname IS DISTINCT FROM EXCLUDED.uname
145
+ RETURNING *
146
+ )
147
+ SELECT * FROM upsert
148
+ UNION ALL
149
+ SELECT * FROM hub.user
150
+ WHERE casino_id = $1 AND mp_user_id = $2
151
+ AND NOT EXISTS (SELECT 1 FROM upsert)
152
+ LIMIT 1;
153
+
150
154
  `, [casinoId, mpUserId, uname])
151
155
  .then(exactlyOneRow);
152
156
  return user;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@moneypot/hub",
3
- "version": "1.12.0-dev.6",
3
+ "version": "1.12.1",
4
4
  "author": "moneypot.com",
5
5
  "homepage": "https://moneypot.com/hub",
6
6
  "keywords": [