refactor: consolidate admin/users management under /people
This commit is contained in:
@@ -2,6 +2,14 @@ import type { Person, Prisma } from "@/generated/prisma/client"
|
||||
import { paginate } from "@/lib/paginate"
|
||||
import prisma from "@/lib/prisma"
|
||||
|
||||
const personWithUserSelect = {
|
||||
include: { user: true },
|
||||
} as const
|
||||
|
||||
export type PersonWithUser = Prisma.PersonGetPayload<
|
||||
typeof personWithUserSelect
|
||||
>
|
||||
|
||||
export const PersonService = {
|
||||
findAll: async (): Promise<Person[]> => {
|
||||
return prisma.person.findMany({
|
||||
@@ -19,10 +27,11 @@ export const PersonService = {
|
||||
pageSize?: number
|
||||
search?: string
|
||||
}) => {
|
||||
return paginate<Person>({
|
||||
return paginate<PersonWithUser>({
|
||||
model: prisma.person,
|
||||
page,
|
||||
pageSize,
|
||||
include: personWithUserSelect.include,
|
||||
where: {
|
||||
...(search
|
||||
? {
|
||||
@@ -47,6 +56,16 @@ export const PersonService = {
|
||||
return db.person.findUnique({ where: { id } })
|
||||
},
|
||||
|
||||
findByIdWithUser: async (
|
||||
id: string,
|
||||
db: Prisma.TransactionClient | typeof prisma = prisma,
|
||||
): Promise<PersonWithUser | null> => {
|
||||
return db.person.findUnique({
|
||||
where: { id },
|
||||
include: personWithUserSelect.include,
|
||||
})
|
||||
},
|
||||
|
||||
findByEmail: async (
|
||||
email: string,
|
||||
db: Prisma.TransactionClient | typeof prisma = prisma,
|
||||
|
||||
Reference in New Issue
Block a user