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
|
||||
|
||||
Reference in New Issue
Block a user