add payment, trust badge, handle race condition, fix booking schema

This commit is contained in:
arifal
2026-04-20 23:57:31 +07:00
parent ba5f64ae0e
commit fcdca34460
33 changed files with 1781 additions and 138 deletions
+39
View File
@@ -0,0 +1,39 @@
import { prisma } from "@/lib/prisma";
import { TRIP_LEADER_MIN_TRIPS } from "@/lib/trust";
export type OrganizerTrust = {
isVerified: boolean;
tripsCreated: number;
avgRating: number | null;
reviewCount: number;
isTripLeader: boolean;
};
export const trustService = {
async getOrganizerTrust(organizerId: string): Promise<OrganizerTrust> {
const [user, tripsCreated, reviewAgg] = await Promise.all([
prisma.user.findUnique({
where: { id: organizerId },
select: { isVerified: true },
}),
prisma.trip.count({ where: { organizerId } }),
prisma.tripReview.aggregate({
where: {
trip: { organizerId },
},
_avg: { rating: true },
_count: { _all: true },
}),
]);
const avg = reviewAgg._avg.rating;
return {
isVerified: user?.isVerified ?? false,
tripsCreated,
avgRating:
avg != null ? Math.round(Number(avg) * 10) / 10 : null,
reviewCount: reviewAgg._count._all,
isTripLeader: tripsCreated >= TRIP_LEADER_MIN_TRIPS,
};
},
};