debugging and add image uploader to guild good
This commit is contained in:
@@ -6,6 +6,7 @@ import {
|
||||
PartnerStatus,
|
||||
} from '@/generated/prisma/enums'
|
||||
import { ConsumerCreateInput, ConsumerSelect } from '@/generated/prisma/models'
|
||||
import mapConsumerWithLicenseUtil from '@/modules/consumer/utils/mapConsumerWithLicense.util'
|
||||
import { PrismaService } from '@/prisma/prisma.service'
|
||||
import { BadRequestException, Injectable } from '@nestjs/common'
|
||||
import { ResponseMapper } from 'common/response/response-mapper'
|
||||
@@ -45,44 +46,6 @@ export class AdminConsumersService {
|
||||
},
|
||||
}
|
||||
|
||||
private readonly mapConsumer = (consumer: any) => {
|
||||
const { activated_licenses, ...rest } = consumer
|
||||
|
||||
let lastLicense: any = null
|
||||
|
||||
if (consumer.activated_licenses.length) {
|
||||
lastLicense = consumer.activated_licenses[0]
|
||||
if (consumer.activated_licenses.length > 1) {
|
||||
const activeLicenseInfo = consumer.activated_licenses.find(
|
||||
activated_license => activated_license.expires_at,
|
||||
)
|
||||
|
||||
if (!activeLicenseInfo) {
|
||||
consumer.activated_licenses.sort((a, b) =>
|
||||
a.expires_at > b.expires_at ? 1 : -1,
|
||||
)
|
||||
lastLicense = consumer.activated_licenses[0]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
...rest,
|
||||
fullname: `${rest?.first_name} ${rest?.last_name}`,
|
||||
license_info: this.prepareLicenseInfo(lastLicense),
|
||||
}
|
||||
}
|
||||
|
||||
private readonly prepareLicenseInfo = (latestLicense: any) => {
|
||||
if (!latestLicense) return null
|
||||
const { license, ...rest } = latestLicense
|
||||
|
||||
return {
|
||||
...rest,
|
||||
partner: license.charged_license_transaction.partner,
|
||||
}
|
||||
}
|
||||
|
||||
async findAll() {
|
||||
const [consumers, count] = await this.prisma.$transaction([
|
||||
this.prisma.consumer.findMany({
|
||||
@@ -91,7 +54,7 @@ export class AdminConsumersService {
|
||||
this.prisma.consumer.count(),
|
||||
])
|
||||
|
||||
return ResponseMapper.paginate(consumers.map(this.mapConsumer), { count })
|
||||
return ResponseMapper.paginate(consumers.map(mapConsumerWithLicenseUtil), { count })
|
||||
}
|
||||
|
||||
async findOne(id: string) {
|
||||
@@ -100,7 +63,7 @@ export class AdminConsumersService {
|
||||
select: this.defaultSelect,
|
||||
})
|
||||
|
||||
return ResponseMapper.single(this.mapConsumer(consumer))
|
||||
return ResponseMapper.single(mapConsumerWithLicenseUtil(consumer))
|
||||
}
|
||||
|
||||
async create(data: CreateConsumerDto) {
|
||||
|
||||
Reference in New Issue
Block a user