Skip to content

Commit

Permalink
transform data into content for activity 8, 12, 13 and 14. Modif requ…
Browse files Browse the repository at this point in the history
…et to get only publish activity
  • Loading branch information
guillaume-pages committed Jun 11, 2024
1 parent 4c930c2 commit c3c1615
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 75 deletions.
33 changes: 1 addition & 32 deletions server/controllers/mediatheque.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,38 +40,7 @@ mediathequeController.post({ path: '' }, async (req: Request, res: Response) =>
}),
);
});
const activities = await subQueryBuilder.getMany();
res.send(activities);
} catch (error) {
console.error('Error fetching media data:', error);
res.status(500).send({ error: 'Internal Server Error' });
}
});

mediathequeController.post({ path: '/pelico' }, async (req: Request, res: Response) => {
try {
const filters: Array<Filter[]> = req.body.filters || [];

if (!Array.isArray(filters)) {
return res.status(400).send({ error: 'Invalid filters format' });
}

const subQueryBuilderUser = AppDataSource.getRepository(User)
.createQueryBuilder('user')
.where('user.type = :superAdmin', { superAdmin: 0 })
.orWhere('user.type = :admin', { admin: 1 })
.orWhere('user.type = :mediator', { mediator: 2 });

const users = await subQueryBuilderUser.getMany();

const usersId: number[] = users.map((user) => user.id);

const subQueryBuilderActivity = AppDataSource.getRepository(Activity)
.createQueryBuilder('activity')
.where('activity.userId IN (:...usersId)', { usersId });

const activities = await subQueryBuilderActivity.getMany();

const activities = await subQueryBuilder.andWhere('activity.status = :status', { status: 0 }).getMany();
res.send(activities);
} catch (error) {
console.error('Error fetching media data:', error);
Expand Down
1 change: 0 additions & 1 deletion src/components/admin/mediatheque/CardMediatheque.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ export default function MediaCard({ page }: { page: number }) {
const { allFiltered } = useContext(MediathequeContext);

const slicedData = allFiltered?.slice(page, page + 6);
console.log(slicedData)

return (
<div style={{ display: 'flex' }}>
Expand Down
108 changes: 69 additions & 39 deletions src/contexts/mediathequeContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,46 +31,74 @@ export const MediathequeProvider: React.FC<MediathequeProviderProps> = ({ childr
const [dataToUse, setDataToUse] = useState<any[]>([]);

Check warning on line 31 in src/contexts/mediathequeContext.tsx

View workflow job for this annotation

GitHub Actions / lint

Unexpected any. Specify a different type

useEffect(() => {
const activitiesMediaFinder = usersData?.map(
({
id,
content,
subType,
type,
villageId,
userId,
user,
village,
}: {
id: number;
content: object;
subType: number;
type: number;
villageId: number;
userId: number;
user: object;
village: object;
}) => {
const result = { id, subType, type, villageId, userId, content: [], user, village };
if (content.game) {
content.game.map(({ inputs }) =>
inputs.map((input: { type: number; selectedValue: string }) => {
if (input.type === 3 || input.type === 4) {
result.content.push({ type: input.type === 3 ? 'image' : 'video', value: input.selectedValue });
}
}),
);
} else {
content.map(({ type, value }: { type: string; value: string }) => {
const wantedTypes = ['image', 'video', 'sound'];
if (wantedTypes.includes(type)) {
result.content.push({ type, value });
const activitiesMediaFinder = usersData
?.filter(({ type }: { type: number }) => ![3, 5, 11].includes(type))
.map(
({
id,
content,
subType,
type,
villageId,
userId,
user,
village,
data,
}: {
id: number;
content: object;
subType: number;
type: number;
villageId: number;
userId: number;
user: object;
village: object;
data: object;
}) => {
const result = { id, subType, type, villageId, userId, content: [], user, village };
if (type === 8 || type === 12 || type === 13 || type === 14) {
if (type === 8) {
result.content.push({ type: 'image', value: data.mascotteImage });

Check failure on line 61 in src/contexts/mediathequeContext.tsx

View workflow job for this annotation

GitHub Actions / typescript

Type 'string' is not assignable to type 'never'.

Check failure on line 61 in src/contexts/mediathequeContext.tsx

View workflow job for this annotation

GitHub Actions / typescript

Type 'any' is not assignable to type 'never'.

Check failure on line 61 in src/contexts/mediathequeContext.tsx

View workflow job for this annotation

GitHub Actions / typescript

Property 'mascotteImage' does not exist on type 'object'.
}
if (type === 12) {
result.content.push({ type: 'sound', value: data.verseFinalMixUrl });

Check failure on line 64 in src/contexts/mediathequeContext.tsx

View workflow job for this annotation

GitHub Actions / typescript

Type 'string' is not assignable to type 'never'.

Check failure on line 64 in src/contexts/mediathequeContext.tsx

View workflow job for this annotation

GitHub Actions / typescript

Type 'any' is not assignable to type 'never'.

Check failure on line 64 in src/contexts/mediathequeContext.tsx

View workflow job for this annotation

GitHub Actions / typescript

Property 'verseFinalMixUrl' does not exist on type 'object'.
result.content.push({ type: 'sound', value: data.verseMixUrl });
result.content.push({ type: 'sound', value: data.verseMixWithIntroUrl });
result.content.push({ type: 'sound', value: data.verseMixWithVocalsUrl });
}
});
}
return result;
},
);
if (type === 13 || type === 14) {
const properties = ['odd', 'object', 'place', 'tale'];

properties.forEach((prop) => {
if (prop === 'tale') {
result.content.push({ type: 'image', value: data[prop].imageStory });
} else {
result.content.push({ type: 'image', value: data[prop].imageUrl });
}
});
}
}
if (content.game) {
content.game.map(({ inputs }) =>
inputs.map((input: { type: number; selectedValue: string }) => {
if (input.type === 3 || input.type === 4) {
result.content.push({ type: input.type === 3 ? 'image' : 'video', value: input.selectedValue });
}
}),
);
} else {
content.map(({ type, value }: { type: string; value: string }) => {
const wantedTypes = ['image', 'video', 'sound'];
if (wantedTypes.includes(type)) {
result.content.push({ type, value });
}
});
}
return result;
},
);

console.log('activitiesMediaFinder', activitiesMediaFinder);

Check failure on line 101 in src/contexts/mediathequeContext.tsx

View workflow job for this annotation

GitHub Actions / lint

Unexpected console statement

const activitiesWithMediaOnly = activitiesMediaFinder?.filter((a) => a.content.length > 0);
const activitiesFromPelico = activitiesWithMediaOnly?.filter((a) => [0, 1, 2].includes(a.user.type));
Expand All @@ -93,6 +121,8 @@ export const MediathequeProvider: React.FC<MediathequeProviderProps> = ({ childr
[filters, dataToUse, useAdminData],
);

console.log('data to use = ', dataToUse);

Check failure on line 124 in src/contexts/mediathequeContext.tsx

View workflow job for this annotation

GitHub Actions / lint

Unexpected console statement

return <MediathequeContext.Provider value={value}>{children}</MediathequeContext.Provider>;
};

Expand Down
4 changes: 1 addition & 3 deletions src/pages/admin/newportal/medialibrary/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,7 @@ const Mediatheque = () => {
const { setFilters, allFiltered, setUseAdminData } = useContext(MediathequeContext);
const [page, setPage] = useState<number>(0);
const [updateFiltersKey, setUpdateFiltersKey] = useState(0);
const [isChecked, setIsChecked] = useState(false); // État de la case à cocher

// Explication : Dans React, lorsque la valeur de la clé (key) d'un composant change, React considère que ce composant est un composant différent de celui qui était rendu précédemment avec la même clé. En conséquence, React déclenche un rechargement complet du composant avec la nouvelle clé.
const [isChecked, setIsChecked] = useState(false);

const handleResetFilters = () => {
setUseAdminData(false);
Expand Down

0 comments on commit c3c1615

Please sign in to comment.