@time2win/t2w 2.0.5 → 2.1.0

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/CHANGELOG.md CHANGED
@@ -5,6 +5,10 @@ All notable changes to this project will be documented in this file.
5
5
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6
6
  and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
7
 
8
+ ## 2.1.0 - 2025-08-28
9
+ ### Added
10
+ getIndividualResult() to get a single individual result by signupId
11
+
8
12
  ## 2.0.5 - 2025-08-26
9
13
  ### Added
10
14
  page size option to participantInfo and individualResults methods
package/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { EventDataOptions, IndividualResultsOptions, ParticipantInfoOptions, T2WEvent, T2WEventResponse, T2WIndividualResultResponse, T2WParticipantResponse, T2WTeamResponse, T2WTeamResultsResponse, TeamResultOptions, TeamsWithMembersOptions } from './models';
1
+ import { EventDataOptions, IndividualResultOptions, IndividualResultsOptions, ParticipantInfoOptions, T2WEvent, T2WEventResponse, T2WIndividualResultResponse, T2WIndividualResultsResponse, T2WParticipantResponse, T2WTeamResponse, T2WTeamResultsResponse, TeamResultOptions, TeamsWithMembersOptions } from './models';
2
2
  export default class Time2WinAPI {
3
3
  private readonly apiUrl;
4
4
  private readonly _apiKey;
@@ -9,7 +9,8 @@ export default class Time2WinAPI {
9
9
  getEventDataWithCache(eventId: number, options?: EventDataOptions, maxAge?: number): Promise<T2WEvent>;
10
10
  getTeamResult(eventId: number, raceId: number, options?: TeamResultOptions, page?: number): Promise<T2WTeamResultsResponse>;
11
11
  getTeamsWithMembers(eventId: number, options?: TeamsWithMembersOptions, page?: number): Promise<T2WTeamResponse>;
12
- getIndividualResults(eventId: number, raceId: number, options?: IndividualResultsOptions, page?: number): Promise<T2WIndividualResultResponse>;
12
+ getIndividualResults(eventId: number, raceId: number, options?: IndividualResultsOptions, page?: number): Promise<T2WIndividualResultsResponse>;
13
+ getIndividualResult(eventId: number, raceId: number, signupId: number, options?: IndividualResultOptions): Promise<T2WIndividualResultResponse>;
13
14
  getParticipantInfos(eventId: number, options?: ParticipantInfoOptions, page?: number): Promise<T2WParticipantResponse>;
14
15
  /**
15
16
  * if no params are given, the events in the next seven days are returned
package/index.js CHANGED
@@ -259,6 +259,47 @@ var Time2WinAPI = /** @class */ (function () {
259
259
  });
260
260
  });
261
261
  };
262
+ Time2WinAPI.prototype.getIndividualResult = function (eventId, raceId, signupId, options) {
263
+ return __awaiter(this, void 0, void 0, function () {
264
+ var _this = this;
265
+ return __generator(this, function (_a) {
266
+ return [2 /*return*/, new Promise(function (resolve, reject) {
267
+ var _a;
268
+ var queryParams = {
269
+ 'race_id': raceId,
270
+ id: signupId,
271
+ 'data_extra': ((_a = options === null || options === void 0 ? void 0 : options.dataExtra) === null || _a === void 0 ? void 0 : _a.join(',')) || ''
272
+ };
273
+ fetch(_this.getUrl(_this.apiUrl, "results/".concat(eventId, "/individual"), queryParams))
274
+ .then(function (response) { return __awaiter(_this, void 0, void 0, function () {
275
+ var body, event;
276
+ var _this = this;
277
+ var _a;
278
+ return __generator(this, function (_b) {
279
+ switch (_b.label) {
280
+ case 0: return [4 /*yield*/, response.json()];
281
+ case 1:
282
+ body = _b.sent();
283
+ if (response.status === 403) {
284
+ reject(body);
285
+ return [2 /*return*/];
286
+ }
287
+ return [4 /*yield*/, this.getEventDataWithCache(eventId, { dataExtra: ['splits'] }, options === null || options === void 0 ? void 0 : options.maxEventAge)];
288
+ case 2:
289
+ event = _b.sent();
290
+ body.results = ((_a = body.results) === null || _a === void 0 ? void 0 : _a.map(function (p) {
291
+ return __assign(__assign({}, p), { birthdate: p.birthdate ? new Date(p.birthdate) : null, racenumNumeric: _this.getNumericBib(p.racenum), speedNetto: _this.calculateSpeed(p, event, 'speed', 'netto') + ' km/h', speedBrutto: _this.calculateSpeed(p, event, 'speed', 'brutto') + ' km/h', paceNetto: _this.calculateSpeed(p, event, 'pace', 'netto') + ' min/km', paceBrutto: _this.calculateSpeed(p, event, 'pace', 'brutto') + ' min/km' });
292
+ })) || [];
293
+ resolve(body);
294
+ return [2 /*return*/];
295
+ }
296
+ });
297
+ }); })
298
+ .catch(function (reason) { return reject(reason); });
299
+ })];
300
+ });
301
+ });
302
+ };
262
303
  Time2WinAPI.prototype.getParticipantInfos = function (eventId, options, page) {
263
304
  if (page === void 0) { page = 1; }
264
305
  return __awaiter(this, void 0, void 0, function () {
package/models.d.ts CHANGED
@@ -152,13 +152,16 @@ export interface T2WTeam {
152
152
  attr_2: string | null;
153
153
  members: T2WTeamMember[];
154
154
  }
155
- export interface T2WIndividualResultResponse {
155
+ export interface T2WIndividualResultsResponse {
156
156
  page_size: number;
157
157
  page: number;
158
158
  page_total: number;
159
159
  count_total: number;
160
160
  list: T2WIndividualResult[];
161
161
  }
162
+ export interface T2WIndividualResultResponse {
163
+ results: T2WIndividualResult[];
164
+ }
162
165
  export interface T2WIndividualResult extends T2WParticipantBasic {
163
166
  pos_overall: number;
164
167
  pos_gender: number;
@@ -284,6 +287,10 @@ export interface IndividualResultsOptions {
284
287
  maxEventAge?: number;
285
288
  pageSize?: number;
286
289
  }
290
+ export interface IndividualResultOptions {
291
+ dataExtra?: ('splits' | 'laps' | 'positions' | 'attributes')[];
292
+ maxEventAge?: number;
293
+ }
287
294
  export interface EventDataOptions {
288
295
  dataExtra?: ('prices' | 'splits' | 'categories' | 'attributes')[];
289
296
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@time2win/t2w",
3
- "version": "2.0.5",
3
+ "version": "2.1.0",
4
4
  "description": "providing latest-state models and advanced methods to interact with the T2W API",
5
5
  "keywords": [
6
6
  "time2win",
package/test.js CHANGED
@@ -8,6 +8,6 @@ var api = new index_1.default('09f006ca-23ee-44da-bec5-4372580f4113');
8
8
  // api.getIndividualResults(38, 161).then(res => {
9
9
  // console.log(res.list[0]);
10
10
  // });
11
- api.getEventDataWithCache(664, { dataExtra: ['splits'] }, 5).then(function (res) {
12
- console.log(res);
13
- }).catch(console.log);
11
+ // api.getEventDataWithCache(664, { dataExtra: [ 'splits'] }, 5).then(res => {
12
+ // console.log(res);
13
+ // }).catch(console.log);