import { PrismaService } from '@/prisma/prisma.service' import { Injectable, NotFoundException } from '@nestjs/common' import { ResponseMapper } from 'common/response/response-mapper' import { CreateUserDto, UpdateUserDto } from './dto/user.dto' @Injectable() export class AdminUsersService { constructor(private readonly prisma: PrismaService) {} async findAll() { const [users, total] = await this.prisma.$transaction([ this.prisma.admin.findMany(), this.prisma.admin.count(), ]) return ResponseMapper.paginate( users.map(user => ({ ...user, fullname: `${user.first_name} ${user.last_name}` })), { total }, ) } async findOne(id: string) { const user = await this.prisma.admin.findUnique({ where: { id }, }) if (!user) { throw new NotFoundException('کاربری یافت نشد') } return ResponseMapper.single({ ...user, fullname: `${user?.first_name} ${user?.last_name}`, }) } async create(data: CreateUserDto) { return this.prisma.admin.create({ data }) } async update(id: string, data: UpdateUserDto) { return this.prisma.admin.update({ where: { id }, data }) } async delete(id: string) { return this.prisma.admin.delete({ where: { id } }) } }