@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.
- package/dist/src/db/index.js +15 -11
- package/package.json +1 -1
package/dist/src/db/index.js
CHANGED
|
@@ -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
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
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;
|