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
All checks were successful
CI/CD — Build & Deploy / Build & Deploy (push) Successful in 22s
This commit is contained in:
@@ -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,
|
||||
}));
|
||||
|
||||
|
||||
Reference in New Issue
Block a user