75 lines
1.9 KiB
TypeScript
75 lines
1.9 KiB
TypeScript
import { QUERY_CONSTANTS } from '@/common/queryConstants'
|
|
import { translateEnumValue } from '@/common/utils'
|
|
import { TspProviderResponseStatus } from '@/generated/prisma/enums'
|
|
import { PrismaService } from '@/prisma/prisma.service'
|
|
import { Injectable } from '@nestjs/common'
|
|
import { ResponseMapper } from 'common/response/response-mapper'
|
|
|
|
@Injectable()
|
|
export class StatisticsService {
|
|
constructor(private readonly prisma: PrismaService) {}
|
|
|
|
private readonly invoiceMapper = (invoice: any) => {
|
|
const { last_tsp_status, ...rest } = invoice || {}
|
|
|
|
return {
|
|
...rest,
|
|
status: translateEnumValue(
|
|
'TspProviderResponseStatus',
|
|
last_tsp_status || TspProviderResponseStatus.NOT_SEND,
|
|
),
|
|
}
|
|
}
|
|
|
|
async getInvoices(consumer_id: string) {
|
|
const startOfToday = new Date()
|
|
startOfToday.setHours(0, 0, 0, 0)
|
|
|
|
const invoices = await this.prisma.salesInvoice.findMany({
|
|
where: {
|
|
consumer_account: {
|
|
consumer_id,
|
|
},
|
|
created_at: {
|
|
gte: startOfToday,
|
|
},
|
|
},
|
|
select: {
|
|
...QUERY_CONSTANTS.SALE_INVOICE.summarySelect,
|
|
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,
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
orderBy: {
|
|
created_at: 'desc',
|
|
},
|
|
})
|
|
return ResponseMapper.list(invoices.map(this.invoiceMapper))
|
|
}
|
|
}
|