79 lines
2.2 KiB
TypeScript
79 lines
2.2 KiB
TypeScript
import { prisma } from "@/lib/prisma";
|
|
import { Prisma } from "@/app/generated/prisma/client";
|
|
|
|
export const organizerRepo = {
|
|
async findByUserId(userId: string) {
|
|
return prisma.organizerVerification.findUnique({ where: { userId } });
|
|
},
|
|
|
|
async findById(id: string) {
|
|
return prisma.organizerVerification.findUnique({ where: { id } });
|
|
},
|
|
|
|
async findByNikHash(nikHash: string) {
|
|
return prisma.organizerVerification.findUnique({ where: { nikHash } });
|
|
},
|
|
|
|
async upsertForUser(
|
|
userId: string,
|
|
data: Omit<Prisma.OrganizerVerificationUncheckedCreateInput, "id" | "userId" | "createdAt" | "updatedAt">
|
|
) {
|
|
return prisma.organizerVerification.upsert({
|
|
where: { userId },
|
|
create: { userId, ...data },
|
|
update: data,
|
|
});
|
|
},
|
|
|
|
async listByStatus(status?: "PENDING" | "APPROVED" | "REJECTED") {
|
|
return prisma.organizerVerification.findMany({
|
|
where: status ? { status } : undefined,
|
|
orderBy: { createdAt: "desc" },
|
|
include: {
|
|
user: { select: { id: true, name: true, email: true } },
|
|
reviewedBy: { select: { id: true, name: true, email: true } },
|
|
},
|
|
});
|
|
},
|
|
|
|
async countByStatus(status: "PENDING" | "APPROVED" | "REJECTED") {
|
|
return prisma.organizerVerification.count({ where: { status } });
|
|
},
|
|
|
|
/** Verifikasi terbaru (default PENDING) untuk preview di dashboard admin. */
|
|
async listRecent(status: "PENDING" | "APPROVED" | "REJECTED", limit = 3) {
|
|
return prisma.organizerVerification.findMany({
|
|
where: { status },
|
|
orderBy: { createdAt: "desc" },
|
|
take: limit,
|
|
select: {
|
|
id: true,
|
|
fullName: true,
|
|
createdAt: true,
|
|
user: { select: { id: true, name: true, email: true } },
|
|
},
|
|
});
|
|
},
|
|
|
|
async updateReview(
|
|
id: string,
|
|
data: {
|
|
status: "APPROVED" | "REJECTED";
|
|
rejectionReason?: string | null;
|
|
reviewedById: string;
|
|
}
|
|
) {
|
|
const now = new Date();
|
|
return prisma.organizerVerification.update({
|
|
where: { id },
|
|
data: {
|
|
status: data.status,
|
|
rejectionReason: data.rejectionReason ?? null,
|
|
reviewedById: data.reviewedById,
|
|
reviewedAt: now,
|
|
verifiedAt: data.status === "APPROVED" ? now : null,
|
|
},
|
|
});
|
|
},
|
|
};
|