Skip to content

Commit 9751f4f

Browse files
authored
Merge pull request #837 from Sim-sat/no-explicit-any-pages
fix(lint): fix remaining no-explicit-any errors
2 parents 547ad71 + b28ce7c commit 9751f4f

44 files changed

Lines changed: 799 additions & 892 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

SparkyFitnessFrontend/src/api/Auth/auth.ts

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,17 @@
11
import { authClient } from '@/lib/auth-client';
2-
import type { AccessibleUser, AuthResponse, LoginSettings } from '@/types/auth';
2+
import type {
3+
AccessibleUser,
4+
AuthResponse,
5+
BetterAuthUser,
6+
LoginSettings,
7+
} from '@/types/auth';
38
import { apiCall } from '../api';
49

510
interface AuthError extends Error {
611
code?: string;
712
status?: number;
813
}
914

10-
interface BetterAuthUser {
11-
id: string;
12-
email: string;
13-
name: string;
14-
role?: string;
15-
twoFactorEnabled?: boolean;
16-
mfaEmailEnabled?: boolean;
17-
}
18-
1915
interface BetterAuthResponse {
2016
user: BetterAuthUser;
2117
twoFactorRedirect?: boolean;

SparkyFitnessFrontend/src/api/Exercises/exerciseEntryService.ts

Lines changed: 6 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -4,40 +4,9 @@ import type { WorkoutPresetSet } from '@/types/workout';
44
import { debug } from '@/utils/logging';
55
import { getUserLoggingLevel } from '@/utils/userPreferences';
66
import type { ExerciseEntry } from '@/types/diary';
7-
import type { GroupedExerciseEntry } from '@/types/exercises';
7+
import type { GroupedExerciseEntry, LapDTO } from '@/types/exercises';
88
import type { ExerciseProgressData } from '@/types/reports';
9-
10-
interface RawActivityDetail {
11-
id?: string;
12-
detail_type: string;
13-
detail_data: unknown;
14-
provider_name?: string;
15-
}
16-
17-
interface RawExerciseSnapshot {
18-
equipment?: string;
19-
primary_muscles?: string;
20-
secondary_muscles?: string;
21-
instructions?: string;
22-
images?: string;
23-
[key: string]: unknown;
24-
}
25-
26-
interface RawExercise {
27-
sets?: string | unknown[];
28-
exercise_snapshot?: RawExerciseSnapshot;
29-
activity_details?: RawActivityDetail[];
30-
[key: string]: unknown;
31-
}
32-
33-
interface RawGroupedEntry {
34-
type?: string;
35-
exercises?: RawExercise[];
36-
sets?: string | unknown[];
37-
exercise_snapshot?: RawExerciseSnapshot;
38-
activity_details?: RawActivityDetail[];
39-
[key: string]: unknown;
40-
}
9+
import { ActivityDetailMetric } from '@/pages/Reports/ActivityReportVisualizer';
4110

4211
export const getExerciseEntriesForDate = async (
4312
date: string
@@ -83,7 +52,7 @@ export const fetchExerciseEntries = async (
8352
value:
8453
typeof detail.detail_data === 'object'
8554
? JSON.stringify(detail.detail_data, null, 2)
86-
: detail.detail_data,
55+
: String(detail.detail_data),
8756
provider_name: detail.provider_name,
8857
detail_type: detail.detail_type,
8958
}))
@@ -114,7 +83,7 @@ export const fetchExerciseEntries = async (
11483
value:
11584
typeof detail.detail_data === 'object'
11685
? JSON.stringify(detail.detail_data, null, 2)
117-
: detail.detail_data,
86+
: String(detail.detail_data),
11887
provider_name: detail.provider_name,
11988
detail_type: detail.detail_type,
12089
}))
@@ -327,15 +296,15 @@ export interface ActivityDetailsResponse {
327296
activity?: {
328297
details?: {
329298
metricDescriptors?: unknown[];
330-
activityDetailMetrics?: unknown[];
299+
activityDetailMetrics?: ActivityDetailMetric[];
331300
geoPolylineDTO?: {
332301
polyline: { lat: number; lon: number }[];
333302
};
334303
[key: string]: unknown;
335304
};
336305
hr_in_timezones?: unknown[];
337306
splits?: {
338-
lapDTOs: unknown[];
307+
lapDTOs: LapDTO[];
339308
[key: string]: unknown;
340309
};
341310
activity?: {

SparkyFitnessFrontend/src/api/Foods/usda.ts

Lines changed: 7 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -1,82 +1,11 @@
11
import { apiCall } from '@/api/api';
2+
import {
3+
RawUsdaNutrient,
4+
UsdaFoodDetails,
5+
UsdaFoodSearchItem,
6+
UsdaNutrientMap,
7+
} from '@/types/exercises';
28

3-
interface UsdaFoodSearchItem {
4-
fdcId: number;
5-
description: string;
6-
brandOwner?: string;
7-
dataType: string;
8-
foodCategory: string;
9-
publicationDate: string;
10-
foodNutrients: UsdaFoodNutrient[];
11-
servingSize?: number;
12-
servingSizeUnit?: string;
13-
}
14-
15-
interface UsdaFoodNutrient {
16-
nutrientId: number;
17-
nutrientName: string;
18-
nutrientNumber: string;
19-
unitName: string;
20-
value: number;
21-
}
22-
23-
interface UsdaFoodDetails {
24-
fdcId: number;
25-
description: string;
26-
brandOwner?: string;
27-
servingSize?: number;
28-
servingSizeUnit?: string;
29-
calories: number;
30-
protein: number;
31-
fat: number;
32-
carbohydrates: number;
33-
sugars?: number;
34-
fiber?: number;
35-
sodium?: number;
36-
cholesterol?: number;
37-
saturatedFat?: number;
38-
transFat?: number;
39-
monounsaturatedFat?: number;
40-
polyunsaturatedFat?: number;
41-
potassium?: number;
42-
vitaminA?: number;
43-
vitaminC?: number;
44-
calcium?: number;
45-
iron?: number;
46-
}
47-
48-
interface RawUsdaNutrient {
49-
nutrient?: {
50-
id?: number;
51-
name?: string;
52-
unitName?: string;
53-
};
54-
nutrientName?: string;
55-
nutrientId?: number;
56-
unitName?: string;
57-
amount?: number;
58-
value?: number;
59-
}
60-
61-
interface NutrientMap {
62-
calories?: number;
63-
protein?: number;
64-
fat?: number;
65-
carbohydrates?: number;
66-
sugars?: number;
67-
fiber?: number;
68-
sodium?: number;
69-
cholesterol?: number;
70-
saturatedFat?: number;
71-
transFat?: number;
72-
monounsaturatedFat?: number;
73-
polyunsaturatedFat?: number;
74-
potassium?: number;
75-
vitaminA?: number;
76-
vitaminC?: number;
77-
calcium?: number;
78-
iron?: number;
79-
}
809
export const searchUsdaFoods = async (
8110
query: string,
8211
providerId: string,
@@ -107,7 +36,7 @@ export const getUsdaFoodDetails = async (
10736

10837
if (!response) return null;
10938

110-
const nutrientMap: NutrientMap = {};
39+
const nutrientMap: UsdaNutrientMap = {};
11140
if (response.foodNutrients) {
11241
response.foodNutrients.forEach((n: RawUsdaNutrient) => {
11342
// USDA returns various spellings, try to normalize or check multiple

SparkyFitnessFrontend/src/api/api.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@ interface ApiCallOptions extends RequestInit {
1616
export const API_BASE_URL = '/api';
1717
//export const API_BASE_URL = 'http://192.168.1.111:3010';
1818

19-
export async function apiCall(
19+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
20+
export async function apiCall<T = any>(
2021
endpoint: string,
2122
options?: ApiCallOptions
22-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
23-
): Promise<any> {
23+
): Promise<T> {
2424
const userLoggingLevel = getUserLoggingLevel();
2525
let url = options?.externalApi ? endpoint : `${API_BASE_URL}${endpoint}`;
2626

@@ -118,7 +118,7 @@ export async function apiCall(
118118
userLoggingLevel,
119119
`Frontend workaround triggered for ${endpoint}: Backend returned 400. Returning empty array.`
120120
);
121-
return []; // Return empty array to gracefully handle 400 errors on these endpoints
121+
return [] as unknown as T; // Return empty array to gracefully handle 400 errors on these endpoints
122122
}
123123

124124
// Special handling for 404 errors on exercise search endpoints
@@ -130,7 +130,7 @@ export async function apiCall(
130130
userLoggingLevel,
131131
`Frontend workaround triggered for ${endpoint}: Backend returned 404. Returning empty array.`
132132
);
133-
return []; // Return empty array to gracefully handle 404 errors on exercise search
133+
return [] as unknown as T; // Return empty array to gracefully handle 404 errors on exercise search
134134
}
135135

136136
// Suppress toast for 404 errors if suppress404Toast is true
@@ -163,7 +163,7 @@ export async function apiCall(
163163
userLoggingLevel,
164164
`API Call: Received blob response from ${url}.`
165165
);
166-
return blobResponse;
166+
return blobResponse as unknown as T;
167167
}
168168
// Handle cases where the response might be empty (e.g., DELETE requests)
169169
const text = await response.text();

SparkyFitnessFrontend/src/components/FoodSearch/FoodSearch.tsx

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ import {
4949
convertNutritionixToFood,
5050
convertOpenFoodFactsToFood,
5151
convertUsdaToFood,
52+
mapUsdaItemToDetails,
5253
} from '@/utils/foodSearch.ts';
5354
import FoodResultCard from './FoodResultCard.tsx';
5455
import { BarcodeScannerDialog } from './BarcodeScannerDialog.tsx';
@@ -116,7 +117,7 @@ export interface NutritionixItem {
116117
glycemic_index?: GlycemicIndex;
117118
}
118119

119-
interface UsdaItem {
120+
export interface UsdaItem {
120121
fdcId: number;
121122
description: string;
122123
brandOwner?: string;
@@ -157,6 +158,7 @@ const EnhancedFoodSearch = ({
157158
convertEnergy,
158159
getEnergyUnitString,
159160
autoScaleOpenFoodFactsImports,
161+
loggingLevel,
160162
} = usePreferences();
161163
const isMobile = useIsMobile();
162164
const platform = isMobile ? 'mobile' : 'desktop';
@@ -354,7 +356,7 @@ const EnhancedFoodSearch = ({
354356
data.map((item) => ({
355357
provider_type: 'fatsecret',
356358
raw: item,
357-
food: convertFatSecretToFood(item, item),
359+
food: convertFatSecretToFood(item),
358360
}))
359361
);
360362
},
@@ -366,7 +368,10 @@ const EnhancedFoodSearch = ({
366368
data.map((item) => ({
367369
provider_type: 'usda',
368370
raw: item,
369-
food: convertUsdaToFood(item, item),
371+
food: convertUsdaToFood(
372+
item,
373+
mapUsdaItemToDetails(item, loggingLevel)
374+
),
370375
}))
371376
);
372377
},

SparkyFitnessFrontend/src/components/Onboarding/NutrientGoals.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -519,7 +519,7 @@ export const NutrientGoals = ({
519519
<Input
520520
type="number"
521521
step={0.1}
522-
value={(editedPlan?.[cn.name] ?? 0).toFixed(1)}
522+
value={Number(editedPlan?.[cn.name] ?? 0).toFixed(1)}
523523
onChange={(e) =>
524524
setEditedPlan((prev) =>
525525
prev

SparkyFitnessFrontend/src/hooks/Admin/useBackups.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,27 +27,42 @@ export const useBackupSettings = () => {
2727

2828
export const useUpdateBackupSettings = () => {
2929
const queryClient = useQueryClient();
30+
const { t } = useTranslation();
3031
return useMutation({
3132
mutationFn: (data: Partial<BackupSettingsResponse>) =>
3233
saveBackupSettings(data),
3334
onSuccess: () => {
3435
return queryClient.invalidateQueries({ queryKey: backupKeys.all });
3536
},
37+
meta: {
38+
successMessage: t('admin.backupSettings.backupSettingsSaved', 'Saved'),
39+
errorMessage: t('error', 'Error'),
40+
},
3641
});
3742
};
3843

3944
export const useTriggerManualBackup = () => {
4045
const queryClient = useQueryClient();
46+
4147
return useMutation({
4248
mutationFn: triggerManualBackup,
4349
onSuccess: () => {
4450
return queryClient.invalidateQueries({ queryKey: backupKeys.all });
4551
},
52+
meta: {
53+
successMessage: (_data, variables) => {
54+
const typedVars = variables as { message: string };
55+
return typedVars.message ? typedVars.message : 'Backup done';
56+
},
57+
},
4658
});
4759
};
4860

4961
export const useRestoreBackup = () => {
5062
return useMutation({
5163
mutationFn: restoreBackup,
64+
meta: {
65+
successMessage: 'Restored. Logging out..',
66+
},
5267
});
5368
};

0 commit comments

Comments
 (0)