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:
@@ -1,6 +1,6 @@
|
||||
import { ComplexSelect, ComplexWhereInput } from '@/generated/prisma/models'
|
||||
import { PrismaService } from '@/prisma/prisma.service'
|
||||
import { Injectable } from '@nestjs/common'
|
||||
import { BadRequestException, Injectable } from '@nestjs/common'
|
||||
import { ResponseMapper } from 'common/response/response-mapper'
|
||||
import { CreateComplexDto, UpdateComplexDto } from './dto/complex.dto'
|
||||
|
||||
@@ -55,16 +55,62 @@ export class BusinessActivityComplexesService {
|
||||
}
|
||||
|
||||
async create(partner_id: string, business_id: string, data: CreateComplexDto) {
|
||||
const complex = await this.prisma.complex.create({
|
||||
data: {
|
||||
...data,
|
||||
business_activity: {
|
||||
connect: {
|
||||
id: business_id,
|
||||
const complex = this.prisma.$transaction(async tx => {
|
||||
const now = new Date()
|
||||
|
||||
const relatedLicense = await tx.licenseAccountAllocation.findFirst({
|
||||
where: {
|
||||
license_activation: {
|
||||
license: {
|
||||
charge_transaction: {
|
||||
partner_id,
|
||||
},
|
||||
},
|
||||
business_activity: {
|
||||
id: business_id,
|
||||
},
|
||||
OR: [
|
||||
{
|
||||
expires_at: {
|
||||
gte: now,
|
||||
},
|
||||
},
|
||||
{
|
||||
license_renews: {
|
||||
some: {
|
||||
expires_at: {
|
||||
gte: now,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
account_id: null,
|
||||
},
|
||||
select: {
|
||||
id: true,
|
||||
},
|
||||
})
|
||||
|
||||
if (!relatedLicense) {
|
||||
throw new BadRequestException(
|
||||
`متاسفانه به دلیل به پایان رسیدن محدودیت تعریف کاربران برای این فعالیت اقتصادی،امکان ایجاد شعبهی جدید وجود ندارد.`,
|
||||
)
|
||||
}
|
||||
|
||||
return await this.prisma.complex.create({
|
||||
data: {
|
||||
...data,
|
||||
business_activity: {
|
||||
connect: {
|
||||
id: business_id,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
})
|
||||
})
|
||||
|
||||
return ResponseMapper.create(complex)
|
||||
}
|
||||
|
||||
|
||||
+40
-50
@@ -5,7 +5,7 @@ import {
|
||||
ConsumerRole,
|
||||
POSStatus,
|
||||
} from '@/generated/prisma/enums'
|
||||
import { PosCreateInput, PosSelect } from '@/generated/prisma/models'
|
||||
import { PosSelect } from '@/generated/prisma/models'
|
||||
import { PrismaService } from '@/prisma/prisma.service'
|
||||
import { BadRequestException, Injectable } from '@nestjs/common'
|
||||
import { ResponseMapper } from 'common/response/response-mapper'
|
||||
@@ -95,35 +95,6 @@ export class ComplexPosesService {
|
||||
}
|
||||
}
|
||||
|
||||
private readonly defaultInsert = (data: CreatePosDto, complex_id: string) => {
|
||||
const { device_id, provider_id, ...rest } = data
|
||||
|
||||
const dataToCreate: PosCreateInput = {
|
||||
...rest,
|
||||
complex: {
|
||||
connect: {
|
||||
id: complex_id,
|
||||
},
|
||||
},
|
||||
provider: provider_id
|
||||
? {
|
||||
connect: {
|
||||
id: provider_id,
|
||||
},
|
||||
}
|
||||
: undefined,
|
||||
device: device_id
|
||||
? {
|
||||
connect: {
|
||||
id: device_id,
|
||||
},
|
||||
}
|
||||
: undefined,
|
||||
}
|
||||
|
||||
return dataToCreate
|
||||
}
|
||||
|
||||
async findAll(partner_id: string, business_activity_id: string, complex_id: string) {
|
||||
const poses = await this.prisma.pos.findMany({
|
||||
where: this.defaultWhere(partner_id, complex_id, business_activity_id),
|
||||
@@ -155,26 +126,43 @@ export class ComplexPosesService {
|
||||
data: CreatePosDto,
|
||||
) {
|
||||
const pos = this.prisma.$transaction(async tx => {
|
||||
const ba = await tx.businessActivity.findUniqueOrThrow({
|
||||
const now = new Date()
|
||||
|
||||
const activeAccountAllocation = await tx.licenseAccountAllocation.findFirst({
|
||||
where: {
|
||||
id: business_activity_id,
|
||||
consumer: {
|
||||
partner_id,
|
||||
account_id: null,
|
||||
license_activation: {
|
||||
business_activity_id,
|
||||
OR: [
|
||||
{
|
||||
expires_at: {
|
||||
gte: now,
|
||||
},
|
||||
},
|
||||
{
|
||||
license_renews: {
|
||||
some: {
|
||||
expires_at: {
|
||||
gte: now,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
],
|
||||
license: {
|
||||
charge_transaction: {
|
||||
partner_id,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
select: {
|
||||
consumer_id: true,
|
||||
id: true,
|
||||
license_activation: {
|
||||
select: {
|
||||
_count: {
|
||||
business_activity: {
|
||||
select: {
|
||||
account_allocations: {
|
||||
where: {
|
||||
account_id: {
|
||||
not: undefined,
|
||||
},
|
||||
},
|
||||
},
|
||||
consumer_id: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -182,7 +170,7 @@ export class ComplexPosesService {
|
||||
},
|
||||
})
|
||||
|
||||
if (!ba.license_activation?._count.account_allocations) {
|
||||
if (!activeAccountAllocation) {
|
||||
throw new BadRequestException(
|
||||
`محدودیت تعریف تعداد کاربران این فعالیت تجاری به پایان رسیده است.`,
|
||||
)
|
||||
@@ -198,9 +186,16 @@ export class ComplexPosesService {
|
||||
account: {
|
||||
create: {
|
||||
role: ConsumerRole.OPERATOR,
|
||||
|
||||
consumer: {
|
||||
connect: {
|
||||
id: ba.consumer_id,
|
||||
id: activeAccountAllocation.license_activation!.business_activity
|
||||
.consumer_id,
|
||||
},
|
||||
},
|
||||
account_allocation: {
|
||||
connect: {
|
||||
id: activeAccountAllocation.id,
|
||||
},
|
||||
},
|
||||
account: {
|
||||
@@ -274,9 +269,4 @@ export class ComplexPosesService {
|
||||
})
|
||||
return ResponseMapper.update(pos)
|
||||
}
|
||||
|
||||
// async delete(id: string) {
|
||||
// await this.prisma.complex.delete({ where: { id } })
|
||||
// return ResponseMapper.delete()
|
||||
// }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user