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:
@@ -19,16 +19,20 @@ export type PartnerBusinessActivityAllocationLimits = {
|
||||
remaining_credits: number
|
||||
}
|
||||
|
||||
export const getPartnerBusinessActivityAllocationLimits = async (
|
||||
const getPartnerBusinessActivityActiveActivation = async (
|
||||
prisma: PartnerBusinessActivityAllocationClient,
|
||||
params: GetPartnerBusinessActivityAllocationLimitsParams,
|
||||
): Promise<PartnerBusinessActivityAllocationLimits> => {
|
||||
options?: {
|
||||
includeAccountAllocations?: boolean
|
||||
},
|
||||
) => {
|
||||
const { partner_id, business_activity_id, referenceDate = new Date() } = params
|
||||
const { includeAccountAllocations = true } = options ?? {}
|
||||
|
||||
const startOfDay = new Date(referenceDate)
|
||||
startOfDay.setHours(0, 0, 0, 0)
|
||||
|
||||
const activation = await prisma.licenseActivation.findFirst({
|
||||
return prisma.licenseActivation.findFirst({
|
||||
where: {
|
||||
business_activity_id,
|
||||
business_activity: {
|
||||
@@ -53,16 +57,59 @@ export const getPartnerBusinessActivityAllocationLimits = async (
|
||||
},
|
||||
],
|
||||
},
|
||||
select: {
|
||||
id: true,
|
||||
account_allocations: {
|
||||
select: {
|
||||
select: includeAccountAllocations
|
||||
? {
|
||||
id: true,
|
||||
account_allocations: {
|
||||
select: {
|
||||
id: true,
|
||||
account_id: true,
|
||||
},
|
||||
},
|
||||
}
|
||||
: {
|
||||
id: true,
|
||||
account_id: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
export const hasPartnerBusinessActivityEmptyAccountAllocation = async (
|
||||
prisma: PartnerBusinessActivityAllocationClient,
|
||||
params: GetPartnerBusinessActivityAllocationLimitsParams,
|
||||
) => {
|
||||
const activation = await getPartnerBusinessActivityActiveActivation(prisma, params)
|
||||
|
||||
if (!activation) {
|
||||
throw new BadRequestException('لایسنس فعال برای این فعالیت تجاری یافت نشد.')
|
||||
}
|
||||
|
||||
return activation.account_allocations.some(
|
||||
account_allocation => !account_allocation.account_id,
|
||||
)
|
||||
}
|
||||
|
||||
export const getPartnerBusinessActivityEmptyAccountAllocation = async (
|
||||
prisma: PartnerBusinessActivityAllocationClient,
|
||||
params: GetPartnerBusinessActivityAllocationLimitsParams,
|
||||
) => {
|
||||
const activation = await getPartnerBusinessActivityActiveActivation(prisma, params)
|
||||
|
||||
if (!activation) {
|
||||
throw new BadRequestException('لایسنس فعال برای این فعالیت تجاری یافت نشد.')
|
||||
}
|
||||
|
||||
return (
|
||||
activation.account_allocations.find(
|
||||
account_allocation => !account_allocation.account_id,
|
||||
) ?? null
|
||||
)
|
||||
}
|
||||
|
||||
export const getPartnerBusinessActivityAllocationLimits = async (
|
||||
prisma: PartnerBusinessActivityAllocationClient,
|
||||
params: GetPartnerBusinessActivityAllocationLimitsParams,
|
||||
): Promise<PartnerBusinessActivityAllocationLimits> => {
|
||||
const activation = await getPartnerBusinessActivityActiveActivation(prisma, params)
|
||||
|
||||
if (!activation) {
|
||||
throw new BadRequestException('لایسنس فعال برای این فعالیت تجاری یافت نشد.')
|
||||
|
||||
Reference in New Issue
Block a user