@smartico/public-api 0.0.288 → 0.0.290
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/Quiz/ScoreResultTypes.d.ts +1 -1
- package/dist/Tournaments/TournamentPlayer.d.ts +2 -0
- package/dist/Tournaments/TournamentUtils.d.ts +3 -0
- package/dist/WSAPI/WSAPITypes.d.ts +18 -0
- package/dist/index.js +19 -8
- package/dist/index.js.map +1 -1
- package/dist/index.modern.mjs +18 -9
- package/dist/index.modern.mjs.map +1 -1
- package/docs/interfaces/TTournament.md +3 -0
- package/docs/interfaces/TTournamentDetailed.md +4 -1
- package/package.json +1 -1
- package/src/Quiz/ScoreResultTypes.ts +1 -1
- package/src/SmarticoAPI.ts +15 -10
- package/src/Tournaments/TournamentPlayer.ts +2 -0
- package/src/Tournaments/TournamentUtils.ts +3 -0
- package/src/WSAPI/WSAPITypes.ts +18 -0
|
@@ -145,6 +145,9 @@ Info about current player in tournament
|
|
|
145
145
|
| `avatar_url` | `string` | The URL to the avatar of the participant |
|
|
146
146
|
| `position` | `number` | The position of the participant in the tournament |
|
|
147
147
|
| `scores` | `number` | The scores of the participant in the tournament |
|
|
148
|
+
| `user_ext_id` | `string` | The external user id of the participant |
|
|
149
|
+
| `crm_brand_id` | `number` | The crm brand id of the participant |
|
|
150
|
+
| `user_id` | `number` | The user id of the participant |
|
|
148
151
|
|
|
149
152
|
___
|
|
150
153
|
|
|
@@ -441,7 +441,7 @@ ___
|
|
|
441
441
|
|
|
442
442
|
### players
|
|
443
443
|
|
|
444
|
-
• `Optional` **players**: \{ `public_username`: `string` ; `avatar_url`: `string` ; `position`: `number` ; `scores`: `number` ; `is_me`: `boolean` }[]
|
|
444
|
+
• `Optional` **players**: \{ `public_username`: `string` ; `avatar_url`: `string` ; `position`: `number` ; `scores`: `number` ; `is_me`: `boolean` ; `user_ext_id`: `string` ; `crm_brand_id`: `number` ; `user_id`: `number` }[]
|
|
445
445
|
|
|
446
446
|
The list of the tournament participants
|
|
447
447
|
|
|
@@ -461,6 +461,9 @@ The information about current user in the tournament if he is registered in the
|
|
|
461
461
|
| `avatar_url` | `string` | The URL to the avatar of the current user |
|
|
462
462
|
| `position` | `number` | The position of the current user in the tournament |
|
|
463
463
|
| `scores` | `number` | The scores of the current user in the tournament |
|
|
464
|
+
| `user_ext_id` | `string` | The external user id of the current user |
|
|
465
|
+
| `crm_brand_id` | `number` | The crm brand id of the current user |
|
|
466
|
+
| `user_id` | `number` | The user id of the current user |
|
|
464
467
|
|
|
465
468
|
#### Overrides
|
|
466
469
|
|
package/package.json
CHANGED
package/src/SmarticoAPI.ts
CHANGED
|
@@ -1034,27 +1034,32 @@ class SmarticoAPI {
|
|
|
1034
1034
|
const userInfo = await this.getUserGamificationInfo(user_ext_id);
|
|
1035
1035
|
if (!levels || levels.length === 0) return null;
|
|
1036
1036
|
|
|
1037
|
-
const
|
|
1037
|
+
const sortedLevels = [...levels].sort((a, b) => a.required_points - b.required_points);
|
|
1038
1038
|
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
let currentLevelIndex = sortedLevels.findIndex((level, index) => {
|
|
1042
|
-
const nextLevel = sortedLevels[index + 1];
|
|
1043
|
-
return userPoints >= level.required_points && (!nextLevel || userPoints < nextLevel.required_points);
|
|
1044
|
-
});
|
|
1039
|
+
let currentLevelIndex = sortedLevels.findIndex((level) => level.id === userInfo.current_level);
|
|
1045
1040
|
|
|
1046
1041
|
if (currentLevelIndex === -1) {
|
|
1047
|
-
|
|
1042
|
+
const userPointsEver = userInfo.points_ever ?? 0;
|
|
1043
|
+
currentLevelIndex = sortedLevels.findIndex((level, index) => {
|
|
1044
|
+
const nextLevel = sortedLevels[index + 1];
|
|
1045
|
+
return userPointsEver >= level.required_points && (!nextLevel || userPointsEver < nextLevel.required_points);
|
|
1046
|
+
});
|
|
1047
|
+
if (currentLevelIndex === -1) {
|
|
1048
|
+
currentLevelIndex = sortedLevels.length - 1;
|
|
1049
|
+
}
|
|
1048
1050
|
}
|
|
1049
1051
|
|
|
1050
1052
|
const currentLevel = sortedLevels[currentLevelIndex];
|
|
1051
1053
|
const nextLevel = sortedLevels[currentLevelIndex + 1];
|
|
1052
|
-
const
|
|
1054
|
+
const userPointsEver = userInfo.points_ever ?? 0;
|
|
1055
|
+
const progress = nextLevel
|
|
1056
|
+
? ((userPointsEver - currentLevel.required_points) / (nextLevel.required_points - currentLevel.required_points)) * 100
|
|
1057
|
+
: 100;
|
|
1053
1058
|
|
|
1054
1059
|
return {
|
|
1055
1060
|
...currentLevel,
|
|
1056
1061
|
ordinal_position: currentLevelIndex + 1,
|
|
1057
|
-
progress: Math.min(Math.max(progress, 0), 100)
|
|
1062
|
+
progress: Math.min(Math.max(progress, 0), 100),
|
|
1058
1063
|
};
|
|
1059
1064
|
}
|
|
1060
1065
|
|
package/src/WSAPI/WSAPITypes.ts
CHANGED
|
@@ -331,6 +331,12 @@ export interface TTournament {
|
|
|
331
331
|
position: number;
|
|
332
332
|
/** The scores of the participant in the tournament */
|
|
333
333
|
scores: number;
|
|
334
|
+
/** The external user id of the participant */
|
|
335
|
+
user_ext_id: string;
|
|
336
|
+
/** The crm brand id of the participant */
|
|
337
|
+
crm_brand_id: number;
|
|
338
|
+
/** The user id of the participant */
|
|
339
|
+
user_id: number;
|
|
334
340
|
};
|
|
335
341
|
/** Prize structure */
|
|
336
342
|
prizes?: {
|
|
@@ -412,6 +418,12 @@ export interface TTournamentDetailed extends TTournament {
|
|
|
412
418
|
scores: number;
|
|
413
419
|
/** The indicator if the participant is current user */
|
|
414
420
|
is_me: boolean;
|
|
421
|
+
/** The external user id of the participant */
|
|
422
|
+
user_ext_id: string;
|
|
423
|
+
/** The crm brand id of the participant */
|
|
424
|
+
crm_brand_id: number;
|
|
425
|
+
/** The user id of the participant */
|
|
426
|
+
user_id: number;
|
|
415
427
|
}[];
|
|
416
428
|
/** The information about current user in the tournament if he is registered in the tournamnet */
|
|
417
429
|
me?: {
|
|
@@ -423,6 +435,12 @@ export interface TTournamentDetailed extends TTournament {
|
|
|
423
435
|
position: number;
|
|
424
436
|
/** The scores of the current user in the tournament */
|
|
425
437
|
scores: number;
|
|
438
|
+
/** The external user id of the current user */
|
|
439
|
+
user_ext_id: string;
|
|
440
|
+
/** The crm brand id of the current user */
|
|
441
|
+
crm_brand_id: number;
|
|
442
|
+
/** The user id of the current user */
|
|
443
|
+
user_id: number;
|
|
426
444
|
};
|
|
427
445
|
|
|
428
446
|
prizes?: {
|