2026-03-14 16:26:44 +03:30
|
|
|
import { ComplexSelect } 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 BusinessActivityComplexesService {
|
|
|
|
|
constructor(private readonly prisma: PrismaService) {}
|
|
|
|
|
|
|
|
|
|
defaultSelect = {
|
|
|
|
|
id: true,
|
|
|
|
|
name: true,
|
|
|
|
|
address: true,
|
|
|
|
|
tax_id: true,
|
|
|
|
|
created_at: true,
|
|
|
|
|
} as ComplexSelect
|
|
|
|
|
|
2026-04-11 14:47:05 +03:30
|
|
|
async findAll(consumer_id: string, business_activity_id: string) {
|
2026-03-14 16:26:44 +03:30
|
|
|
const accounts = await this.prisma.complex.findMany({
|
|
|
|
|
where: {
|
|
|
|
|
business_activity: {
|
|
|
|
|
id: business_activity_id,
|
2026-04-11 14:47:05 +03:30
|
|
|
consumer: {
|
|
|
|
|
id: consumer_id,
|
2026-03-14 16:26:44 +03:30
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
select: this.defaultSelect,
|
|
|
|
|
})
|
|
|
|
|
return ResponseMapper.list(accounts)
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-11 14:47:05 +03:30
|
|
|
async findOne(consumer_id: string, business_activity_id: string, id: string) {
|
2026-03-14 16:26:44 +03:30
|
|
|
const account = await this.prisma.complex.findUnique({
|
|
|
|
|
where: {
|
|
|
|
|
business_activity: {
|
|
|
|
|
id: business_activity_id,
|
2026-04-11 14:47:05 +03:30
|
|
|
consumer: {
|
|
|
|
|
id: consumer_id,
|
2026-03-14 16:26:44 +03:30
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
id,
|
|
|
|
|
},
|
|
|
|
|
select: this.defaultSelect,
|
|
|
|
|
})
|
|
|
|
|
return ResponseMapper.single(account)
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-23 20:59:39 +03:30
|
|
|
// async create(business_id: string, data: CreateComplexDto) {
|
|
|
|
|
// const account = await this.prisma.complex.create({
|
|
|
|
|
// data: {
|
|
|
|
|
// ...data,
|
|
|
|
|
// business_activity: {
|
|
|
|
|
// connect: {
|
|
|
|
|
// id: business_id,
|
|
|
|
|
// },
|
|
|
|
|
// },
|
|
|
|
|
// },
|
|
|
|
|
// })
|
|
|
|
|
// return ResponseMapper.create(account)
|
|
|
|
|
// }
|
2026-03-14 16:26:44 +03:30
|
|
|
|
2026-04-23 20:59:39 +03:30
|
|
|
// async update(
|
|
|
|
|
// consumer_id: string,
|
|
|
|
|
// business_activity_id: string,
|
|
|
|
|
// id: string,
|
|
|
|
|
// data: UpdateComplexDto,
|
|
|
|
|
// ) {
|
|
|
|
|
// const account = await this.prisma.complex.update({
|
|
|
|
|
// where: {
|
|
|
|
|
// business_activity: {
|
|
|
|
|
// id: business_activity_id,
|
|
|
|
|
// consumer: {
|
|
|
|
|
// id: consumer_id,
|
|
|
|
|
// },
|
|
|
|
|
// },
|
|
|
|
|
// id,
|
|
|
|
|
// },
|
|
|
|
|
// data,
|
|
|
|
|
// })
|
|
|
|
|
// return ResponseMapper.update(account)
|
|
|
|
|
// }
|
2026-03-14 16:26:44 +03:30
|
|
|
|
|
|
|
|
// async delete(id: string) {
|
|
|
|
|
// await this.prisma.complex.delete({ where: { id } })
|
|
|
|
|
// return ResponseMapper.delete()
|
|
|
|
|
// }
|
|
|
|
|
}
|