/* eslint-disable prettier/prettier */ import { Injectable } from '@nestjs/common' import { Prisma, User } from '@prisma/client' import { PrismaService } from 'src/prisma.service' @Injectable() export class UserService { constructor(private prisma: PrismaService) { prisma.$on('query', (event: Prisma.QueryEvent) => { console.log('Query: ' + event.query) console.log('Duration: ' + event.duration + 'ms') }) } //전체조회 async count(params: { cursor?: Prisma.UserWhereUniqueInput where?: Prisma.UserWhereInput }): Promise { const { cursor, where } = params return this.prisma.user.count({ cursor, where }) } //전체조회 async fetchAll(params: { skip?: number take?: number cursor?: Prisma.UserWhereUniqueInput where?: Prisma.UserWhereInput orderBy?: Prisma.UserOrderByWithRelationInput }): Promise { const { skip, take, cursor, where, orderBy } = params return this.prisma.user.findMany({ skip, take, cursor, where, orderBy }) } //단일 조회 async fetchOne(where: Prisma.UserWhereInput): Promise { return this.prisma.user.findFirstOrThrow({ where: where }) } //단일 추가 async add(data: Prisma.UserCreateInput): Promise { return this.prisma.user.create({ data }) } //단일 수정 async update(params: { where: Prisma.UserWhereUniqueInput data: Prisma.UserUpdateInput }): Promise { const { where, data } = params return this.prisma.user.update({ data, where }) } //단일 삭제 async remove(where: Prisma.UserWhereUniqueInput): Promise { return this.prisma.user.delete({ where }) } }