|
| 1 | +import { jsonFetch } from '@helpers/api.js' |
| 2 | + |
| 3 | +/** |
| 4 | + * Représentation d'un commentaire de l'API |
| 5 | + * @typedef {{id: number, username: string, avatar: string, content: string, createdAt: number, replies: ReplyResource[]}} ReplyResource |
| 6 | + */ |
| 7 | + |
| 8 | +/** |
| 9 | + * @param {number} target |
| 10 | + * @return {Promise<ReplyResource[]>} |
| 11 | + */ |
| 12 | +export async function findAllReplies (target) { |
| 13 | + return await jsonFetch(`/api/replies/${target}`) |
| 14 | +} |
| 15 | + |
| 16 | +/** |
| 17 | + * @param {{target: number, username: ?string, email: ?string, content: string}} data |
| 18 | + * @return {Promise<Object>} |
| 19 | + */ |
| 20 | +export async function addReply (body) { |
| 21 | + return jsonFetch('/api/replies', { |
| 22 | + method: 'POST', |
| 23 | + body |
| 24 | + }) |
| 25 | +} |
| 26 | + |
| 27 | +/** |
| 28 | + * @param {int} id |
| 29 | + * @param {int} userId |
| 30 | + * @return {Promise<Object>} |
| 31 | + */ |
| 32 | +export async function likeReply(id, userId) { |
| 33 | + return jsonFetch(`/api/like/${id}`, { |
| 34 | + method: 'POST', |
| 35 | + body: JSON.stringify({ userId }) |
| 36 | + }) |
| 37 | +} |
| 38 | + |
| 39 | +/** |
| 40 | + * @param {int} id |
| 41 | + * @return {Promise<null>} |
| 42 | + */ |
| 43 | +export async function deleteReply (id) { |
| 44 | + return jsonFetch(`/api/replies/${id}`, { |
| 45 | + method: 'DELETE' |
| 46 | + }) |
| 47 | +} |
| 48 | + |
| 49 | +/** |
| 50 | + * @param {int} id |
| 51 | + * @param {string} body |
| 52 | + * @return {Promise<ReplyResource>} |
| 53 | + */ |
| 54 | +export async function updateReply (id, body) { |
| 55 | + return jsonFetch(`/api/replies/${id}`, { |
| 56 | + method: 'PUT', |
| 57 | + body: JSON.stringify({ body }) |
| 58 | + }) |
| 59 | +} |
0 commit comments