From 2d5ea601b97d76fd1f2fc5a2f4fc25e68cb425c2 Mon Sep 17 00:00:00 2001 From: Dustin Do Date: Mon, 23 Sep 2024 11:18:58 +0700 Subject: [PATCH] feat(api): include UserMetadata in User queries --- apps/api/v1/services/user.service.ts | 25 +++++++++++-------------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/apps/api/v1/services/user.service.ts b/apps/api/v1/services/user.service.ts index d925297..6b099bc 100644 --- a/apps/api/v1/services/user.service.ts +++ b/apps/api/v1/services/user.service.ts @@ -1,6 +1,6 @@ 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 { @@ -8,30 +8,28 @@ import { 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 @@ -39,9 +37,8 @@ export async function createUser({ data }: { data: CreateUser }) { export async function deleteUser(userId: string) { return await prisma.user.delete({ - where: { - id: userId, - }, + where: { id: userId }, + include: USER_INCLUDE, }) }