Skip to content

Commit

Permalink
feat(api): include UserMetadata in User queries
Browse files Browse the repository at this point in the history
  • Loading branch information
duongdev committed Sep 23, 2024
1 parent 0781de5 commit 2d5ea60
Showing 1 changed file with 11 additions and 14 deletions.
25 changes: 11 additions & 14 deletions apps/api/v1/services/user.service.ts
Original file line number Diff line number Diff line change
@@ -1,47 +1,44 @@
import type { UserEntitlement } from '@6pm/utilities'
import type { CreateUser } from '@6pm/validation'
import type { User } from '@prisma/client'
import type { Prisma, User } from '@prisma/client'
import { getLogger } from '../../lib/log'
import prisma from '../../lib/prisma'
import {
getCustomerActiveSubscription,
getOrCreateCustomer,
} from './revenue-cat.service'

const USER_INCLUDE: Prisma.UserInclude = { metadata: true }

export async function findUserById(id: string) {
return await prisma.user.findUnique({
where: {
id,
},
where: { id },
include: USER_INCLUDE,
})
}

export async function findUserByEmail(email: string) {
return await prisma.user.findUnique({
where: {
email,
},
where: { email },
include: USER_INCLUDE,
})
}

export async function createUser({ data }: { data: CreateUser }) {
const user = await prisma.user.upsert({
where: {
id: data.id,
email: data.email,
},
where: { id: data.id, email: data.email },
create: data,
update: data,
include: USER_INCLUDE,
})

return user
}

export async function deleteUser(userId: string) {
return await prisma.user.delete({
where: {
id: userId,
},
where: { id: userId },
include: USER_INCLUDE,
})
}

Expand Down

0 comments on commit 2d5ea60

Please sign in to comment.