init to statistics and manage pos type users
This commit is contained in:
@@ -0,0 +1,15 @@
|
||||
import { TokenAccount } from '@/common/decorators/tokenInfo.decorator'
|
||||
import { Controller, Get } from '@nestjs/common'
|
||||
import { ApiTags } from '@nestjs/swagger'
|
||||
import { SaleInvoicesService } from './saleInvoices.service'
|
||||
|
||||
@ApiTags('ConsumerStatistics')
|
||||
@Controller('consumer/statistics')
|
||||
export class StatisticsController {
|
||||
constructor(private readonly service: SaleInvoicesService) {}
|
||||
|
||||
@Get('invoices')
|
||||
async getInvoices(@TokenAccount('userId') consumerId: string) {
|
||||
return this.service.getInvoices(consumerId)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
import { PrismaModule } from '@/prisma/prisma.module'
|
||||
import { Module } from '@nestjs/common'
|
||||
import { StatisticsController } from './saleInvoices.controller'
|
||||
import { SaleInvoicesService } from './saleInvoices.service'
|
||||
|
||||
@Module({
|
||||
imports: [PrismaModule],
|
||||
controllers: [StatisticsController],
|
||||
providers: [SaleInvoicesService],
|
||||
exports: [SaleInvoicesService],
|
||||
})
|
||||
export class ConsumerSaleInvoicesModule {}
|
||||
@@ -0,0 +1,113 @@
|
||||
import {
|
||||
SalesInvoiceWhereInput,
|
||||
SalesInvoiceWhereUniqueInput,
|
||||
} from '@/generated/prisma/models'
|
||||
import { PrismaService } from '@/prisma/prisma.service'
|
||||
import { Injectable } from '@nestjs/common'
|
||||
import { ResponseMapper } from 'common/response/response-mapper'
|
||||
|
||||
@Injectable()
|
||||
export class SaleInvoicesService {
|
||||
constructor(private readonly prisma: PrismaService) {}
|
||||
|
||||
private readonly defaultSelect = {
|
||||
id: true,
|
||||
code: true,
|
||||
total_amount: true,
|
||||
unknown_customer: true,
|
||||
invoice_date: true,
|
||||
consumer_account: {
|
||||
select: {
|
||||
role: true,
|
||||
account: {
|
||||
select: {
|
||||
username: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
pos: {
|
||||
select: {
|
||||
id: true,
|
||||
name: true,
|
||||
complex: {
|
||||
select: {
|
||||
id: true,
|
||||
name: true,
|
||||
business_activity: {
|
||||
select: {
|
||||
id: true,
|
||||
name: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
|
||||
customer: {
|
||||
select: {
|
||||
id: true,
|
||||
type: true,
|
||||
customer_legal: {
|
||||
select: {
|
||||
company_name: true,
|
||||
},
|
||||
},
|
||||
customer_individual: {
|
||||
select: {
|
||||
first_name: true,
|
||||
last_name: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
async getInvoices(consumer_id: string, page = 1, pageSize = 10) {
|
||||
const invoicesWhere: SalesInvoiceWhereInput = {
|
||||
consumer_account: {
|
||||
consumer_id,
|
||||
},
|
||||
}
|
||||
const [invoices, count] = await this.prisma.$transaction(async tx => [
|
||||
await tx.salesInvoice.findMany({
|
||||
where: invoicesWhere,
|
||||
select: this.defaultSelect,
|
||||
skip: (page - 1) * pageSize,
|
||||
take: pageSize,
|
||||
}),
|
||||
await tx.salesInvoice.count({ where: invoicesWhere }),
|
||||
])
|
||||
return ResponseMapper.paginate(invoices, { page, pageSize, count })
|
||||
}
|
||||
|
||||
async getInvoice(consumer_id: string, id: string) {
|
||||
const invoicesWhere: SalesInvoiceWhereUniqueInput = {
|
||||
id,
|
||||
consumer_account: {
|
||||
consumer_id,
|
||||
},
|
||||
}
|
||||
const invoice = await this.prisma.salesInvoice.findUniqueOrThrow({
|
||||
where: invoicesWhere,
|
||||
select: {
|
||||
...this.defaultSelect,
|
||||
notes: true,
|
||||
created_at: true,
|
||||
items: {
|
||||
select: {
|
||||
id: true,
|
||||
good: {
|
||||
select: {
|
||||
id: true,
|
||||
name: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
})
|
||||
return ResponseMapper.single(invoice)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user