76 lines
1.8 KiB
TypeScript
76 lines
1.8 KiB
TypeScript
|
|
import { ComplexSelect } from '@/generated/prisma/models'
|
||
|
|
import { PrismaService } from '@/prisma/prisma.service'
|
||
|
|
import { Injectable } from '@nestjs/common'
|
||
|
|
import { ResponseMapper } from 'common/response/response-mapper'
|
||
|
|
import { UpdateComplexDto } from './dto/complex.dto'
|
||
|
|
|
||
|
|
@Injectable()
|
||
|
|
export class BusinessActivityComplexesService {
|
||
|
|
constructor(private readonly prisma: PrismaService) {}
|
||
|
|
|
||
|
|
defaultSelect = {
|
||
|
|
id: true,
|
||
|
|
name: true,
|
||
|
|
address: true,
|
||
|
|
tax_id: true,
|
||
|
|
created_at: true,
|
||
|
|
} as ComplexSelect
|
||
|
|
|
||
|
|
async findAll(user_id: string, business_activity_id: string) {
|
||
|
|
const accounts = await this.prisma.complex.findMany({
|
||
|
|
where: {
|
||
|
|
business_activity: {
|
||
|
|
id: business_activity_id,
|
||
|
|
user: {
|
||
|
|
id: user_id,
|
||
|
|
},
|
||
|
|
},
|
||
|
|
},
|
||
|
|
select: this.defaultSelect,
|
||
|
|
})
|
||
|
|
return ResponseMapper.list(accounts)
|
||
|
|
}
|
||
|
|
|
||
|
|
async findOne(user_id: string, business_activity_id: string, id: string) {
|
||
|
|
const account = await this.prisma.complex.findUnique({
|
||
|
|
where: {
|
||
|
|
business_activity: {
|
||
|
|
id: business_activity_id,
|
||
|
|
user: {
|
||
|
|
id: user_id,
|
||
|
|
},
|
||
|
|
},
|
||
|
|
id,
|
||
|
|
},
|
||
|
|
select: this.defaultSelect,
|
||
|
|
})
|
||
|
|
return ResponseMapper.single(account)
|
||
|
|
}
|
||
|
|
|
||
|
|
async update(
|
||
|
|
user_id: string,
|
||
|
|
business_activity_id: string,
|
||
|
|
id: string,
|
||
|
|
data: UpdateComplexDto,
|
||
|
|
) {
|
||
|
|
const account = await this.prisma.complex.update({
|
||
|
|
where: {
|
||
|
|
business_activity: {
|
||
|
|
id: business_activity_id,
|
||
|
|
user: {
|
||
|
|
id: user_id,
|
||
|
|
},
|
||
|
|
},
|
||
|
|
id,
|
||
|
|
},
|
||
|
|
data,
|
||
|
|
})
|
||
|
|
return ResponseMapper.update(account)
|
||
|
|
}
|
||
|
|
|
||
|
|
// async delete(id: string) {
|
||
|
|
// await this.prisma.complex.delete({ where: { id } })
|
||
|
|
// return ResponseMapper.delete()
|
||
|
|
// }
|
||
|
|
}
|