fix: bugs
Some checks failed
Format / formatting (push) Successful in 6s
Build / build (push) Successful in 41s
CI / build (push) Failing after 11s
Format / formatting (pull_request) Successful in 6s

This commit is contained in:
ALAMI Adnane 2025-04-29 00:28:56 +02:00
commit 820c979c94
9 changed files with 104 additions and 80 deletions

View File

@ -95,7 +95,7 @@ const props = defineProps<{
title: number; title: number;
titleText: string; titleText: string;
description: string; description: string;
isAdmin: number; isAdmin: boolean;
}>(); }>();
const IS_MOCK_MODE = false; const IS_MOCK_MODE = false;
@ -107,18 +107,23 @@ const editedDescriptions = ref<SectionCell[]>([]);
const isEditing = ref<boolean[]>([]); const isEditing = ref<boolean[]>([]);
function getCurrentFormattedDate(): string { function getCurrentFormattedDate(): string {
const now = new Date(); const now = new Date();
const year = now.getFullYear(); const year = now.getFullYear();
const month = String(now.getMonth() + 1).padStart(2, '0'); // +1 car janvier = 0 const month = String(now.getMonth() + 1).padStart(2, "0"); // +1 car janvier = 0
const day = String(now.getDate()).padStart(2, '0'); const day = String(now.getDate()).padStart(2, "0");
const hours = String(now.getHours()).padStart(2, '0'); const hours = String(now.getHours()).padStart(2, "0");
const minutes = String(now.getMinutes()).padStart(2, '0'); const minutes = String(now.getMinutes()).padStart(2, "0");
return `${year}-${month}-${day} ${hours}:${minutes}`; return `${year}-${month}-${day} ${hours}:${minutes}`;
} }
onMounted(() => { onMounted(() => {
fetchData(props.projectId, props.title, getCurrentFormattedDate(), IS_MOCK_MODE); fetchData(
props.projectId,
props.title,
getCurrentFormattedDate(),
IS_MOCK_MODE
);
}); });
// Fonctions // Fonctions
@ -137,10 +142,14 @@ const saveEdit = (index: number) => {
editedDescriptions.value[index].contentSectionCell; editedDescriptions.value[index].contentSectionCell;
isEditing.value[index] = false; isEditing.value[index] = false;
if (!IS_MOCK_MODE){ if (!IS_MOCK_MODE) {
addSectionCell(currentDescriptions.value[index], addSectionCell(
currentDescriptions.value[index],
(response) => { (response) => {
console.log("Modification enregistrée avec succès :", response.data); console.log(
"Modification enregistrée avec succès :",
response.data
);
}, },
(error) => { (error) => {
console.error("Erreur lors de l'enregistrement :", error); console.error("Erreur lors de l'enregistrement :", error);
@ -149,7 +158,6 @@ const saveEdit = (index: number) => {
} }
}; };
const handleClick = () => { const handleClick = () => {
if (expanded.value) { if (expanded.value) {
const editingInProgress = isEditing.value.some((edit) => edit); const editingInProgress = isEditing.value.some((edit) => edit);
@ -165,11 +173,13 @@ const handleClick = () => {
const handleFetchSuccess = (sectionCells: SectionCell[]) => { const handleFetchSuccess = (sectionCells: SectionCell[]) => {
currentDescriptions.value = sectionCells; currentDescriptions.value = sectionCells;
editedDescriptions.value = sectionCells.map( editedDescriptions.value = sectionCells.map(
(cell) => new SectionCell({ (cell) =>
idSectionCell: cell.idSectionCell, new SectionCell({
sectionId: cell.sectionId, idSectionCell: cell.idSectionCell,
contentSectionCell: cell.contentSectionCell, sectionId: cell.sectionId,
modificationDate: cell.modificationDate, }) contentSectionCell: cell.contentSectionCell,
modificationDate: cell.modificationDate,
})
); );
isEditing.value = Array(sectionCells.length).fill(false); isEditing.value = Array(sectionCells.length).fill(false);
}; };
@ -178,28 +188,43 @@ const handleFetchError = (error: unknown) => {
console.error("Erreur lors de la récupération des données :", error); console.error("Erreur lors de la récupération des données :", error);
}; };
const fetchData = async ( projectId: number, title: number, date: string, useMock = false ) => { const fetchData = async (
projectId: number,
title: number,
date: string,
useMock = false
) => {
try { try {
if (useMock) { if (useMock) {
const responseData = await mockFetch(projectId, title, date); const responseData = await mockFetch(projectId, title, date);
handleFetchSuccess(responseData); handleFetchSuccess(responseData);
} else { } else {
await new Promise<void>((resolve, reject) => { await new Promise<void>((resolve, reject) => {
getSectionCellsByDate( projectId, title, date, getSectionCellsByDate(
projectId,
title,
date,
(response: AxiosResponse) => { (response: AxiosResponse) => {
const data = response.data; const data = response.data;
if (Array.isArray(data) && data.length > 0) { if (Array.isArray(data) && data.length > 0) {
const sectionCells = data.map((cellData) => new SectionCell({ const sectionCells = data.map(
idSectionCell: cellData.idSectionCell, (cellData) =>
sectionId: cellData.sectionId, new SectionCell({
contentSectionCell: cellData.contentSectionCell, idSectionCell: cellData.idSectionCell,
modificationDate: sectionId: cellData.sectionId,
cellData.modificationDate, }) contentSectionCell:
cellData.contentSectionCell,
modificationDate:
cellData.modificationDate,
})
); );
handleFetchSuccess(sectionCells); handleFetchSuccess(sectionCells);
} else { } else {
console.warn( "Aucune donnée reçue ou format inattendu :", data); console.warn(
"Aucune donnée reçue ou format inattendu :",
data
);
} }
resolve(); resolve();
@ -216,7 +241,11 @@ const fetchData = async ( projectId: number, title: number, date: string, useMoc
} }
}; };
const mockFetch = async ( projectId: number, title: number, date: string ): Promise<SectionCell[]> => { const mockFetch = async (
projectId: number,
title: number,
date: string
): Promise<SectionCell[]> => {
console.log( console.log(
`Mock fetch pour projectId: ${projectId}, title: ${title}, date: ${date}` `Mock fetch pour projectId: ${projectId}, title: ${title}, date: ${date}`
); );
@ -272,8 +301,13 @@ const mockFetch = async ( projectId: number, title: number, date: string ): Prom
// On crée des instances de SectionCell // On crée des instances de SectionCell
const result = section.map( const result = section.map(
(txt, index) => new SectionCell({ idSectionCell: index + 1, sectionId: title, (txt, index) =>
contentSectionCell: txt, modificationDate: date, }) new SectionCell({
idSectionCell: index + 1,
sectionId: title,
contentSectionCell: txt,
modificationDate: date,
})
); );
return new Promise<SectionCell[]>((resolve) => { return new Promise<SectionCell[]>((resolve) => {

View File

@ -18,7 +18,7 @@ import { ref } from "vue";
import CanvasItem from "@/components/canvas/CanvasItem.vue"; import CanvasItem from "@/components/canvas/CanvasItem.vue";
const props = defineProps<{ const props = defineProps<{
isAdmin: number; isAdmin: boolean;
}>(); }>();
const items = ref([ const items = ref([

View File

@ -5,7 +5,6 @@ import { createPinia } from "pinia";
import piniaPluginPersistedstate from "pinia-plugin-persistedstate"; import piniaPluginPersistedstate from "pinia-plugin-persistedstate";
import keycloakService from "./services/keycloak"; import keycloakService from "./services/keycloak";
import { type AuthStore, useAuthStore } from "@/stores/authStore.ts"; import { type AuthStore, useAuthStore } from "@/stores/authStore.ts";
import { jwtDecode } from "jwt-decode";
let store: AuthStore; let store: AuthStore;
@ -29,32 +28,6 @@ keycloakService.CallInit(() => {
} }
}); });
type TokenPayload = {
realm_access?: {
roles?: string[];
};
};
function isAdmin(): boolean {
if (store.authenticated && store.user.token) {
try {
const decoded = jwtDecode<TokenPayload>(store.user.token);
const roles = decoded.realm_access?.roles || [];
if (roles.includes("MyINPulse-admin")) {
return true;
} else {
return false;
}
} catch (err) {
console.error("Failed to decode token", err);
}
}
}
// this shit made by me so i can run the canva vue app // this shit made by me so i can run the canva vue app
//createApp(App).use(router).mount('#app'); //createApp(App).use(router).mount('#app');
@ -97,4 +70,4 @@ app.use(VueKeyCloak,{
} ); } );
*/ */
export { store, isAdmin }; export { store };

View File

@ -1,7 +1,11 @@
import { type AxiosError, type AxiosResponse } from "axios"; import { type AxiosError, type AxiosResponse } from "axios";
import Project from "@/ApiClasses/Project"; import Project from "@/ApiClasses/Project";
import Report from "@/ApiClasses/Repport"; import Report from "@/ApiClasses/Repport";
import { axiosInstance, defaultApiErrorHandler, defaultApiSuccessHandler } from "@/services/api" import {
axiosInstance,
defaultApiErrorHandler,
defaultApiSuccessHandler,
} from "@/services/api";
// Admin API // Admin API
function getPendingAccounts( function getPendingAccounts(

View File

@ -1,6 +1,10 @@
import Project from "@/ApiClasses/Project"; import Project from "@/ApiClasses/Project";
import SectionCell from "@/ApiClasses/SectionCell"; import SectionCell from "@/ApiClasses/SectionCell";
import { axiosInstance, defaultApiErrorHandler, defaultApiSuccessHandler } from "@/services/api" import {
axiosInstance,
defaultApiErrorHandler,
defaultApiSuccessHandler,
} from "@/services/api";
axiosInstance.interceptors.response.use( axiosInstance.interceptors.response.use(
(response) => response, // Directly return successful responses. (response) => response, // Directly return successful responses.
@ -62,7 +66,7 @@ function addSectionCell(
onErrorHandler?: (error: AxiosError) => void onErrorHandler?: (error: AxiosError) => void
): void { ): void {
axiosInstance axiosInstance
.post("/entrepreneur/sectionCells", sectionCellDetails.toPlainObject()) // <-- Ici .post("/entrepreneur/sectionCells", sectionCellDetails.toPlainObject()) // <-- Ici
.then((response) => { .then((response) => {
if (onSuccessHandler) { if (onSuccessHandler) {
onSuccessHandler(response); onSuccessHandler(response);

View File

@ -1,7 +1,10 @@
import { type AxiosError, type AxiosResponse } from "axios"; import { type AxiosError, type AxiosResponse } from "axios";
import Appointment from "@/ApiClasses/Appointment"; import Appointment from "@/ApiClasses/Appointment";
import { axiosInstance, defaultApiErrorHandler, defaultApiSuccessHandler } from "@/services/api" import {
axiosInstance,
defaultApiErrorHandler,
defaultApiSuccessHandler,
} from "@/services/api";
// Shared API // Shared API
function getSectionCellsByDate( function getSectionCellsByDate(

View File

@ -1,7 +1,10 @@
import { type AxiosError, type AxiosResponse } from "axios"; import { type AxiosError, type AxiosResponse } from "axios";
import { axiosInstance, defaultApiErrorHandler, defaultApiSuccessHandler } from "@/services/api" import {
axiosInstance,
defaultApiErrorHandler,
defaultApiSuccessHandler,
} from "@/services/api";
// Unauth API // Unauth API
function finalizeAccount( function finalizeAccount(
@ -49,8 +52,7 @@ function finalizeAccount(
// }); // });
// } // }
export {
export {
finalizeAccount, finalizeAccount,
// requestJoinProject, // Not yet implemented [cite: 4] // requestJoinProject, // Not yet implemented [cite: 4]
}; };

View File

@ -1,7 +1,7 @@
import axios, { type AxiosError, type AxiosResponse } from "axios"; import axios, { type AxiosError, type AxiosResponse } from "axios";
import { store } from "@/main.ts"; import { store } from "@/main.ts";
import { addNewMessage, color } from "@/services/popupDisplayer.ts"; import { addNewMessage, color } from "@/services/popupDisplayer.ts";
import router from "@/router/router"; import router from "@/router/router";
const axiosInstance = axios.create({ const axiosInstance = axios.create({
baseURL: import.meta.env.VITE_BACKEND_URL, baseURL: import.meta.env.VITE_BACKEND_URL,
@ -43,8 +43,7 @@ axiosInstance.interceptors.response.use(
// TODO: spawn a error modal // TODO: spawn a error modal
function defaultApiErrorHandler(err: AxiosError) { function defaultApiErrorHandler(err: AxiosError) {
const errorMessage = const errorMessage =
(err.response?.data as { message?: string })?.message ?? (err.response?.data as { message?: string })?.message ?? err.message;
err.message;
addNewMessage(errorMessage, color.Red); addNewMessage(errorMessage, color.Red);
} }
@ -94,4 +93,11 @@ function deleteApi(
//export { axiosInstance, callApi, postApi, deleteApi }; //export { axiosInstance, callApi, postApi, deleteApi };
export{ axiosInstance, defaultApiErrorHandler, defaultApiSuccessHandler, callApi, postApi, deleteApi } export {
axiosInstance,
defaultApiErrorHandler,
defaultApiSuccessHandler,
callApi,
postApi,
deleteApi,
};

View File

@ -10,7 +10,7 @@
Cliquez sur un champ du tableau pour afficher son contenu en détail Cliquez sur un champ du tableau pour afficher son contenu en détail
ci-dessous. ci-dessous.
</p> </p>
<LeanCanvas :is-admin="isAdmin" /> <LeanCanvas :is-admin="isAdmin_" />
<div class="info-box"> <div class="info-box">
<p> <p>
Responsable : Responsable :
@ -35,20 +35,18 @@ import HeaderCanvas from "../components/canvas/HeaderCanvas.vue";
import LeanCanvas from "../components/canvas/LeanCanvas.vue"; import LeanCanvas from "../components/canvas/LeanCanvas.vue";
import { ref, onMounted /*, defineProps*/ } from "vue"; import { ref, onMounted /*, defineProps*/ } from "vue";
import { axiosInstance } from "@/services/api.ts"; import { axiosInstance } from "@/services/api.ts";
import { isAdmin } from "@/services/tools.ts";
const IS_MOCK_MODE = true; const IS_MOCK_MODE = true;
/* /*
const props = defineProps<{ const props = defineProps<{
projectId: number; projectId: number;
token: TokenPayload;
}>(); }>();
const projectId = props.projectId;
*/
is_admin = token.includes("MyINPulse-admin") const isAdmin_: boolean = isAdmin();
*/
const isAdmin = 0;
// Variables pour les informations de l'administrateur // Variables pour les informations de l'administrateur
const admin = ref({ const admin = ref({