Files
AnimeTV-Backend/src/modules/heroBanner/repositories/GET/findAllActiveHeroBanner.repository.ts
Rafi Arrafif 5cebd200c4
All checks were successful
Integration Tests / integration-tests (pull_request) Successful in 56s
👔 feat: support user collection check on hero banner
2026-03-30 19:03:37 +07:00

58 lines
1.3 KiB
TypeScript

import { AppError } from "../../../../helpers/error/instances/app";
import { prisma } from "../../../../utils/databases/prisma/connection";
export const findAllActiveHeroBannerRepository = async (userId?: string) => {
try {
return await prisma.heroBanner.findMany({
where: {
startDate: {
lte: new Date(),
},
endDate: {
gte: new Date(),
},
},
orderBy: [
{
orderPriority: "asc",
},
{
startDate: "asc",
},
],
select: {
orderPriority: true,
imageUrl: true,
media: {
select: {
id: true,
title: true,
slug: true,
pictureLarge: true,
synopsis: true,
genres: {
select: {
slug: true,
name: true,
},
},
_count: {
select: {
inCollections: {
where: {
collection: {
ownerId: userId,
},
},
},
},
},
},
},
},
});
} catch (error) {
throw new AppError(500, "Failed to fetch active hero banners", error);
}
};