debugging and add image uploader to guild good
This commit is contained in:
@@ -7,6 +7,7 @@ import { ConsumerMiddleware } from './consumer.middleware'
|
||||
import { ConsumerService } from './consumer.service'
|
||||
import { ConsumerCustomersModule } from './customers/customers.module'
|
||||
import { ConsumerPosesModule } from './poses/poses.module'
|
||||
import { ConsumerSaleInvoicesModule } from './saleInvoices/saleInvoices.module'
|
||||
import { ConsumerStatisticsModule } from './statistics/statistics.module'
|
||||
|
||||
@Module({
|
||||
@@ -17,6 +18,7 @@ import { ConsumerStatisticsModule } from './statistics/statistics.module'
|
||||
ConsumerCustomersModule,
|
||||
ConsumerStatisticsModule,
|
||||
ConsumerPosesModule,
|
||||
ConsumerSaleInvoicesModule,
|
||||
],
|
||||
providers: [JwtService, ConsumerService],
|
||||
})
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { ResponseMapper } from '@/common/response/response-mapper'
|
||||
import { PrismaService } from '@/prisma/prisma.service'
|
||||
import { Injectable } from '@nestjs/common'
|
||||
import mapConsumerWithLicenseUtil from './utils/mapConsumerWithLicense.util'
|
||||
|
||||
@Injectable()
|
||||
export class ConsumerService {
|
||||
@@ -41,26 +42,6 @@ export class ConsumerService {
|
||||
},
|
||||
})
|
||||
|
||||
const { activated_licenses, ...rest } = consumer
|
||||
|
||||
const mappedData = {
|
||||
...rest,
|
||||
activated_licenses: activated_licenses.map(activatedLicense => {
|
||||
const { license, ...rest } = activatedLicense
|
||||
return {
|
||||
...rest,
|
||||
license: {
|
||||
id: license.id,
|
||||
partner: license.charged_license_transaction.partner,
|
||||
},
|
||||
}
|
||||
}),
|
||||
}
|
||||
|
||||
return ResponseMapper.single({
|
||||
...consumer,
|
||||
full_name: `${consumer?.first_name} ${consumer?.last_name}`,
|
||||
activated_licenses: mappedData,
|
||||
})
|
||||
return ResponseMapper.single(mapConsumerWithLicenseUtil(consumer))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,15 +1,20 @@
|
||||
import { TokenAccount } from '@/common/decorators/tokenInfo.decorator'
|
||||
import { Controller, Get } from '@nestjs/common'
|
||||
import { Controller, Get, Param } from '@nestjs/common'
|
||||
import { ApiTags } from '@nestjs/swagger'
|
||||
import { SaleInvoicesService } from './saleInvoices.service'
|
||||
|
||||
@ApiTags('ConsumerStatistics')
|
||||
@Controller('consumer/statistics')
|
||||
@ApiTags('ConsumerSaleInvoices')
|
||||
@Controller('consumer/sale-invoices')
|
||||
export class StatisticsController {
|
||||
constructor(private readonly service: SaleInvoicesService) {}
|
||||
|
||||
@Get('invoices')
|
||||
async getInvoices(@TokenAccount('userId') consumerId: string) {
|
||||
return this.service.getInvoices(consumerId)
|
||||
@Get('')
|
||||
async findAll(@TokenAccount('userId') consumerId: string) {
|
||||
return this.service.findAll(consumerId)
|
||||
}
|
||||
|
||||
@Get(':id')
|
||||
async findOne(@TokenAccount('userId') consumerId: string, @Param('id') id: string) {
|
||||
return this.service.findOne(consumerId, id)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -64,7 +64,7 @@ export class SaleInvoicesService {
|
||||
},
|
||||
}
|
||||
|
||||
async getInvoices(consumer_id: string, page = 1, pageSize = 10) {
|
||||
async findAll(consumer_id: string, page = 1, pageSize = 10) {
|
||||
const invoicesWhere: SalesInvoiceWhereInput = {
|
||||
consumer_account: {
|
||||
consumer_id,
|
||||
@@ -82,7 +82,7 @@ export class SaleInvoicesService {
|
||||
return ResponseMapper.paginate(invoices, { page, pageSize, count })
|
||||
}
|
||||
|
||||
async getInvoice(consumer_id: string, id: string) {
|
||||
async findOne(consumer_id: string, id: string) {
|
||||
const invoicesWhere: SalesInvoiceWhereUniqueInput = {
|
||||
id,
|
||||
consumer_account: {
|
||||
@@ -95,6 +95,12 @@ export class SaleInvoicesService {
|
||||
...this.defaultSelect,
|
||||
notes: true,
|
||||
created_at: true,
|
||||
payments: {
|
||||
select: {
|
||||
amount: true,
|
||||
payment_method: true,
|
||||
},
|
||||
},
|
||||
items: {
|
||||
select: {
|
||||
id: true,
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
export * from './mapConsumerWithLicense.util'
|
||||
@@ -0,0 +1,35 @@
|
||||
export default (consumer: any) => {
|
||||
const { activated_licenses, ...rest } = consumer
|
||||
|
||||
let lastLicense: any = null
|
||||
|
||||
if (consumer.activated_licenses.length) {
|
||||
lastLicense = consumer.activated_licenses[0]
|
||||
if (consumer.activated_licenses.length > 1) {
|
||||
const activeLicenseInfo = consumer.activated_licenses.find(
|
||||
activated_license => activated_license.expires_at,
|
||||
)
|
||||
|
||||
if (!activeLicenseInfo) {
|
||||
consumer.activated_licenses.sort((a, b) => (a.expires_at > b.expires_at ? 1 : -1))
|
||||
lastLicense = consumer.activated_licenses[0]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
...rest,
|
||||
fullname: `${rest?.first_name} ${rest?.last_name}`,
|
||||
license_info: prepareLicenseInfo(lastLicense),
|
||||
}
|
||||
}
|
||||
|
||||
function prepareLicenseInfo(latestLicense: any) {
|
||||
if (!latestLicense) return null
|
||||
const { license, ...rest } = latestLicense
|
||||
|
||||
return {
|
||||
...rest,
|
||||
partner: license.charged_license_transaction.partner,
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user