feat: B3 — search vidéos (filtre client-side + param ?q= backend)
All checks were successful
CI/CD — Build & Deploy / Build & Deploy (push) Successful in 22s

This commit is contained in:
2026-03-15 02:22:04 +01:00
parent 426cd4bbbd
commit d69281a2e0
2 changed files with 37 additions and 11 deletions

View File

@@ -35,19 +35,26 @@ router.get("/", async (req: Request, res: Response): Promise<void> => {
try {
const user = (req as AuthenticatedRequest).user as AuthenticatedUser | undefined;
const userLevel = user ? await getUserPlanLevel(user.id) : 0;
const q = typeof req.query.q === "string" ? req.query.q.trim() : "";
const videos = await AppDataSource.getRepository(Video).find({
where: { isPublished: true },
order: { publishedAt: "DESC" },
select: ["id", "title", "description", "thumbnailUrl", "duration",
"storageType", "storageKey", "requiredLevel", "publishedAt"],
});
const qb = AppDataSource.getRepository(Video)
.createQueryBuilder("v")
.where("v.isPublished = :pub", { pub: true })
.select([
"v.id", "v.title", "v.description", "v.thumbnailUrl", "v.duration",
"v.storageType", "v.storageKey", "v.requiredLevel", "v.publishedAt",
])
.orderBy("v.publishedAt", "DESC");
if (q) {
qb.andWhere("(v.title LIKE :q OR v.description LIKE :q)", { q: `%${q}%` });
}
const videos = await qb.getMany();
// Injequer un flag `locked` côté client pour les vidéos hors niveau
const result = videos.map((v) => ({
...v,
locked: v.requiredLevel > userLevel,
// Ne pas exposer storageKey si la vidéo est verrouillée
storageKey: v.requiredLevel > userLevel ? null : v.storageKey,
}));