feat: add consumer accounts and business activities management
- Implemented AccountsService for managing consumer accounts including create, update, delete, and find operations. - Created DTOs for account creation and updates. - Developed BusinessActivitiesController and BusinessActivitiesService for handling business activities related to consumers. - Added complexes management with ComplexesController and ComplexesService. - Introduced POS management with ComplexPosesController and ComplexPosesService. - Created necessary DTOs for business activities and POS. - Established Licenses management with LicensesController and LicensesService. - Integrated consumer management with PartnerConsumersController and PartnerConsumersService. - Added Prisma module imports and service connections across modules.
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import { PasswordUtil } from '@/common/utils/password.util'
|
||||
import { ChargedLicenseTransactions } from '@/generated/prisma/client'
|
||||
import { LicenseChargeTransaction } from '@/generated/prisma/client'
|
||||
import {
|
||||
AccountStatus,
|
||||
AccountType,
|
||||
@@ -22,24 +22,10 @@ export class PartnersService {
|
||||
code: true,
|
||||
status: true,
|
||||
created_at: true,
|
||||
chargedLicenseTransactions: {
|
||||
select: {
|
||||
activation_expires_at: true,
|
||||
licenses: {
|
||||
select: {
|
||||
activated_license: {
|
||||
select: {
|
||||
id: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
private readonly separateLicenseCount = (
|
||||
transactions: ChargedLicenseTransactions[] | null,
|
||||
transactions: LicenseChargeTransaction[] | null,
|
||||
) => {
|
||||
function toDateOnlyString(date) {
|
||||
return date.toISOString().slice(0, 10)
|
||||
@@ -49,9 +35,7 @@ export class PartnersService {
|
||||
|
||||
const used = transactions?.reduce((sum, cur) => {
|
||||
const license = cur as any
|
||||
return (
|
||||
sum + license.licenses.filter(license => license.activated_license).length || 0
|
||||
)
|
||||
return sum + license.licenses.filter(license => license.activation).length || 0
|
||||
}, 0)
|
||||
|
||||
const total = transactions?.reduce((sum, cur) => {
|
||||
@@ -64,9 +48,7 @@ export class PartnersService {
|
||||
const license = cur as any
|
||||
const activationExpiresDate = toDateOnlyString(license.activation_expires_at)
|
||||
if (startOfTodayDate > activationExpiresDate)
|
||||
return (
|
||||
sum + license.licenses.filter(license => !license.activated_license).length || 0
|
||||
)
|
||||
return sum + license.licenses.filter(license => !license.activation).length || 0
|
||||
return sum
|
||||
}, 0)
|
||||
|
||||
@@ -82,27 +64,85 @@ export class PartnersService {
|
||||
select: this.defaultSelect,
|
||||
})
|
||||
|
||||
const mappedPartners = partners.map(partner => {
|
||||
const { chargedLicenseTransactions, ...rest } = partner
|
||||
return {
|
||||
...rest,
|
||||
licenses_status: this.separateLicenseCount(chargedLicenseTransactions),
|
||||
}
|
||||
})
|
||||
// const mappedPartners = partners.map(partner => {
|
||||
// const { license_charge_transactions, account_quota_charge_transactions, ...rest } = partner
|
||||
// const a = { total: 0, used: 0, expired: 0 }
|
||||
|
||||
return ResponseMapper.list(mappedPartners)
|
||||
// account_quota_charge_transactions.forEach(account_quota_charge_transaction => {
|
||||
// a.total += account_quota_charge_transaction.
|
||||
// })
|
||||
// return {
|
||||
// ...rest,
|
||||
// licenses_status: this.separateLicenseCount(license_charge_transactions),
|
||||
// }
|
||||
// })
|
||||
|
||||
return ResponseMapper.list(partners)
|
||||
}
|
||||
|
||||
async findOne(id: string) {
|
||||
const partner = await this.prisma.partner.findUniqueOrThrow({
|
||||
where: { id },
|
||||
select: this.defaultSelect,
|
||||
select: {
|
||||
...this.defaultSelect,
|
||||
license_charge_transactions: {
|
||||
select: {
|
||||
purchased_count: true,
|
||||
_count: {
|
||||
select: {
|
||||
licenses: {
|
||||
where: {
|
||||
activation: {
|
||||
isNot: null,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
account_quota_charge_transactions: {
|
||||
select: {
|
||||
purchased_count: true,
|
||||
_count: {
|
||||
select: {
|
||||
allocations: {
|
||||
where: {
|
||||
license_id: null,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
const { license_charge_transactions, account_quota_charge_transactions, ...rest } =
|
||||
partner
|
||||
|
||||
const account_quota_status = { total: 0, used: 0, expired: 0 }
|
||||
account_quota_charge_transactions.forEach(account_quota_charge_transaction => {
|
||||
account_quota_status.total += account_quota_charge_transaction.purchased_count
|
||||
account_quota_status.used += account_quota_charge_transaction._count.allocations
|
||||
account_quota_status.expired +=
|
||||
account_quota_charge_transaction.purchased_count -
|
||||
account_quota_charge_transaction._count.allocations
|
||||
})
|
||||
|
||||
const licenses_status = { total: 0, used: 0, expired: 0 }
|
||||
license_charge_transactions.forEach(license_charge_transaction => {
|
||||
licenses_status.total += license_charge_transaction.purchased_count
|
||||
licenses_status.used += license_charge_transaction._count.licenses
|
||||
licenses_status.expired +=
|
||||
license_charge_transaction.purchased_count -
|
||||
license_charge_transaction._count.licenses
|
||||
})
|
||||
|
||||
const { chargedLicenseTransactions, ...rest } = partner
|
||||
const mappedPartner = {
|
||||
...rest,
|
||||
licenses_status: this.separateLicenseCount(chargedLicenseTransactions),
|
||||
licenses_status,
|
||||
account_quota_status,
|
||||
}
|
||||
|
||||
return ResponseMapper.single(mappedPartner)
|
||||
|
||||
Reference in New Issue
Block a user