Skip to content

Commit

Permalink
feat(ZMS-2936): add baseUrl
Browse files Browse the repository at this point in the history
  • Loading branch information
lehju committed Feb 13, 2025
1 parent 95fb00b commit 51a44be
Show file tree
Hide file tree
Showing 5 changed files with 176 additions and 127 deletions.
89 changes: 55 additions & 34 deletions zmscitizenview/src/api/ZMSAppointmentAPI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,11 @@ const MAXDATE = new Date(

export function fetchServicesAndProviders(
serviceId?: string,
locationId?: string
locationId?: string,
baseUrl?: string
): Promise<OfficesAndServicesDTO> {
let apiUrl =
getAPIBaseURL() + VUE_APP_ZMS_API_PROVIDERS_AND_SERVICES_ENDPOINT;
getAPIBaseURL(baseUrl) + VUE_APP_ZMS_API_PROVIDERS_AND_SERVICES_ENDPOINT;

if (serviceId && locationId) {
apiUrl += `?serviceId=${serviceId}&locationId=${locationId}`;
Expand All @@ -44,7 +45,8 @@ export function fetchServicesAndProviders(
export function fetchAvailableDays(
provider: OfficeImpl,
serviceIds: string[],
serviceCounts: number[]
serviceCounts: number[],
baseUrl?: string
): Promise<AvailableDaysDTO | ErrorDTO> {
const params: Record<string, any> = {
startDate: convertDateToString(TODAY),
Expand All @@ -55,7 +57,7 @@ export function fetchAvailableDays(
};

return fetch(
getAPIBaseURL() +
getAPIBaseURL(baseUrl) +
VUE_APP_ZMS_API_CALENDAR_ENDPOINT +
"?" +
new URLSearchParams(params).toString()
Expand All @@ -68,7 +70,8 @@ export function fetchAvailableTimeSlots(
date: string,
provider: OfficeImpl,
serviceIds: string[],
serviceCounts: number[]
serviceCounts: number[],
baseUrl?: string
): Promise<AvailableTimeSlotsDTO | ErrorDTO> {
const params: Record<string, any> = {
date: date,
Expand All @@ -78,7 +81,7 @@ export function fetchAvailableTimeSlots(
};

return fetch(
getAPIBaseURL() +
getAPIBaseURL(baseUrl) +
VUE_APP_ZMS_API_AVAILABLE_TIME_SLOTS_ENDPOINT +
"?" +
new URLSearchParams(params).toString()
Expand All @@ -98,7 +101,8 @@ export function reserveAppointment(
timeSlot: number,
serviceIds: string[],
serviceCount: number[],
providerId: string
providerId: string,
baseUrl?: string
): Promise<AppointmentDTO | ErrorDTO> {
const requestBody = {
timestamp: timeSlot,
Expand All @@ -108,17 +112,21 @@ export function reserveAppointment(
captchaSolution: null,
};

return fetch(getAPIBaseURL() + VUE_APP_ZMS_API_RESERVE_APPOINTMENT_ENDPOINT, {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify(requestBody),
}).then((response) => {
return fetch(
getAPIBaseURL(baseUrl) + VUE_APP_ZMS_API_RESERVE_APPOINTMENT_ENDPOINT,
{
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify(requestBody),
}
).then((response) => {
return response.json();
});
}

export function updateAppointment(
appointment: AppointmentDTO
appointment: AppointmentDTO,
baseUrl?: string
): Promise<AppointmentDTO | ErrorDTO> {
const requestBody = {
processId: appointment.processId,
Expand All @@ -130,17 +138,21 @@ export function updateAppointment(
customTextfield: appointment.customTextfield,
};

return fetch(getAPIBaseURL() + VUE_APP_ZMS_API_UPDATE_APPOINTMENT_ENDPOINT, {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify(requestBody),
}).then((response) => {
return fetch(
getAPIBaseURL(baseUrl) + VUE_APP_ZMS_API_UPDATE_APPOINTMENT_ENDPOINT,
{
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify(requestBody),
}
).then((response) => {
return response.json();
});
}

export function preconfirmAppointment(
appointment: AppointmentDTO
appointment: AppointmentDTO,
baseUrl?: string
): Promise<AppointmentDTO | ErrorDTO> {
const requestBody = {
processId: appointment.processId,
Expand All @@ -150,7 +162,7 @@ export function preconfirmAppointment(
};

return fetch(
getAPIBaseURL() + VUE_APP_ZMS_API_PRECONFIRM_APPOINTMENT_ENDPOINT,
getAPIBaseURL(baseUrl) + VUE_APP_ZMS_API_PRECONFIRM_APPOINTMENT_ENDPOINT,
{
method: "POST",
headers: { "Content-Type": "application/json" },
Expand All @@ -162,25 +174,30 @@ export function preconfirmAppointment(
}

export function confirmAppointment(
appointment: AppointmentHash
appointment: AppointmentHash,
baseUrl?: string
): Promise<AppointmentDTO | ErrorDTO> {
const requestBody = {
processId: appointment.id,
authKey: appointment.authKey,
scope: appointment.scope,
};

return fetch(getAPIBaseURL() + VUE_APP_ZMS_API_CONFIRM_APPOINTMENT_ENDPOINT, {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify(requestBody),
}).then((response) => {
return fetch(
getAPIBaseURL(baseUrl) + VUE_APP_ZMS_API_CONFIRM_APPOINTMENT_ENDPOINT,
{
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify(requestBody),
}
).then((response) => {
return response.json();
});
}

export function fetchAppointment(
appointment: AppointmentHash
appointment: AppointmentHash,
baseUrl?: string
): Promise<AppointmentDTO | ErrorDTO> {
const params: Record<string, any> = {
processId: appointment.id,
Expand All @@ -189,7 +206,7 @@ export function fetchAppointment(
};

return fetch(
getAPIBaseURL() +
getAPIBaseURL(baseUrl) +
VUE_APP_ZMS_API_APPOINTMENT_ENDPOINT +
"?" +
new URLSearchParams(params).toString()
Expand All @@ -199,19 +216,23 @@ export function fetchAppointment(
}

export function cancelAppointment(
appointment: AppointmentDTO
appointment: AppointmentDTO,
baseUrl?: string
): Promise<AppointmentDTO | ErrorDTO> {
const requestBody = {
processId: appointment.processId,
authKey: appointment.authKey,
scope: appointment.scope,
};

return fetch(getAPIBaseURL() + VUE_APP_ZMS_API_CANCEL_APPOINTMENT_ENDPOINT, {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify(requestBody),
}).then((response) => {
return fetch(
getAPIBaseURL(baseUrl) + VUE_APP_ZMS_API_CANCEL_APPOINTMENT_ENDPOINT,
{
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify(requestBody),
}
).then((response) => {
return response.json();
});
}
Loading

0 comments on commit 51a44be

Please sign in to comment.