diff --git a/apps/api/v1/services/transaction.service.ts b/apps/api/v1/services/transaction.service.ts index 93f6b58c..3c877b94 100644 --- a/apps/api/v1/services/transaction.service.ts +++ b/apps/api/v1/services/transaction.service.ts @@ -1,6 +1,7 @@ import type { CreateTransaction, UpdateTransaction } from '@6pm/validation' import type { Budget, + Prisma, Transaction, User, UserWalletAccount, @@ -16,6 +17,13 @@ import { getExchangeRate } from './exchange-rates.service' const VND = 'VND' +const TRANSACTION_INCLUDE: Prisma.TransactionInclude = { + category: true, + blobAttachments: true, + walletAccount: true, + budget: true, +} + export async function canUserCreateTransaction({ user, budget, @@ -110,7 +118,7 @@ export async function findTransaction({ }) { return prisma.transaction.findUnique({ where: { id: transactionId }, - include: { category: true, blobAttachments: true }, + include: TRANSACTION_INCLUDE, }) } @@ -149,7 +157,7 @@ export async function createTransaction({ connect: blobAttachmentIds?.map((id) => ({ id })), }, }, - include: { category: true, blobAttachments: true }, + include: TRANSACTION_INCLUDE, }) return transaction @@ -206,7 +214,7 @@ export async function updateTransaction({ amountInVnd, blobAttachments: { set: blobAttachmentIds?.map((id) => ({ id })) }, }, - include: { category: true, blobAttachments: true }, + include: TRANSACTION_INCLUDE, }) return transaction @@ -252,7 +260,7 @@ export async function listTransactions({ }, orderBy: { date: 'desc' }, take: pagination.first || pagination.last, - include: { category: true, blobAttachments: true }, + include: TRANSACTION_INCLUDE, }) const totalCount = await prisma.transaction.count({ diff --git a/packages/validation/src/transaction.zod.ts b/packages/validation/src/transaction.zod.ts index ec4b63d9..f50bc2bb 100644 --- a/packages/validation/src/transaction.zod.ts +++ b/packages/validation/src/transaction.zod.ts @@ -1,5 +1,11 @@ import { z } from 'zod' -import { CategorySchema, TransactionSchema } from './prisma' +import { + BlobObjectSchema, + BudgetSchema, + CategorySchema, + TransactionSchema, + UserWalletAccountSchema, +} from './prisma' export const zCreateTransaction = z.object({ id: z.string().optional(), @@ -36,6 +42,9 @@ export const TransactionPopulatedSchema = TransactionSchema.extend({ }) .nullable() .optional(), + budget: BudgetSchema.nullable().optional(), + walletAccount: UserWalletAccountSchema.nullable().optional(), + blobAttachments: z.array(BlobObjectSchema).nullable().optional(), amount: z.number({ coerce: true }), amountInVnd: z.number({ coerce: true }), })