@moneypot/hub 1.3.0-dev.14 → 1.3.0-dev.15
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.
|
@@ -119,9 +119,6 @@ export function MakeOutcomeBetPlugin({ betConfigs }) {
|
|
|
119
119
|
if (!betConfig) {
|
|
120
120
|
throw new GraphQLError(`Invalid bet kind`);
|
|
121
121
|
}
|
|
122
|
-
if (!betKinds.includes(rawInput.kind)) {
|
|
123
|
-
throw new GraphQLError(`Invalid bet kind`);
|
|
124
|
-
}
|
|
125
122
|
let initializedMetadata;
|
|
126
123
|
if (betConfig.initializeMetadataFromUntrustedUserInput) {
|
|
127
124
|
const result = betConfig.initializeMetadataFromUntrustedUserInput(input);
|
|
@@ -1,55 +1,30 @@
|
|
|
1
|
-
import { access,
|
|
1
|
+
import { access, constant, context } from "postgraphile/grafast";
|
|
2
2
|
import { gql, makeExtendSchemaPlugin } from "postgraphile/utils";
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
3
|
+
import { TYPES } from "postgraphile/@dataplan/pg";
|
|
4
|
+
import { sql } from "postgraphile/pg-sql2";
|
|
5
5
|
export const HubUserBalanceByCurrencyPlugin = makeExtendSchemaPlugin((build) => {
|
|
6
|
-
const
|
|
6
|
+
const balanceTable = build.input.pgRegistry.pgResources.hub_balance;
|
|
7
7
|
return {
|
|
8
8
|
typeDefs: gql `
|
|
9
9
|
extend type HubUser {
|
|
10
|
-
|
|
10
|
+
hubBalanceByCurrency(currency: String!): HubBalance
|
|
11
11
|
}
|
|
12
12
|
`,
|
|
13
13
|
plans: {
|
|
14
14
|
HubUser: {
|
|
15
|
-
|
|
15
|
+
hubBalanceByCurrency: ($record, { $currency }) => {
|
|
16
16
|
const $identity = context().get("identity");
|
|
17
|
-
const $
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
17
|
+
const $balances = balanceTable.find();
|
|
18
|
+
$balances.where(sql `
|
|
19
|
+
${$balances}.currency_key = ${$balances.placeholder($currency, TYPES.text)}
|
|
20
|
+
AND ${$balances}.user_id = ${$balances.placeholder($record.get("id"), TYPES.uuid)}
|
|
21
|
+
AND ${$balances}.casino_id = ${$balances.placeholder(access($identity, ["session", "casino_id"]), TYPES.uuid)}
|
|
22
|
+
AND ${$balances}.experience_id = ${$balances.placeholder(access($identity, ["session", "experience_id"]), TYPES.uuid)}
|
|
23
|
+
`);
|
|
24
|
+
$balances.setFirst(constant(1));
|
|
25
|
+
return $balances.single();
|
|
25
26
|
},
|
|
26
27
|
},
|
|
27
28
|
},
|
|
28
29
|
};
|
|
29
30
|
});
|
|
30
|
-
async function batchGetUserBalanceByCurrency(paramsArray) {
|
|
31
|
-
const values = [];
|
|
32
|
-
const valuePlaceholders = [];
|
|
33
|
-
paramsArray.forEach((p, index) => {
|
|
34
|
-
const baseIndex = index * 4 + 1;
|
|
35
|
-
valuePlaceholders.push(`($${baseIndex}, $${baseIndex + 1}::uuid, $${baseIndex + 2}::uuid, $${baseIndex + 3}::uuid)`);
|
|
36
|
-
values.push(p.currency, p.targetUserId, p.casino_id, p.experience_id);
|
|
37
|
-
});
|
|
38
|
-
const sql = `
|
|
39
|
-
SELECT b.*
|
|
40
|
-
FROM hub.balance b
|
|
41
|
-
JOIN (
|
|
42
|
-
VALUES
|
|
43
|
-
${valuePlaceholders.join(",\n ")}
|
|
44
|
-
) AS vals(currency_key, user_id, casino_id, experience_id)
|
|
45
|
-
ON b.currency_key = vals.currency_key
|
|
46
|
-
AND b.user_id = vals.user_id
|
|
47
|
-
AND b.casino_id = vals.casino_id
|
|
48
|
-
AND b.experience_id = vals.experience_id
|
|
49
|
-
`;
|
|
50
|
-
const { rows } = await superuserPool.query(sql, values);
|
|
51
|
-
return paramsArray.map((p) => rows.find((row) => row.currency_key === p.currency &&
|
|
52
|
-
row.user_id === p.targetUserId &&
|
|
53
|
-
row.casino_id === p.casino_id &&
|
|
54
|
-
row.experience_id === p.experience_id));
|
|
55
|
-
}
|