38 lines
916 B
TypeScript
38 lines
916 B
TypeScript
import axios from 'axios';
|
|
|
|
axios.defaults.baseURL = '/api';
|
|
axios.defaults.headers.post['Content-Type'] = 'application/json';
|
|
axios.defaults.headers.put['Content-Type'] = 'application/json';
|
|
|
|
export interface Pagination {
|
|
page: number;
|
|
limit: number;
|
|
}
|
|
|
|
export function channels() {
|
|
return axios.get('/channels')
|
|
}
|
|
|
|
export function channelInfo(id) {
|
|
return axios.get(`/channels/${id}`);
|
|
}
|
|
|
|
export function channelMessages(channelId, pagination: Pagination) {
|
|
return axios.get(`/channels/${channelId}/messages`, {
|
|
params: pagination,
|
|
});
|
|
}
|
|
|
|
export function favoriteMessages(pagination: Pagination) {
|
|
return axios.get('/favorites', {
|
|
params: pagination,
|
|
});
|
|
}
|
|
|
|
export function toggleFavoriteMessage(messageId) {
|
|
return axios.patch(`/channels/${messageId}/messages`);
|
|
}
|
|
|
|
export function deleteMessage(messageID) {
|
|
return axios.delete(`/messages/${messageID}`);
|
|
} |