diff --git a/src/api/scheduleApi.js b/src/api/scheduleApi.js new file mode 100644 index 0000000..76927c2 --- /dev/null +++ b/src/api/scheduleApi.js @@ -0,0 +1,35 @@ +import { API_BASE_URL } from '../constants/api'; + +export const scheduleApi = { + scheduleMessage: async (s, authBearerToken) => { + console.log('Scheduling message'); + const reqBody = { + scheduled: s.scheduedTime.toISOString(), + status: s.status, + user_id: s.userId, + }; + + console.log(`Request body: ${reqBody}`); + const response = await fetch(`${API_BASE_URL}/api/v1/schedule/message`, + { + method: 'POST', + headers: { + 'Content-Type': 'application/json', + Authorization: authBearerToken, + }, + body: JSON.stringify(reqBody) + }); + + if (!response.ok) { + throw new Error('Error scheduling message'); + } else { + return response.json(); + } + } +}; + +/* + * "scheduled": "{{scheduling_time}}", + "status": "{{status_pending}}", + "user_id": "{{user_id}}" +*/