gambling-bot-shared 1.0.9 → 1.0.11

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.
@@ -63,7 +63,7 @@ export declare const AtmRequestSchema: Schema<TAtmRequest, import("mongoose").Mo
63
63
  }, "id"> & {
64
64
  id: string;
65
65
  }> | undefined;
66
- status?: import("mongoose").SchemaDefinitionProperty<"pending" | "approved" | "rejected", TAtmRequest, import("mongoose").Document<unknown, {}, TAtmRequest, {
66
+ status?: import("mongoose").SchemaDefinitionProperty<"pending" | "approved" | "rejected" | "cancelled", TAtmRequest, import("mongoose").Document<unknown, {}, TAtmRequest, {
67
67
  id: string;
68
68
  }, import("mongoose").DefaultSchemaOptions> & Omit<TAtmRequest & {
69
69
  _id: import("mongoose").Types.ObjectId;
@@ -11,7 +11,7 @@ exports.AtmRequestSchema = new mongoose_1.Schema({
11
11
  account: { type: String, required: true },
12
12
  status: {
13
13
  type: String,
14
- enum: ['pending', 'approved', 'rejected'],
14
+ enum: ['pending', 'approved', 'rejected', 'cancelled'],
15
15
  required: true,
16
16
  default: 'pending',
17
17
  index: true
@@ -5,7 +5,7 @@ export type TAtmRequest = {
5
5
  type: 'deposit' | 'withdraw';
6
6
  amount: number;
7
7
  account: string;
8
- status: 'pending' | 'approved' | 'rejected';
8
+ status: 'pending' | 'approved' | 'rejected' | 'cancelled';
9
9
  handledBy?: string;
10
10
  handledAt?: Date;
11
11
  notes?: string;
@@ -5,8 +5,12 @@ import type { PayPredictionResult } from './types';
5
5
  type PredictionLifecycleDeps = {
6
6
  predictionDb: PredictionDb;
7
7
  casinoBet: Pick<CasinoBetService, 'refundLockedBet' | 'settleCasinoWinnings'>;
8
+ hasSettlementTransactions?: (params: {
9
+ guildId: string;
10
+ referenceIds: string[];
11
+ }) => Promise<boolean>;
8
12
  };
9
- export declare function createPredictionLifecycleService({ predictionDb, casinoBet }: PredictionLifecycleDeps): {
13
+ export declare function createPredictionLifecycleService({ predictionDb, casinoBet, hasSettlementTransactions }: PredictionLifecycleDeps): {
10
14
  endPrediction: ({ predictionId, guildId }: {
11
15
  predictionId: string;
12
16
  guildId: string;
@@ -20,6 +24,16 @@ export declare function createPredictionLifecycleService({ predictionDb, casinoB
20
24
  guildId: string;
21
25
  winnerChoice: string;
22
26
  }) => Promise<PayPredictionResult>;
27
+ resetStuckPayout: ({ predictionId, guildId }: {
28
+ predictionId: string;
29
+ guildId: string;
30
+ }) => Promise<{
31
+ ok: true;
32
+ prediction: TPrediction;
33
+ } | {
34
+ ok: false;
35
+ code: "NOT_FOUND" | "INVALID_STATUS" | "PARTIAL_PAYOUT";
36
+ }>;
23
37
  };
24
38
  export type PredictionLifecycleService = ReturnType<typeof createPredictionLifecycleService>;
25
39
  export {};
@@ -2,7 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.createPredictionLifecycleService = createPredictionLifecycleService;
4
4
  const predictionSummary_1 = require("./predictionSummary");
5
- function createPredictionLifecycleService({ predictionDb, casinoBet }) {
5
+ function createPredictionLifecycleService({ predictionDb, casinoBet, hasSettlementTransactions }) {
6
6
  const { getPredictionById, updatePredictionStatus } = predictionDb;
7
7
  const { refundLockedBet, settleCasinoWinnings } = casinoBet;
8
8
  const finalizePaid = async (predictionId, guildId) => {
@@ -24,6 +24,34 @@ function createPredictionLifecycleService({ predictionDb, casinoBet }) {
24
24
  toStatus: 'ended'
25
25
  });
26
26
  };
27
+ const resetStuckPayout = async ({ predictionId, guildId }) => {
28
+ const prediction = await getPredictionById({ predictionId, guildId });
29
+ if (!prediction)
30
+ return { ok: false, code: 'NOT_FOUND' };
31
+ if (prediction.status !== 'paying') {
32
+ return { ok: false, code: 'INVALID_STATUS' };
33
+ }
34
+ const betIds = prediction.choices
35
+ .flatMap((choice) => choice.bets)
36
+ .map((bet) => (0, predictionSummary_1.resolvePredictionBetId)(bet, predictionId));
37
+ if (betIds.length > 0 && hasSettlementTransactions) {
38
+ const hasSettlement = await hasSettlementTransactions({
39
+ guildId,
40
+ referenceIds: betIds
41
+ });
42
+ if (hasSettlement)
43
+ return { ok: false, code: 'PARTIAL_PAYOUT' };
44
+ }
45
+ const updated = await updatePredictionStatus({
46
+ predictionId,
47
+ guildId,
48
+ fromStatus: 'paying',
49
+ toStatus: 'ended'
50
+ });
51
+ if (!updated)
52
+ return { ok: false, code: 'INVALID_STATUS' };
53
+ return { ok: true, prediction: updated };
54
+ };
27
55
  const endPrediction = async ({ predictionId, guildId }) => {
28
56
  return updatePredictionStatus({
29
57
  predictionId,
@@ -128,6 +156,7 @@ function createPredictionLifecycleService({ predictionDb, casinoBet }) {
128
156
  return {
129
157
  endPrediction,
130
158
  cancelPrediction,
131
- payoutPrediction
159
+ payoutPrediction,
160
+ resetStuckPayout
132
161
  };
133
162
  }
@@ -7,6 +7,8 @@ export declare const STAFF_ADMIN_ACTIONS: {
7
7
  readonly PREDICTION_END: "prediction-end";
8
8
  readonly PREDICTION_PAYOUT: "prediction-payout";
9
9
  readonly PREDICTION_CANCEL: "prediction-cancel";
10
+ readonly PREDICTION_RESET_PAYOUT: "prediction-reset-payout";
11
+ readonly BLACKJACK_FORCE_CLOSE: "blackjack-force-close";
10
12
  readonly ATM_REJECT: "atm-reject";
11
13
  readonly USER_BAN: "user-ban";
12
14
  readonly USER_UNBAN: "user-unban";
@@ -10,6 +10,8 @@ exports.STAFF_ADMIN_ACTIONS = {
10
10
  PREDICTION_END: 'prediction-end',
11
11
  PREDICTION_PAYOUT: 'prediction-payout',
12
12
  PREDICTION_CANCEL: 'prediction-cancel',
13
+ PREDICTION_RESET_PAYOUT: 'prediction-reset-payout',
14
+ BLACKJACK_FORCE_CLOSE: 'blackjack-force-close',
13
15
  ATM_REJECT: 'atm-reject',
14
16
  USER_BAN: 'user-ban',
15
17
  USER_UNBAN: 'user-unban',
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gambling-bot-shared",
3
- "version": "1.0.9",
3
+ "version": "1.0.11",
4
4
  "license": "MIT",
5
5
  "type": "commonjs",
6
6
  "repository": {