From bec891725e292692c0c1a3f7af1d1b0a34ba08ab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl?= <41128238+raphckrman@users.noreply.github.com> Date: Thu, 7 Mar 2024 15:12:10 +0100 Subject: [PATCH] Major Change on Bookins --- lib/routes/User.ts | 25 +++++++++++++++++++++---- package.json | 2 +- 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/lib/routes/User.ts b/lib/routes/User.ts index 0403ea0..5e5e95a 100644 --- a/lib/routes/User.ts +++ b/lib/routes/User.ts @@ -136,7 +136,7 @@ export class User { * @param token The token of the user. * @param week The week number to get. */ - async getBookings(hoteId: number, token: string, week?: number): Promise { + async getBookings(hoteId: number, token: string, week?: number): Promise { return this.#manager.makeAuthRequest({ method: "GET", url: endpoints.BOOKINGS(hoteId) + (week ? `?num=${week}` : ""), @@ -144,8 +144,7 @@ export class User { "Authorization": "Bearer " + token } }).then((data: unknown) => { - let typedData = data as bookingResponse; - return typedData.rsvWebDto; + return data as bookingResponse; }); } @@ -192,7 +191,7 @@ export class User { * @param bookEvening If the evening should be booked. */ async bookDay(hoteId: number, token: string, state: number, weekNumber?: number, dayOfWeek?: number, bookEvening?: boolean ): Promise { - const weekId: string = await this.getBookings(hoteId, token, weekNumber).then((data) => data[0]?.id) ?? await this.getBookings(hoteId, token).then((data) => data[0]?.id); + const weekId: string = await this.getBookings(hoteId, token, weekNumber).then((data) => data.rsvWebDto[0]?.id) ?? await this.getBookings(hoteId, token).then((data) => data.rsvWebDto[0]?.id); return this.#manager.makeAuthRequest({ method: "PUT", url: endpoints.BOOK_DAY(hoteId), @@ -212,4 +211,22 @@ export class User { return typedData; }); } + + /** This method is used to get the week for a weekNumber. + * @param hoteId The ID of the hote to get. + * @param week The week number to get. + * @param token The token of the user. + */ + async getBookingWeek(hoteId: number, week: number, token: string): Promise { + return this.#manager.makeAuthRequest({ + method: "GET", + url: endpoints.BOOKINGS(hoteId) + (week ? `?num=${week}` : ""), + headers: { + "Authorization": "Bearer " + token + } + }).then((data: unknown) => { + let typedData = data as bookingResponse; + return typedData.dateSemaine; + }); + } } diff --git a/package.json b/package.json index 9bf63b1..32101f0 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "turboself-api", - "version": "0.1.1", + "version": "0.1.2", "description": "A wrapper around Turboself internal API.", "repository": "github:raphckrman/turboself-api", "main": "./dist/index.js",