Skip to content

Commit

Permalink
run formatter
Browse files Browse the repository at this point in the history
  • Loading branch information
reyniersbram committed May 3, 2024
1 parent d717c72 commit f876ce1
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 9 deletions.
11 changes: 9 additions & 2 deletions frontend/src/router/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,12 @@ import { createRouter, createWebHistory } from "vue-router";
import { type Middleware, type MiddlewareContext, nextFactory } from "./middleware/index";
import isAuthenticated from "./middleware/isAuthenticated";
import loginMiddleware from "./middleware/login";
import useCanVisit, { useIsAdminCondition, useIsTeacherCondition, useIsPartOfSubjectCondition, useAndCondition } from "./middleware/canVisit";
import useCanVisit, {
useIsAdminCondition,
useIsTeacherCondition,
useIsPartOfSubjectCondition,
useAndCondition,
} from "./middleware/canVisit";
import { ref } from "vue";

declare module "vue-router" {
Expand Down Expand Up @@ -93,7 +98,9 @@ const router = createRouter({
component: () => import("../views/CreateProjectView.vue"),
props: (route) => ({ subjectId: Number(route.params.subjectId) }),
meta: {
middleware: useCanVisit(useAndCondition(useIsPartOfSubjectCondition, useIsTeacherCondition)),
middleware: useCanVisit(
useAndCondition(useIsPartOfSubjectCondition, useIsTeacherCondition)
),
},
},
{
Expand Down
17 changes: 10 additions & 7 deletions frontend/src/router/middleware/canVisit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@ import useIsTeacher from "@/composables/useIsTeacher";
import { useSubjectsQuery } from "@/queries/Subject";

export interface CanVisitCondition {
(queryClient: QueryClient, context: MiddlewareContext): { condition: Ref<boolean>; isLoading: Ref<boolean> };
(
queryClient: QueryClient,
context: MiddlewareContext
): { condition: Ref<boolean>; isLoading: Ref<boolean> };
}

function useCanVisit(useCondition: CanVisitCondition): Middleware {
Expand Down Expand Up @@ -72,10 +75,10 @@ export const useIsTeacherCondition: CanVisitCondition = (qc) => {
};

export const useIsPartOfSubjectCondition: CanVisitCondition = (qc, ctx) => {
const subjectId = Number(ctx.to.params.subjectId);
const {data: subjects, isLoading} = useSubjectsQuery(qc);
const condition = computed(() => {
return subjects.value?.findIndex((subject) => subject.id === subjectId) !== -1;
})
return { condition, isLoading };
const subjectId = Number(ctx.to.params.subjectId);
const { data: subjects, isLoading } = useSubjectsQuery(qc);
const condition = computed(() => {
return subjects.value?.findIndex((subject) => subject.id === subjectId) !== -1;
});
return { condition, isLoading };
};

0 comments on commit f876ce1

Please sign in to comment.