add end date and create logo and fix filter
This commit is contained in:
@@ -13,9 +13,34 @@ export const tripRepo = {
|
||||
});
|
||||
},
|
||||
|
||||
async findOpen() {
|
||||
async findOpen(filters?: { q?: string; from?: string; to?: string }) {
|
||||
const where: Prisma.TripWhereInput = {
|
||||
status: "OPEN",
|
||||
date: { gte: new Date() },
|
||||
};
|
||||
|
||||
if (filters?.q) {
|
||||
where.OR = [
|
||||
{ title: { contains: filters.q, mode: "insensitive" } },
|
||||
{ mountain: { contains: filters.q, mode: "insensitive" } },
|
||||
{ location: { contains: filters.q, mode: "insensitive" } },
|
||||
];
|
||||
}
|
||||
|
||||
if (filters?.from || filters?.to) {
|
||||
const dateFilter: Prisma.DateTimeFilter = { gte: new Date() };
|
||||
if (filters.from) {
|
||||
const fromDate = new Date(filters.from);
|
||||
if (fromDate > new Date()) dateFilter.gte = fromDate;
|
||||
}
|
||||
if (filters.to) {
|
||||
dateFilter.lte = new Date(filters.to + "T23:59:59.999Z");
|
||||
}
|
||||
where.date = dateFilter;
|
||||
}
|
||||
|
||||
return prisma.trip.findMany({
|
||||
where: { status: "OPEN", date: { gte: new Date() } },
|
||||
where,
|
||||
include: {
|
||||
organizer: { select: { id: true, name: true, image: true } },
|
||||
images: { orderBy: { order: "asc" }, take: 1 },
|
||||
|
||||
Reference in New Issue
Block a user