$crim
$crim
Explore posts from servers
PPrisma
Created by $crim on 4/30/2024 in #help-and-questions
Prisma Query
Hello I'm trying to create a search logic using nest js and prisma, async searchConsumer( prisma: Prisma.TransactionClient, query: SearchAccountQuery, page: number, pageSize: number, ) { try { console.log('Rewarding Transactions Where:', { AND: [ query.fromAmount !== undefined ? { amount: { gte: query.fromAmount } } : {}, query.toAmount !== undefined ? { amount: { lte: query.toAmount } } : {}, query.fromPoints !== undefined ? { points: { gte: query.fromPoints } } : {}, query.toPoints !== undefined ? { points: { lte: query.toPoints } } : {}, ], }); const consumers = await prisma.account.findMany({ where: { AND: { account_type: 'consumer' }, OR: [ { name: { contains: query.name, mode: 'insensitive' } }, { email: { contains: query.email, mode: 'insensitive' } }, { phone_number: { contains: query.phone_number } }, { id: { equals: query.id } }, ], }, include: { rewarding_transactions: { where: { AND: [ query.fromAmount !== undefined ? { amount: { gte: query.fromAmount } } : {}, query.toAmount !== undefined ? { amount: { lte: query.toAmount } } : {}, query.fromPoints !== undefined ? { points: { gte: query.fromPoints } } : {}, query.toPoints !== undefined ? { points: { lte: query.toPoints } } : {}, ], }, select: { amount: true, points: true, }, }, }, ...(page && { ...(pageSize && { skip: Number(pageSize) * Number(page - 1), take: Number(pageSize), }), }), }); return { totalCount: consumers.length, data: consumers, }; } catch (error) { this.logger.error(error); throw new BadRequestException(error); } } But When I send a from and to amount or points I didn't get anything.
4 replies