117 lines
2.6 KiB
TypeScript
117 lines
2.6 KiB
TypeScript
import { PrismaService } from '@/prisma/prisma.service'
|
|
import { Injectable } from '@nestjs/common'
|
|
import { ResponseMapper } from 'common/response/response-mapper'
|
|
import { CreateAccountDto } from './dto/permission.dto'
|
|
|
|
@Injectable()
|
|
export class AccountsService {
|
|
constructor(private readonly prisma: PrismaService) {}
|
|
|
|
async findAll(userId: string, account_id: string) {
|
|
const businessActivities = await this.prisma.businessActivity.findMany({
|
|
where: {
|
|
user_id: userId,
|
|
},
|
|
select: {
|
|
id: true,
|
|
name: true,
|
|
complexes: {
|
|
select: {
|
|
id: true,
|
|
name: true,
|
|
pos_list: {
|
|
select: {
|
|
id: true,
|
|
name: true,
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
})
|
|
|
|
const permissions = await this.prisma.permissionConsumer.findMany({
|
|
where: {
|
|
account_id,
|
|
},
|
|
select: {
|
|
posPermissions: {
|
|
select: {
|
|
pos_id: true,
|
|
role: true,
|
|
},
|
|
},
|
|
businessPermissions: {
|
|
select: {
|
|
business_id: true,
|
|
role: true,
|
|
},
|
|
},
|
|
complexPermissions: {
|
|
select: {
|
|
complex_id: true,
|
|
role: true,
|
|
},
|
|
},
|
|
},
|
|
})
|
|
|
|
const businesses = [] as any
|
|
const complexes = [] as any
|
|
const poses = [] as any
|
|
|
|
businessActivities.forEach(businessActivity => {
|
|
businesses.push({
|
|
id: businessActivity.id,
|
|
name: businessActivity.name,
|
|
hasAccess: false,
|
|
role: null,
|
|
})
|
|
|
|
businessActivity.complexes.forEach(complex => {
|
|
complexes.push({
|
|
id: complex.id,
|
|
name: complex.name,
|
|
hasAccess: false,
|
|
role: null,
|
|
})
|
|
|
|
complex.pos_list.forEach(pos => {
|
|
poses.push({
|
|
id: pos.id,
|
|
name: pos.name,
|
|
hasAccess: false,
|
|
role: null,
|
|
})
|
|
})
|
|
})
|
|
})
|
|
|
|
permissions.forEach(permission => {
|
|
permission.posPermissions.forEach(posPermission => {
|
|
poses.map(pos => {
|
|
if (pos.id === posPermission.pos_id) {
|
|
return {
|
|
...pos,
|
|
role: posPermission.role,
|
|
hasAccess: true,
|
|
}
|
|
}
|
|
return pos
|
|
})
|
|
})
|
|
})
|
|
}
|
|
|
|
async findOne(id: string) {
|
|
const account = await this.prisma.account.findUnique({
|
|
where: { id },
|
|
})
|
|
return ResponseMapper.single(account)
|
|
}
|
|
|
|
async create(userId: string, data: CreateAccountDto) {
|
|
return ResponseMapper.create({})
|
|
}
|
|
}
|