Closes #6 Reviewed-on: phoenix/textsender#22 Co-authored-by: phoenix <kundeng00@pm.me> Co-committed-by: phoenix <kundeng00@pm.me>
30 lines
722 B
JavaScript
30 lines
722 B
JavaScript
import { API_BASE_URL } from '../constants/api';
|
|
|
|
export class CreateMessageRequest {
|
|
content = '';
|
|
user_id = '';
|
|
}
|
|
|
|
export const messageApi = {
|
|
createMessage: async (requestBody, authBearerToken) => {
|
|
const response = await fetch(`${API_BASE_URL}/api/v1/message/new`, {
|
|
method: 'POST',
|
|
headers: {
|
|
'Content-Type': 'application/json',
|
|
Authorization: authBearerToken,
|
|
},
|
|
body: JSON.stringify(requestBody),
|
|
});
|
|
|
|
if (!response.ok) {
|
|
if (response.status === 500) {
|
|
throw new Error('Something went wrong with the system');
|
|
} else {
|
|
throw new Error('Failed to create message');
|
|
}
|
|
} else {
|
|
return response.json();
|
|
}
|
|
},
|
|
};
|