Skip to content

Commit

Permalink
fix: lint
Browse files Browse the repository at this point in the history
  • Loading branch information
Lukasambry committed Nov 8, 2024
1 parent 64b09fd commit 3fbf244
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 24 deletions.
21 changes: 12 additions & 9 deletions server/controllers/archive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,18 @@ import { Controller } from './controller';
const archiveController = new Controller('/archives');

// get file
archiveController.get({ path: '/*', userType: [UserType.SUPER_ADMIN, UserType.ADMIN, UserType.MEDIATOR] }, async (req: Request, res: Response, next: NextFunction) => {
const url = decodeURI(req.url);
const key = `archives${url}${url.split('/').length === 2 ? '/index.html' : url.indexOf('.') === -1 ? '.html' : ''}`;
try {
streamFile(key, req, res, next);
} catch {
next();
}
});
archiveController.get(
{ path: '/*', userType: [UserType.SUPER_ADMIN, UserType.ADMIN, UserType.MEDIATOR] },
async (req: Request, res: Response, next: NextFunction) => {
const url = decodeURI(req.url);
const key = `archives${url}${url.split('/').length === 2 ? '/index.html' : url.indexOf('.') === -1 ? '.html' : ''}`;
try {
streamFile(key, req, res, next);
} catch {
next();
}
},
);

/**
* Liste les dossiers dans un préfixe S3 spécifié.
Expand Down
30 changes: 17 additions & 13 deletions src/api/archive/archive.get.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,26 @@
import axios from 'axios';
import React from 'react';
import { useQuery } from 'react-query';
import {UserContext} from "../../contexts/userContext";
import React from "react";
import {UserType} from "../../../types/user.type";
const { user } = React.useContext(UserContext);

import { UserType } from '../../../types/user.type';
import { UserContext } from '../../contexts/userContext';

const BASE_URL = '/api/archives';

// Récupérer la liste des années déjà archivées
export const useListArchives = () => {
const { user } = React.useContext(UserContext);
if(!user) return;
const hasAccess = user?.type === [UserType.SUPER_ADMIN, UserType.ADMIN, UserType.MEDIATOR].find((type) => type === user?.type);
if (!hasAccess) {
return;
}
return useQuery(['archives'], async () => {
const { data } = await axios.get(`${BASE_URL}`);
return data;
});

const hasAccess = user && [UserType.SUPER_ADMIN, UserType.ADMIN, UserType.MEDIATOR].includes(user.type);

return useQuery(
['archives'],
async () => {
const { data } = await axios.get(`${BASE_URL}`);
return data;
},
{
enabled: hasAccess, // La requête ne sera exécutée que si hasAccess est true

Check failure on line 23 in src/api/archive/archive.get.ts

View workflow job for this annotation

GitHub Actions / typescript

Type 'boolean | null' is not assignable to type 'boolean | undefined'.
},
);
};
2 changes: 0 additions & 2 deletions src/pages/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ import { UserContext } from 'src/contexts/userContext';

const Home = () => {
const { isLoggedIn } = React.useContext(UserContext);
const { user } = React.useContext(UserContext);
console.log(user);

if (!isLoggedIn) {
return <NewHome />;
Expand Down

0 comments on commit 3fbf244

Please sign in to comment.