Files
calendar/packages/lib/fetch-wrapper.ts
T
54e518efad feat: Allow reschedule when max booker bookings have been reached (#21778)
* feat - Restrict same email to create more than 'n' active bookings at a time

* updated checkbookerbookinglimit function

* type fix

* minor change

* import fix

* minor fixes

* back to null on disable

* back

* type check

* managed edge cases

* chore: name changes

* name changes

* fix

* minor change

* changed name

* use default value for maxactivebookingsperbooker, and some minor changes

* disabling bookerbooking limit for recurring event

* disabling bookerbooking limit for recurring event

* type fix

* ui fix and backend eventtype update check

* Add `maxActiveBookingPerBookerOfferReschedule` to schema

* Create `MaxActiveBookingsPerBookerController` and offer reschedule option

* Add offer reschedule to event type form data

* Pass data through to HttpError

* When checking max bookings, return last booking info if applicable

* removed unused code

* minor changes

* update validation

* chore

* Do not check booking limits if rescheduling

* Add data for reschedule

* Add reschedule specific error code

* On maximum booking error, write to booker store reschedule params

* Add translations for error codes

* Write to error message previous booking time

* minor fix

* Write to error message previous booking time

* Type fixes

* Clean up comment

* Refactor eventType update errors

* Typo fix

* Type fix

* Type fix

* Type fix

* Fix test

* Fix test

* Add migration

* Addressed feedback and missed merges

---------

Co-authored-by: romit <romitgabani@icloud.com>
2025-06-13 23:54:33 +00:00

67 lines
1.8 KiB
TypeScript

import { HttpError } from "./http-error";
async function http<T>(path: string, config: RequestInit): Promise<T> {
const request = new Request(path, config);
const response: Response = await fetch(request);
if (!response.ok) {
const errJson = await response.json();
const err = HttpError.fromRequest(
request,
{
...response,
statusText: errJson.message || response.statusText,
},
errJson
);
throw err;
}
// may error if there is no body, return empty array
return await response.json();
}
export async function get<T>(path: string, config?: RequestInit): Promise<T> {
const init = { method: "GET", ...config };
return await http<T>(path, init);
}
export async function post<T, U>(path: string, body: T, config?: RequestInit): Promise<U> {
const init = {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify(body),
...config,
};
return await http<U>(path, init);
}
export async function put<T, U>(path: string, body: T, config?: RequestInit): Promise<U> {
const init = {
method: "PUT",
headers: { "Content-Type": "application/json" },
body: JSON.stringify(body),
...config,
};
return await http<U>(path, init);
}
export async function patch<T, U>(path: string, body: T, config?: RequestInit): Promise<U> {
const init = {
method: "PATCH",
headers: { "Content-Type": "application/json" },
body: JSON.stringify(body),
...config,
};
return await http<U>(path, init);
}
export async function remove<T, U>(path: string, body: T, config?: RequestInit): Promise<U> {
const init = {
method: "DELETE",
headers: { "Content-Type": "application/json" },
body: JSON.stringify(body),
...config,
};
return await http<U>(path, init);
}