feat: implement correction and original send functionality for Nama provider
- Added new DTOs for correction requests and responses in `nama-provider.dto.ts`. - Updated `nama-provider.adapter.ts` to include `originalSend` and `correctionSend` methods. - Enhanced `nama-provider.util.ts` with mapping functions for correction requests. - Created operational guidelines for agents in `AGENT.md`. - Updated Prisma migrations to support new invoice types and relationships. - Introduced new service and DTO for creating sales invoices in `sale-invoice-create.service.ts` and `sale-invoice-create.dto.ts`. - Added utility for handling Prisma errors in `prisma-error.util.ts`.
This commit is contained in:
@@ -42,18 +42,30 @@ export class BusinessActivityComplexesService {
|
||||
},
|
||||
})
|
||||
|
||||
async findAll(partner_id: string, consumer_id: string, business_activity_id: string) {
|
||||
const complexes = await this.prisma.complex.findMany({
|
||||
where: this.defaultWhere(partner_id, consumer_id, business_activity_id),
|
||||
select: {
|
||||
...this.defaultSelect,
|
||||
_count: {
|
||||
select: {
|
||||
pos_list: true,
|
||||
async findAll(
|
||||
partner_id: string,
|
||||
consumer_id: string,
|
||||
business_activity_id: string,
|
||||
page = 1,
|
||||
perPage = 10,
|
||||
) {
|
||||
const where = this.defaultWhere(partner_id, consumer_id, business_activity_id)
|
||||
const [complexes, total] = await this.prisma.$transaction(async tx => [
|
||||
await tx.complex.findMany({
|
||||
where,
|
||||
select: {
|
||||
...this.defaultSelect,
|
||||
_count: {
|
||||
select: {
|
||||
pos_list: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
})
|
||||
skip: (page - 1) * perPage,
|
||||
take: perPage,
|
||||
}),
|
||||
await tx.complex.count({ where }),
|
||||
])
|
||||
|
||||
const mappedComplexes = complexes.map(complex => {
|
||||
const { _count, ...rest } = complex
|
||||
@@ -62,7 +74,7 @@ export class BusinessActivityComplexesService {
|
||||
pos_count: _count.pos_list,
|
||||
}
|
||||
})
|
||||
return ResponseMapper.list(mappedComplexes)
|
||||
return ResponseMapper.paginate(mappedComplexes, { total, page, perPage })
|
||||
}
|
||||
|
||||
async findOne(
|
||||
|
||||
+114
-90
@@ -1,5 +1,6 @@
|
||||
import { QUERY_CONSTANTS } from '@/common/queryConstants'
|
||||
import { consumerRelatedPartner } from '@/common/queryConstants/consumer'
|
||||
import { PrismaErrorUtil } from '@/common/utils/prisma-error.util'
|
||||
import { PasswordUtil } from '@/common/utils/password.util'
|
||||
import {
|
||||
AccountStatus,
|
||||
@@ -97,17 +98,32 @@ export class ComplexPosesService {
|
||||
}
|
||||
}
|
||||
|
||||
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),
|
||||
},
|
||||
select: this.defaultSelect,
|
||||
})
|
||||
async findAll(
|
||||
partner_id: string,
|
||||
business_activity_id: string,
|
||||
complex_id: string,
|
||||
page = 1,
|
||||
perPage = 10,
|
||||
) {
|
||||
const [poses, total] = await this.prisma.$transaction(async tx => [
|
||||
await tx.pos.findMany({
|
||||
where: {
|
||||
...this.defaultWhere(partner_id, complex_id, business_activity_id),
|
||||
},
|
||||
select: this.defaultSelect,
|
||||
skip: (page - 1) * perPage,
|
||||
take: perPage,
|
||||
}),
|
||||
await tx.pos.count({
|
||||
where: {
|
||||
...this.defaultWhere(partner_id, complex_id, business_activity_id),
|
||||
},
|
||||
}),
|
||||
])
|
||||
|
||||
const mappedPoses = poses.map(this.mapPos)
|
||||
|
||||
return ResponseMapper.list(mappedPoses)
|
||||
return ResponseMapper.paginate(mappedPoses, { total, page, perPage })
|
||||
}
|
||||
|
||||
async findOne(
|
||||
@@ -129,94 +145,102 @@ export class ComplexPosesService {
|
||||
complex_id: string,
|
||||
data: CreatePosDto,
|
||||
) {
|
||||
const pos = this.prisma.$transaction(async tx => {
|
||||
const activeAccountAllocation = await tx.licenseAccountAllocation.findFirst({
|
||||
where: {
|
||||
account_id: null,
|
||||
license_activation: {
|
||||
business_activity_id,
|
||||
...QUERY_CONSTANTS.LICENSE_ACTIVATION.activeOnDate(),
|
||||
license: {
|
||||
charge_transaction: {
|
||||
partner_id,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
select: {
|
||||
id: true,
|
||||
license_activation: {
|
||||
select: {
|
||||
business_activity: {
|
||||
select: {
|
||||
consumer_id: true,
|
||||
let pos
|
||||
try {
|
||||
pos = await this.prisma.$transaction(async tx => {
|
||||
const activeAccountAllocation = await tx.licenseAccountAllocation.findFirst({
|
||||
where: {
|
||||
account_id: null,
|
||||
license_activation: {
|
||||
business_activity_id,
|
||||
...QUERY_CONSTANTS.LICENSE_ACTIVATION.activeOnDate(),
|
||||
license: {
|
||||
charge_transaction: {
|
||||
partner_id,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
select: {
|
||||
id: true,
|
||||
license_activation: {
|
||||
select: {
|
||||
business_activity: {
|
||||
select: {
|
||||
consumer_id: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
if (!activeAccountAllocation) {
|
||||
throw new BadRequestException(
|
||||
`محدودیت تعریف تعداد کاربران این فعالیت تجاری به پایان رسیده است.`,
|
||||
)
|
||||
}
|
||||
|
||||
const { device_id, provider_id, username, password, ...rest } = data
|
||||
|
||||
return await tx.pos.create({
|
||||
data: {
|
||||
...rest,
|
||||
status: POSStatus.ACTIVE,
|
||||
|
||||
account: {
|
||||
create: {
|
||||
role: ConsumerRole.OPERATOR,
|
||||
|
||||
consumer: {
|
||||
connect: {
|
||||
id: activeAccountAllocation.license_activation!.business_activity
|
||||
.consumer_id,
|
||||
},
|
||||
},
|
||||
account_allocation: {
|
||||
connect: {
|
||||
id: activeAccountAllocation.id,
|
||||
},
|
||||
},
|
||||
account: {
|
||||
create: {
|
||||
username,
|
||||
password: await PasswordUtil.hash(password),
|
||||
type: AccountType.CONSUMER,
|
||||
status: AccountStatus.ACTIVE,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
complex: {
|
||||
connect: {
|
||||
id: complex_id,
|
||||
},
|
||||
},
|
||||
device: device_id
|
||||
? {
|
||||
connect: {
|
||||
id: device_id,
|
||||
},
|
||||
}
|
||||
: undefined,
|
||||
provider: provider_id
|
||||
? {
|
||||
connect: {
|
||||
id: provider_id,
|
||||
},
|
||||
}
|
||||
: undefined,
|
||||
},
|
||||
})
|
||||
})
|
||||
|
||||
if (!activeAccountAllocation) {
|
||||
throw new BadRequestException(
|
||||
`محدودیت تعریف تعداد کاربران این فعالیت تجاری به پایان رسیده است.`,
|
||||
)
|
||||
}
|
||||
|
||||
const { device_id, provider_id, username, password, ...rest } = data
|
||||
|
||||
return await tx.pos.create({
|
||||
data: {
|
||||
...rest,
|
||||
status: POSStatus.ACTIVE,
|
||||
|
||||
account: {
|
||||
create: {
|
||||
role: ConsumerRole.OPERATOR,
|
||||
|
||||
consumer: {
|
||||
connect: {
|
||||
id: activeAccountAllocation.license_activation!.business_activity
|
||||
.consumer_id,
|
||||
},
|
||||
},
|
||||
account_allocation: {
|
||||
connect: {
|
||||
id: activeAccountAllocation.id,
|
||||
},
|
||||
},
|
||||
account: {
|
||||
create: {
|
||||
username,
|
||||
password: await PasswordUtil.hash(password),
|
||||
type: AccountType.CONSUMER,
|
||||
status: AccountStatus.ACTIVE,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
complex: {
|
||||
connect: {
|
||||
id: complex_id,
|
||||
},
|
||||
},
|
||||
device: device_id
|
||||
? {
|
||||
connect: {
|
||||
id: device_id,
|
||||
},
|
||||
}
|
||||
: undefined,
|
||||
provider: provider_id
|
||||
? {
|
||||
connect: {
|
||||
id: provider_id,
|
||||
},
|
||||
}
|
||||
: undefined,
|
||||
},
|
||||
} catch (error) {
|
||||
PrismaErrorUtil.throwIfKnown(error, {
|
||||
username: 'نام کاربری تکراری است',
|
||||
accounts_username_key: 'نام کاربری تکراری است',
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
return ResponseMapper.create(pos)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user