MED-177: add booking confirmation
This commit is contained in:
@@ -99,7 +99,12 @@ export async function bookAppointment(
|
||||
syncUserID: number,
|
||||
startTime: string,
|
||||
comments = '',
|
||||
) {
|
||||
): Promise<{
|
||||
success: boolean;
|
||||
reason?: FailureReason;
|
||||
bookingCode: string | null;
|
||||
clinicKey: string | null;
|
||||
}> {
|
||||
const logger = await getLogger();
|
||||
const supabase = getSupabaseServerClient();
|
||||
|
||||
@@ -148,7 +153,7 @@ export async function bookAppointment(
|
||||
supabase
|
||||
.schema('medreport')
|
||||
.from('connected_online_reservation')
|
||||
.select('id')
|
||||
.select('id,location_sync_id')
|
||||
.eq('clinic_id', clinicId)
|
||||
.eq('service_id', serviceId)
|
||||
.eq('start_time', formattedStartTime)
|
||||
@@ -202,8 +207,8 @@ export async function bookAppointment(
|
||||
},
|
||||
param: JSON.stringify({
|
||||
ClinicID: clinic.id,
|
||||
ServiceID: service.sync_id,
|
||||
ClinicServiceID: service.id,
|
||||
ServiceID: service.id,
|
||||
ClinicServiceID: service.sync_id,
|
||||
UserID: appointmentUserId,
|
||||
SyncUserID: syncUserID,
|
||||
StartTime: startTime,
|
||||
@@ -216,6 +221,7 @@ export async function bookAppointment(
|
||||
AddToBasket: false,
|
||||
Key: dbClinic.key,
|
||||
Lang: 'et',
|
||||
Location: dbReservation.location_sync_id,
|
||||
}),
|
||||
},
|
||||
);
|
||||
@@ -275,16 +281,34 @@ export async function bookAppointment(
|
||||
'Booked time, updated reservation with id ' + updatedReservation?.id,
|
||||
);
|
||||
|
||||
await logRequestResult(
|
||||
ExternalApi.ConnectedOnline,
|
||||
ConnectedOnlineMethodName.BookTime,
|
||||
RequestStatus.Success,
|
||||
JSON.stringify(connectedOnlineBookingResponseData),
|
||||
startTime.toString(),
|
||||
service.id,
|
||||
clinicId,
|
||||
);
|
||||
return { success: true };
|
||||
if (responseParts[1]) {
|
||||
await logRequestResult(
|
||||
ExternalApi.ConnectedOnline,
|
||||
ConnectedOnlineMethodName.BookTime,
|
||||
RequestStatus.Success,
|
||||
JSON.stringify(connectedOnlineBookingResponseData),
|
||||
startTime.toString(),
|
||||
service.id,
|
||||
clinicId,
|
||||
);
|
||||
return {
|
||||
success: true,
|
||||
bookingCode: responseParts[1],
|
||||
clinicKey: dbClinic.key,
|
||||
};
|
||||
} else {
|
||||
logger.error(`Missing booking code: ${responseParts}`);
|
||||
await logRequestResult(
|
||||
ExternalApi.ConnectedOnline,
|
||||
ConnectedOnlineMethodName.BookTime,
|
||||
RequestStatus.Fail,
|
||||
JSON.stringify(error),
|
||||
startTime.toString(),
|
||||
serviceId,
|
||||
clinicId,
|
||||
);
|
||||
return { success: false, bookingCode: null, clinicKey: null };
|
||||
}
|
||||
} catch (error) {
|
||||
logger.error(`Failed to book time, error: ${JSON.stringify(error)}`);
|
||||
await logRequestResult(
|
||||
@@ -296,41 +320,33 @@ export async function bookAppointment(
|
||||
serviceId,
|
||||
clinicId,
|
||||
);
|
||||
return { success: false, reason };
|
||||
return { success: false, reason, bookingCode: null, clinicKey: null };
|
||||
}
|
||||
}
|
||||
|
||||
export async function getConfirmedService(reservationCode: string) {
|
||||
export async function getConfirmedService(
|
||||
reservationCode: string,
|
||||
clinicKey: string,
|
||||
) {
|
||||
try {
|
||||
const response = await axios.post(
|
||||
`${process.env.CONNECTED_ONLINE_URL!}/${ConnectedOnlineMethodName.ConfirmedLoad}`,
|
||||
{
|
||||
headers: {
|
||||
'Content-Type': 'application/json; charset=utf-8',
|
||||
},
|
||||
param: JSON.stringify({ Value: `${reservationCode}|7T624nlu|et` }),
|
||||
const url = new URL(process.env.CONNECTED_ONLINE_CONFIRMED_URL!);
|
||||
url.searchParams.set('code1', reservationCode);
|
||||
url.searchParams.set('key', clinicKey);
|
||||
url.searchParams.set('lang', 'et');
|
||||
await fetch(url, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json; charset=utf-8',
|
||||
},
|
||||
);
|
||||
|
||||
const responseData: ConfirmedLoadResponse = JSON.parse(response.data.d);
|
||||
|
||||
if (responseData?.ErrorCode !== 0) {
|
||||
await logRequestResult(
|
||||
ExternalApi.ConnectedOnline,
|
||||
ConnectedOnlineMethodName.ConfirmedLoad,
|
||||
RequestStatus.Fail,
|
||||
JSON.stringify(responseData),
|
||||
);
|
||||
return null;
|
||||
}
|
||||
});
|
||||
|
||||
await logRequestResult(
|
||||
ExternalApi.ConnectedOnline,
|
||||
ConnectedOnlineMethodName.ConfirmedLoad,
|
||||
RequestStatus.Success,
|
||||
JSON.stringify(responseData),
|
||||
'ok',
|
||||
);
|
||||
return responseData.Data;
|
||||
return;
|
||||
} catch (error) {
|
||||
await logRequestResult(
|
||||
ExternalApi.ConnectedOnline,
|
||||
|
||||
@@ -438,9 +438,6 @@ export async function readPrivateMessageResponse({
|
||||
medusaOrderId,
|
||||
orderStatus: 'PARTIAL_ANALYSIS_RESPONSE',
|
||||
});
|
||||
if (IS_ENABLED_DELETE_PRIVATE_MESSAGE) {
|
||||
await deletePrivateMessage(privateMessageId);
|
||||
}
|
||||
hasAnalysisResponse = true;
|
||||
hasPartialAnalysisResponse = true;
|
||||
} else if (status.isCompleted) {
|
||||
|
||||
@@ -12,4 +12,5 @@ export type Order = {
|
||||
location?: string;
|
||||
bookingCode?: string | null;
|
||||
clinicId?: number;
|
||||
medusaLineItemId?: string | null;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user