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,9 +1,5 @@
|
||||
import { Body, Controller, Get, Param, Post, Put } from '@nestjs/common'
|
||||
import { Controller, Get, Param } from '@nestjs/common'
|
||||
import { BusinessActivitiesService } from './business-activities.service'
|
||||
import {
|
||||
CreateBusinessActivitiesDto,
|
||||
UpdateBusinessActivityDto,
|
||||
} from './dto/create-business-activities.dto'
|
||||
|
||||
@Controller('admin/consumers/:consumerId/business_activities')
|
||||
export class BusinessActivitiesController {
|
||||
@@ -19,22 +15,22 @@ export class BusinessActivitiesController {
|
||||
return this.businessActivitiesService.findOne(consumerId, id)
|
||||
}
|
||||
|
||||
@Post()
|
||||
async create(
|
||||
@Param('consumerId') consumerId: string,
|
||||
@Body() data: CreateBusinessActivitiesDto,
|
||||
) {
|
||||
return this.businessActivitiesService.create(consumerId, data)
|
||||
}
|
||||
// @Post()
|
||||
// async create(
|
||||
// @Param('consumerId') consumerId: string,
|
||||
// @Body() data: CreateBusinessActivitiesDto,
|
||||
// ) {
|
||||
// return this.businessActivitiesService.create(consumerId, data)
|
||||
// }
|
||||
|
||||
@Put(':id')
|
||||
async update(
|
||||
@Param('consumerId') consumerId: string,
|
||||
@Param('id') id: string,
|
||||
@Body() data: UpdateBusinessActivityDto,
|
||||
) {
|
||||
return this.businessActivitiesService.update(consumerId, id, data)
|
||||
}
|
||||
// @Put(':id')
|
||||
// async update(
|
||||
// @Param('consumerId') consumerId: string,
|
||||
// @Param('id') id: string,
|
||||
// @Body() data: UpdateBusinessActivityDto,
|
||||
// ) {
|
||||
// return this.businessActivitiesService.update(consumerId, id, data)
|
||||
// }
|
||||
|
||||
// @Delete(':id')
|
||||
// async delete(@Param('id') id: string) {
|
||||
|
||||
@@ -2,7 +2,6 @@ import { BusinessActivitySelect } from '@/generated/prisma/models'
|
||||
import { PrismaService } from '@/prisma/prisma.service'
|
||||
import { Injectable } from '@nestjs/common'
|
||||
import { ResponseMapper } from 'common/response/response-mapper'
|
||||
import { CreateBusinessActivitiesDto } from './dto/create-business-activities.dto'
|
||||
|
||||
@Injectable()
|
||||
export class BusinessActivitiesService {
|
||||
@@ -39,37 +38,37 @@ export class BusinessActivitiesService {
|
||||
return ResponseMapper.single(businessActivity)
|
||||
}
|
||||
|
||||
async create(consumer_id: string, data: CreateBusinessActivitiesDto) {
|
||||
const businessActivity = await this.prisma.businessActivity.create({
|
||||
data: {
|
||||
name: data.name,
|
||||
guild: {
|
||||
connect: {
|
||||
id: data.guild_id,
|
||||
},
|
||||
},
|
||||
consumer: {
|
||||
connect: {
|
||||
id: consumer_id,
|
||||
},
|
||||
},
|
||||
},
|
||||
select: this.defaultSelect,
|
||||
})
|
||||
return ResponseMapper.create(businessActivity)
|
||||
}
|
||||
// async create(consumer_id: string, data: CreateBusinessActivitiesDto) {
|
||||
// const businessActivity = await this.prisma.businessActivity.create({
|
||||
// data: {
|
||||
// name: data.name,
|
||||
// guild: {
|
||||
// connect: {
|
||||
// id: data.guild_id,
|
||||
// },
|
||||
// },
|
||||
// consumer: {
|
||||
// connect: {
|
||||
// id: consumer_id,
|
||||
// },
|
||||
// },
|
||||
// },
|
||||
// select: this.defaultSelect,
|
||||
// })
|
||||
// return ResponseMapper.create(businessActivity)
|
||||
// }
|
||||
|
||||
async update(consumer_id: string, id: string, data: any) {
|
||||
const businessActivity = await this.prisma.businessActivity.update({
|
||||
where: { id, consumer_id },
|
||||
data,
|
||||
select: this.defaultSelect,
|
||||
})
|
||||
return ResponseMapper.update(businessActivity)
|
||||
}
|
||||
// async update(consumer_id: string, id: string, data: any) {
|
||||
// const businessActivity = await this.prisma.businessActivity.update({
|
||||
// where: { id, consumer_id },
|
||||
// data,
|
||||
// select: this.defaultSelect,
|
||||
// })
|
||||
// return ResponseMapper.update(businessActivity)
|
||||
// }
|
||||
|
||||
async delete(id: string) {
|
||||
await this.prisma.businessActivity.delete({ where: { id } })
|
||||
return ResponseMapper.delete()
|
||||
}
|
||||
// async delete(id: string) {
|
||||
// await this.prisma.businessActivity.delete({ where: { id } })
|
||||
// return ResponseMapper.delete()
|
||||
// }
|
||||
}
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import { Body, Controller, Get, Param, Patch, Post } from '@nestjs/common'
|
||||
import { Controller, Get, Param } from '@nestjs/common'
|
||||
import { ApiTags } from '@nestjs/swagger'
|
||||
import { BusinessActivityComplexesService } from './complexes.service'
|
||||
import { CreateComplexDto, UpdateComplexDto } from './dto/complex.dto'
|
||||
|
||||
@ApiTags('AdminBusinessActivityComplexes')
|
||||
@Controller(
|
||||
@@ -27,23 +26,23 @@ export class BusinessActivityComplexesController {
|
||||
return this.service.findOne(consumerId, businessActivityId, id)
|
||||
}
|
||||
|
||||
@Post()
|
||||
async create(
|
||||
@Param('businessActivityId') businessActivityId: string,
|
||||
@Body() data: CreateComplexDto,
|
||||
) {
|
||||
return this.service.create(businessActivityId, data)
|
||||
}
|
||||
// @Post()
|
||||
// async create(
|
||||
// @Param('businessActivityId') businessActivityId: string,
|
||||
// @Body() data: CreateComplexDto,
|
||||
// ) {
|
||||
// return this.service.create(businessActivityId, data)
|
||||
// }
|
||||
|
||||
@Patch(':id')
|
||||
async update(
|
||||
@Param('id') id: string,
|
||||
@Param('consumerId') consumerId: string,
|
||||
@Param('businessActivityId') businessActivityId: string,
|
||||
@Body() data: UpdateComplexDto,
|
||||
) {
|
||||
return this.service.update(consumerId, businessActivityId, id, data)
|
||||
}
|
||||
// @Patch(':id')
|
||||
// async update(
|
||||
// @Param('id') id: string,
|
||||
// @Param('consumerId') consumerId: string,
|
||||
// @Param('businessActivityId') businessActivityId: string,
|
||||
// @Body() data: UpdateComplexDto,
|
||||
// ) {
|
||||
// return this.service.update(consumerId, businessActivityId, id, data)
|
||||
// }
|
||||
|
||||
// @Delete(':id')
|
||||
// async delete(@Param('id') id: string) {
|
||||
|
||||
@@ -2,7 +2,6 @@ import { ComplexSelect } from '@/generated/prisma/models'
|
||||
import { PrismaService } from '@/prisma/prisma.service'
|
||||
import { Injectable } from '@nestjs/common'
|
||||
import { ResponseMapper } from 'common/response/response-mapper'
|
||||
import { CreateComplexDto, UpdateComplexDto } from './dto/complex.dto'
|
||||
|
||||
@Injectable()
|
||||
export class BusinessActivityComplexesService {
|
||||
@@ -47,40 +46,40 @@ export class BusinessActivityComplexesService {
|
||||
return ResponseMapper.single(account)
|
||||
}
|
||||
|
||||
async create(business_id: string, data: CreateComplexDto) {
|
||||
const account = await this.prisma.complex.create({
|
||||
data: {
|
||||
...data,
|
||||
business_activity: {
|
||||
connect: {
|
||||
id: business_id,
|
||||
},
|
||||
},
|
||||
},
|
||||
})
|
||||
return ResponseMapper.create(account)
|
||||
}
|
||||
// async create(business_id: string, data: CreateComplexDto) {
|
||||
// const account = await this.prisma.complex.create({
|
||||
// data: {
|
||||
// ...data,
|
||||
// business_activity: {
|
||||
// connect: {
|
||||
// id: business_id,
|
||||
// },
|
||||
// },
|
||||
// },
|
||||
// })
|
||||
// return ResponseMapper.create(account)
|
||||
// }
|
||||
|
||||
async update(
|
||||
consumer_id: string,
|
||||
business_activity_id: string,
|
||||
id: string,
|
||||
data: UpdateComplexDto,
|
||||
) {
|
||||
const account = await this.prisma.complex.update({
|
||||
where: {
|
||||
business_activity: {
|
||||
id: business_activity_id,
|
||||
consumer: {
|
||||
id: consumer_id,
|
||||
},
|
||||
},
|
||||
id,
|
||||
},
|
||||
data,
|
||||
})
|
||||
return ResponseMapper.update(account)
|
||||
}
|
||||
// async update(
|
||||
// consumer_id: string,
|
||||
// business_activity_id: string,
|
||||
// id: string,
|
||||
// data: UpdateComplexDto,
|
||||
// ) {
|
||||
// const account = await this.prisma.complex.update({
|
||||
// where: {
|
||||
// business_activity: {
|
||||
// id: business_activity_id,
|
||||
// consumer: {
|
||||
// id: consumer_id,
|
||||
// },
|
||||
// },
|
||||
// id,
|
||||
// },
|
||||
// data,
|
||||
// })
|
||||
// return ResponseMapper.update(account)
|
||||
// }
|
||||
|
||||
// async delete(id: string) {
|
||||
// await this.prisma.complex.delete({ where: { id } })
|
||||
|
||||
+14
-15
@@ -1,6 +1,5 @@
|
||||
import { Body, Controller, Get, Param, Patch, Post } from '@nestjs/common'
|
||||
import { Controller, Get, Param } from '@nestjs/common'
|
||||
import { ApiTags } from '@nestjs/swagger'
|
||||
import { CreatePosDto, UpdatePosDto } from './dto/pos.dto'
|
||||
import { ComplexPosesService } from './poses.service'
|
||||
|
||||
@ApiTags('AdminComplexPoses')
|
||||
@@ -25,20 +24,20 @@ export class ComplexPosesController {
|
||||
return this.service.findOne(businessActivityId, complexId, id)
|
||||
}
|
||||
|
||||
@Post()
|
||||
async create(@Param('complexId') complexId: string, @Body() data: CreatePosDto) {
|
||||
return this.service.create(complexId, data)
|
||||
}
|
||||
// @Post()
|
||||
// async create(@Param('complexId') complexId: string, @Body() data: CreatePosDto) {
|
||||
// return this.service.create(complexId, data)
|
||||
// }
|
||||
|
||||
@Patch(':id')
|
||||
async update(
|
||||
@Param('businessActivityId') businessActivityId: string,
|
||||
@Param('complexId') complexId: string,
|
||||
@Param('id') id: string,
|
||||
@Body() data: UpdatePosDto,
|
||||
) {
|
||||
return this.service.update(businessActivityId, complexId, id, data)
|
||||
}
|
||||
// @Patch(':id')
|
||||
// async update(
|
||||
// @Param('businessActivityId') businessActivityId: string,
|
||||
// @Param('complexId') complexId: string,
|
||||
// @Param('id') id: string,
|
||||
// @Body() data: UpdatePosDto,
|
||||
// ) {
|
||||
// return this.service.update(businessActivityId, complexId, id, data)
|
||||
// }
|
||||
|
||||
// @Delete(':id')
|
||||
// async delete(@Param('id') id: string) {
|
||||
|
||||
@@ -1,9 +1,8 @@
|
||||
import { POSStatus } from '@/generated/prisma/enums'
|
||||
import { PosCreateInput, PosSelect } from '@/generated/prisma/models'
|
||||
import { PrismaService } from '@/prisma/prisma.service'
|
||||
import { Injectable } from '@nestjs/common'
|
||||
import { ResponseMapper } from 'common/response/response-mapper'
|
||||
import { CreatePosDto, UpdatePosDto } from './dto/pos.dto'
|
||||
import { CreatePosDto } from './dto/pos.dto'
|
||||
|
||||
@Injectable()
|
||||
export class ComplexPosesService {
|
||||
@@ -108,58 +107,58 @@ export class ComplexPosesService {
|
||||
return ResponseMapper.single(account)
|
||||
}
|
||||
|
||||
async create(complex_id: string, data: CreatePosDto) {
|
||||
const account = await this.prisma.pos.create({
|
||||
data: {
|
||||
...this.defaultInsert(data, complex_id),
|
||||
status: POSStatus.ACTIVE,
|
||||
},
|
||||
})
|
||||
return ResponseMapper.create(account)
|
||||
}
|
||||
// async create(complex_id: string, data: CreatePosDto) {
|
||||
// const account = await this.prisma.pos.create({
|
||||
// data: {
|
||||
// ...this.defaultInsert(data, complex_id),
|
||||
// status: POSStatus.ACTIVE,
|
||||
// },
|
||||
// })
|
||||
// return ResponseMapper.create(account)
|
||||
// }
|
||||
|
||||
async update(
|
||||
business_activity_id: string,
|
||||
complex_id: string,
|
||||
id: string,
|
||||
data: UpdatePosDto,
|
||||
) {
|
||||
const { device_id, provider_id, ...rest } = data
|
||||
const account = await this.prisma.pos.update({
|
||||
where: {
|
||||
complex: {
|
||||
id: complex_id,
|
||||
business_activity: {
|
||||
id: business_activity_id,
|
||||
},
|
||||
},
|
||||
id,
|
||||
},
|
||||
data: {
|
||||
complex: {
|
||||
connect: {
|
||||
id: complex_id,
|
||||
},
|
||||
},
|
||||
provider: provider_id
|
||||
? {
|
||||
connect: {
|
||||
id: provider_id,
|
||||
},
|
||||
}
|
||||
: undefined,
|
||||
device: device_id
|
||||
? {
|
||||
connect: {
|
||||
id: device_id,
|
||||
},
|
||||
}
|
||||
: undefined,
|
||||
...rest,
|
||||
},
|
||||
})
|
||||
return ResponseMapper.update(account)
|
||||
}
|
||||
// async update(
|
||||
// business_activity_id: string,
|
||||
// complex_id: string,
|
||||
// id: string,
|
||||
// data: UpdatePosDto,
|
||||
// ) {
|
||||
// const { device_id, provider_id, ...rest } = data
|
||||
// const account = await this.prisma.pos.update({
|
||||
// where: {
|
||||
// complex: {
|
||||
// id: complex_id,
|
||||
// business_activity: {
|
||||
// id: business_activity_id,
|
||||
// },
|
||||
// },
|
||||
// id,
|
||||
// },
|
||||
// data: {
|
||||
// complex: {
|
||||
// connect: {
|
||||
// id: complex_id,
|
||||
// },
|
||||
// },
|
||||
// provider: provider_id
|
||||
// ? {
|
||||
// connect: {
|
||||
// id: provider_id,
|
||||
// },
|
||||
// }
|
||||
// : undefined,
|
||||
// device: device_id
|
||||
// ? {
|
||||
// connect: {
|
||||
// id: device_id,
|
||||
// },
|
||||
// }
|
||||
// : undefined,
|
||||
// ...rest,
|
||||
// },
|
||||
// })
|
||||
// return ResponseMapper.update(account)
|
||||
// }
|
||||
|
||||
// async delete(id: string) {
|
||||
// await this.prisma.complex.delete({ where: { id } })
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import { Body, Controller, Get, Param, Patch, Post } from '@nestjs/common'
|
||||
import { Controller, Get, Param } from '@nestjs/common'
|
||||
import { AdminConsumersService } from './consumers.service'
|
||||
import { CreateConsumerDto, UpdateConsumerDto } from './dto/consumer.dto'
|
||||
|
||||
@Controller('admin/consumers')
|
||||
export class AdminUsersController {
|
||||
@@ -16,13 +15,13 @@ export class AdminUsersController {
|
||||
return this.usersService.findOne(id)
|
||||
}
|
||||
|
||||
@Post()
|
||||
async create(@Body() data: CreateConsumerDto) {
|
||||
return this.usersService.create(data)
|
||||
}
|
||||
// @Post()
|
||||
// async create(@Body() data: CreateConsumerDto) {
|
||||
// return this.usersService.create(data)
|
||||
// }
|
||||
|
||||
@Patch(':id')
|
||||
async update(@Param('id') id: string, @Body() data: UpdateConsumerDto) {
|
||||
return this.usersService.update(id, data)
|
||||
}
|
||||
// @Patch(':id')
|
||||
// async update(@Param('id') id: string, @Body() data: UpdateConsumerDto) {
|
||||
// return this.usersService.update(id, data)
|
||||
// }
|
||||
}
|
||||
|
||||
@@ -1,16 +1,8 @@
|
||||
import { PasswordUtil } from '@/common/utils/password.util'
|
||||
import {
|
||||
AccountStatus,
|
||||
AccountType,
|
||||
ConsumerRole,
|
||||
PartnerStatus,
|
||||
} from '@/generated/prisma/enums'
|
||||
import { ConsumerCreateInput, ConsumerSelect } from '@/generated/prisma/models'
|
||||
import { 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 { Injectable } from '@nestjs/common'
|
||||
import { ResponseMapper } from 'common/response/response-mapper'
|
||||
import { CreateConsumerDto, UpdateConsumerDto } from './dto/consumer.dto'
|
||||
|
||||
@Injectable()
|
||||
export class AdminConsumersService {
|
||||
@@ -22,28 +14,35 @@ export class AdminConsumersService {
|
||||
last_name: true,
|
||||
mobile_number: true,
|
||||
status: true,
|
||||
created_at: true,
|
||||
activated_licenses: {
|
||||
partner: {
|
||||
select: {
|
||||
id: true,
|
||||
starts_at: true,
|
||||
expires_at: true,
|
||||
license: {
|
||||
select: {
|
||||
charged_license_transaction: {
|
||||
select: {
|
||||
partner: {
|
||||
select: {
|
||||
id: true,
|
||||
name: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
name: true,
|
||||
code: true,
|
||||
},
|
||||
},
|
||||
created_at: true,
|
||||
// activation: {
|
||||
// select: {
|
||||
// id: true,
|
||||
// starts_at: true,
|
||||
// expires_at: true,
|
||||
// license: {
|
||||
// select: {
|
||||
// charge_transaction: {
|
||||
// select: {
|
||||
// partner: {
|
||||
// select: {
|
||||
// id: true,
|
||||
// name: true,
|
||||
// },
|
||||
// },
|
||||
// },
|
||||
// },
|
||||
// },
|
||||
// },
|
||||
// },
|
||||
// },
|
||||
}
|
||||
|
||||
async findAll() {
|
||||
@@ -66,70 +65,70 @@ export class AdminConsumersService {
|
||||
return ResponseMapper.single(mapConsumerWithLicenseUtil(consumer))
|
||||
}
|
||||
|
||||
async create(data: CreateConsumerDto) {
|
||||
const startOfToday = new Date()
|
||||
startOfToday.setHours(0, 0, 0, 0)
|
||||
// async create(data: CreateConsumerDto) {
|
||||
// const startOfToday = new Date()
|
||||
// startOfToday.setHours(0, 0, 0, 0)
|
||||
|
||||
const { username, password, partner_id, ...rest } = data
|
||||
const dataToCreate: ConsumerCreateInput = {
|
||||
...rest,
|
||||
consumer_accounts: {
|
||||
create: {
|
||||
role: ConsumerRole.OWNER,
|
||||
account: {
|
||||
create: {
|
||||
username,
|
||||
password: await PasswordUtil.hash(password),
|
||||
type: AccountType.CONSUMER,
|
||||
status: AccountStatus.ACTIVE,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
if (partner_id) {
|
||||
const partnerLicense = await this.prisma.license.findFirst({
|
||||
where: {
|
||||
charged_license_transaction: {
|
||||
partner: {
|
||||
id: partner_id,
|
||||
status: PartnerStatus.ACTIVE,
|
||||
},
|
||||
},
|
||||
activated_license: null,
|
||||
},
|
||||
select: {
|
||||
id: true,
|
||||
charged_license_transaction: {
|
||||
select: {
|
||||
partner: {
|
||||
select: {
|
||||
id: true,
|
||||
name: true,
|
||||
status: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
})
|
||||
// const { username, password, partner_id, ...rest } = data
|
||||
// const dataToCreate: ConsumerCreateInput = {
|
||||
// ...rest,
|
||||
// consumer_accounts: {
|
||||
// create: {
|
||||
// role: ConsumerRole.OWNER,
|
||||
// account: {
|
||||
// create: {
|
||||
// username,
|
||||
// password: await PasswordUtil.hash(password),
|
||||
// type: AccountType.CONSUMER,
|
||||
// status: AccountStatus.ACTIVE,
|
||||
// },
|
||||
// },
|
||||
// },
|
||||
// },
|
||||
// }
|
||||
// if (partner_id) {
|
||||
// const partnerLicense = await this.prisma.license.findFirst({
|
||||
// where: {
|
||||
// charge_transaction: {
|
||||
// partner: {
|
||||
// id: partner_id,
|
||||
// status: PartnerStatus.ACTIVE,
|
||||
// },
|
||||
// },
|
||||
// activation: null,
|
||||
// },
|
||||
// select: {
|
||||
// id: true,
|
||||
// charge_transaction: {
|
||||
// select: {
|
||||
// partner: {
|
||||
// select: {
|
||||
// id: true,
|
||||
// name: true,
|
||||
// status: true,
|
||||
// },
|
||||
// },
|
||||
// },
|
||||
// },
|
||||
// },
|
||||
// })
|
||||
|
||||
if (!partnerLicense) {
|
||||
throw new BadRequestException(
|
||||
`تعداد لایسنسهای فعلی شریک تجاری به پایان رسیده است.`,
|
||||
)
|
||||
}
|
||||
}
|
||||
return this.prisma.consumer.create({
|
||||
data: dataToCreate,
|
||||
select: this.defaultSelect,
|
||||
})
|
||||
}
|
||||
// if (!partnerLicense) {
|
||||
// throw new BadRequestException(
|
||||
// `تعداد لایسنسهای فعلی شریک تجاری به پایان رسیده است.`,
|
||||
// )
|
||||
// }
|
||||
// }
|
||||
// return this.prisma.consumer.create({
|
||||
// data: dataToCreate,
|
||||
// select: this.defaultSelect,
|
||||
// })
|
||||
// }
|
||||
|
||||
async update(id: string, data: UpdateConsumerDto) {
|
||||
return this.prisma.consumer.update({
|
||||
where: { id },
|
||||
data,
|
||||
})
|
||||
}
|
||||
// async update(id: string, data: UpdateConsumerDto) {
|
||||
// return this.prisma.consumer.update({
|
||||
// where: { id },
|
||||
// data,
|
||||
// })
|
||||
// }
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { ActivatedLicenseSelect } from '@/generated/prisma/models'
|
||||
import { LicenseActivationSelect } from '@/generated/prisma/models'
|
||||
import { PrismaService } from '@/prisma/prisma.service'
|
||||
import { Injectable } from '@nestjs/common'
|
||||
import { ResponseMapper } from 'common/response/response-mapper'
|
||||
@@ -7,22 +7,27 @@ import { ResponseMapper } from 'common/response/response-mapper'
|
||||
export class PartnerLicensesService {
|
||||
constructor(private readonly prisma: PrismaService) {}
|
||||
|
||||
private readonly licenseDefaultSelect: ActivatedLicenseSelect = {
|
||||
private readonly licenseDefaultSelect: LicenseActivationSelect = {
|
||||
id: true,
|
||||
starts_at: true,
|
||||
expires_at: true,
|
||||
consumer: {
|
||||
business_activity: {
|
||||
select: {
|
||||
first_name: true,
|
||||
last_name: true,
|
||||
mobile_number: true,
|
||||
status: true,
|
||||
id: true,
|
||||
name: true,
|
||||
consumer: {
|
||||
select: {
|
||||
id: true,
|
||||
first_name: true,
|
||||
last_name: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
license: {
|
||||
select: {
|
||||
id: true,
|
||||
charged_license_transaction: {
|
||||
charge_transaction: {
|
||||
select: {
|
||||
partner: {
|
||||
select: {
|
||||
@@ -39,12 +44,12 @@ export class PartnerLicensesService {
|
||||
|
||||
async findAll(page = 1, pageSize = 10) {
|
||||
const [licenses, count] = await this.prisma.$transaction([
|
||||
this.prisma.activatedLicense.findMany({
|
||||
this.prisma.licenseActivation.findMany({
|
||||
select: this.licenseDefaultSelect,
|
||||
skip: (page - 1) * pageSize,
|
||||
take: pageSize,
|
||||
}),
|
||||
this.prisma.activatedLicense.count(),
|
||||
this.prisma.licenseActivation.count(),
|
||||
])
|
||||
|
||||
return ResponseMapper.paginate(licenses, {
|
||||
@@ -55,7 +60,7 @@ export class PartnerLicensesService {
|
||||
}
|
||||
|
||||
async findOne(id: string) {
|
||||
const license = await this.prisma.activatedLicense.findFirst({
|
||||
const license = await this.prisma.licenseActivation.findFirst({
|
||||
where: {
|
||||
id,
|
||||
},
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { ActivatedLicenseWhereInput } from '@/generated/prisma/models'
|
||||
import { LicenseActivationWhereInput } from '@/generated/prisma/models'
|
||||
import { PrismaService } from '@/prisma/prisma.service'
|
||||
import { Injectable } from '@nestjs/common'
|
||||
import { ResponseMapper } from 'common/response/response-mapper'
|
||||
@@ -8,15 +8,15 @@ export class PartnerActivatedLicensesService {
|
||||
constructor(private readonly prisma: PrismaService) {}
|
||||
|
||||
async findAll(partner_id: string, page = 1, pageSize = 10) {
|
||||
const defaultWhere: ActivatedLicenseWhereInput = {
|
||||
const defaultWhere: LicenseActivationWhereInput = {
|
||||
license: {
|
||||
charged_license_transaction: {
|
||||
charge_transaction: {
|
||||
partner_id,
|
||||
},
|
||||
},
|
||||
}
|
||||
const [licenses, count] = await this.prisma.$transaction(async tx => [
|
||||
await tx.activatedLicense.findMany({
|
||||
await tx.licenseActivation.findMany({
|
||||
where: defaultWhere,
|
||||
skip: (page - 1) * pageSize,
|
||||
take: pageSize,
|
||||
@@ -26,16 +26,22 @@ export class PartnerActivatedLicensesService {
|
||||
expires_at: true,
|
||||
license_id: true,
|
||||
created_at: true,
|
||||
consumer: {
|
||||
business_activity: {
|
||||
select: {
|
||||
id: true,
|
||||
first_name: true,
|
||||
last_name: true,
|
||||
name: true,
|
||||
consumer: {
|
||||
select: {
|
||||
id: true,
|
||||
first_name: true,
|
||||
last_name: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}),
|
||||
await tx.activatedLicense.count({
|
||||
await tx.licenseActivation.count({
|
||||
where: defaultWhere,
|
||||
}),
|
||||
])
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
import { Controller, Get, Param } from '@nestjs/common'
|
||||
import { ApiTags } from '@nestjs/swagger'
|
||||
import { PartnerAllocatedAccountsService } from './allocatedAccounts.service'
|
||||
|
||||
@ApiTags('AdminPartnerAllocatedAccounts')
|
||||
@Controller('admin/partners/:partnerId/allocated-accounts')
|
||||
export class PartnerAllocatedAccountsController {
|
||||
constructor(private readonly service: PartnerAllocatedAccountsService) {}
|
||||
|
||||
@Get()
|
||||
async findAll(@Param('partnerId') partnerId: string) {
|
||||
return this.service.findAll(partnerId)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
import { PrismaModule } from '@/prisma/prisma.module'
|
||||
import { Module } from '@nestjs/common'
|
||||
import { PartnerAllocatedAccountsController } from './allocatedAccounts.controller'
|
||||
import { PartnerAllocatedAccountsService } from './allocatedAccounts.service'
|
||||
|
||||
@Module({
|
||||
imports: [PrismaModule],
|
||||
controllers: [PartnerAllocatedAccountsController],
|
||||
providers: [PartnerAllocatedAccountsService],
|
||||
exports: [PartnerAllocatedAccountsService],
|
||||
})
|
||||
export class AdminPartnerAllocatedAccountsModule {}
|
||||
@@ -0,0 +1,61 @@
|
||||
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,
|
||||
})
|
||||
}
|
||||
}
|
||||
+37
@@ -0,0 +1,37 @@
|
||||
import { Body, Controller, Get, Param, Post } from '@nestjs/common'
|
||||
import { ApiTags } from '@nestjs/swagger'
|
||||
import { PartnerAccountChargeTransactionService } from './chargeAccountQuotaTransactions.service'
|
||||
import { ChargeAccountQuotaDto } from './dto/chargeAccountQuotaTransactions.dto'
|
||||
|
||||
@ApiTags('Admin Partner Account Charge')
|
||||
@Controller('admin/partners/:partnerId/charge-account-transactions')
|
||||
export class PartnerAccountChargeTransactionController {
|
||||
constructor(private readonly service: PartnerAccountChargeTransactionService) {}
|
||||
|
||||
@Get()
|
||||
async findAll(@Param('partnerId') partnerId: string) {
|
||||
return this.service.findAll(partnerId)
|
||||
}
|
||||
|
||||
@Get(':id')
|
||||
async findOne(@Param('partnerId') partnerId: string, @Param('id') id: string) {
|
||||
return this.service.findOne(partnerId, id)
|
||||
}
|
||||
|
||||
@Post()
|
||||
async create(
|
||||
@Param('partnerId') partnerId: string,
|
||||
@Body() data: ChargeAccountQuotaDto,
|
||||
) {
|
||||
return this.service.create(partnerId, data)
|
||||
}
|
||||
|
||||
// @Patch(':id')
|
||||
// async update(
|
||||
// @Param('partnerId') partnerId: string,
|
||||
// @Param('id') id: string,
|
||||
// @Body() data: UpdateLicenseDto,
|
||||
// ) {
|
||||
// return this.licensesService.update(partnerId, id, data)
|
||||
// }
|
||||
}
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
import { PrismaModule } from '@/prisma/prisma.module'
|
||||
import { Module } from '@nestjs/common'
|
||||
import { PartnerAccountChargeTransactionController } from './chargeAccountQuotaTransactions.controller'
|
||||
import { PartnerAccountChargeTransactionService } from './chargeAccountQuotaTransactions.service'
|
||||
|
||||
@Module({
|
||||
imports: [PrismaModule],
|
||||
controllers: [PartnerAccountChargeTransactionController],
|
||||
providers: [PartnerAccountChargeTransactionService],
|
||||
})
|
||||
export class PartnerAccountChargeTransactionModule {}
|
||||
+154
@@ -0,0 +1,154 @@
|
||||
import {
|
||||
generateTrackingCode,
|
||||
isTrackingCodeUniqueViolation,
|
||||
} from '@/common/utils/tracking-code-generator.util'
|
||||
import {
|
||||
PartnerAccountQuotaAllocationCreateInput,
|
||||
PartnerAccountQuotaChargeTransactionSelect,
|
||||
PartnerAccountQuotaChargeTransactionWhereInput,
|
||||
} from '@/generated/prisma/models'
|
||||
import { PrismaService } from '@/prisma/prisma.service'
|
||||
import { BadRequestException, Injectable } from '@nestjs/common'
|
||||
import { ResponseMapper } from 'common/response/response-mapper'
|
||||
import { ChargeAccountQuotaDto } from './dto/chargeAccountQuotaTransactions.dto'
|
||||
|
||||
@Injectable()
|
||||
export class PartnerAccountChargeTransactionService {
|
||||
constructor(private readonly prisma: PrismaService) {}
|
||||
|
||||
private readonly TRACKING_CODE_LENGTH = 8
|
||||
private readonly TRACKING_CODE_MAX_ATTEMPTS = 5
|
||||
|
||||
private readonly mappedTransaction = (transaction: any) => {
|
||||
const { allocations, purchased_count, _count, ...rest } = transaction
|
||||
|
||||
const activation_count = _count.allocations
|
||||
|
||||
return {
|
||||
...rest,
|
||||
charged_license_count: purchased_count,
|
||||
activation_count,
|
||||
remained_license_count: purchased_count - activation_count,
|
||||
}
|
||||
}
|
||||
|
||||
private readonly defaultSelect: PartnerAccountQuotaChargeTransactionSelect = {
|
||||
id: true,
|
||||
created_at: true,
|
||||
tracking_code: true,
|
||||
activation_expires_at: true,
|
||||
purchased_count: true,
|
||||
_count: {
|
||||
select: {
|
||||
allocations: {
|
||||
where: {
|
||||
license_id: {
|
||||
not: null,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
async findAll(partner_id: string, page = 1, pageSize = 10) {
|
||||
const defaultWhere: PartnerAccountQuotaChargeTransactionWhereInput = {
|
||||
partner_id,
|
||||
}
|
||||
|
||||
const [transactions, count] = await this.prisma.$transaction(async tx => [
|
||||
await tx.partnerAccountQuotaChargeTransaction.findMany({
|
||||
where: defaultWhere,
|
||||
skip: (page - 1) * pageSize,
|
||||
take: pageSize,
|
||||
select: this.defaultSelect,
|
||||
}),
|
||||
await tx.partnerAccountQuotaChargeTransaction.count({
|
||||
where: defaultWhere,
|
||||
}),
|
||||
])
|
||||
|
||||
const mappedTransactions = transactions.map(this.mappedTransaction)
|
||||
|
||||
return ResponseMapper.paginate(mappedTransactions, {
|
||||
page,
|
||||
pageSize,
|
||||
count,
|
||||
})
|
||||
}
|
||||
|
||||
async findOne(partner_id: string, id: string) {
|
||||
const transaction =
|
||||
this.prisma.partnerAccountQuotaChargeTransaction.findUniqueOrThrow({
|
||||
where: {
|
||||
id,
|
||||
partner_id,
|
||||
},
|
||||
select: this.defaultSelect,
|
||||
})
|
||||
return ResponseMapper.single(this.mappedTransaction(transaction))
|
||||
}
|
||||
|
||||
async create(partner_id: string, data: ChargeAccountQuotaDto) {
|
||||
try {
|
||||
return await this.prisma.$transaction(async tx => {
|
||||
let transaction: { id: string } | null = null
|
||||
|
||||
for (let attempt = 0; attempt < this.TRACKING_CODE_MAX_ATTEMPTS; attempt++) {
|
||||
try {
|
||||
transaction = await tx.partnerAccountQuotaChargeTransaction.create({
|
||||
data: {
|
||||
activation_expires_at: data.activated_expires_at,
|
||||
tracking_code: generateTrackingCode('AQC', this.TRACKING_CODE_LENGTH),
|
||||
purchased_count: data.quantity,
|
||||
partner: { connect: { id: partner_id } },
|
||||
},
|
||||
})
|
||||
break
|
||||
} catch (error) {
|
||||
if (
|
||||
isTrackingCodeUniqueViolation(error) &&
|
||||
attempt < this.TRACKING_CODE_MAX_ATTEMPTS - 1
|
||||
) {
|
||||
continue
|
||||
}
|
||||
throw error
|
||||
}
|
||||
}
|
||||
|
||||
if (!transaction) {
|
||||
throw new BadRequestException('متاسفانه مشکلی پیش آمده است.')
|
||||
}
|
||||
|
||||
const accountCreationPromises: any[] = []
|
||||
for (let i = 0; i < data.quantity; i++) {
|
||||
const account: PartnerAccountQuotaAllocationCreateInput = {
|
||||
charge_transaction: {
|
||||
connect: {
|
||||
id: transaction.id,
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
accountCreationPromises.push(
|
||||
tx.partnerAccountQuotaAllocation.create({ data: account }),
|
||||
)
|
||||
}
|
||||
const createdAllocations = await Promise.all(accountCreationPromises)
|
||||
|
||||
console.log(createdAllocations)
|
||||
|
||||
if (
|
||||
createdAllocations.some(
|
||||
createdAllocation => createdAllocation.activation_id === null,
|
||||
)
|
||||
) {
|
||||
throw new BadRequestException('متاسفانه مشکلی پیش آمده است. ')
|
||||
}
|
||||
return { transaction, createdAllocations }
|
||||
})
|
||||
} catch (error) {
|
||||
throw error
|
||||
}
|
||||
}
|
||||
}
|
||||
+20
@@ -0,0 +1,20 @@
|
||||
import { ApiProperty } from '@nestjs/swagger'
|
||||
import { IsDateString, IsNumber } from 'class-validator'
|
||||
|
||||
export class ChargeAccountQuotaDto {
|
||||
@ApiProperty({
|
||||
required: true,
|
||||
minimum: 1,
|
||||
maximum: 10_000,
|
||||
})
|
||||
@IsNumber({
|
||||
maxDecimalPlaces: 0,
|
||||
})
|
||||
quantity: number
|
||||
|
||||
@ApiProperty({
|
||||
required: true,
|
||||
})
|
||||
@IsDateString()
|
||||
activated_expires_at: string
|
||||
}
|
||||
+4
-4
@@ -1,12 +1,12 @@
|
||||
import { Body, Controller, Get, Param, Post } from '@nestjs/common'
|
||||
import { ApiTags } from '@nestjs/swagger'
|
||||
import { PartnerChargedLicenseTransactionsService } from './chargedLicenseTransactions.service'
|
||||
import { PartnerLicenseChargeTransactionService } from './chargedLicenseTransactions.service'
|
||||
import { ChargeLicenseDto } from './dto/chargedLicenseTransactions.dto'
|
||||
|
||||
@ApiTags('AdminPartnerChargedLicenseTransactions')
|
||||
@ApiTags('AdminPartnerLicenseChargeTransaction')
|
||||
@Controller('admin/partners/:partnerId/charge-license-transactions')
|
||||
export class PartnerChargedLicenseTransactionsController {
|
||||
constructor(private readonly service: PartnerChargedLicenseTransactionsService) {}
|
||||
export class PartnerLicenseChargeTransactionController {
|
||||
constructor(private readonly service: PartnerLicenseChargeTransactionService) {}
|
||||
|
||||
@Get()
|
||||
async findAll(@Param('partnerId') partnerId: string) {
|
||||
|
||||
+6
-6
@@ -1,12 +1,12 @@
|
||||
import { PrismaModule } from '@/prisma/prisma.module'
|
||||
import { Module } from '@nestjs/common'
|
||||
import { PartnerChargedLicenseTransactionsController } from './chargedLicenseTransactions.controller'
|
||||
import { PartnerChargedLicenseTransactionsService } from './chargedLicenseTransactions.service'
|
||||
import { PartnerLicenseChargeTransactionController } from './chargedLicenseTransactions.controller'
|
||||
import { PartnerLicenseChargeTransactionService } from './chargedLicenseTransactions.service'
|
||||
|
||||
@Module({
|
||||
imports: [PrismaModule],
|
||||
controllers: [PartnerChargedLicenseTransactionsController],
|
||||
providers: [PartnerChargedLicenseTransactionsService],
|
||||
exports: [PartnerChargedLicenseTransactionsService],
|
||||
controllers: [PartnerLicenseChargeTransactionController],
|
||||
providers: [PartnerLicenseChargeTransactionService],
|
||||
exports: [PartnerLicenseChargeTransactionService],
|
||||
})
|
||||
export class AdminPartnerChargedLicenseTransactionsModule {}
|
||||
export class AdminPartnerLicenseChargeTransactionModule {}
|
||||
|
||||
+43
-44
@@ -3,7 +3,8 @@ import {
|
||||
isTrackingCodeUniqueViolation,
|
||||
} from '@/common/utils/tracking-code-generator.util'
|
||||
import {
|
||||
ChargedLicenseTransactionsWhereInput,
|
||||
LicenseChargeTransactionSelect,
|
||||
LicenseChargeTransactionWhereInput,
|
||||
LicenseCreateInput,
|
||||
} from '@/generated/prisma/models'
|
||||
import { PrismaService } from '@/prisma/prisma.service'
|
||||
@@ -12,51 +13,57 @@ import { ResponseMapper } from 'common/response/response-mapper'
|
||||
import { ChargeLicenseDto } from './dto/chargedLicenseTransactions.dto'
|
||||
|
||||
@Injectable()
|
||||
export class PartnerChargedLicenseTransactionsService {
|
||||
export class PartnerLicenseChargeTransactionService {
|
||||
constructor(private readonly prisma: PrismaService) {}
|
||||
|
||||
private readonly TRACKING_CODE_LENGTH = 8
|
||||
private readonly TRACKING_CODE_MAX_ATTEMPTS = 5
|
||||
|
||||
private readonly mappedTransaction = (transaction: any) => {
|
||||
const { licenses, ...rest } = transaction
|
||||
const { licenses, purchased_count, _count, ...rest } = transaction
|
||||
|
||||
const activation_count = _count.licenses
|
||||
|
||||
return {
|
||||
...rest,
|
||||
charged_license_count: licenses.length,
|
||||
activated_license_count: licenses.filter(license => license?.activated_license)
|
||||
.length,
|
||||
remained_license_count: licenses.filter(license => !license?.activated_license)
|
||||
.length,
|
||||
charged_license_count: purchased_count,
|
||||
activation_count,
|
||||
remained_license_count: purchased_count - activation_count,
|
||||
}
|
||||
}
|
||||
|
||||
private readonly defaultSelect: LicenseChargeTransactionSelect = {
|
||||
id: true,
|
||||
created_at: true,
|
||||
activation_expires_at: true,
|
||||
tracking_code: true,
|
||||
purchased_count: true,
|
||||
_count: {
|
||||
select: {
|
||||
licenses: {
|
||||
where: {
|
||||
activation: {
|
||||
isNot: null,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
async findAll(partner_id: string, page = 1, pageSize = 10) {
|
||||
const defaultWhere: ChargedLicenseTransactionsWhereInput = {
|
||||
const defaultWhere: LicenseChargeTransactionWhereInput = {
|
||||
partner_id,
|
||||
}
|
||||
|
||||
const [transactions, count] = await this.prisma.$transaction(async tx => [
|
||||
await tx.chargedLicenseTransactions.findMany({
|
||||
await tx.licenseChargeTransaction.findMany({
|
||||
where: defaultWhere,
|
||||
skip: (page - 1) * pageSize,
|
||||
take: pageSize,
|
||||
select: {
|
||||
id: true,
|
||||
created_at: true,
|
||||
activation_expires_at: true,
|
||||
tracking_code: true,
|
||||
licenses: {
|
||||
select: {
|
||||
activated_license: {
|
||||
select: {
|
||||
id: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
select: this.defaultSelect,
|
||||
}),
|
||||
await tx.chargedLicenseTransactions.count({
|
||||
await tx.licenseChargeTransaction.count({
|
||||
where: defaultWhere,
|
||||
}),
|
||||
])
|
||||
@@ -71,26 +78,12 @@ export class PartnerChargedLicenseTransactionsService {
|
||||
}
|
||||
|
||||
async findOne(partner_id: string, id: string) {
|
||||
const transaction = this.prisma.chargedLicenseTransactions.findUniqueOrThrow({
|
||||
const transaction = this.prisma.licenseChargeTransaction.findUniqueOrThrow({
|
||||
where: {
|
||||
id,
|
||||
partner_id,
|
||||
},
|
||||
select: {
|
||||
id: true,
|
||||
created_at: true,
|
||||
activation_expires_at: true,
|
||||
licenses: {
|
||||
select: {
|
||||
id: true,
|
||||
activated_license: {
|
||||
select: {
|
||||
id: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
select: this.defaultSelect,
|
||||
})
|
||||
return ResponseMapper.single(this.mappedTransaction(transaction))
|
||||
}
|
||||
@@ -102,10 +95,11 @@ export class PartnerChargedLicenseTransactionsService {
|
||||
|
||||
for (let attempt = 0; attempt < this.TRACKING_CODE_MAX_ATTEMPTS; attempt++) {
|
||||
try {
|
||||
transaction = await tx.chargedLicenseTransactions.create({
|
||||
transaction = await tx.licenseChargeTransaction.create({
|
||||
data: {
|
||||
activation_expires_at: data.activated_expires_at,
|
||||
tracking_code: generateTrackingCode('LIC', this.TRACKING_CODE_LENGTH),
|
||||
purchased_count: data.quantity,
|
||||
partner: { connect: { id: partner_id } },
|
||||
},
|
||||
})
|
||||
@@ -128,7 +122,7 @@ export class PartnerChargedLicenseTransactionsService {
|
||||
const licenseCreationPromises: any[] = []
|
||||
for (let i = 0; i < data.quantity; i++) {
|
||||
const license: LicenseCreateInput = {
|
||||
charged_license_transaction: {
|
||||
charge_transaction: {
|
||||
connect: {
|
||||
id: transaction.id,
|
||||
},
|
||||
@@ -139,6 +133,11 @@ export class PartnerChargedLicenseTransactionsService {
|
||||
}
|
||||
const createdLicenses = await Promise.all(licenseCreationPromises)
|
||||
|
||||
if (
|
||||
createdLicenses.some(createdLicense => createdLicense.activation_id === null)
|
||||
) {
|
||||
throw new BadRequestException('متاسفانه مشکلی پیش آمده است. ')
|
||||
}
|
||||
return { transaction, createdLicenses }
|
||||
})
|
||||
} catch (error) {
|
||||
|
||||
@@ -2,7 +2,9 @@ import { PrismaModule } from '@/prisma/prisma.module'
|
||||
import { Module } from '@nestjs/common'
|
||||
|
||||
import { AdminPartnerActivatedLicensesModule } from './activatedLicenses/activatedLicenses.module'
|
||||
import { AdminPartnerChargedLicenseTransactionsModule } from './chargedLicenseTransactions/chargedLicenseTransactions.module'
|
||||
import { AdminPartnerAllocatedAccountsModule } from './allocatedAccounts/allocatedAccounts.module'
|
||||
import { PartnerAccountChargeTransactionModule } from './chargeAccountQoutaTransactions/chargeAccountQuotaTransactions.module'
|
||||
import { AdminPartnerLicenseChargeTransactionModule } from './chargedLicenseTransactions/chargedLicenseTransactions.module'
|
||||
import { AdminPartnerAccountsModule } from './partnerAccounts/accounts.module'
|
||||
import { PartnersController } from './partners.controller'
|
||||
import { PartnersService } from './partners.service'
|
||||
@@ -10,8 +12,10 @@ import { PartnersService } from './partners.service'
|
||||
@Module({
|
||||
imports: [
|
||||
PrismaModule,
|
||||
AdminPartnerChargedLicenseTransactionsModule,
|
||||
AdminPartnerLicenseChargeTransactionModule,
|
||||
AdminPartnerActivatedLicensesModule,
|
||||
AdminPartnerAllocatedAccountsModule,
|
||||
PartnerAccountChargeTransactionModule,
|
||||
AdminPartnerAccountsModule,
|
||||
],
|
||||
controllers: [PartnersController],
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -8,7 +8,7 @@ import { AppService } from './application.service'
|
||||
export class AppController {
|
||||
constructor(private service: AppService) {}
|
||||
|
||||
@Get('/check-version')
|
||||
@Get('check-version')
|
||||
@Public()
|
||||
checkVersion() {
|
||||
return this.service.checkVersion()
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { ResponseMapper } from '@/common/response/response-mapper'
|
||||
import { PrismaService } from '@/prisma/prisma.service'
|
||||
import { Injectable } from '@nestjs/common'
|
||||
|
||||
@@ -6,6 +7,7 @@ export class AppService {
|
||||
constructor(private readonly prisma: PrismaService) {}
|
||||
|
||||
async checkVersion() {
|
||||
return ResponseMapper.single({})
|
||||
return await this.prisma.applicationReleasedInfo.findFirst({
|
||||
where: {
|
||||
is_minimum_supported: true,
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { Public } from '@/common/decorators/public.decorator'
|
||||
import { TokenAccount } from '@/common/decorators/tokenInfo.decorator'
|
||||
import { Body, Controller, Get, Param, Post } from '@nestjs/common'
|
||||
import { ConfigService } from './config.service'
|
||||
@@ -13,6 +14,7 @@ export class ConfigController {
|
||||
}
|
||||
|
||||
@Post()
|
||||
@Public()
|
||||
create(@TokenAccount('userId') consumerId: string, @Body() data: CreateConfigDto) {
|
||||
return this.configService.create(consumerId, data)
|
||||
}
|
||||
|
||||
@@ -18,27 +18,6 @@ export class ConsumerService {
|
||||
last_name: true,
|
||||
mobile_number: true,
|
||||
status: true,
|
||||
activated_licenses: {
|
||||
select: {
|
||||
id: true,
|
||||
starts_at: true,
|
||||
expires_at: true,
|
||||
license: {
|
||||
select: {
|
||||
id: true,
|
||||
charged_license_transaction: {
|
||||
select: {
|
||||
partner: {
|
||||
select: {
|
||||
name: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
|
||||
@@ -1,26 +1,10 @@
|
||||
export default (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]
|
||||
}
|
||||
}
|
||||
}
|
||||
const { activation, ...rest } = consumer
|
||||
|
||||
return {
|
||||
...rest,
|
||||
fullname: `${rest?.first_name} ${rest?.last_name}`,
|
||||
license_info: prepareLicenseInfo(lastLicense),
|
||||
license_info: prepareLicenseInfo(activation),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,6 +14,5 @@ function prepareLicenseInfo(latestLicense: any) {
|
||||
|
||||
return {
|
||||
...rest,
|
||||
partner: license.charged_license_transaction.partner,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
import { Body, Controller, Get, Param, Patch, Post } from '@nestjs/common'
|
||||
import { ApiTags } from '@nestjs/swagger'
|
||||
import { AccountsService } from './accounts.service'
|
||||
import { CreateConsumerAccountDto, UpdateAccountDto } from './dto/account.dto'
|
||||
|
||||
@ApiTags('PartnerConsumerAccounts')
|
||||
@Controller('partner/consumers/:consumerId/accounts')
|
||||
export class AccountsController {
|
||||
constructor(private readonly accountsService: AccountsService) {}
|
||||
|
||||
@Get()
|
||||
async findAll(@Param('consumerId') consumerId: string) {
|
||||
return this.accountsService.findAll(consumerId)
|
||||
}
|
||||
|
||||
@Get(':id')
|
||||
async findOne(@Param('id') id: string) {
|
||||
return this.accountsService.findOne(id)
|
||||
}
|
||||
|
||||
@Post()
|
||||
async create(
|
||||
@Param('consumerId') consumerId: string,
|
||||
@Body() data: CreateConsumerAccountDto,
|
||||
) {
|
||||
return this.accountsService.create(consumerId, data)
|
||||
}
|
||||
|
||||
@Patch(':id')
|
||||
async update(@Param('id') id: string, @Body() data: UpdateAccountDto) {
|
||||
return this.accountsService.update(id, data)
|
||||
}
|
||||
|
||||
// @Delete(':id')
|
||||
// async delete(@Param('id') id: string) {
|
||||
// return this.accountsService.delete(id)
|
||||
// }
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
import { PrismaModule } from '@/prisma/prisma.module'
|
||||
import { Module } from '@nestjs/common'
|
||||
import { AccountsController } from './accounts.controller'
|
||||
import { AccountsService } from './accounts.service'
|
||||
|
||||
@Module({
|
||||
imports: [PrismaModule],
|
||||
controllers: [AccountsController],
|
||||
providers: [AccountsService],
|
||||
exports: [AccountsService],
|
||||
})
|
||||
export class PartnerConsumerAccountsModule {}
|
||||
@@ -0,0 +1,82 @@
|
||||
import { PasswordUtil } from '@/common/utils/password.util'
|
||||
import { AccountStatus, AccountType } from '@/generated/prisma/enums'
|
||||
import { PrismaService } from '@/prisma/prisma.service'
|
||||
import { Injectable } from '@nestjs/common'
|
||||
import { ResponseMapper } from 'common/response/response-mapper'
|
||||
import { CreateConsumerAccountDto, UpdateAccountDto } from './dto/account.dto'
|
||||
|
||||
@Injectable()
|
||||
export class AccountsService {
|
||||
constructor(private readonly prisma: PrismaService) {}
|
||||
|
||||
async findAll(consumer_id: string) {
|
||||
const accounts = await this.prisma.consumerAccount.findMany({
|
||||
where: { consumer_id },
|
||||
select: {
|
||||
id: true,
|
||||
role: true,
|
||||
created_at: true,
|
||||
account: {
|
||||
select: {
|
||||
username: true,
|
||||
status: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
})
|
||||
return ResponseMapper.list(accounts)
|
||||
}
|
||||
|
||||
async findOne(id: string) {
|
||||
const account = await this.prisma.consumerAccount.findMany({
|
||||
where: { id },
|
||||
select: {
|
||||
id: true,
|
||||
role: true,
|
||||
created_at: true,
|
||||
account: {
|
||||
select: {
|
||||
username: true,
|
||||
status: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
})
|
||||
return ResponseMapper.single(account)
|
||||
}
|
||||
|
||||
async create(consumerId: string, data: CreateConsumerAccountDto) {
|
||||
const account = await this.prisma.consumerAccount.create({
|
||||
data: {
|
||||
role: data.role,
|
||||
account: {
|
||||
create: {
|
||||
password: await PasswordUtil.hash(data.password),
|
||||
status: AccountStatus.ACTIVE,
|
||||
type: AccountType.CONSUMER,
|
||||
username: data.username,
|
||||
},
|
||||
},
|
||||
consumer: {
|
||||
connect: {
|
||||
id: consumerId,
|
||||
},
|
||||
},
|
||||
permission: {
|
||||
create: {},
|
||||
},
|
||||
},
|
||||
})
|
||||
return ResponseMapper.create(account)
|
||||
}
|
||||
|
||||
async update(id: string, data: UpdateAccountDto) {
|
||||
const account = await this.prisma.account.update({ where: { id }, data })
|
||||
return ResponseMapper.update(account)
|
||||
}
|
||||
|
||||
async delete(id: string) {
|
||||
await this.prisma.account.delete({ where: { id } })
|
||||
return ResponseMapper.delete()
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
import { ApiProperty, PartialType } from '@nestjs/swagger'
|
||||
import { IsEnum, IsOptional, IsString } from 'class-validator'
|
||||
import { AccountStatus, ConsumerRole } from 'generated/prisma/enums'
|
||||
|
||||
export class CreateConsumerAccountDto {
|
||||
@IsString()
|
||||
@ApiProperty({ required: true })
|
||||
username: string
|
||||
|
||||
@IsString()
|
||||
@ApiProperty({ required: true })
|
||||
password: string
|
||||
|
||||
@IsEnum(ConsumerRole)
|
||||
@ApiProperty({ required: true, enum: ConsumerRole })
|
||||
role: ConsumerRole
|
||||
}
|
||||
|
||||
export class UpdateAccountDto extends PartialType(CreateConsumerAccountDto) {
|
||||
@IsOptional()
|
||||
@IsEnum(AccountStatus)
|
||||
@ApiProperty({ enum: AccountStatus })
|
||||
status?: AccountStatus
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
import { PartnerInfo } from '@/common/decorators/partnerInfo.decorator'
|
||||
import { Body, Controller, Get, Param, Post, Put } from '@nestjs/common'
|
||||
import { ApiTags } from '@nestjs/swagger'
|
||||
import { BusinessActivitiesService } from './business-activities.service'
|
||||
import {
|
||||
CreateBusinessActivitiesDto,
|
||||
UpdateBusinessActivityDto,
|
||||
} from './dto/create-business-activities.dto'
|
||||
|
||||
@ApiTags('PartnerConsumerBA')
|
||||
@Controller('partner/consumers/:consumerId/business_activities')
|
||||
export class BusinessActivitiesController {
|
||||
constructor(private readonly businessActivitiesService: BusinessActivitiesService) {}
|
||||
|
||||
@Get()
|
||||
async findAll(
|
||||
@PartnerInfo('id') partnerId: string,
|
||||
@Param('consumerId') consumerId: string,
|
||||
) {
|
||||
return this.businessActivitiesService.findAll(partnerId, consumerId)
|
||||
}
|
||||
|
||||
@Get(':id')
|
||||
async findOne(
|
||||
@PartnerInfo('id') partnerId: string,
|
||||
@Param('consumerId') consumerId: string,
|
||||
@Param('id') id: string,
|
||||
) {
|
||||
return this.businessActivitiesService.findOne(partnerId, consumerId, id)
|
||||
}
|
||||
|
||||
@Post()
|
||||
async create(
|
||||
@Param('consumerId') consumerId: string,
|
||||
@Body() data: CreateBusinessActivitiesDto,
|
||||
) {
|
||||
return this.businessActivitiesService.create(consumerId, data)
|
||||
}
|
||||
|
||||
@Put(':id')
|
||||
async update(
|
||||
@PartnerInfo('id') partnerId: string,
|
||||
@Param('consumerId') consumerId: string,
|
||||
@Param('id') id: string,
|
||||
@Body() data: UpdateBusinessActivityDto,
|
||||
) {
|
||||
return this.businessActivitiesService.update(partnerId, consumerId, id, data)
|
||||
}
|
||||
|
||||
// @Delete(':id')
|
||||
// async delete(@Param('id') id: string) {
|
||||
// return this.businessActivitiesService.delete(id)
|
||||
// }
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
import { PrismaModule } from '@/prisma/prisma.module'
|
||||
import { Module } from '@nestjs/common'
|
||||
import { BusinessActivitiesController } from './business-activities.controller'
|
||||
import { BusinessActivitiesService } from './business-activities.service'
|
||||
import { AdminBusinessActivityComplexesModule } from './complexes/complexes.module'
|
||||
|
||||
@Module({
|
||||
imports: [PrismaModule, AdminBusinessActivityComplexesModule],
|
||||
controllers: [BusinessActivitiesController],
|
||||
providers: [BusinessActivitiesService],
|
||||
})
|
||||
export class PartnerConsumerBusinessActivitiesModule {}
|
||||
@@ -0,0 +1,86 @@
|
||||
import { BusinessActivitySelect } from '@/generated/prisma/models'
|
||||
import { PrismaService } from '@/prisma/prisma.service'
|
||||
import { Injectable } from '@nestjs/common'
|
||||
import { ResponseMapper } from 'common/response/response-mapper'
|
||||
import { CreateBusinessActivitiesDto } from './dto/create-business-activities.dto'
|
||||
|
||||
@Injectable()
|
||||
export class BusinessActivitiesService {
|
||||
constructor(private readonly prisma: PrismaService) {}
|
||||
|
||||
defaultSelect: BusinessActivitySelect = {
|
||||
id: true,
|
||||
name: true,
|
||||
economic_code: true,
|
||||
created_at: true,
|
||||
guild: {
|
||||
select: {
|
||||
id: true,
|
||||
code: true,
|
||||
name: true,
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
async findAll(partner_id: string, consumer_id: string) {
|
||||
const businessActivities = await this.prisma.businessActivity.findMany({
|
||||
where: {
|
||||
consumer: {
|
||||
id: consumer_id,
|
||||
partner_id,
|
||||
},
|
||||
},
|
||||
select: this.defaultSelect,
|
||||
})
|
||||
return ResponseMapper.list(businessActivities)
|
||||
}
|
||||
|
||||
async findOne(partner_id: string, consumer_id: string, id: string) {
|
||||
const businessActivity = await this.prisma.businessActivity.findUnique({
|
||||
where: {
|
||||
consumer: {
|
||||
id: consumer_id,
|
||||
partner_id,
|
||||
},
|
||||
id,
|
||||
},
|
||||
select: this.defaultSelect,
|
||||
})
|
||||
return ResponseMapper.single(businessActivity)
|
||||
}
|
||||
|
||||
async create(consumer_id: string, data: CreateBusinessActivitiesDto) {
|
||||
const { guild_id, ...rest } = data
|
||||
const businessActivity = await this.prisma.businessActivity.create({
|
||||
data: {
|
||||
...rest,
|
||||
guild: {
|
||||
connect: {
|
||||
id: data.guild_id,
|
||||
},
|
||||
},
|
||||
consumer: {
|
||||
connect: {
|
||||
id: consumer_id,
|
||||
},
|
||||
},
|
||||
},
|
||||
select: this.defaultSelect,
|
||||
})
|
||||
return ResponseMapper.create(businessActivity)
|
||||
}
|
||||
|
||||
async update(partner_id: string, consumer_id: string, id: string, data: any) {
|
||||
const businessActivity = await this.prisma.businessActivity.update({
|
||||
where: { id, consumer: { id: consumer_id, partner_id } },
|
||||
data,
|
||||
select: this.defaultSelect,
|
||||
})
|
||||
return ResponseMapper.update(businessActivity)
|
||||
}
|
||||
|
||||
// async delete(id: string) {
|
||||
// await this.prisma.businessActivity.delete({ where: { id } })
|
||||
// return ResponseMapper.delete()
|
||||
// }
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
import { PartnerInfo } from '@/common/decorators/partnerInfo.decorator'
|
||||
import { Body, Controller, Get, Param, Patch, Post } from '@nestjs/common'
|
||||
import { ApiTags } from '@nestjs/swagger'
|
||||
import { BusinessActivityComplexesService } from './complexes.service'
|
||||
import { CreateComplexDto, UpdateComplexDto } from './dto/complex.dto'
|
||||
|
||||
@ApiTags('PartnerBusinessActivityComplexes')
|
||||
@Controller(
|
||||
'partner/consumers/:consumerId/business_activities/:businessActivityId/complexes',
|
||||
)
|
||||
export class BusinessActivityComplexesController {
|
||||
constructor(private readonly service: BusinessActivityComplexesService) {}
|
||||
|
||||
@Get()
|
||||
async findAll(
|
||||
@PartnerInfo('id') partnerId: string,
|
||||
@Param('consumerId') consumerId: string,
|
||||
@Param('businessActivityId') businessActivityId: string,
|
||||
) {
|
||||
return this.service.findAll(partnerId, consumerId, businessActivityId)
|
||||
}
|
||||
|
||||
@Get(':id')
|
||||
async findOne(
|
||||
@PartnerInfo('id') partnerId: string,
|
||||
@Param('consumerId') consumerId: string,
|
||||
@Param('businessActivityId') businessActivityId: string,
|
||||
@Param('id') id: string,
|
||||
) {
|
||||
return this.service.findOne(partnerId, consumerId, businessActivityId, id)
|
||||
}
|
||||
|
||||
@Post()
|
||||
async create(
|
||||
@PartnerInfo('id') partnerId: string,
|
||||
@Param('businessActivityId') businessActivityId: string,
|
||||
@Body() data: CreateComplexDto,
|
||||
) {
|
||||
return this.service.create(businessActivityId, data)
|
||||
}
|
||||
|
||||
@Patch(':id')
|
||||
async update(
|
||||
@PartnerInfo('id') partnerId: string,
|
||||
@Param('consumerId') consumerId: string,
|
||||
@Param('businessActivityId') businessActivityId: string,
|
||||
@Param('id') id: string,
|
||||
@Body() data: UpdateComplexDto,
|
||||
) {
|
||||
return this.service.update(partnerId, consumerId, businessActivityId, id, data)
|
||||
}
|
||||
|
||||
// @Delete(':id')
|
||||
// async delete(@Param('id') id: string) {
|
||||
// return this.businessActivityAccountsService.delete(id)
|
||||
// }
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
import { PrismaModule } from '@/prisma/prisma.module'
|
||||
import { Module } from '@nestjs/common'
|
||||
import { BusinessActivityComplexesController } from './complexes.controller'
|
||||
import { BusinessActivityComplexesService } from './complexes.service'
|
||||
import { AdminComplexPosesModule } from './poses/poses.module'
|
||||
|
||||
@Module({
|
||||
imports: [PrismaModule, AdminComplexPosesModule],
|
||||
controllers: [BusinessActivityComplexesController],
|
||||
providers: [BusinessActivityComplexesService],
|
||||
exports: [BusinessActivityComplexesService],
|
||||
})
|
||||
export class AdminBusinessActivityComplexesModule {}
|
||||
@@ -0,0 +1,89 @@
|
||||
import { ComplexSelect, ComplexWhereInput } from '@/generated/prisma/models'
|
||||
import { PrismaService } from '@/prisma/prisma.service'
|
||||
import { Injectable } from '@nestjs/common'
|
||||
import { ResponseMapper } from 'common/response/response-mapper'
|
||||
import { CreateComplexDto, UpdateComplexDto } from './dto/complex.dto'
|
||||
|
||||
@Injectable()
|
||||
export class BusinessActivityComplexesService {
|
||||
constructor(private readonly prisma: PrismaService) {}
|
||||
|
||||
private readonly defaultSelect: ComplexSelect = {
|
||||
id: true,
|
||||
name: true,
|
||||
address: true,
|
||||
branch_code: true,
|
||||
created_at: true,
|
||||
}
|
||||
|
||||
private readonly defaultWhere = (
|
||||
partner_id,
|
||||
consumer_id,
|
||||
business_activity_id,
|
||||
): ComplexWhereInput => ({
|
||||
business_activity: {
|
||||
id: business_activity_id,
|
||||
consumer: {
|
||||
id: consumer_id,
|
||||
partner_id,
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
async findAll(partner_id: string, consumer_id: string, business_activity_id: string) {
|
||||
const accounts = await this.prisma.complex.findMany({
|
||||
where: this.defaultWhere(partner_id, consumer_id, business_activity_id),
|
||||
select: this.defaultSelect,
|
||||
})
|
||||
return ResponseMapper.list(accounts)
|
||||
}
|
||||
|
||||
async findOne(
|
||||
partner_id: string,
|
||||
consumer_id: string,
|
||||
business_activity_id: string,
|
||||
id: string,
|
||||
) {
|
||||
const account = await this.prisma.complex.findUnique({
|
||||
where: {
|
||||
...this.defaultWhere(partner_id, consumer_id, business_activity_id),
|
||||
id,
|
||||
},
|
||||
select: this.defaultSelect,
|
||||
})
|
||||
return ResponseMapper.single(account)
|
||||
}
|
||||
|
||||
async create(business_id: string, data: CreateComplexDto) {
|
||||
const account = await this.prisma.complex.create({
|
||||
data: {
|
||||
...data,
|
||||
business_activity: {
|
||||
connect: {
|
||||
id: business_id,
|
||||
},
|
||||
},
|
||||
},
|
||||
})
|
||||
return ResponseMapper.create(account)
|
||||
}
|
||||
|
||||
async update(
|
||||
partner_id: string,
|
||||
consumer_id: string,
|
||||
business_activity_id: string,
|
||||
id: string,
|
||||
data: UpdateComplexDto,
|
||||
) {
|
||||
const account = await this.prisma.complex.update({
|
||||
where: { ...this.defaultWhere(partner_id, consumer_id, business_activity_id), id },
|
||||
data,
|
||||
})
|
||||
return ResponseMapper.update(account)
|
||||
}
|
||||
|
||||
// async delete(id: string) {
|
||||
// await this.prisma.complex.delete({ where: { id } })
|
||||
// return ResponseMapper.delete()
|
||||
// }
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
import { ApiProperty, PartialType } from '@nestjs/swagger'
|
||||
import { IsString } from 'class-validator'
|
||||
|
||||
export class CreateComplexDto {
|
||||
@IsString()
|
||||
@ApiProperty({})
|
||||
name: string
|
||||
|
||||
@IsString()
|
||||
@ApiProperty({})
|
||||
branch_code: string
|
||||
|
||||
@IsString()
|
||||
@ApiProperty({})
|
||||
address: string
|
||||
}
|
||||
|
||||
export class UpdateComplexDto extends PartialType(CreateComplexDto) {}
|
||||
@@ -0,0 +1,39 @@
|
||||
import { POSStatus, POSType } from '@/generated/prisma/enums'
|
||||
import { ApiProperty, PartialType } from '@nestjs/swagger'
|
||||
import { IsEnum, IsOptional, IsString } from 'class-validator'
|
||||
|
||||
export class CreatePosDto {
|
||||
@IsString()
|
||||
@ApiProperty({})
|
||||
name: string
|
||||
|
||||
@IsString()
|
||||
@ApiProperty({})
|
||||
serial: string
|
||||
|
||||
// @IsString()
|
||||
// @IsOptional()
|
||||
// @ApiProperty({ required: false })
|
||||
// model: string
|
||||
|
||||
@IsEnum(POSType)
|
||||
@ApiProperty({ enum: POSType })
|
||||
pos_type: POSType
|
||||
|
||||
@IsString()
|
||||
@IsOptional()
|
||||
@ApiProperty({})
|
||||
device_id: string
|
||||
|
||||
@IsString()
|
||||
@IsOptional()
|
||||
@ApiProperty()
|
||||
provider_id: string
|
||||
}
|
||||
|
||||
export class UpdatePosDto extends PartialType(CreatePosDto) {
|
||||
@IsEnum(POSStatus)
|
||||
@IsOptional()
|
||||
@ApiProperty({ enum: POSStatus })
|
||||
status: POSStatus
|
||||
}
|
||||
+55
@@ -0,0 +1,55 @@
|
||||
import { PartnerInfo } from '@/common/decorators/partnerInfo.decorator'
|
||||
import { Body, Controller, Get, Param, Patch, Post } from '@nestjs/common'
|
||||
import { ApiTags } from '@nestjs/swagger'
|
||||
import { CreatePosDto, UpdatePosDto } from './dto/pos.dto'
|
||||
import { ComplexPosesService } from './poses.service'
|
||||
|
||||
@ApiTags('AdminComplexPoses')
|
||||
@Controller('admin/business_activities/:businessActivityId/complexes/:complexId/poses')
|
||||
export class ComplexPosesController {
|
||||
constructor(private readonly service: ComplexPosesService) {}
|
||||
|
||||
@Get()
|
||||
async findAll(
|
||||
@PartnerInfo('id') partnerId: string,
|
||||
@Param('businessActivityId') businessActivityId: string,
|
||||
@Param('complexId') complexId: string,
|
||||
) {
|
||||
return this.service.findAll(partnerId, businessActivityId, complexId)
|
||||
}
|
||||
|
||||
@Get(':id')
|
||||
async findOne(
|
||||
@PartnerInfo('id') partnerId: string,
|
||||
@Param('businessActivityId') businessActivityId: string,
|
||||
@Param('complexId') complexId: string,
|
||||
@Param('id') id: string,
|
||||
) {
|
||||
return this.service.findOne(partnerId, businessActivityId, complexId, id)
|
||||
}
|
||||
|
||||
@Post()
|
||||
async create(
|
||||
@PartnerInfo('id') partnerId: string,
|
||||
@Param('complexId') complexId: string,
|
||||
@Body() data: CreatePosDto,
|
||||
) {
|
||||
return this.service.create(complexId, data)
|
||||
}
|
||||
|
||||
@Patch(':id')
|
||||
async update(
|
||||
@PartnerInfo('id') partnerId: string,
|
||||
@Param('businessActivityId') businessActivityId: string,
|
||||
@Param('complexId') complexId: string,
|
||||
@Param('id') id: string,
|
||||
@Body() data: UpdatePosDto,
|
||||
) {
|
||||
return this.service.update(partnerId, businessActivityId, complexId, id, data)
|
||||
}
|
||||
|
||||
// @Delete(':id')
|
||||
// async delete(@Param('id') id: string) {
|
||||
// return this.businessActivityAccountsService.delete(id)
|
||||
// }
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
import { PrismaModule } from '@/prisma/prisma.module'
|
||||
import { Module } from '@nestjs/common'
|
||||
import { ComplexPosesController } from './poses.controller'
|
||||
import { ComplexPosesService } from './poses.service'
|
||||
|
||||
@Module({
|
||||
imports: [PrismaModule],
|
||||
controllers: [ComplexPosesController],
|
||||
providers: [ComplexPosesService],
|
||||
exports: [ComplexPosesService],
|
||||
})
|
||||
export class AdminComplexPosesModule {}
|
||||
@@ -0,0 +1,168 @@
|
||||
import { POSStatus } from '@/generated/prisma/enums'
|
||||
import { PosCreateInput, PosSelect } from '@/generated/prisma/models'
|
||||
import { PrismaService } from '@/prisma/prisma.service'
|
||||
import { Injectable } from '@nestjs/common'
|
||||
import { ResponseMapper } from 'common/response/response-mapper'
|
||||
import { CreatePosDto, UpdatePosDto } from './dto/pos.dto'
|
||||
|
||||
@Injectable()
|
||||
export class ComplexPosesService {
|
||||
constructor(private readonly prisma: PrismaService) {}
|
||||
|
||||
private readonly defaultSelect: PosSelect = {
|
||||
id: true,
|
||||
name: true,
|
||||
model: true,
|
||||
serial: true,
|
||||
status: true,
|
||||
created_at: true,
|
||||
pos_type: true,
|
||||
|
||||
provider: {
|
||||
select: {
|
||||
id: true,
|
||||
name: true,
|
||||
},
|
||||
},
|
||||
device: {
|
||||
select: {
|
||||
name: true,
|
||||
id: true,
|
||||
brand: {
|
||||
select: {
|
||||
id: true,
|
||||
name: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
complex: {
|
||||
select: {
|
||||
id: true,
|
||||
name: true,
|
||||
business_activity: {
|
||||
select: {
|
||||
id: true,
|
||||
name: true,
|
||||
economic_code: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
private readonly defaultWhere = (
|
||||
partner_id: string,
|
||||
complex_id: string,
|
||||
business_activity_id: string,
|
||||
): any => ({
|
||||
complex: {
|
||||
id: complex_id,
|
||||
business_activity: {
|
||||
id: business_activity_id,
|
||||
consumer: {
|
||||
partner_id,
|
||||
},
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
private readonly defaultInsert = (data: CreatePosDto, complex_id: string) => {
|
||||
const { device_id, provider_id, ...rest } = data
|
||||
|
||||
return {
|
||||
...rest,
|
||||
complex: {
|
||||
connect: {
|
||||
id: complex_id,
|
||||
},
|
||||
},
|
||||
provider: provider_id
|
||||
? {
|
||||
connect: {
|
||||
id: provider_id,
|
||||
},
|
||||
}
|
||||
: undefined,
|
||||
device: device_id
|
||||
? {
|
||||
connect: {
|
||||
id: device_id,
|
||||
},
|
||||
}
|
||||
: undefined,
|
||||
} as PosCreateInput
|
||||
}
|
||||
|
||||
async findAll(partner_id: string, business_activity_id: string, complex_id: string) {
|
||||
const accounts = await this.prisma.pos.findMany({
|
||||
where: this.defaultWhere(partner_id, complex_id, business_activity_id),
|
||||
select: this.defaultSelect,
|
||||
})
|
||||
return ResponseMapper.list(accounts)
|
||||
}
|
||||
|
||||
async findOne(
|
||||
partner_id: string,
|
||||
business_activity_id: string,
|
||||
complex_id: string,
|
||||
id: string,
|
||||
) {
|
||||
const account = await this.prisma.pos.findUniqueOrThrow({
|
||||
where: { ...this.defaultWhere(partner_id, complex_id, business_activity_id), id },
|
||||
select: this.defaultSelect,
|
||||
})
|
||||
return ResponseMapper.single(account)
|
||||
}
|
||||
|
||||
async create(complex_id: string, data: CreatePosDto) {
|
||||
const account = await this.prisma.pos.create({
|
||||
data: {
|
||||
...this.defaultInsert(data, complex_id),
|
||||
status: POSStatus.ACTIVE,
|
||||
},
|
||||
})
|
||||
return ResponseMapper.create(account)
|
||||
}
|
||||
|
||||
async update(
|
||||
partner_id: string,
|
||||
business_activity_id: string,
|
||||
complex_id: string,
|
||||
id: string,
|
||||
data: UpdatePosDto,
|
||||
) {
|
||||
const { device_id, provider_id, ...rest } = data
|
||||
const account = await this.prisma.pos.update({
|
||||
where: { ...this.defaultWhere(partner_id, complex_id, business_activity_id), id },
|
||||
data: {
|
||||
complex: {
|
||||
connect: {
|
||||
id: complex_id,
|
||||
},
|
||||
},
|
||||
provider: provider_id
|
||||
? {
|
||||
connect: {
|
||||
id: provider_id,
|
||||
},
|
||||
}
|
||||
: undefined,
|
||||
device: device_id
|
||||
? {
|
||||
connect: {
|
||||
id: device_id,
|
||||
},
|
||||
}
|
||||
: undefined,
|
||||
...rest,
|
||||
},
|
||||
})
|
||||
return ResponseMapper.update(account)
|
||||
}
|
||||
|
||||
// async delete(id: string) {
|
||||
// await this.prisma.complex.delete({ where: { id } })
|
||||
// return ResponseMapper.delete()
|
||||
// }
|
||||
}
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
import { ApiProperty, PartialType } from '@nestjs/swagger'
|
||||
import { IsString } from 'class-validator'
|
||||
|
||||
export class CreateBusinessActivitiesDto {
|
||||
@IsString()
|
||||
@ApiProperty({ required: true })
|
||||
name: string
|
||||
|
||||
@IsString()
|
||||
@ApiProperty({ required: true })
|
||||
economic_code: string
|
||||
|
||||
@IsString()
|
||||
@ApiProperty({})
|
||||
guild_id: string
|
||||
}
|
||||
|
||||
export class UpdateBusinessActivityDto extends PartialType(CreateBusinessActivitiesDto) {}
|
||||
@@ -0,0 +1,33 @@
|
||||
import { PartnerInfo } from '@/common/decorators/partnerInfo.decorator'
|
||||
import { Body, Controller, Get, Param, Patch, Post } from '@nestjs/common'
|
||||
import { PartnerConsumersService } from './consumers.service'
|
||||
import { CreateConsumerDto, UpdateConsumerDto } from './dto/create-consumers.dto'
|
||||
|
||||
@Controller('partner/consumers')
|
||||
export class PartnerConsumersController {
|
||||
constructor(private readonly service: PartnerConsumersService) {}
|
||||
|
||||
@Get()
|
||||
async findAll(@PartnerInfo('id') partnerId: string) {
|
||||
return this.service.findAll(partnerId)
|
||||
}
|
||||
|
||||
@Get(':id')
|
||||
async findOne(@PartnerInfo('id') partnerId: string, @Param('id') id: string) {
|
||||
return this.service.findOne(partnerId, id)
|
||||
}
|
||||
|
||||
@Post()
|
||||
async create(@PartnerInfo('id') partnerId: string, @Body() data: CreateConsumerDto) {
|
||||
return this.service.create(partnerId, data)
|
||||
}
|
||||
|
||||
@Patch(':id')
|
||||
async update(
|
||||
@Param('id') id: string,
|
||||
@PartnerInfo('id') partnerId: string,
|
||||
@Body() data: UpdateConsumerDto,
|
||||
) {
|
||||
return this.service.update(id, partnerId, data)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
import { PrismaModule } from '@/prisma/prisma.module'
|
||||
import { Module } from '@nestjs/common'
|
||||
import { PartnerConsumerAccountsModule } from './accounts/accounts.module'
|
||||
import { PartnerConsumerBusinessActivitiesModule } from './business-activities/business-activities.module'
|
||||
import { PartnerConsumersController } from './consumers.controller'
|
||||
import { PartnerConsumersService } from './consumers.service'
|
||||
|
||||
@Module({
|
||||
imports: [
|
||||
PrismaModule,
|
||||
PartnerConsumerAccountsModule,
|
||||
PartnerConsumerBusinessActivitiesModule,
|
||||
],
|
||||
controllers: [PartnerConsumersController],
|
||||
providers: [PartnerConsumersService],
|
||||
})
|
||||
export class PartnerCustomersModule {}
|
||||
@@ -0,0 +1,166 @@
|
||||
import { PasswordUtil } from '@/common/utils/password.util'
|
||||
import {
|
||||
AccountStatus,
|
||||
AccountType,
|
||||
ConsumerRole,
|
||||
ConsumerStatus,
|
||||
PartnerStatus,
|
||||
} from '@/generated/prisma/enums'
|
||||
import { ConsumerSelect, ConsumerWhereInput } 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'
|
||||
import { CreateConsumerDto, UpdateConsumerDto } from './dto/create-consumers.dto'
|
||||
|
||||
@Injectable()
|
||||
export class PartnerConsumersService {
|
||||
constructor(private readonly prisma: PrismaService) {}
|
||||
|
||||
private readonly setExpireDate = (starts_at: Date) => {
|
||||
return new Date(
|
||||
new Date(starts_at).setFullYear(new Date(starts_at).getFullYear() + 1),
|
||||
).toISOString()
|
||||
}
|
||||
|
||||
defaultSelect: ConsumerSelect = {
|
||||
id: true,
|
||||
first_name: true,
|
||||
last_name: true,
|
||||
mobile_number: true,
|
||||
national_code: true,
|
||||
status: true,
|
||||
created_at: true,
|
||||
}
|
||||
|
||||
private defaultWhere = (partner_id: string): ConsumerWhereInput => ({
|
||||
partner_id,
|
||||
})
|
||||
|
||||
async findAll(partner_id: string, page = 1, pageSize = 10) {
|
||||
const [consumers, count] = await this.prisma.$transaction(async tx => [
|
||||
await tx.consumer.findMany({
|
||||
where: this.defaultWhere(partner_id),
|
||||
select: this.defaultSelect,
|
||||
skip: (page - 1) * pageSize,
|
||||
take: 10,
|
||||
}),
|
||||
await tx.consumer.count({
|
||||
where: this.defaultWhere(partner_id),
|
||||
}),
|
||||
])
|
||||
return ResponseMapper.paginate(consumers.map(mapConsumerWithLicenseUtil), {
|
||||
count,
|
||||
page,
|
||||
pageSize,
|
||||
})
|
||||
}
|
||||
|
||||
async findOne(partner_id: string, consumer_id: string) {
|
||||
const consumer = await this.prisma.consumer.findUniqueOrThrow({
|
||||
where: {
|
||||
...(this.defaultWhere(partner_id) as any),
|
||||
id: consumer_id,
|
||||
},
|
||||
select: this.defaultSelect,
|
||||
})
|
||||
|
||||
return ResponseMapper.single(mapConsumerWithLicenseUtil(consumer))
|
||||
}
|
||||
|
||||
async create(partner_id: string, data: CreateConsumerDto) {
|
||||
const consumer = await this.prisma.$transaction(async tx => {
|
||||
const partnerLicense = await tx.license.findFirst({
|
||||
where: {
|
||||
charge_transaction: {
|
||||
partner: {
|
||||
id: partner_id,
|
||||
status: PartnerStatus.ACTIVE,
|
||||
},
|
||||
},
|
||||
activation: null,
|
||||
},
|
||||
orderBy: {
|
||||
charge_transaction: {
|
||||
activation_expires_at: 'asc',
|
||||
},
|
||||
},
|
||||
select: {
|
||||
id: true,
|
||||
charge_transaction: {
|
||||
select: {
|
||||
partner: {
|
||||
select: {
|
||||
id: true,
|
||||
name: true,
|
||||
status: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
if (!partnerLicense) {
|
||||
throw new BadRequestException(`تعداد لایسنسهای فعلی شما به پایان رسیده است.`)
|
||||
}
|
||||
|
||||
const { username, password, license_starts_at, ...rest } = data
|
||||
|
||||
const existingConsumer = await tx.consumer.findFirst({
|
||||
where: {
|
||||
partner_id,
|
||||
OR: [
|
||||
{ mobile_number: data.mobile_number },
|
||||
{ national_code: data.national_code },
|
||||
],
|
||||
},
|
||||
select: { id: true, first_name: true, last_name: true },
|
||||
})
|
||||
|
||||
if (existingConsumer) {
|
||||
throw new BadRequestException(
|
||||
`مصرف کنندهی ${existingConsumer.first_name} ${existingConsumer.last_name} با شماره موبایل یا کد ملی وارد شده از قبل ثبت شده است.`,
|
||||
)
|
||||
}
|
||||
|
||||
return await tx.consumer.create({
|
||||
data: {
|
||||
...rest,
|
||||
partner: {
|
||||
connect: {
|
||||
id: partner_id,
|
||||
},
|
||||
},
|
||||
consumer_accounts: {
|
||||
create: {
|
||||
role: ConsumerRole.OWNER,
|
||||
account: {
|
||||
create: {
|
||||
username,
|
||||
password: await PasswordUtil.hash(password),
|
||||
type: AccountType.CONSUMER,
|
||||
status: AccountStatus.ACTIVE,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
status: ConsumerStatus.ACTIVE,
|
||||
},
|
||||
select: this.defaultSelect,
|
||||
})
|
||||
})
|
||||
|
||||
return ResponseMapper.single(mapConsumerWithLicenseUtil(consumer))
|
||||
}
|
||||
|
||||
async update(id: string, partner_id: string, data: UpdateConsumerDto) {
|
||||
return this.prisma.consumer.update({
|
||||
where: {
|
||||
...(this.defaultWhere(partner_id) as any),
|
||||
id,
|
||||
},
|
||||
data,
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
import { ConsumerStatus } from '@/generated/prisma/enums'
|
||||
import { ApiProperty, OmitType, PartialType } from '@nestjs/swagger'
|
||||
import { IsDateString, IsEnum, IsString } from 'class-validator'
|
||||
|
||||
export class CreateConsumerDto {
|
||||
@IsString()
|
||||
@ApiProperty({ required: true })
|
||||
first_name: string
|
||||
|
||||
@IsString()
|
||||
@ApiProperty({ required: true })
|
||||
last_name: string
|
||||
|
||||
@IsString()
|
||||
@ApiProperty({ required: true })
|
||||
mobile_number: string
|
||||
|
||||
@IsString()
|
||||
@ApiProperty({ required: true })
|
||||
national_code: string
|
||||
|
||||
@IsString()
|
||||
@ApiProperty({ required: true })
|
||||
username: string
|
||||
|
||||
@IsString()
|
||||
@ApiProperty({ required: true })
|
||||
password: string
|
||||
|
||||
@ApiProperty({ required: true })
|
||||
@IsDateString(
|
||||
{ strict: true },
|
||||
{ message: 'invoice_date must be a valid ISO-8601 string' },
|
||||
)
|
||||
license_starts_at: Date
|
||||
}
|
||||
export class UpdateConsumerDto extends OmitType(PartialType(CreateConsumerDto), [
|
||||
'password',
|
||||
'username',
|
||||
]) {
|
||||
@IsEnum(ConsumerStatus)
|
||||
@ApiProperty({ enum: ConsumerStatus })
|
||||
status: ConsumerStatus
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
import { LicenseStatus } from '@/generated/prisma/enums'
|
||||
import { ApiProperty, PartialType } from '@nestjs/swagger'
|
||||
import { IsDateString, IsEnum } from 'class-validator'
|
||||
|
||||
export class CreateLicenseDto {
|
||||
@ApiProperty({ required: true, default: new Date().toISOString() })
|
||||
@IsDateString(
|
||||
{ strict: true },
|
||||
{ message: 'invoice_date must be a valid ISO-8601 string' },
|
||||
)
|
||||
starts_at: Date
|
||||
|
||||
@ApiProperty()
|
||||
@IsDateString(
|
||||
{ strict: true },
|
||||
{ message: 'invoice_date must be a valid ISO-8601 string' },
|
||||
)
|
||||
expires_at?: Date
|
||||
|
||||
@ApiProperty({
|
||||
required: true,
|
||||
nullable: false,
|
||||
})
|
||||
partner_id: string
|
||||
}
|
||||
|
||||
export class UpdateLicenseDto extends PartialType(CreateLicenseDto) {
|
||||
@ApiProperty({ enum: LicenseStatus })
|
||||
@IsEnum(LicenseStatus)
|
||||
status?: LicenseStatus
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
import { PartnerInfo } from '@/common/decorators/partnerInfo.decorator'
|
||||
import { Controller, Get, Param } from '@nestjs/common'
|
||||
import { ApiTags } from '@nestjs/swagger'
|
||||
import { LicensesService } from './licenses.service'
|
||||
|
||||
@ApiTags('AdminConsumerAccounts')
|
||||
@Controller('admin/consumers/:consumerId/licenses')
|
||||
export class LicensesController {
|
||||
constructor(private readonly service: LicensesService) {}
|
||||
|
||||
@Get()
|
||||
async findAll(
|
||||
@PartnerInfo('id') partnerId: string,
|
||||
@Param('consumerId') consumerId: string,
|
||||
) {
|
||||
return this.service.findAll(partnerId, consumerId)
|
||||
}
|
||||
|
||||
// @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) {
|
||||
// return this.service.update(id, data)
|
||||
// }
|
||||
|
||||
// @Delete(':id')
|
||||
// async delete(@Param('id') id: string) {
|
||||
// return this.service.delete(id)
|
||||
// }
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
import { PrismaModule } from '@/prisma/prisma.module'
|
||||
import { Module } from '@nestjs/common'
|
||||
import { LicensesController } from './licenses.controller'
|
||||
import { LicensesService } from './licenses.service'
|
||||
|
||||
@Module({
|
||||
imports: [PrismaModule],
|
||||
controllers: [LicensesController],
|
||||
providers: [LicensesService],
|
||||
exports: [LicensesService],
|
||||
})
|
||||
export class AdminConsumerLicensesModule {}
|
||||
@@ -0,0 +1,165 @@
|
||||
import { PrismaService } from '@/prisma/prisma.service'
|
||||
import { Injectable } from '@nestjs/common'
|
||||
import { ResponseMapper } from 'common/response/response-mapper'
|
||||
|
||||
@Injectable()
|
||||
export class LicensesService {
|
||||
private startOfToday = new Date()
|
||||
|
||||
constructor(private readonly prisma: PrismaService) {
|
||||
this.startOfToday.setHours(0, 0, 0, 0)
|
||||
}
|
||||
|
||||
private readonly setExpireDate = (starts_at: Date) => {
|
||||
return new Date(
|
||||
new Date(starts_at).setFullYear(new Date(starts_at).getFullYear() + 1),
|
||||
).toISOString()
|
||||
}
|
||||
|
||||
async findAll(partner_id: string, consumer_id: string) {
|
||||
const licenses = await this.prisma.licenseActivation.findMany({
|
||||
where: {
|
||||
business_activity: {
|
||||
consumer_id,
|
||||
},
|
||||
license: {
|
||||
charge_transaction: {
|
||||
partner_id,
|
||||
},
|
||||
},
|
||||
},
|
||||
select: {
|
||||
id: true,
|
||||
starts_at: true,
|
||||
expires_at: true,
|
||||
created_at: true,
|
||||
license: {
|
||||
select: {
|
||||
id: true,
|
||||
charge_transaction: {
|
||||
select: {
|
||||
partner: {
|
||||
select: {
|
||||
id: true,
|
||||
name: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
return ResponseMapper.list(licenses)
|
||||
}
|
||||
|
||||
// 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: {
|
||||
// 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(
|
||||
// `تعداد لایسنسهای فعلی شریک تجاری به پایان رسیده است.`,
|
||||
// )
|
||||
// }
|
||||
|
||||
// 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)
|
||||
// }
|
||||
|
||||
// async update(id: string, data: UpdateLicenseDto) {
|
||||
// const { starts_at, expires_at, partner_id } = data
|
||||
// const currentLicense = await this.prisma.license.findUnique({
|
||||
// where: { id },
|
||||
// select: {
|
||||
// partner_id: true,
|
||||
// },
|
||||
// })
|
||||
|
||||
// if (partner_id && currentLicense?.partner_id !== partner_id) {
|
||||
// const partner = await this.prisma.partner.findUnique({
|
||||
// where: {
|
||||
// id: partner_id,
|
||||
// },
|
||||
// select: {
|
||||
// name: true,
|
||||
// license_quota: true,
|
||||
// _count: {
|
||||
// select: {
|
||||
// licenses: true,
|
||||
// },
|
||||
// },
|
||||
// },
|
||||
// })
|
||||
|
||||
// if (!((partner?.license_quota || 0) - (partner?._count.licenses || 0))) {
|
||||
// throw new BadRequestException(`تعداد لایسنسهای ${partner?.name} کافی نیست.`)
|
||||
// }
|
||||
// }
|
||||
|
||||
// const dataToUpdate: LicenseUpdateInput = {}
|
||||
|
||||
// if (partner_id) {
|
||||
// dataToUpdate.partner = {
|
||||
// connect: {
|
||||
// id: partner_id,
|
||||
// },
|
||||
// }
|
||||
// } else if (currentLicense?.partner_id) {
|
||||
// dataToUpdate.partner = {
|
||||
// disconnect: {
|
||||
// id: currentLicense?.partner_id,
|
||||
// },
|
||||
// }
|
||||
// }
|
||||
|
||||
// if (starts_at) {
|
||||
// dataToUpdate.starts_at = starts_at
|
||||
// dataToUpdate.expires_at = this.setExpireDate(starts_at)
|
||||
// }
|
||||
|
||||
// const license = await this.prisma.license.update({
|
||||
// where: { id },
|
||||
// data: {
|
||||
// ...dataToUpdate,
|
||||
// },
|
||||
// })
|
||||
// return ResponseMapper.update(license)
|
||||
// }
|
||||
}
|
||||
@@ -1,18 +0,0 @@
|
||||
import { PartnerInfo } from '@/common/decorators/partnerInfo.decorator'
|
||||
import { Controller, Get, Param } from '@nestjs/common'
|
||||
import { PartnerCustomersService } from './customers.service'
|
||||
|
||||
@Controller('partner/customers')
|
||||
export class PartnerCustomersController {
|
||||
constructor(private readonly service: PartnerCustomersService) {}
|
||||
|
||||
@Get()
|
||||
async findAll(@PartnerInfo('id') partnerId: string) {
|
||||
return this.service.findAll(partnerId)
|
||||
}
|
||||
|
||||
@Get(':id')
|
||||
async findOne(@PartnerInfo('id') partnerId: string, @Param('id') id: string) {
|
||||
return this.service.findOne(partnerId, id)
|
||||
}
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
import { PrismaModule } from '@/prisma/prisma.module'
|
||||
import { Module } from '@nestjs/common'
|
||||
import { PartnerCustomersController } from './customers.controller'
|
||||
import { PartnerCustomersService } from './customers.service'
|
||||
|
||||
@Module({
|
||||
imports: [PrismaModule],
|
||||
controllers: [PartnerCustomersController],
|
||||
providers: [PartnerCustomersService],
|
||||
})
|
||||
export class PartnerCustomersModule {}
|
||||
@@ -1,64 +0,0 @@
|
||||
import { ConsumerSelect, ConsumerWhereInput } 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 PartnerCustomersService {
|
||||
constructor(private readonly prisma: PrismaService) {}
|
||||
|
||||
defaultSelect: ConsumerSelect = {
|
||||
id: true,
|
||||
first_name: true,
|
||||
last_name: true,
|
||||
status: true,
|
||||
activated_licenses: {
|
||||
select: {
|
||||
id: true,
|
||||
starts_at: true,
|
||||
expires_at: true,
|
||||
created_at: true,
|
||||
},
|
||||
},
|
||||
created_at: true,
|
||||
}
|
||||
|
||||
private defaultWhere = (partner_id: string): ConsumerWhereInput => ({
|
||||
activated_licenses: {
|
||||
some: {
|
||||
license: {
|
||||
charged_license_transaction: {
|
||||
partner_id,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
async findAll(partner_id: string, page = 1, pageSize = 10) {
|
||||
const [partners, count] = await this.prisma.$transaction(async tx => [
|
||||
await tx.consumer.findMany({
|
||||
where: this.defaultWhere(partner_id),
|
||||
select: this.defaultSelect,
|
||||
skip: (page - 1) * pageSize,
|
||||
take: 10,
|
||||
}),
|
||||
await tx.consumer.count({
|
||||
where: this.defaultWhere(partner_id),
|
||||
}),
|
||||
])
|
||||
return ResponseMapper.paginate(partners, { count, page, pageSize })
|
||||
}
|
||||
|
||||
async findOne(partner_id: string, consumer_id: string) {
|
||||
const partner = await this.prisma.consumer.findUniqueOrThrow({
|
||||
where: {
|
||||
...(this.defaultWhere(partner_id) as any),
|
||||
id: consumer_id,
|
||||
},
|
||||
select: this.defaultSelect,
|
||||
})
|
||||
|
||||
return ResponseMapper.single(partner)
|
||||
}
|
||||
}
|
||||
@@ -1,74 +0,0 @@
|
||||
import { ApiProperty } from '@nestjs/swagger'
|
||||
import {
|
||||
IsBoolean,
|
||||
IsNumber,
|
||||
IsOptional,
|
||||
IsString,
|
||||
MaxLength,
|
||||
MinLength,
|
||||
} from 'class-validator'
|
||||
|
||||
export class UpdateCustomerLegalDto {
|
||||
@IsString()
|
||||
@IsOptional()
|
||||
@ApiProperty({ required: true })
|
||||
company_name?: string
|
||||
|
||||
@IsString()
|
||||
@IsOptional()
|
||||
@ApiProperty({ required: true })
|
||||
economic_code?: string
|
||||
|
||||
@IsString()
|
||||
@IsOptional()
|
||||
@ApiProperty({ required: true })
|
||||
registration_number?: string
|
||||
|
||||
@IsNumber()
|
||||
@MaxLength(10)
|
||||
@MinLength(10)
|
||||
@IsOptional()
|
||||
@ApiProperty({ maxLength: 10, minLength: 10 })
|
||||
postal_code?: string
|
||||
|
||||
@IsBoolean()
|
||||
@IsOptional()
|
||||
@ApiProperty({ required: false })
|
||||
is_favorite?: boolean
|
||||
}
|
||||
|
||||
export class UpdateCustomerIndividualDto {
|
||||
@IsString()
|
||||
@IsOptional()
|
||||
@ApiProperty({ required: true })
|
||||
first_name?: string
|
||||
|
||||
@IsString()
|
||||
@IsOptional()
|
||||
@ApiProperty({ required: true })
|
||||
last_name?: string
|
||||
|
||||
@IsNumber()
|
||||
@MaxLength(10)
|
||||
@MinLength(10)
|
||||
@IsOptional()
|
||||
@ApiProperty({ required: true, maxLength: 10, minLength: 10 })
|
||||
national_code?: string
|
||||
|
||||
@IsNumber()
|
||||
@MaxLength(10)
|
||||
@MinLength(10)
|
||||
@IsOptional()
|
||||
@ApiProperty({ maxLength: 10, minLength: 10 })
|
||||
postal_code?: string
|
||||
|
||||
@IsBoolean()
|
||||
@IsOptional()
|
||||
@ApiProperty({ required: false })
|
||||
is_favorite?: boolean
|
||||
|
||||
@IsNumber()
|
||||
@IsOptional()
|
||||
@ApiProperty({ required: false })
|
||||
economic_code?: string
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
import { MiddlewareConsumer, Module, NestModule, RequestMethod } from '@nestjs/common'
|
||||
import { JwtService } from '@nestjs/jwt'
|
||||
import { PartnerAccountsModule } from './accounts/accounts.module'
|
||||
import { PartnerCustomersModule } from './customers/customers.module'
|
||||
import { PartnerCustomersModule } from './consumers/consumers.module'
|
||||
import { PartnerController } from './partners.controller'
|
||||
import { PartnerMiddleware } from './partners.middleware'
|
||||
import { PartnerService } from './partners.service'
|
||||
|
||||
@@ -15,6 +15,19 @@ export class PartnerService {
|
||||
id: true,
|
||||
name: true,
|
||||
status: true,
|
||||
account_quota_charge_transactions: {
|
||||
select: {
|
||||
_count: {
|
||||
select: {
|
||||
allocations: {
|
||||
where: {
|
||||
license_id: undefined,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
|
||||
@@ -11,7 +11,6 @@ export class PosController {
|
||||
|
||||
@Get()
|
||||
async getInfo(@PosInfo('pos_id') pos_id: string, @Res({ passthrough: true }) res) {
|
||||
console.log('getInfo', pos_id)
|
||||
const result = await this.service.getInfo(pos_id)
|
||||
|
||||
if (result) {
|
||||
|
||||
@@ -18,11 +18,32 @@ export class PosService {
|
||||
select: {
|
||||
id: true,
|
||||
name: true,
|
||||
tax_id: true,
|
||||
business_activity: {
|
||||
select: {
|
||||
id: true,
|
||||
name: true,
|
||||
economic_code: true,
|
||||
license_activation: {
|
||||
select: {
|
||||
expires_at: true,
|
||||
license: {
|
||||
select: {
|
||||
id: true,
|
||||
charge_transaction: {
|
||||
select: {
|
||||
partner: {
|
||||
select: {
|
||||
id: true,
|
||||
name: true,
|
||||
code: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
guild: {
|
||||
select: {
|
||||
id: true,
|
||||
@@ -37,21 +58,32 @@ export class PosService {
|
||||
},
|
||||
})
|
||||
const { name, complex } = pos
|
||||
const { name: complexName, id: complexId, tax_id, business_activity } = complex
|
||||
const { name: businessName, id: businessId, guild } = business_activity
|
||||
const { name: complexName, id: complexId, business_activity } = complex
|
||||
const {
|
||||
name: businessName,
|
||||
id: businessId,
|
||||
guild,
|
||||
economic_code,
|
||||
license_activation,
|
||||
} = business_activity
|
||||
|
||||
return ResponseMapper.single({
|
||||
name,
|
||||
complex: {
|
||||
id: complexId,
|
||||
name: complexName,
|
||||
tax_id,
|
||||
},
|
||||
businessActivity: {
|
||||
id: businessId,
|
||||
name: businessName,
|
||||
economic_code,
|
||||
},
|
||||
guild,
|
||||
license_info: {
|
||||
expires_at: license_activation?.expires_at,
|
||||
license_id: license_activation?.license.id,
|
||||
},
|
||||
partner: license_activation?.license.charge_transaction.partner,
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user