Skip to content

Commit

Permalink
Major Change on Bookins
Browse files Browse the repository at this point in the history
  • Loading branch information
raphckrman committed Mar 7, 2024
1 parent 27d3737 commit bec8917
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 5 deletions.
25 changes: 21 additions & 4 deletions lib/routes/User.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,16 +136,15 @@ 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<bookings[]> {
async getBookings(hoteId: number, token: string, week?: number): Promise<bookingResponse> {
return this.#manager.makeAuthRequest<bookingResponse>({
method: "GET",
url: endpoints.BOOKINGS(hoteId) + (week ? `?num=${week}` : ""),
headers: {
"Authorization": "Bearer " + token
}
}).then((data: unknown) => {
let typedData = data as bookingResponse;
return typedData.rsvWebDto;
return data as bookingResponse;
});
}

Expand Down Expand Up @@ -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<bookMealResponse> {
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<bookMealResponse>({
method: "PUT",
url: endpoints.BOOK_DAY(hoteId),
Expand All @@ -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<string> {
return this.#manager.makeAuthRequest<bookingResponse>({
method: "GET",
url: endpoints.BOOKINGS(hoteId) + (week ? `?num=${week}` : ""),
headers: {
"Authorization": "Bearer " + token
}
}).then((data: unknown) => {
let typedData = data as bookingResponse;
return typedData.dateSemaine;
});
}
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down

0 comments on commit bec8917

Please sign in to comment.