feat: refactor ComplexPosesService to remove unused defaultInsert method and improve findAll logic
fix: update PartnersService to use 'isNot' instead of 'not' for allocation checks refactor: enhance BusinessActivityComplexesService to validate license activation before creating a complex fix: adjust ComplexPosesService to ensure account allocation checks are accurate and handle errors properly refactor: modify ConsumerMiddleware to set consumerData instead of partnerData for better clarity feat: expand SaleInvoicesService to include additional fields in the invoice selection chore: update business-activities module to include accounts-charge module for better organization fix: ensure ComplexPosesService correctly handles account allocation during POS creation feat: implement PartnerBusinessActivityAccountsCharge module with create functionality for account charges refactor: streamline getPartnerBusinessActivityAllocationLimits utility for better clarity and functionality chore: add migration script to update database schema with necessary constraints and foreign keys feat: create DTO for accounts charge to validate incoming data
This commit is contained in:
@@ -2,7 +2,6 @@ import { ComplexSelect } from '@/generated/prisma/models'
|
||||
import { PrismaService } from '@/prisma/prisma.service'
|
||||
import { BadRequestException, Injectable } from '@nestjs/common'
|
||||
import { ResponseMapper } from 'common/response/response-mapper'
|
||||
import { getBusinessActivityRemainingAccounts } from '../../utils/getBusinessActivityRemainingAccounts.util'
|
||||
import { CreateConsumerComplexDto, UpdateConsumerComplexDto } from './dto/complex.dto'
|
||||
|
||||
@Injectable()
|
||||
@@ -54,12 +53,40 @@ export class BusinessActivityComplexesService {
|
||||
data: CreateConsumerComplexDto,
|
||||
) {
|
||||
const complex = await this.prisma.$transaction(async tx => {
|
||||
const quota = await getBusinessActivityRemainingAccounts(tx, {
|
||||
consumer_id,
|
||||
business_activity_id,
|
||||
const now = new Date()
|
||||
|
||||
const relatedLicense = await tx.licenseAccountAllocation.findFirst({
|
||||
where: {
|
||||
license_activation: {
|
||||
business_activity: {
|
||||
id: business_activity_id,
|
||||
consumer_id,
|
||||
},
|
||||
OR: [
|
||||
{
|
||||
expires_at: {
|
||||
gte: now,
|
||||
},
|
||||
},
|
||||
{
|
||||
license_renews: {
|
||||
some: {
|
||||
expires_at: {
|
||||
gte: now,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
account_id: null,
|
||||
},
|
||||
select: {
|
||||
id: true,
|
||||
},
|
||||
})
|
||||
|
||||
if (quota.remaining_accounts <= 0) {
|
||||
if (!relatedLicense) {
|
||||
throw new BadRequestException(
|
||||
`متاسفانه به دلیل به پایان رسیدن محدودیت تعریف کاربران برای این فعالیت اقتصادی،امکان ایجاد شعبهی جدید وجود ندارد.`,
|
||||
)
|
||||
|
||||
@@ -94,6 +94,7 @@ export class ComplexPosesService {
|
||||
id: complex_id,
|
||||
},
|
||||
},
|
||||
|
||||
account: {
|
||||
create: {
|
||||
role: ConsumerRole.OPERATOR,
|
||||
|
||||
Reference in New Issue
Block a user