create review and profile
This commit is contained in:
@@ -0,0 +1,51 @@
|
||||
import { userRepo } from "@/server/repositories/user.repo";
|
||||
import { tripRepo } from "@/server/repositories/trip.repo";
|
||||
import { participantRepo } from "@/server/repositories/participant.repo";
|
||||
import { isPastTripLastDayForReview } from "@/lib/trip-dates";
|
||||
|
||||
export const profileService = {
|
||||
async getProfileDashboard(userId: string) {
|
||||
const user = await userRepo.findPublicProfileById(userId);
|
||||
if (!user) {
|
||||
throw new Error("Pengguna tidak ditemukan");
|
||||
}
|
||||
|
||||
const [organizedTrips, participations] = await Promise.all([
|
||||
tripRepo.findByOrganizerId(userId),
|
||||
participantRepo.findWithTripForProfile(userId),
|
||||
]);
|
||||
|
||||
const activeJoined = participations
|
||||
.filter((p) => p.status !== "CANCELLED")
|
||||
.sort(
|
||||
(a, b) =>
|
||||
new Date(b.trip.date).getTime() - new Date(a.trip.date).getTime()
|
||||
);
|
||||
const cancelledJoined = participations
|
||||
.filter((p) => p.status === "CANCELLED")
|
||||
.sort(
|
||||
(a, b) =>
|
||||
new Date(b.trip.date).getTime() - new Date(a.trip.date).getTime()
|
||||
);
|
||||
|
||||
const reviewable = activeJoined
|
||||
.filter((p) => {
|
||||
if (p.status !== "CONFIRMED") return false;
|
||||
const t = p.trip;
|
||||
if (t.organizerId === userId) return false;
|
||||
return isPastTripLastDayForReview(t.date, t.endDate);
|
||||
})
|
||||
.sort(
|
||||
(a, b) =>
|
||||
new Date(b.trip.date).getTime() - new Date(a.trip.date).getTime()
|
||||
);
|
||||
|
||||
return {
|
||||
user,
|
||||
organizedTrips,
|
||||
activeJoined,
|
||||
cancelledJoined,
|
||||
reviewable,
|
||||
};
|
||||
},
|
||||
};
|
||||
Reference in New Issue
Block a user