Files
setrip/server/repositories/user.repo.ts
T
2026-05-08 18:23:51 +07:00

68 lines
1.7 KiB
TypeScript

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 } });
},
/** Profil publik (tanpa password) untuk halaman akun. */
async findPublicProfileById(id: string) {
return prisma.user.findUnique({
where: { id },
select: {
id: true,
name: true,
email: true,
image: true,
createdAt: true,
},
});
},
/**
* Profil sosial publik untuk halaman /u/[id]. JANGAN sertakan field sensitif
* (email, password, KYC). Hanya yang user pilih untuk dibagikan.
*/
async findSocialProfileById(id: string) {
return prisma.user.findUnique({
where: { id },
select: {
id: true,
name: true,
image: true,
createdAt: true,
profile: {
select: {
bio: true,
city: true,
interests: true,
instagram: true,
},
},
organizerVerification: { select: { status: true } },
},
});
},
async create(data: Prisma.UserCreateInput) {
return prisma.user.create({ data });
},
/**
* Tandai user sudah accept T&C/Privacy. Idempotent: kalau sudah `true`,
* tidak overwrite `acceptedAt` (audit trail pertama tetap akurat).
*/
async markAcceptedTerms(id: string) {
const result = await prisma.user.updateMany({
where: { id, acceptedTermsAndPrivacy: false },
data: { acceptedTermsAndPrivacy: true, acceptedAt: new Date() },
});
return { updated: result.count > 0 };
},
};