transform core api codes into this project, update modules as admin/pos context modules
This commit is contained in:
@@ -0,0 +1,42 @@
|
||||
import { PrismaService } from '@/prisma/prisma.service'
|
||||
import { Injectable } 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, count] = await this.prisma.$transaction([
|
||||
this.prisma.user.findMany(),
|
||||
this.prisma.user.count(),
|
||||
])
|
||||
return ResponseMapper.paginate(
|
||||
users.map(user => ({ ...user, fullname: `${user.first_name} ${user.last_name}` })),
|
||||
{ count },
|
||||
)
|
||||
}
|
||||
|
||||
async findOne(id: string) {
|
||||
const user = await this.prisma.user.findUnique({
|
||||
where: { id },
|
||||
})
|
||||
return ResponseMapper.single({
|
||||
...user,
|
||||
fullname: `${user?.first_name} ${user?.last_name}`,
|
||||
})
|
||||
}
|
||||
|
||||
async create(data: CreateUserDto) {
|
||||
return this.prisma.user.create({ data })
|
||||
}
|
||||
|
||||
async update(id: string, data: UpdateUserDto) {
|
||||
return this.prisma.user.update({ where: { id }, data: data as UpdateUserDto })
|
||||
}
|
||||
|
||||
async delete(id: string) {
|
||||
return this.prisma.user.delete({ where: { id } })
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user