feat: enhance sales invoice functionality with inquiry, send, retry, and revoke actions
This commit is contained in:
+40
-1
@@ -1,4 +1,4 @@
|
||||
import { Controller, Get, Param } from '@nestjs/common'
|
||||
import { Controller, Get, Param, Post } from '@nestjs/common'
|
||||
|
||||
import { TokenAccount } from '@/common/decorators/tokenInfo.decorator'
|
||||
import { ApiTags } from '@nestjs/swagger'
|
||||
@@ -26,4 +26,43 @@ export class SalesInvoicesController {
|
||||
) {
|
||||
return this.salesInvoicesService.findOne(complexId, posId, id)
|
||||
}
|
||||
|
||||
@Get(':id/inquiry')
|
||||
inquiry(
|
||||
@TokenAccount('userId') userId: string,
|
||||
@Param('posId') posId: string,
|
||||
@Param('id') id: string,
|
||||
) {
|
||||
return this.salesInvoicesService.inquiry(userId, posId, id)
|
||||
}
|
||||
|
||||
@Post(':id/send')
|
||||
send(
|
||||
@TokenAccount('userId') userId: string,
|
||||
@Param('complexId') complexId: string,
|
||||
@Param('posId') posId: string,
|
||||
@Param('id') id: string,
|
||||
) {
|
||||
return this.salesInvoicesService.send(userId, complexId, posId, id)
|
||||
}
|
||||
|
||||
@Post(':id/retry')
|
||||
retry(
|
||||
@TokenAccount('userId') userId: string,
|
||||
@Param('complexId') complexId: string,
|
||||
@Param('posId') posId: string,
|
||||
@Param('id') id: string,
|
||||
) {
|
||||
return this.salesInvoicesService.retry(userId, complexId, posId, id)
|
||||
}
|
||||
|
||||
@Post(':id/revoke')
|
||||
revoke(
|
||||
@TokenAccount('userId') userId: string,
|
||||
@Param('complexId') complexId: string,
|
||||
@Param('posId') posId: string,
|
||||
@Param('id') id: string,
|
||||
) {
|
||||
return this.salesInvoicesService.revoke(userId, complexId, posId, id)
|
||||
}
|
||||
}
|
||||
|
||||
+9
-1
@@ -1,9 +1,17 @@
|
||||
import { SharedSaleInvoiceActionsService } from '@/common/services/saleInvoices/sale-invoice-actions.service'
|
||||
import { SharedSaleInvoiceAccessService } from '@/common/services/saleInvoices/sale-invoice-access.service'
|
||||
import { SaleInvoiceTspModule } from '@/modules/tspProviders/sales-invoice-tsp.module'
|
||||
import { Module } from '@nestjs/common'
|
||||
import { SalesInvoicesController } from './sales-invoices.controller'
|
||||
import { SalesInvoicesService } from './sales-invoices.service'
|
||||
|
||||
@Module({
|
||||
imports: [SaleInvoiceTspModule],
|
||||
controllers: [SalesInvoicesController],
|
||||
providers: [SalesInvoicesService],
|
||||
providers: [
|
||||
SalesInvoicesService,
|
||||
SharedSaleInvoiceActionsService,
|
||||
SharedSaleInvoiceAccessService,
|
||||
],
|
||||
})
|
||||
export class ConsumerPosSalesInvoicesModule {}
|
||||
|
||||
+77
-2
@@ -1,11 +1,15 @@
|
||||
import { SharedSaleInvoiceActionsService } from '@/common/services/saleInvoices/sale-invoice-actions.service'
|
||||
import { ResponseMapper } from '@/common/response/response-mapper'
|
||||
import { SalesInvoiceWhereInput } from '@/generated/prisma/models'
|
||||
import { PrismaService } from '@/prisma/prisma.service'
|
||||
import { Injectable } from '@nestjs/common'
|
||||
import { Injectable, NotFoundException } from '@nestjs/common'
|
||||
|
||||
@Injectable()
|
||||
export class SalesInvoicesService {
|
||||
constructor(private prisma: PrismaService) {}
|
||||
constructor(
|
||||
private prisma: PrismaService,
|
||||
private readonly sharedSaleInvoiceActionsService: SharedSaleInvoiceActionsService,
|
||||
) {}
|
||||
|
||||
async findAll(consumer_id: string, complex_id: string, pos_id: string) {
|
||||
const defaultWhere: SalesInvoiceWhereInput = {
|
||||
@@ -117,4 +121,75 @@ export class SalesInvoicesService {
|
||||
// TODO: Implement fetching a single sales invoice
|
||||
return {}
|
||||
}
|
||||
|
||||
async send(
|
||||
consumerAccountId: string,
|
||||
complexId: string,
|
||||
posId: string,
|
||||
invoiceId: string,
|
||||
) {
|
||||
const invoice = await this.sharedSaleInvoiceActionsService.send(
|
||||
consumerAccountId,
|
||||
posId,
|
||||
invoiceId,
|
||||
)
|
||||
return ResponseMapper.single(invoice)
|
||||
}
|
||||
|
||||
async retry(
|
||||
consumerAccountId: string,
|
||||
complexId: string,
|
||||
posId: string,
|
||||
invoiceId: string,
|
||||
) {
|
||||
const invoice = await this.sharedSaleInvoiceActionsService.retry(
|
||||
consumerAccountId,
|
||||
posId,
|
||||
invoiceId,
|
||||
)
|
||||
return ResponseMapper.single(invoice)
|
||||
}
|
||||
|
||||
async revoke(
|
||||
consumerAccountId: string,
|
||||
complexId: string,
|
||||
posId: string,
|
||||
invoiceId: string,
|
||||
) {
|
||||
const pos = await this.prisma.pos.findUnique({
|
||||
where: {
|
||||
id: posId,
|
||||
complex: {
|
||||
id: complexId,
|
||||
},
|
||||
},
|
||||
select: {
|
||||
complex: {
|
||||
select: {
|
||||
business_activity_id: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
if (!pos) throw new NotFoundException('پایانه فروش مورد نظر یافت نشد.')
|
||||
|
||||
const invoice = await this.sharedSaleInvoiceActionsService.revoke(
|
||||
consumerAccountId,
|
||||
posId,
|
||||
complexId,
|
||||
pos.complex.business_activity_id,
|
||||
invoiceId,
|
||||
)
|
||||
return ResponseMapper.single(invoice)
|
||||
}
|
||||
|
||||
async inquiry(consumerAccountId: string, posId: string, invoiceId: string) {
|
||||
const invoice = await this.sharedSaleInvoiceActionsService.inquiry(
|
||||
consumerAccountId,
|
||||
posId,
|
||||
invoiceId,
|
||||
)
|
||||
return ResponseMapper.single(invoice)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user