From 4229a050060661b1b912820e69b5647a4a530205 Mon Sep 17 00:00:00 2001 From: marcin2121 <13873718+marcin2121@users.noreply.github.com> Date: Tue, 31 Mar 2026 20:40:37 +0000 Subject: [PATCH] Refactor: Remove `any` type in array operations within `spin-wheel.ts` - Defined `UserCoupon` and `WheelPrize` interfaces mirroring the schema retrieved from the database. - Substituted `any` parameter types with these specific interfaces inside `filter()`, `map()`, and `reduce()` callback functions. - Addressed `@typescript-eslint/no-explicit-any` ESLint warning. Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com> --- app/actions/spin-wheel.ts | 22 ++++++++++++++++---- package-lock.json | 42 +++++++++++++++++++-------------------- package.json | 2 +- 3 files changed, 40 insertions(+), 26 deletions(-) diff --git a/app/actions/spin-wheel.ts b/app/actions/spin-wheel.ts index ef2d6ad..ce8af42 100644 --- a/app/actions/spin-wheel.ts +++ b/app/actions/spin-wheel.ts @@ -3,6 +3,20 @@ import { createClient } from '@/lib/supabase/server' import { revalidatePath } from 'next/cache' +interface UserCoupon { + title: string; + current_usage: number | null; + usage_limit: number | null; +} + +interface WheelPrize { + title: string; + chance: number | string; + code_prefix: string; + description: string | null; + gradient: string | null; +} + export async function spinWheel() { const supabase = await createClient() if (!supabase) return { error: 'Usługa tymczasowo niedostępna.' } @@ -47,18 +61,18 @@ export async function spinWheel() { .eq('user_id', user.id) .eq('is_active', true) - const unspentCoupons = userCurrentCoupons?.filter((c: any) => (c.current_usage || 0) < (c.usage_limit || 1)) || []; - const usedTitles = unspentCoupons.map((c: any) => c.title); + const unspentCoupons = userCurrentCoupons?.filter((c: UserCoupon) => (c.current_usage || 0) < (c.usage_limit || 1)) || []; + const usedTitles = unspentCoupons.map((c: UserCoupon) => c.title); // Filtrujemy nagrody - const availablePrizes = prizes.filter((p: any) => !usedTitles.includes(p.title)); + const availablePrizes = prizes.filter((p: WheelPrize) => !usedTitles.includes(p.title)); if (availablePrizes.length === 0) { return { error: 'Posiadasz już wszystkie rabaty! Zużyj przynajmniej jeden z nich pod kasą, by zwolnić miejsce.' } } // 4. ALGORYTM LOSOWANIA (Ważony) z puli tylko dostępnych nagród - const totalWeight = availablePrizes.reduce((sum: number, p: any) => sum + Number(p.chance), 0) + const totalWeight = availablePrizes.reduce((sum: number, p: WheelPrize) => sum + Number(p.chance), 0) let randomNum = Math.random() * totalWeight let winningPrize = availablePrizes[0] diff --git a/package-lock.json b/package-lock.json index 433dffd..24527b2 100644 --- a/package-lock.json +++ b/package-lock.json @@ -71,7 +71,7 @@ "@types/three": "^0.182.0", "@types/web-push": "^3.6.4", "esbuild": "^0.27.4", - "eslint": "^9", + "eslint": "^9.39.4", "eslint-config-next": "16.1.6", "serwist": "^9.5.7", "shadcn": "^3.8.4", @@ -1383,15 +1383,15 @@ } }, "node_modules/@eslint/config-array": { - "version": "0.21.1", - "resolved": "https://registry.npmjs.org/@eslint/config-array/-/config-array-0.21.1.tgz", - "integrity": "sha512-aw1gNayWpdI/jSYVgzN5pL0cfzU02GT3NBpeT/DXbx1/1x7ZKxFPd9bwrzygx/qiwIQiJ1sw/zD8qY/kRvlGHA==", + "version": "0.21.2", + "resolved": "https://registry.npmjs.org/@eslint/config-array/-/config-array-0.21.2.tgz", + "integrity": "sha512-nJl2KGTlrf9GjLimgIru+V/mzgSK0ABCDQRvxw5BjURL7WfH5uoWmizbH7QB6MmnMBd8cIC9uceWnezL1VZWWw==", "dev": true, "license": "Apache-2.0", "dependencies": { "@eslint/object-schema": "^2.1.7", "debug": "^4.3.1", - "minimatch": "^3.1.2" + "minimatch": "^3.1.5" }, "engines": { "node": "^18.18.0 || ^20.9.0 || >=21.1.0" @@ -1424,20 +1424,20 @@ } }, "node_modules/@eslint/eslintrc": { - "version": "3.3.3", - "resolved": "https://registry.npmjs.org/@eslint/eslintrc/-/eslintrc-3.3.3.tgz", - "integrity": "sha512-Kr+LPIUVKz2qkx1HAMH8q1q6azbqBAsXJUxBl/ODDuVPX45Z9DfwB8tPjTi6nNZ8BuM3nbJxC5zCAg5elnBUTQ==", + "version": "3.3.5", + "resolved": "https://registry.npmjs.org/@eslint/eslintrc/-/eslintrc-3.3.5.tgz", + "integrity": "sha512-4IlJx0X0qftVsN5E+/vGujTRIFtwuLbNsVUe7TO6zYPDR1O6nFwvwhIKEKSrl6dZchmYBITazxKoUYOjdtjlRg==", "dev": true, "license": "MIT", "dependencies": { - "ajv": "^6.12.4", + "ajv": "^6.14.0", "debug": "^4.3.2", "espree": "^10.0.1", "globals": "^14.0.0", "ignore": "^5.2.0", "import-fresh": "^3.2.1", "js-yaml": "^4.1.1", - "minimatch": "^3.1.2", + "minimatch": "^3.1.5", "strip-json-comments": "^3.1.1" }, "engines": { @@ -1448,9 +1448,9 @@ } }, "node_modules/@eslint/js": { - "version": "9.39.2", - "resolved": "https://registry.npmjs.org/@eslint/js/-/js-9.39.2.tgz", - "integrity": "sha512-q1mjIoW1VX4IvSocvM/vbTiveKC4k9eLrajNEuSsmjymSDEbpGddtpfOoN7YGAqBK3NG+uqo8ia4PDTt8buCYA==", + "version": "9.39.4", + "resolved": "https://registry.npmjs.org/@eslint/js/-/js-9.39.4.tgz", + "integrity": "sha512-nE7DEIchvtiFTwBw4Lfbu59PG+kCofhjsKaCWzxTpt4lfRjRMqG6uMBzKXuEcyXhOHoUp9riAm7/aWYGhXZ9cw==", "dev": true, "license": "MIT", "engines": { @@ -8821,25 +8821,25 @@ } }, "node_modules/eslint": { - "version": "9.39.2", - "resolved": "https://registry.npmjs.org/eslint/-/eslint-9.39.2.tgz", - "integrity": "sha512-LEyamqS7W5HB3ujJyvi0HQK/dtVINZvd5mAAp9eT5S/ujByGjiZLCzPcHVzuXbpJDJF/cxwHlfceVUDZ2lnSTw==", + "version": "9.39.4", + "resolved": "https://registry.npmjs.org/eslint/-/eslint-9.39.4.tgz", + "integrity": "sha512-XoMjdBOwe/esVgEvLmNsD3IRHkm7fbKIUGvrleloJXUZgDHig2IPWNniv+GwjyJXzuNqVjlr5+4yVUZjycJwfQ==", "dev": true, "license": "MIT", "dependencies": { "@eslint-community/eslint-utils": "^4.8.0", "@eslint-community/regexpp": "^4.12.1", - "@eslint/config-array": "^0.21.1", + "@eslint/config-array": "^0.21.2", "@eslint/config-helpers": "^0.4.2", "@eslint/core": "^0.17.0", - "@eslint/eslintrc": "^3.3.1", - "@eslint/js": "9.39.2", + "@eslint/eslintrc": "^3.3.5", + "@eslint/js": "9.39.4", "@eslint/plugin-kit": "^0.4.1", "@humanfs/node": "^0.16.6", "@humanwhocodes/module-importer": "^1.0.1", "@humanwhocodes/retry": "^0.4.2", "@types/estree": "^1.0.6", - "ajv": "^6.12.4", + "ajv": "^6.14.0", "chalk": "^4.0.0", "cross-spawn": "^7.0.6", "debug": "^4.3.2", @@ -8858,7 +8858,7 @@ "is-glob": "^4.0.0", "json-stable-stringify-without-jsonify": "^1.0.1", "lodash.merge": "^4.6.2", - "minimatch": "^3.1.2", + "minimatch": "^3.1.5", "natural-compare": "^1.4.0", "optionator": "^0.9.3" }, diff --git a/package.json b/package.json index 2ae4b5a..35ebe2a 100644 --- a/package.json +++ b/package.json @@ -72,7 +72,7 @@ "@types/three": "^0.182.0", "@types/web-push": "^3.6.4", "esbuild": "^0.27.4", - "eslint": "^9", + "eslint": "^9.39.4", "eslint-config-next": "16.1.6", "serwist": "^9.5.7", "shadcn": "^3.8.4",