feat: account page content

This commit is contained in:
Takeshi Kimata
2024-06-03 21:53:52 +09:00
parent 24fe7bebb3
commit e4db79047a
9 changed files with 151 additions and 40 deletions

View File

@@ -28,7 +28,7 @@ async function fetchProject(jwt: string, projectId: number) {
}
/**
* fetch project records
* fetch projects (public and user own projects)
*/
async function fetchProjects(jwt: string) {
const url = `${apiServer}/projects`;
@@ -53,6 +53,32 @@ async function fetchProjects(jwt: string) {
}
}
/**
* fetch projects (user own projects)
*/
async function fetchMyProjects(jwt: string) {
const url = `${apiServer}/projects?onlyUserProjects=true`;
try {
const response = await fetch(url, {
method: 'GET',
headers: {
'Content-Type': 'application/json',
Authorization: `Bearer ${jwt}`,
},
});
if (!response.ok) {
throw new Error(`HTTP error! Status: ${response.status}`);
}
const data = await response.json();
return data;
} catch (error: any) {
console.error('Error fetching data:', error.message);
}
}
/**
* Create project
*/
@@ -146,4 +172,4 @@ async function deleteProject(jwt: string, projectId: number) {
}
}
export { fetchProject, fetchProjects, createProject, updateProject, deleteProject };
export { fetchProject, fetchProjects, fetchMyProjects, createProject, updateProject, deleteProject };

View File

@@ -62,6 +62,10 @@ async function fetchMyRoles(jwt: string) {
}
function isProjectManager(projectRoles: ProjectRoleType[], projectId: number) {
if (!projectRoles) {
return false;
}
const found = projectRoles.find((role) => {
return role.projectId === projectId;
});
@@ -83,6 +87,10 @@ function isProjectManager(projectRoles: ProjectRoleType[], projectId: number) {
}
function isProjectDeveloper(projectRoles: ProjectRoleType[], projectId: number) {
if (!projectRoles) {
return false;
}
const found = projectRoles.find((role) => {
return role.projectId === projectId;
});