add end date and create logo and fix filter

This commit is contained in:
arifal
2026-04-17 00:16:31 +07:00
parent 82c1da9951
commit 7159e9108f
35 changed files with 743 additions and 82 deletions
+27 -2
View File
@@ -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 },
+4 -2
View File
@@ -7,6 +7,7 @@ interface CreateTripInput {
mountain: string;
location: string;
date: Date;
endDate?: Date;
maxParticipants: number;
price: number;
organizerId: string;
@@ -14,8 +15,8 @@ interface CreateTripInput {
}
export const tripService = {
async getOpenTrips() {
return tripRepo.findOpen();
async getOpenTrips(filters?: { q?: string; from?: string; to?: string }) {
return tripRepo.findOpen(filters);
},
async getAllTrips() {
@@ -43,6 +44,7 @@ export const tripService = {
mountain: input.mountain,
location: input.location,
date: input.date,
endDate: input.endDate,
maxParticipants: input.maxParticipants,
price: input.price,
organizer: { connect: { id: input.organizerId } },