@rimori/client 2.3.0-next.2 → 2.3.0-next.4
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.
- package/dist/controller/ExerciseController.d.ts +6 -4
- package/dist/controller/ExerciseController.js +21 -17
- package/dist/plugin/RimoriClient.d.ts +5 -4
- package/dist/plugin/RimoriClient.js +6 -4
- package/package.json +1 -1
- package/src/controller/ExerciseController.ts +26 -17
- package/src/plugin/RimoriClient.ts +7 -5
|
@@ -11,6 +11,7 @@ export interface CreateExerciseParams {
|
|
|
11
11
|
name: string;
|
|
12
12
|
description: string;
|
|
13
13
|
estimated_duration: number;
|
|
14
|
+
topics: string[];
|
|
14
15
|
}
|
|
15
16
|
export interface Exercise {
|
|
16
17
|
id: string;
|
|
@@ -35,13 +36,14 @@ export declare class ExerciseController {
|
|
|
35
36
|
*/
|
|
36
37
|
viewWeeklyExercises(): Promise<Exercise[]>;
|
|
37
38
|
/**
|
|
38
|
-
* Creates
|
|
39
|
+
* Creates multiple exercises via the backend API.
|
|
40
|
+
* All requests are made in parallel but only one event is emitted.
|
|
39
41
|
* @param token The token to use for authentication.
|
|
40
42
|
* @param backendUrl The URL of the backend API.
|
|
41
|
-
* @param
|
|
42
|
-
* @returns Created exercise
|
|
43
|
+
* @param exercises Exercise creation parameters.
|
|
44
|
+
* @returns Created exercise objects.
|
|
43
45
|
*/
|
|
44
|
-
addExercise(token: string, backendUrl: string,
|
|
46
|
+
addExercise(token: string, backendUrl: string, exercises: CreateExerciseParams[]): Promise<Exercise[]>;
|
|
45
47
|
/**
|
|
46
48
|
* Deletes an exercise via the backend API.
|
|
47
49
|
* @param token The token to use for authentication.
|
|
@@ -27,28 +27,32 @@ export class ExerciseController {
|
|
|
27
27
|
});
|
|
28
28
|
}
|
|
29
29
|
/**
|
|
30
|
-
* Creates
|
|
30
|
+
* Creates multiple exercises via the backend API.
|
|
31
|
+
* All requests are made in parallel but only one event is emitted.
|
|
31
32
|
* @param token The token to use for authentication.
|
|
32
33
|
* @param backendUrl The URL of the backend API.
|
|
33
|
-
* @param
|
|
34
|
-
* @returns Created exercise
|
|
34
|
+
* @param exercises Exercise creation parameters.
|
|
35
|
+
* @returns Created exercise objects.
|
|
35
36
|
*/
|
|
36
|
-
addExercise(token, backendUrl,
|
|
37
|
+
addExercise(token, backendUrl, exercises) {
|
|
37
38
|
return __awaiter(this, void 0, void 0, function* () {
|
|
38
|
-
const
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
39
|
+
const responses = yield Promise.all(exercises.map((exercise) => __awaiter(this, void 0, void 0, function* () {
|
|
40
|
+
const response = yield fetch(`${backendUrl}/exercises`, {
|
|
41
|
+
method: 'POST',
|
|
42
|
+
headers: {
|
|
43
|
+
'Content-Type': 'application/json',
|
|
44
|
+
Authorization: `Bearer ${token}`,
|
|
45
|
+
},
|
|
46
|
+
body: JSON.stringify(exercise),
|
|
47
|
+
});
|
|
48
|
+
if (!response.ok) {
|
|
49
|
+
const errorText = yield response.text();
|
|
50
|
+
throw new Error(`Failed to create exercise: ${errorText}`);
|
|
51
|
+
}
|
|
52
|
+
return yield response.json();
|
|
53
|
+
})));
|
|
50
54
|
this.rimoriClient.event.emit('global.exercises.triggerChange');
|
|
51
|
-
return
|
|
55
|
+
return responses;
|
|
52
56
|
});
|
|
53
57
|
}
|
|
54
58
|
/**
|
|
@@ -253,11 +253,12 @@ export declare class RimoriClient {
|
|
|
253
253
|
*/
|
|
254
254
|
view: () => Promise<import("../controller/ExerciseController").Exercise[]>;
|
|
255
255
|
/**
|
|
256
|
-
* Creates a new exercise via the backend API.
|
|
257
|
-
*
|
|
258
|
-
* @
|
|
256
|
+
* Creates a new exercise or multiple exercises via the backend API.
|
|
257
|
+
* When creating multiple exercises, all requests are made in parallel but only one event is emitted.
|
|
258
|
+
* @param params Exercise creation parameters (single or array).
|
|
259
|
+
* @returns Created exercise objects.
|
|
259
260
|
*/
|
|
260
|
-
add: (params: CreateExerciseParams) => Promise<import("../controller/ExerciseController").Exercise>;
|
|
261
|
+
add: (params: CreateExerciseParams | CreateExerciseParams[]) => Promise<import("../controller/ExerciseController").Exercise[]>;
|
|
261
262
|
/**
|
|
262
263
|
* Deletes an exercise via the backend API.
|
|
263
264
|
* @param id The exercise ID to delete.
|
|
@@ -250,14 +250,16 @@ export class RimoriClient {
|
|
|
250
250
|
return this.exerciseController.viewWeeklyExercises();
|
|
251
251
|
}),
|
|
252
252
|
/**
|
|
253
|
-
* Creates a new exercise via the backend API.
|
|
254
|
-
*
|
|
255
|
-
* @
|
|
253
|
+
* Creates a new exercise or multiple exercises via the backend API.
|
|
254
|
+
* When creating multiple exercises, all requests are made in parallel but only one event is emitted.
|
|
255
|
+
* @param params Exercise creation parameters (single or array).
|
|
256
|
+
* @returns Created exercise objects.
|
|
256
257
|
*/
|
|
257
258
|
add: (params) => __awaiter(this, void 0, void 0, function* () {
|
|
258
259
|
const token = yield this.pluginController.getToken();
|
|
259
260
|
const backendUrl = this.pluginController.getBackendUrl();
|
|
260
|
-
|
|
261
|
+
const exercises = Array.isArray(params) ? params : [params];
|
|
262
|
+
return this.exerciseController.addExercise(token, backendUrl, exercises);
|
|
261
263
|
}),
|
|
262
264
|
/**
|
|
263
265
|
* Deletes an exercise via the backend API.
|
package/package.json
CHANGED
|
@@ -11,6 +11,7 @@ export interface CreateExerciseParams {
|
|
|
11
11
|
name: string;
|
|
12
12
|
description: string;
|
|
13
13
|
estimated_duration: number;
|
|
14
|
+
topics: string[]; // Required: Array of topics in format "skillCategory.accomplishmentKeyword" for matching accomplishments
|
|
14
15
|
}
|
|
15
16
|
|
|
16
17
|
export interface Exercise {
|
|
@@ -51,29 +52,37 @@ export class ExerciseController {
|
|
|
51
52
|
}
|
|
52
53
|
|
|
53
54
|
/**
|
|
54
|
-
* Creates
|
|
55
|
+
* Creates multiple exercises via the backend API.
|
|
56
|
+
* All requests are made in parallel but only one event is emitted.
|
|
55
57
|
* @param token The token to use for authentication.
|
|
56
58
|
* @param backendUrl The URL of the backend API.
|
|
57
|
-
* @param
|
|
58
|
-
* @returns Created exercise
|
|
59
|
+
* @param exercises Exercise creation parameters.
|
|
60
|
+
* @returns Created exercise objects.
|
|
59
61
|
*/
|
|
60
|
-
public async addExercise(token: string, backendUrl: string,
|
|
61
|
-
const
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
62
|
+
public async addExercise(token: string, backendUrl: string, exercises: CreateExerciseParams[]): Promise<Exercise[]> {
|
|
63
|
+
const responses = await Promise.all(
|
|
64
|
+
exercises.map(async (exercise) => {
|
|
65
|
+
const response = await fetch(`${backendUrl}/exercises`, {
|
|
66
|
+
method: 'POST',
|
|
67
|
+
headers: {
|
|
68
|
+
'Content-Type': 'application/json',
|
|
69
|
+
Authorization: `Bearer ${token}`,
|
|
70
|
+
},
|
|
71
|
+
body: JSON.stringify(exercise),
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
if (!response.ok) {
|
|
75
|
+
const errorText = await response.text();
|
|
76
|
+
throw new Error(`Failed to create exercise: ${errorText}`);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
return await response.json();
|
|
80
|
+
}),
|
|
81
|
+
);
|
|
69
82
|
|
|
70
|
-
if (!response.ok) {
|
|
71
|
-
const errorText = await response.text();
|
|
72
|
-
throw new Error(`Failed to create exercise: ${errorText}`);
|
|
73
|
-
}
|
|
74
83
|
this.rimoriClient.event.emit('global.exercises.triggerChange');
|
|
75
84
|
|
|
76
|
-
return
|
|
85
|
+
return responses;
|
|
77
86
|
}
|
|
78
87
|
|
|
79
88
|
/**
|
|
@@ -475,14 +475,16 @@ export class RimoriClient {
|
|
|
475
475
|
},
|
|
476
476
|
|
|
477
477
|
/**
|
|
478
|
-
* Creates a new exercise via the backend API.
|
|
479
|
-
*
|
|
480
|
-
* @
|
|
478
|
+
* Creates a new exercise or multiple exercises via the backend API.
|
|
479
|
+
* When creating multiple exercises, all requests are made in parallel but only one event is emitted.
|
|
480
|
+
* @param params Exercise creation parameters (single or array).
|
|
481
|
+
* @returns Created exercise objects.
|
|
481
482
|
*/
|
|
482
|
-
add: async (params: CreateExerciseParams) => {
|
|
483
|
+
add: async (params: CreateExerciseParams | CreateExerciseParams[]) => {
|
|
483
484
|
const token = await this.pluginController.getToken();
|
|
484
485
|
const backendUrl = this.pluginController.getBackendUrl();
|
|
485
|
-
|
|
486
|
+
const exercises = Array.isArray(params) ? params : [params];
|
|
487
|
+
return this.exerciseController.addExercise(token, backendUrl, exercises);
|
|
486
488
|
},
|
|
487
489
|
|
|
488
490
|
/**
|