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:
2026-04-25 15:16:59 +03:30
parent 12506de863
commit b72e6c7194
36 changed files with 975 additions and 568 deletions
@@ -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,
+1 -1
View File
@@ -44,7 +44,7 @@ export class ConsumerMiddleware implements NestMiddleware {
return doForbidden()
}
req.partnerData = {
req.consumerData = {
account_id: consumerAccount.id,
id: consumerAccount.consumer_id,
}
@@ -1,4 +1,5 @@
import {
SalesInvoiceSelect,
SalesInvoiceWhereInput,
SalesInvoiceWhereUniqueInput,
} from '@/generated/prisma/models'
@@ -10,12 +11,12 @@ import { ResponseMapper } from 'common/response/response-mapper'
export class SaleInvoicesService {
constructor(private readonly prisma: PrismaService) {}
private readonly defaultSelect = {
private readonly defaultSelect: SalesInvoiceSelect = {
id: true,
code: true,
total_amount: true,
unknown_customer: true,
invoice_date: true,
created_at: true,
consumer_account: {
select: {
role: true,
@@ -44,24 +45,6 @@ export class SaleInvoicesService {
},
},
},
customer: {
select: {
id: true,
type: true,
customer_legal: {
select: {
company_name: true,
},
},
customer_individual: {
select: {
first_name: true,
last_name: true,
},
},
},
},
}
async findAll(consumer_id: string, page = 1, pageSize = 10) {
@@ -104,14 +87,54 @@ export class SaleInvoicesService {
items: {
select: {
id: true,
notes: true,
unit_price: true,
discount: true,
quantity: true,
total_amount: true,
payload: true,
good: {
select: {
id: true,
name: true,
pricing_model: true,
unit_type: true,
category: {
select: {
id: true,
name: true,
image_url: true,
},
},
},
},
},
},
customer: {
select: {
id: true,
type: true,
customer_legal: {
select: {
company_name: true,
economic_code: true,
registration_number: true,
postal_code: true,
},
},
customer_individual: {
select: {
first_name: true,
last_name: true,
economic_code: true,
national_id: true,
postal_code: true,
},
},
},
},
unknown_customer: true,
},
})
return ResponseMapper.single(invoice)