54 lines
1.1 KiB
JavaScript
54 lines
1.1 KiB
JavaScript
|
|
import { API_BASE_URL } from '../../../shared/services/apiConfig';
|
||
|
|
|
||
|
|
async function request(path, options = {}) {
|
||
|
|
const response = await fetch(`${API_BASE_URL}${path}`, {
|
||
|
|
headers: {
|
||
|
|
'Content-Type': 'application/json',
|
||
|
|
...options.headers,
|
||
|
|
},
|
||
|
|
...options,
|
||
|
|
});
|
||
|
|
|
||
|
|
if (!response.ok) {
|
||
|
|
throw new Error('Falha ao consultar templates.');
|
||
|
|
}
|
||
|
|
|
||
|
|
return response.json();
|
||
|
|
}
|
||
|
|
|
||
|
|
export function listTemplates() {
|
||
|
|
return request('/whatsapp/templates');
|
||
|
|
}
|
||
|
|
|
||
|
|
export function saveTemplate(payload) {
|
||
|
|
return request('/whatsapp/templates', {
|
||
|
|
method: 'POST',
|
||
|
|
body: JSON.stringify(payload),
|
||
|
|
});
|
||
|
|
}
|
||
|
|
|
||
|
|
export function updateTemplate(id, payload) {
|
||
|
|
return request(`/whatsapp/templates/update/${id}`, {
|
||
|
|
method: 'POST',
|
||
|
|
body: JSON.stringify(payload),
|
||
|
|
});
|
||
|
|
}
|
||
|
|
|
||
|
|
export function approveTemplateByAdmin(id) {
|
||
|
|
return request(`/whatsapp/templates/approve-admin/${id}`, {
|
||
|
|
method: 'POST',
|
||
|
|
});
|
||
|
|
}
|
||
|
|
|
||
|
|
export function rejectTemplateByAdmin(id) {
|
||
|
|
return request(`/whatsapp/templates/reject-admin/${id}`, {
|
||
|
|
method: 'POST',
|
||
|
|
});
|
||
|
|
}
|
||
|
|
|
||
|
|
export function deleteTemplate(id) {
|
||
|
|
return request(`/whatsapp/templates/${id}`, {
|
||
|
|
method: 'DELETE',
|
||
|
|
});
|
||
|
|
}
|