Skip to content

Commit

Permalink
feat(routing): add nav guard for project-board and group-board
Browse files Browse the repository at this point in the history
  • Loading branch information
NicolasRichel committed Sep 1, 2021
1 parent 4ac9631 commit 2616b09
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/router/guards/views/group-board.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { routeNames } from "@/router";
import GroupService from "@/services/GroupService.js";

export default async function groupBoardGuard(route) {
const group = await GroupService.fetchGroupByID(
{
cloud: { id: route.params.spaceID },
id: route.params.projectID
},
route.params.groupID
);
if (!group) {
return { name: routeNames.pageNotFound };
}
}
12 changes: 12 additions & 0 deletions src/router/guards/views/project-board.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { routeNames } from "@/router";
import ProjectService from "@/services/ProjectService.js";

export default async function projectBoardGuard(route) {
const project = await ProjectService.fetchProjectByID(
{ id: route.params.spaceID },
route.params.projectID
);
if (!project) {
return { name: routeNames.pageNotFound };
}
}
4 changes: 4 additions & 0 deletions src/router/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { createRouter, createWebHistory } from "vue-router";
import authGuard from "./guards/auth.js";
import groupBoardGuard from "./guards/views/group-board.js";
import projectBoardGuard from "./guards/views/project-board.js";
import spaceBoardGuard from "./guards/views/space-board.js";
import rootResolver from "./resolvers/root.js";
import groupBoardResolver from "./resolvers/views/group-board.js";
Expand Down Expand Up @@ -90,6 +92,7 @@ const routes = [
name: routeNames.projectBoard,
component: ProjectBoard,
meta: {
guard: projectBoardGuard,
resolver: projectBoardResolver
}
},
Expand All @@ -114,6 +117,7 @@ const routes = [
name: routeNames.groupBoard,
component: GroupBoard,
meta: {
guard: groupBoardGuard,
resolver: groupBoardResolver
}
},
Expand Down
13 changes: 13 additions & 0 deletions src/services/GroupService.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,19 @@ class GroupService {
}
}

async fetchGroupByID(project, id) {
try {
return await apiClient.collaborationApi.getManageGroup({
cloudPk: project.cloud.id,
projectPk: project.id,
id
});
} catch (error) {
ErrorService.handleError(error);
return null;
}
}

async createGroup(project, group) {
try {
return await apiClient.collaborationApi.createManageGroup({
Expand Down

0 comments on commit 2616b09

Please sign in to comment.