• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

wger-project / react / 19962351311

05 Dec 2025 11:06AM UTC coverage: 75.031% (+0.005%) from 75.026%
19962351311

push

github

rolandgeider
Upgraded packages

1763 of 2672 branches covered (65.98%)

Branch coverage included in aggregate %.

5560 of 7088 relevant lines covered (78.44%)

28.05 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

50.94
/src/services/exerciseTranslation.ts
1
import axios from 'axios';
94✔
2
import { Exercise, ExerciseAdapter } from "components/Exercises/models/exercise";
94✔
3
import { Translation, TranslationAdapter } from "components/Exercises/models/translation";
94✔
4
import { ENGLISH_LANGUAGE_CODE, LANGUAGE_SHORT_ENGLISH } from "utils/consts";
94✔
5
import { makeHeader, makeUrl } from "utils/url";
94✔
6
import { ResponseType } from "./responseType";
7

8
export const EXERCISE_PATH = 'exercise';
94✔
9
export const EXERCISE_TRANSLATION_PATH = 'exercise-translation';
94✔
10

11

12
/*
13
 * Fetch all exercise translations for a given exercise base
14
 */
15
export const getExerciseTranslations = async (id: number): Promise<Translation[]> => {
94✔
16
    const url = makeUrl(EXERCISE_PATH, { query: { exercise: id } });
×
17
    const { data } = await axios.get<ResponseType<Translation>>(url, {
×
18
        headers: makeHeader(),
19
    });
20
    const adapter = new TranslationAdapter();
×
21
    return data.results.map(e => adapter.fromJson(e));
×
22
};
23

24

25
/*
26
 * Search for exercises by name using the exerciseinfo endpoint
27
 */
28
export const searchExerciseTranslations = async (name: string, languageCode: string = ENGLISH_LANGUAGE_CODE, searchEnglish: boolean = true): Promise<Exercise[]> => {
94!
29
    const languages = [languageCode];
×
30
    if (languageCode !== LANGUAGE_SHORT_ENGLISH && searchEnglish) {
×
31
        languages.push(LANGUAGE_SHORT_ENGLISH);
×
32
    }
33

34
    const url = makeUrl('exerciseinfo', {
×
35
        query: {
36
            "name__search": name,
37
            "language__code": languages.join(','),
38
            limit: 50,
39
        }
40
    });
41

42
    try {
×
43
        const { data } = await axios.get<ResponseType<Exercise>>(url);
×
44

45
        if (!data || !data.results || !Array.isArray(data.results)) {
×
46
            return [];
×
47
        }
48

49
        const adapter = new ExerciseAdapter();
×
50
        return data.results.map((item: unknown) => adapter.fromJson(item));
×
51
    } catch {
52
        return [];
×
53
    }
54
};
55

56

57
/*
58
 * Create a new exercise translation
59
 */
60
export interface AddTranslationParams {
61
    exerciseId: number;
62
    languageId: number;
63
    name: string;
64
    description: string;
65
    author: string;
66
}
67

68
export const addTranslation = async (params: AddTranslationParams): Promise<Translation> => {
94✔
69
    const { exerciseId, languageId, name, description, author } = params;
1✔
70

71
    const url = makeUrl(EXERCISE_TRANSLATION_PATH);
1✔
72
    const baseData = {
1✔
73
        exercise: exerciseId,
74
        language: languageId,
75
        name: name,
76
        description: description,
77
        // eslint-disable-next-line camelcase
78
        license_author: author
79
    };
80
    const response = await axios.post(url, baseData, {
1✔
81
        headers: makeHeader(),
82
    });
83

84
    const adapter = new TranslationAdapter();
1✔
85
    return adapter.fromJson(response.data);
1✔
86
};
87

88
/*
89
 * Edit an existing exercise translation
90
 */
91
export interface EditTranslationParams extends AddTranslationParams {
92
    id: number;
93
}
94

95
export const editTranslation = async (data: EditTranslationParams): Promise<Translation> => {
94✔
96
    const { id, exerciseId, languageId, name, description } = data;
1✔
97

98
    const url = makeUrl(EXERCISE_TRANSLATION_PATH, { id: id });
1✔
99
    const baseData = {
1✔
100
        exercise: exerciseId,
101
        language: languageId,
102
        name: name,
103
        description: description,
104
    };
105
    const response = await axios.patch(
1✔
106
        url,
107
        baseData,
108
        { headers: makeHeader() }
109
    );
110

111
    const adapter = new TranslationAdapter();
1✔
112
    return adapter.fromJson(response.data);
1✔
113
};
114

115
/*
116
 * Delete an existing exercise translation
117
 */
118
export const deleteExerciseTranslation = async (id: number): Promise<number> => {
94✔
119
    const url = makeUrl(EXERCISE_TRANSLATION_PATH, { id: id });
1✔
120
    const response = await axios.delete(
1✔
121
        url,
122
        { headers: makeHeader() }
123
    );
124

125
    return response.status;
1✔
126
};
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc