188 lines
4.5 KiB
TypeScript
188 lines
4.5 KiB
TypeScript
import { QUERY_CONSTANTS } from '@/common/queryConstants'
|
|
import consumer_mappersUtil from '@/common/utils/mappers/consumer_mappers.util'
|
|
import { ConsumerStatus } 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 PosService {
|
|
constructor(private readonly prisma: PrismaService) {}
|
|
|
|
async getInfo(pos_id: string) {
|
|
console.log('pos_id', pos_id)
|
|
|
|
const pos = await this.prisma.pos.findUniqueOrThrow({
|
|
where: {
|
|
id: pos_id,
|
|
},
|
|
select: {
|
|
name: true,
|
|
complex: {
|
|
select: {
|
|
id: true,
|
|
name: true,
|
|
branch_code: true,
|
|
business_activity: {
|
|
select: {
|
|
id: true,
|
|
name: true,
|
|
economic_code: true,
|
|
license_activation: {
|
|
select: {
|
|
expires_at: true,
|
|
license: {
|
|
select: {
|
|
id: true,
|
|
charge_transaction: {
|
|
select: {
|
|
partner: {
|
|
select: {
|
|
id: true,
|
|
name: true,
|
|
code: true,
|
|
logo_url: true,
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
guild: {
|
|
select: {
|
|
id: true,
|
|
name: true,
|
|
code: true,
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
})
|
|
const { name, complex } = pos
|
|
const { name: complexName, id: complexId, business_activity } = complex
|
|
const {
|
|
name: businessName,
|
|
id: businessId,
|
|
guild,
|
|
economic_code,
|
|
license_activation,
|
|
} = business_activity
|
|
|
|
return ResponseMapper.single({
|
|
name,
|
|
complex: {
|
|
id: complexId,
|
|
name: complexName,
|
|
branch_code: complex.branch_code,
|
|
},
|
|
businessActivity: {
|
|
id: businessId,
|
|
name: businessName,
|
|
economic_code,
|
|
},
|
|
guild,
|
|
license_info: {
|
|
expires_at: license_activation?.expires_at,
|
|
license_id: license_activation?.license.id,
|
|
},
|
|
partner: license_activation?.license.charge_transaction.partner,
|
|
})
|
|
}
|
|
|
|
async getAccessible(account_id: string) {
|
|
const poses = await this.prisma.pos.findMany({
|
|
where: {
|
|
complex: {
|
|
business_activity: {
|
|
consumer: {
|
|
accounts: {
|
|
some: {
|
|
id: account_id,
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
permission_pos: {
|
|
some: {
|
|
permission: {
|
|
consumer_account_id: account_id,
|
|
},
|
|
},
|
|
},
|
|
},
|
|
select: {
|
|
id: true,
|
|
name: true,
|
|
complex: {
|
|
select: {
|
|
id: true,
|
|
name: true,
|
|
business_activity: {
|
|
select: {
|
|
id: true,
|
|
name: true,
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
})
|
|
|
|
return ResponseMapper.list(poses)
|
|
}
|
|
|
|
async getMe(account_id: string, pos_id: string) {
|
|
const pos = await this.prisma.consumerAccount.findUniqueOrThrow({
|
|
where: {
|
|
id: account_id,
|
|
consumer: {
|
|
status: ConsumerStatus.ACTIVE,
|
|
business_activities: {
|
|
some: {
|
|
complexes: {
|
|
some: {
|
|
pos_list: {
|
|
some: {
|
|
id: pos_id,
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
select: {
|
|
id: true,
|
|
role: true,
|
|
consumer: {
|
|
select: {
|
|
id: true,
|
|
type: true,
|
|
status: true,
|
|
...QUERY_CONSTANTS.CONSUMER.infoSelect,
|
|
},
|
|
},
|
|
account: {
|
|
select: {
|
|
username: true,
|
|
},
|
|
},
|
|
},
|
|
})
|
|
|
|
const { consumer, ...rest } = pos
|
|
|
|
return ResponseMapper.single({
|
|
...rest,
|
|
consumer: consumer_mappersUtil(consumer),
|
|
})
|
|
}
|
|
}
|