gg
Deploy Iddaai Backend / build-and-deploy (push) Successful in 1m8s

This commit is contained in:
2026-05-12 03:06:54 +03:00
parent b6d64b59bf
commit 2b8dce665f
7 changed files with 77 additions and 48 deletions
+2 -2
View File
@@ -16,7 +16,7 @@ RUN npm ci
COPY . . COPY . .
# Generate Prisma client # Generate Prisma client
RUN npx prisma generate RUN DATABASE_URL="postgresql://dummy:dummy@localhost/dummy" npx prisma generate
# Build the application # Build the application
RUN npm run build RUN npm run build
@@ -38,7 +38,7 @@ RUN apk add --no-cache --virtual .build-deps python3 make g++ cairo-dev pango-de
# Copy Prisma schema and generate client # Copy Prisma schema and generate client
COPY prisma ./prisma COPY prisma ./prisma
RUN npx prisma generate RUN DATABASE_URL="postgresql://dummy:dummy@localhost/dummy" npx prisma generate
# Copy built application # Copy built application
COPY --from=builder /app/dist ./dist COPY --from=builder /app/dist ./dist
+2 -3
View File
@@ -122,9 +122,8 @@ export const FINISHED_STATE_VALUES_FOR_DB = [
]; ];
function normalizeToken(value: unknown): string { function normalizeToken(value: unknown): string {
return String(value || "") if (typeof value !== "string") return "";
.trim() return value.trim().toLowerCase();
.toLowerCase();
} }
function parseScoreValue(value: ScoreLikeValue): number | null { function parseScoreValue(value: ScoreLikeValue): number | null {
+15 -6
View File
@@ -307,28 +307,37 @@ export class AdminController {
const user = await this.prisma.user.findUnique({ where: { id: userId } }); const user = await this.prisma.user.findUnique({ where: { id: userId } });
if (!user) throw new NotFoundException("USER_NOT_FOUND"); if (!user) throw new NotFoundException("USER_NOT_FOUND");
const validPlans = [PlanType.FREE, PlanType.PLUS, PlanType.PREMIUM, "past_due", "cancelled"]; const validPlans = [
PlanType.FREE,
PlanType.PLUS,
PlanType.PREMIUM,
"past_due",
"cancelled",
];
const newPlan = data.plan as PlanType; const newPlan = data.plan as PlanType;
if (!validPlans.includes(newPlan)) { if (!validPlans.includes(newPlan)) {
throw new BadRequestException("INVALID_PLAN_TYPE"); throw new BadRequestException("INVALID_PLAN_TYPE");
} }
const updateData: any = { subscriptionStatus: newPlan }; const updateData: any = { subscriptionStatus: newPlan };
if (data.expiresAt) { if (data.expiresAt) {
const parsedDate = new Date(data.expiresAt); const parsedDate = new Date(data.expiresAt);
// Business Logic: If upgrading to Premium/Plus, the expiry date cannot be in the past // Business Logic: If upgrading to Premium/Plus, the expiry date cannot be in the past
const today = new Date(); const today = new Date();
today.setHours(0, 0, 0, 0); // Strip time today.setHours(0, 0, 0, 0); // Strip time
const expiry = new Date(parsedDate); const expiry = new Date(parsedDate);
expiry.setHours(0, 0, 0, 0); expiry.setHours(0, 0, 0, 0);
if ((newPlan === PlanType.PREMIUM || newPlan === PlanType.PLUS) && expiry < today) { if (
(newPlan === PlanType.PREMIUM || newPlan === PlanType.PLUS) &&
expiry < today
) {
throw new BadRequestException("EXPIRES_AT_CANNOT_BE_IN_PAST"); throw new BadRequestException("EXPIRES_AT_CANNOT_BE_IN_PAST");
} }
updateData.subscriptionExpiresAt = parsedDate; updateData.subscriptionExpiresAt = parsedDate;
} else if (data.expiresAt === null) { } else if (data.expiresAt === null) {
updateData.subscriptionExpiresAt = null; updateData.subscriptionExpiresAt = null;
@@ -1,4 +1,4 @@
import { IsString, IsOptional, IsEnum, IsISO8601 } from "class-validator"; import { IsString, IsOptional, IsISO8601 } from "class-validator";
import { ApiProperty } from "@nestjs/swagger"; import { ApiProperty } from "@nestjs/swagger";
export class UpdateUserSubscriptionDto { export class UpdateUserSubscriptionDto {
@@ -6,7 +6,10 @@ export class UpdateUserSubscriptionDto {
@IsString() @IsString()
plan: string; plan: string;
@ApiProperty({ description: "Expiration Date in ISO format", required: false }) @ApiProperty({
description: "Expiration Date in ISO format",
required: false,
})
@IsOptional() @IsOptional()
@IsISO8601() @IsISO8601()
expiresAt?: string | null; expiresAt?: string | null;
@@ -108,14 +108,10 @@ export class SubscriptionsService {
await this.handleSubscriptionResumed(data); await this.handleSubscriptionResumed(data);
break; break;
case "transaction.completed": case "transaction.completed":
this.logger.log( this.logger.log(`Transaction completed: ${data.id}`);
`Transaction completed: ${(data as Record<string, unknown>).id}`,
);
break; break;
case "transaction.payment_failed": case "transaction.payment_failed":
this.logger.warn( this.logger.warn(`Payment failed for transaction: ${data.id}`);
`Payment failed for transaction: ${(data as Record<string, unknown>).id}`,
);
break; break;
default: default:
this.logger.debug(`Unhandled Paddle event: ${eventType}`); this.logger.debug(`Unhandled Paddle event: ${eventType}`);
@@ -218,7 +214,7 @@ export class SubscriptionsService {
// Sync user subscription status // Sync user subscription status
await this.prisma.user.update({ await this.prisma.user.update({
where: { id: userId }, where: { id: userId },
data: { data: {
subscriptionStatus: effectivePlan, subscriptionStatus: effectivePlan,
subscriptionExpiresAt: currentBillingPeriod?.ends_at subscriptionExpiresAt: currentBillingPeriod?.ends_at
? new Date(currentBillingPeriod.ends_at) ? new Date(currentBillingPeriod.ends_at)
@@ -15,55 +15,74 @@ export interface PickRef {
type Resolver = (pick: string, r: MatchResult) => boolean | null; type Resolver = (pick: string, r: MatchResult) => boolean | null;
const ms1x2: Resolver = (pick, r) => { const ms1x2: Resolver = (pick, r) => {
const outcome = r.scoreHome > r.scoreAway ? "1" : r.scoreHome < r.scoreAway ? "2" : "X"; const outcome =
r.scoreHome > r.scoreAway ? "1" : r.scoreHome < r.scoreAway ? "2" : "X";
return pick === outcome; return pick === outcome;
}; };
const ht1x2: Resolver = (pick, r) => { const ht1x2: Resolver = (pick, r) => {
if (r.htScoreHome === null || r.htScoreAway === null) return null; if (r.htScoreHome === null || r.htScoreAway === null) return null;
const outcome = const outcome =
r.htScoreHome > r.htScoreAway ? "1" : r.htScoreHome < r.htScoreAway ? "2" : "X"; r.htScoreHome > r.htScoreAway
? "1"
: r.htScoreHome < r.htScoreAway
? "2"
: "X";
return pick === outcome; return pick === outcome;
}; };
const overUnder = (line: number): Resolver => (pick, r) => { const overUnder =
const total = r.scoreHome + r.scoreAway; (line: number): Resolver =>
if (total === line) return null; (pick, r) => {
const isOver = total > line; const total = r.scoreHome + r.scoreAway;
if (pick === "Üst" || pick === "Ust" || pick.toLowerCase() === "over") return isOver; if (total === line) return null;
if (pick === "Alt" || pick.toLowerCase() === "under") return !isOver; const isOver = total > line;
return null; if (pick === "Üst" || pick === "Ust" || pick.toLowerCase() === "over")
}; return isOver;
if (pick === "Alt" || pick.toLowerCase() === "under") return !isOver;
return null;
};
const overUnderHt = (line: number): Resolver => (pick, r) => { const overUnderHt =
if (r.htScoreHome === null || r.htScoreAway === null) return null; (line: number): Resolver =>
const total = r.htScoreHome + r.htScoreAway; (pick, r) => {
if (total === line) return null; if (r.htScoreHome === null || r.htScoreAway === null) return null;
const isOver = total > line; const total = r.htScoreHome + r.htScoreAway;
if (pick === "Üst" || pick === "Ust" || pick.toLowerCase() === "over") return isOver; if (total === line) return null;
if (pick === "Alt" || pick.toLowerCase() === "under") return !isOver; const isOver = total > line;
return null; if (pick === "Üst" || pick === "Ust" || pick.toLowerCase() === "over")
}; return isOver;
if (pick === "Alt" || pick.toLowerCase() === "under") return !isOver;
return null;
};
const btts: Resolver = (pick, r) => { const btts: Resolver = (pick, r) => {
const both = r.scoreHome > 0 && r.scoreAway > 0; const both = r.scoreHome > 0 && r.scoreAway > 0;
if (pick === "Var" || pick === "KG Var" || pick.toLowerCase() === "yes") return both; if (pick === "Var" || pick === "KG Var" || pick.toLowerCase() === "yes")
if (pick === "Yok" || pick === "KG Yok" || pick.toLowerCase() === "no") return !both; return both;
if (pick === "Yok" || pick === "KG Yok" || pick.toLowerCase() === "no")
return !both;
return null; return null;
}; };
const htft: Resolver = (pick, r) => { const htft: Resolver = (pick, r) => {
if (r.htScoreHome === null || r.htScoreAway === null) return null; if (r.htScoreHome === null || r.htScoreAway === null) return null;
const ht = const ht =
r.htScoreHome > r.htScoreAway ? "1" : r.htScoreHome < r.htScoreAway ? "2" : "X"; r.htScoreHome > r.htScoreAway
const ft = r.scoreHome > r.scoreAway ? "1" : r.scoreHome < r.scoreAway ? "2" : "X"; ? "1"
: r.htScoreHome < r.htScoreAway
? "2"
: "X";
const ft =
r.scoreHome > r.scoreAway ? "1" : r.scoreHome < r.scoreAway ? "2" : "X";
const normalized = pick.replace(/\s/g, "").toUpperCase(); const normalized = pick.replace(/\s/g, "").toUpperCase();
return normalized === `${ht}/${ft}`; return normalized === `${ht}/${ft}`;
}; };
const doubleChance: Resolver = (pick, r) => { const doubleChance: Resolver = (pick, r) => {
const ft = r.scoreHome > r.scoreAway ? "1" : r.scoreHome < r.scoreAway ? "2" : "X"; const ft =
const normalized = pick.replace(/\s/g, "").toUpperCase().split(/[\/\-]/); r.scoreHome > r.scoreAway ? "1" : r.scoreHome < r.scoreAway ? "2" : "X";
const normalized = pick.replace(/\s/g, "").toUpperCase().split(/\/|-/);
if (normalized.length !== 2) return null; if (normalized.length !== 2) return null;
return normalized.includes(ft); return normalized.includes(ft);
}; };
@@ -72,7 +91,8 @@ const oddEven: Resolver = (pick, r) => {
const total = r.scoreHome + r.scoreAway; const total = r.scoreHome + r.scoreAway;
const isOdd = total % 2 === 1; const isOdd = total % 2 === 1;
if (pick === "Tek" || pick.toLowerCase() === "odd") return isOdd; if (pick === "Tek" || pick.toLowerCase() === "odd") return isOdd;
if (pick === "Çift" || pick === "Cift" || pick.toLowerCase() === "even") return !isOdd; if (pick === "Çift" || pick === "Cift" || pick.toLowerCase() === "even")
return !isOdd;
return null; return null;
}; };
@@ -105,7 +125,7 @@ export function resolveOutcomeForPick(
pick: PickRef, pick: PickRef,
result: MatchResult, result: MatchResult,
): boolean | null { ): boolean | null {
const market = pick.market.toUpperCase().replace(/[\s\-]/g, "_"); const market = pick.market.toUpperCase().replace(/[\s-]/g, "_");
const resolver = resolvers[market] ?? resolvers[pick.market]; const resolver = resolvers[market] ?? resolvers[pick.market];
if (!resolver) return null; if (!resolver) return null;
try { try {
+3 -1
View File
@@ -145,7 +145,9 @@ export class PredictionSettlementTask {
return { return {
market: String(main.market), market: String(main.market),
pick: String(main.pick), pick: String(main.pick),
stake_units: Number(main.stake_units ?? advice.suggested_stake_units ?? 1), stake_units: Number(
main.stake_units ?? advice.suggested_stake_units ?? 1,
),
odds: Number(main.odds ?? 0) || null, odds: Number(main.odds ?? 0) || null,
}; };
} }