add / readNotification working

This commit is contained in:
isUnknown 2024-10-28 17:50:40 +01:00
parent 722c6b198e
commit ed73b33234
6 changed files with 159 additions and 20 deletions

View file

@ -1,4 +1,5 @@
import { defineStore } from "pinia";
import uniqid from "uniqid";
export const useApiStore = defineStore("api", () => {
/**
@ -120,5 +121,60 @@ export const useApiStore = defineStore("api", () => {
}
}
return { fetchDataThroughKQL, fetchData, fetchRoute };
async function addComment(comment) {
const headers = {
method: "POST",
body: JSON.stringify(comment),
};
try {
const response = await fetch("/add-comment.json", headers);
if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`);
}
const newFile = await response.json();
return newFile;
} catch (error) {
console.error(
"Une erreur s'est produite lors de l'ajout du commentaire :",
commentaire,
error
);
throw error;
}
}
async function readNotification(userUuid, group, notificationId) {
const headers = {
method: "POST",
body: JSON.stringify({
userUuid,
notificationId,
group,
}),
};
try {
const response = await fetch("/read-notification.json", headers);
if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`);
}
const newNotifications = await response.json();
return newNotifications;
} catch (error) {
console.error(
"Une erreur s'est produite lors de la lecture de la notification n°",
notificationId,
error
);
throw error;
}
}
return {
fetchDataThroughKQL,
fetchData,
fetchRoute,
addComment,
readNotification,
};
});