67 lines
1.6 KiB
TypeScript
67 lines
1.6 KiB
TypeScript
|
|
import { ResponseMapper } from '@/common/response/response-mapper'
|
||
|
|
import { PrismaService } from '@/prisma/prisma.service'
|
||
|
|
import { Injectable } from '@nestjs/common'
|
||
|
|
import { CreateGuildDto } from './dto/create-guild.dto'
|
||
|
|
import { UpdateGuildDto } from './dto/update-guild.dto'
|
||
|
|
|
||
|
|
@Injectable()
|
||
|
|
export class GuildsService {
|
||
|
|
constructor(private prisma: PrismaService) {}
|
||
|
|
|
||
|
|
async findAll() {
|
||
|
|
const [guilds, count] = await this.prisma.$transaction([
|
||
|
|
this.prisma.guild.findMany({
|
||
|
|
include: {
|
||
|
|
_count: {
|
||
|
|
select: {
|
||
|
|
business_activities: true,
|
||
|
|
},
|
||
|
|
},
|
||
|
|
},
|
||
|
|
}),
|
||
|
|
this.prisma.guild.count(),
|
||
|
|
])
|
||
|
|
|
||
|
|
return ResponseMapper.paginate(
|
||
|
|
guilds.map(guild => {
|
||
|
|
const { _count, ...rest } = guild
|
||
|
|
return {
|
||
|
|
...rest,
|
||
|
|
businessActivitiesCount: guild._count.business_activities,
|
||
|
|
}
|
||
|
|
}),
|
||
|
|
{ count },
|
||
|
|
)
|
||
|
|
}
|
||
|
|
|
||
|
|
async findOne(id: string) {
|
||
|
|
const guild = await this.prisma.guild.findUnique({
|
||
|
|
where: { id },
|
||
|
|
include: {
|
||
|
|
business_activities: {
|
||
|
|
omit: {
|
||
|
|
guild_id: true,
|
||
|
|
},
|
||
|
|
},
|
||
|
|
},
|
||
|
|
})
|
||
|
|
|
||
|
|
return ResponseMapper.single(guild)
|
||
|
|
}
|
||
|
|
|
||
|
|
async create(data: CreateGuildDto) {
|
||
|
|
const guild = await this.prisma.guild.create({ data })
|
||
|
|
return ResponseMapper.create(guild)
|
||
|
|
}
|
||
|
|
|
||
|
|
async update(id: string, data: UpdateGuildDto) {
|
||
|
|
const guild = await this.prisma.guild.update({ where: { id }, data })
|
||
|
|
return ResponseMapper.update(guild)
|
||
|
|
}
|
||
|
|
|
||
|
|
// async delete(id: string) {
|
||
|
|
// await this.prisma.guild.delete({ where: { id } })
|
||
|
|
// return ResponseMapper.
|
||
|
|
// }
|
||
|
|
}
|