43 lines
1.1 KiB
TypeScript
43 lines
1.1 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,
|
|
},
|
|
});
|
|
},
|
|
|
|
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 };
|
|
},
|
|
};
|