general category trip
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import { prisma } from "@/lib/prisma";
|
||||
import { Prisma } from "@/app/generated/prisma/client";
|
||||
import type { ActivityCategory } from "@/app/generated/prisma/enums";
|
||||
import {
|
||||
utcStartOfDay,
|
||||
utcDayStartFromYmd,
|
||||
@@ -7,6 +8,13 @@ import {
|
||||
maxUtcDate,
|
||||
} from "@/lib/trip-dates";
|
||||
|
||||
export interface TripFilters {
|
||||
q?: string;
|
||||
from?: string;
|
||||
to?: string;
|
||||
category?: ActivityCategory;
|
||||
}
|
||||
|
||||
export const tripRepo = {
|
||||
async findAll() {
|
||||
return prisma.trip.findMany({
|
||||
@@ -30,11 +38,15 @@ export const tripRepo = {
|
||||
});
|
||||
},
|
||||
|
||||
async findOpen(filters?: { q?: string; from?: string; to?: string }) {
|
||||
async findOpen(filters?: TripFilters) {
|
||||
const todayStart = utcStartOfDay(new Date());
|
||||
|
||||
const andParts: Prisma.TripWhereInput[] = [{ status: "OPEN" }];
|
||||
|
||||
if (filters?.category) {
|
||||
andParts.push({ category: filters.category });
|
||||
}
|
||||
|
||||
if (!filters?.from && !filters?.to) {
|
||||
andParts.push({ date: { gte: todayStart } });
|
||||
} else {
|
||||
@@ -72,7 +84,7 @@ export const tripRepo = {
|
||||
andParts.push({
|
||||
OR: [
|
||||
{ title: { contains: filters.q, mode: "insensitive" } },
|
||||
{ mountain: { contains: filters.q, mode: "insensitive" } },
|
||||
{ destination: { contains: filters.q, mode: "insensitive" } },
|
||||
{ location: { contains: filters.q, mode: "insensitive" } },
|
||||
],
|
||||
});
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { Prisma } from "@/app/generated/prisma/client";
|
||||
import type { ActivityCategory } from "@/app/generated/prisma/enums";
|
||||
import { prisma } from "@/lib/prisma";
|
||||
import { tripRepo } from "@/server/repositories/trip.repo";
|
||||
import { tripRepo, type TripFilters } from "@/server/repositories/trip.repo";
|
||||
import { participantRepo } from "@/server/repositories/participant.repo";
|
||||
import { LIMITS } from "@/lib/limits";
|
||||
import { utcStartOfDay, isTripDepartureDayPast } from "@/lib/trip-dates";
|
||||
@@ -17,9 +18,10 @@ function isSerializationConflict(err: unknown): boolean {
|
||||
}
|
||||
|
||||
interface CreateTripInput {
|
||||
category: ActivityCategory;
|
||||
title: string;
|
||||
description?: string;
|
||||
mountain: string;
|
||||
destination: string;
|
||||
location: string;
|
||||
meetingPoint?: string;
|
||||
itinerary?: string;
|
||||
@@ -34,7 +36,7 @@ interface CreateTripInput {
|
||||
}
|
||||
|
||||
export const tripService = {
|
||||
async getOpenTrips(filters?: { q?: string; from?: string; to?: string }) {
|
||||
async getOpenTrips(filters?: TripFilters) {
|
||||
return tripRepo.findOpen(filters);
|
||||
},
|
||||
|
||||
@@ -67,9 +69,10 @@ export const tripService = {
|
||||
: undefined;
|
||||
|
||||
const tripData = {
|
||||
category: input.category,
|
||||
title: input.title,
|
||||
description: input.description,
|
||||
mountain: input.mountain,
|
||||
destination: input.destination,
|
||||
location: input.location,
|
||||
meetingPoint: input.meetingPoint,
|
||||
itinerary: input.itinerary,
|
||||
|
||||
Reference in New Issue
Block a user