feat: enhance sales invoice functionality with inquiry, send, retry, and revoke actions
This commit is contained in:
@@ -0,0 +1,29 @@
|
||||
import { PrismaService } from '@/prisma/prisma.service'
|
||||
import { BadRequestException, Injectable } from '@nestjs/common'
|
||||
import { ConsumerRole } from 'generated/prisma/enums'
|
||||
|
||||
@Injectable()
|
||||
export class SharedSaleInvoiceAccessService {
|
||||
constructor(private readonly prisma: PrismaService) {}
|
||||
|
||||
async getConsumerIdWithPosAccess(
|
||||
consumerAccountId: string,
|
||||
posId: string,
|
||||
): Promise<string> {
|
||||
const consumer = await this.prisma.consumerAccount.findUnique({
|
||||
where: {
|
||||
id: consumerAccountId,
|
||||
OR: [{ pos: { id: posId } }, { role: ConsumerRole.OWNER }],
|
||||
},
|
||||
select: {
|
||||
consumer_id: true,
|
||||
},
|
||||
})
|
||||
|
||||
if (!consumer) {
|
||||
throw new BadRequestException('شما دسترسی لازم برای ارسال فاکتور را ندارید.')
|
||||
}
|
||||
|
||||
return consumer.consumer_id
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
import { SharedSaleInvoiceAccessService } from '@/common/services/saleInvoices/sale-invoice-access.service'
|
||||
import { Injectable } from '@nestjs/common'
|
||||
import { SalesInvoiceTspService } from '@/modules/tspProviders/sales-invoice-tsp.service'
|
||||
|
||||
@Injectable()
|
||||
export class SharedSaleInvoiceActionsService {
|
||||
constructor(
|
||||
private readonly salesInvoiceTspService: SalesInvoiceTspService,
|
||||
private readonly saleInvoiceAccessService: SharedSaleInvoiceAccessService,
|
||||
) {}
|
||||
|
||||
async send(consumerAccountId: string, posId: string, invoiceId: string) {
|
||||
await this.saleInvoiceAccessService.getConsumerIdWithPosAccess(
|
||||
consumerAccountId,
|
||||
posId,
|
||||
)
|
||||
return this.salesInvoiceTspService.originalSend(posId, invoiceId)
|
||||
}
|
||||
|
||||
async retry(consumerAccountId: string, posId: string, invoiceId: string) {
|
||||
await this.saleInvoiceAccessService.getConsumerIdWithPosAccess(
|
||||
consumerAccountId,
|
||||
posId,
|
||||
)
|
||||
return this.salesInvoiceTspService.originalSend(posId, invoiceId)
|
||||
}
|
||||
|
||||
async revoke(
|
||||
consumerAccountId: string,
|
||||
posId: string,
|
||||
complexId: string,
|
||||
businessId: string,
|
||||
invoiceId: string,
|
||||
) {
|
||||
await this.saleInvoiceAccessService.getConsumerIdWithPosAccess(
|
||||
consumerAccountId,
|
||||
posId,
|
||||
)
|
||||
return this.salesInvoiceTspService.revoke(
|
||||
consumerAccountId,
|
||||
posId,
|
||||
complexId,
|
||||
businessId,
|
||||
invoiceId,
|
||||
)
|
||||
}
|
||||
|
||||
async inquiry(consumerAccountId: string, posId: string, invoiceId: string) {
|
||||
const consumerId = await this.saleInvoiceAccessService.getConsumerIdWithPosAccess(
|
||||
consumerAccountId,
|
||||
posId,
|
||||
)
|
||||
return this.salesInvoiceTspService.get(invoiceId, posId, consumerId)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user