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,6 +1,5 @@
|
||||
import { Body, Controller, Get, Param, Post } from '@nestjs/common'
|
||||
import { Controller, Get, Param } from '@nestjs/common'
|
||||
import { ApiTags } from '@nestjs/swagger'
|
||||
import { CreateLicenseDto } from './dto/license.dto'
|
||||
import { LicensesService } from './licenses.service'
|
||||
|
||||
@ApiTags('AdminConsumerAccounts')
|
||||
@@ -13,10 +12,10 @@ export class LicensesController {
|
||||
return this.service.findAll(consumerId)
|
||||
}
|
||||
|
||||
@Post()
|
||||
async create(@Param('consumerId') consumerId: string, @Body() data: CreateLicenseDto) {
|
||||
return this.service.create(consumerId, data)
|
||||
}
|
||||
// @Post()
|
||||
// async create(@Param('consumerId') consumerId: string, @Body() data: CreateLicenseDto) {
|
||||
// return this.service.create(consumerId, data)
|
||||
// }
|
||||
|
||||
// @Patch(':id')
|
||||
// async update(@Param('id') id: string, @Body() data: UpdateLicenseDto) {
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
import { PartnerStatus } from '@/generated/prisma/enums'
|
||||
import { PrismaService } from '@/prisma/prisma.service'
|
||||
import { BadRequestException, Injectable } from '@nestjs/common'
|
||||
import { Injectable } from '@nestjs/common'
|
||||
import { ResponseMapper } from 'common/response/response-mapper'
|
||||
import { CreateLicenseDto } from './dto/license.dto'
|
||||
|
||||
@Injectable()
|
||||
export class LicensesService {
|
||||
@@ -19,10 +17,10 @@ export class LicensesService {
|
||||
}
|
||||
|
||||
async findAll(consumer_id: string) {
|
||||
const licenses = await this.prisma.activatedLicense.findMany({
|
||||
where: {
|
||||
consumer_id,
|
||||
},
|
||||
const licenses = await this.prisma.licenseActivation.findMany({
|
||||
// where: {
|
||||
// consumer_id,
|
||||
// },
|
||||
select: {
|
||||
id: true,
|
||||
starts_at: true,
|
||||
@@ -31,7 +29,7 @@ export class LicensesService {
|
||||
license: {
|
||||
select: {
|
||||
id: true,
|
||||
charged_license_transaction: {
|
||||
charge_transaction: {
|
||||
select: {
|
||||
partner: {
|
||||
select: {
|
||||
@@ -49,54 +47,54 @@ export class LicensesService {
|
||||
return ResponseMapper.list(licenses)
|
||||
}
|
||||
|
||||
async create(consumerId: string, data: CreateLicenseDto) {
|
||||
const { starts_at, expires_at, partner_id } = data
|
||||
// async create(consumerId: string, data: CreateLicenseDto) {
|
||||
// const { starts_at, expires_at, partner_id } = data
|
||||
|
||||
const license = await this.prisma.$transaction(async tx => {
|
||||
const partnerLicense = await tx.license.findFirst({
|
||||
where: {
|
||||
activated_license: null,
|
||||
charged_license_transaction: {
|
||||
activation_expires_at: {
|
||||
gte: this.startOfToday,
|
||||
},
|
||||
partner: {
|
||||
id: partner_id,
|
||||
status: PartnerStatus.ACTIVE,
|
||||
},
|
||||
},
|
||||
},
|
||||
select: {
|
||||
id: true,
|
||||
},
|
||||
})
|
||||
// const license = await this.prisma.$transaction(async tx => {
|
||||
// const partnerLicense = await tx.license.findFirst({
|
||||
// where: {
|
||||
// activation: null,
|
||||
// charge_transaction: {
|
||||
// activation_expires_at: {
|
||||
// gte: this.startOfToday,
|
||||
// },
|
||||
// partner: {
|
||||
// id: partner_id,
|
||||
// status: PartnerStatus.ACTIVE,
|
||||
// },
|
||||
// },
|
||||
// },
|
||||
// select: {
|
||||
// id: true,
|
||||
// },
|
||||
// })
|
||||
|
||||
if (!partnerLicense) {
|
||||
throw new BadRequestException(
|
||||
`تعداد لایسنسهای فعلی شریک تجاری به پایان رسیده است.`,
|
||||
)
|
||||
}
|
||||
// if (!partnerLicense) {
|
||||
// throw new BadRequestException(
|
||||
// `تعداد لایسنسهای فعلی شریک تجاری به پایان رسیده است.`,
|
||||
// )
|
||||
// }
|
||||
|
||||
return await this.prisma.activatedLicense.create({
|
||||
data: {
|
||||
starts_at,
|
||||
expires_at: expires_at ?? this.setExpireDate(starts_at),
|
||||
consumer: {
|
||||
connect: {
|
||||
id: consumerId,
|
||||
},
|
||||
},
|
||||
license: {
|
||||
connect: {
|
||||
id: partnerLicense.id,
|
||||
},
|
||||
},
|
||||
},
|
||||
})
|
||||
})
|
||||
// return await this.prisma.licenseActivation.create({
|
||||
// data: {
|
||||
// starts_at,
|
||||
// expires_at: expires_at ?? this.setExpireDate(starts_at),
|
||||
// consumer: {
|
||||
// connect: {
|
||||
// id: consumerId,
|
||||
// },
|
||||
// },
|
||||
// license: {
|
||||
// connect: {
|
||||
// id: partnerLicense.id,
|
||||
// },
|
||||
// },
|
||||
// },
|
||||
// })
|
||||
// })
|
||||
|
||||
return ResponseMapper.create(license)
|
||||
}
|
||||
// return ResponseMapper.create(license)
|
||||
// }
|
||||
|
||||
// async update(id: string, data: UpdateLicenseDto) {
|
||||
// const { starts_at, expires_at, partner_id } = data
|
||||
|
||||
Reference in New Issue
Block a user