import { PartnerAccountQuotaAllocationWhereInput } from '@/generated/prisma/models' import { PrismaService } from '@/prisma/prisma.service' import { Injectable } from '@nestjs/common' import { ResponseMapper } from 'common/response/response-mapper' @Injectable() export class PartnerAllocatedAccountsService { constructor(private readonly prisma: PrismaService) {} async findAll(partner_id: string, page = 1, pageSize = 10) { const defaultWhere: PartnerAccountQuotaAllocationWhereInput = { charge_transaction: { partner_id, }, } const [allocations, count] = await this.prisma.$transaction(async tx => [ await tx.partnerAccountQuotaAllocation.findMany({ where: defaultWhere, skip: (page - 1) * pageSize, take: pageSize, select: { id: true, created_at: true, updated_at: true, charge_transaction_id: true, license_id: true, charge_transaction: { select: { id: true, tracking_code: true, purchased_count: true, created_at: true, }, }, license: { select: { id: true, accounts_limit: true, activation: { select: { id: true, business_activity_id: true, }, }, }, }, }, }), await tx.partnerAccountQuotaAllocation.count({ where: defaultWhere, }), ]) return ResponseMapper.paginate(allocations, { page, pageSize, count, }) } }