auth, trips and join trips
This commit is contained in:
@@ -0,0 +1,28 @@
|
||||
import { prisma } from "@/lib/prisma";
|
||||
|
||||
export const participantRepo = {
|
||||
async findByTripAndUser(tripId: string, userId: string) {
|
||||
return prisma.tripParticipant.findUnique({
|
||||
where: { tripId_userId: { tripId, userId } },
|
||||
});
|
||||
},
|
||||
|
||||
async create(tripId: string, userId: string) {
|
||||
return prisma.tripParticipant.create({
|
||||
data: { tripId, userId, status: "CONFIRMED" },
|
||||
});
|
||||
},
|
||||
|
||||
async countByTrip(tripId: string) {
|
||||
return prisma.tripParticipant.count({
|
||||
where: { tripId, status: { not: "CANCELLED" } },
|
||||
});
|
||||
},
|
||||
|
||||
async cancel(tripId: string, userId: string) {
|
||||
return prisma.tripParticipant.update({
|
||||
where: { tripId_userId: { tripId, userId } },
|
||||
data: { status: "CANCELLED" },
|
||||
});
|
||||
},
|
||||
};
|
||||
@@ -0,0 +1,45 @@
|
||||
import { prisma } from "@/lib/prisma";
|
||||
import { Prisma } from "@/app/generated/prisma/client";
|
||||
|
||||
export const tripRepo = {
|
||||
async findAll() {
|
||||
return prisma.trip.findMany({
|
||||
include: {
|
||||
organizer: { select: { id: true, name: true, image: true } },
|
||||
_count: { select: { participants: true } },
|
||||
},
|
||||
orderBy: { date: "asc" },
|
||||
});
|
||||
},
|
||||
|
||||
async findOpen() {
|
||||
return prisma.trip.findMany({
|
||||
where: { status: "OPEN", date: { gte: new Date() } },
|
||||
include: {
|
||||
organizer: { select: { id: true, name: true, image: true } },
|
||||
_count: { select: { participants: true } },
|
||||
},
|
||||
orderBy: { date: "asc" },
|
||||
});
|
||||
},
|
||||
|
||||
async findById(id: string) {
|
||||
return prisma.trip.findUnique({
|
||||
where: { id },
|
||||
include: {
|
||||
organizer: { select: { id: true, name: true, email: true, image: true } },
|
||||
participants: {
|
||||
include: { user: { select: { id: true, name: true, image: true } } },
|
||||
},
|
||||
},
|
||||
});
|
||||
},
|
||||
|
||||
async create(data: Prisma.TripCreateInput) {
|
||||
return prisma.trip.create({ data });
|
||||
},
|
||||
|
||||
async updateStatus(id: string, status: "OPEN" | "FULL" | "CLOSED" | "COMPLETED") {
|
||||
return prisma.trip.update({ where: { id }, data: { status } });
|
||||
},
|
||||
};
|
||||
@@ -0,0 +1,16 @@
|
||||
import { prisma } from "@/lib/prisma";
|
||||
import { Prisma } from "@/app/generated/prisma/client";
|
||||
|
||||
export const userRepo = {
|
||||
async findByEmail(email: string) {
|
||||
return prisma.user.findUnique({ where: { email } });
|
||||
},
|
||||
|
||||
async findById(id: string) {
|
||||
return prisma.user.findUnique({ where: { id } });
|
||||
},
|
||||
|
||||
async create(data: Prisma.UserCreateInput) {
|
||||
return prisma.user.create({ data });
|
||||
},
|
||||
};
|
||||
Reference in New Issue
Block a user