2026-04-13 15:47:59 +03:30
|
|
|
import { ResponseMapper } from '@/common/response/response-mapper'
|
2026-04-24 02:20:15 +03:30
|
|
|
import { PartnerSelect } from '@/generated/prisma/models'
|
2026-04-13 15:47:59 +03:30
|
|
|
import { PrismaService } from '@/prisma/prisma.service'
|
|
|
|
|
import { Injectable } from '@nestjs/common'
|
2026-04-24 02:20:15 +03:30
|
|
|
import { UpdatePartnerProfileDto } from './dto/partner.dto'
|
2026-04-13 15:47:59 +03:30
|
|
|
|
|
|
|
|
@Injectable()
|
|
|
|
|
export class PartnerService {
|
|
|
|
|
constructor(private readonly prisma: PrismaService) {}
|
|
|
|
|
|
2026-04-24 02:20:15 +03:30
|
|
|
private readonly defaultSelect: PartnerSelect = {
|
|
|
|
|
id: true,
|
|
|
|
|
name: true,
|
|
|
|
|
status: true,
|
|
|
|
|
account_quota_charge_transactions: {
|
2026-04-13 15:47:59 +03:30
|
|
|
select: {
|
2026-04-24 02:20:15 +03:30
|
|
|
_count: {
|
2026-04-23 20:59:39 +03:30
|
|
|
select: {
|
2026-04-24 02:20:15 +03:30
|
|
|
allocations: {
|
|
|
|
|
where: {
|
|
|
|
|
license_id: undefined,
|
2026-04-23 20:59:39 +03:30
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
2026-04-13 15:47:59 +03:30
|
|
|
},
|
2026-04-24 02:20:15 +03:30
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async getInfo(partner_id: string) {
|
|
|
|
|
const partner = await this.prisma.partner.findUniqueOrThrow({
|
|
|
|
|
where: {
|
|
|
|
|
id: partner_id,
|
|
|
|
|
},
|
|
|
|
|
select: this.defaultSelect,
|
2026-04-13 15:47:59 +03:30
|
|
|
})
|
|
|
|
|
|
|
|
|
|
return ResponseMapper.single(partner)
|
|
|
|
|
}
|
2026-04-24 02:20:15 +03:30
|
|
|
|
|
|
|
|
async updateInfo(partner_id: string, data: UpdatePartnerProfileDto) {
|
|
|
|
|
const updatedPartner = await this.prisma.partner.update({
|
|
|
|
|
where: {
|
|
|
|
|
id: partner_id,
|
|
|
|
|
},
|
|
|
|
|
data,
|
|
|
|
|
select: this.defaultSelect,
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
return ResponseMapper.single(updatedPartner)
|
|
|
|
|
}
|
2026-04-13 15:47:59 +03:30
|
|
|
}
|