All files / infra/repositore-data-base-prisma user-repository-data-base.ts

92.85% Statements 39/42
85.71% Branches 6/7
100% Functions 5/5
92.85% Lines 39/42

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 422x 2x 2x 2x 2x 2x 2x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 2x 9x 9x 9x 9x 9x 9x       9x 9x 9x 9x 9x 9x 9x 9x 9x 2x 1x 1x 1x 1x 1x
import { PrismaClient } from "@prisma/client";
import { User } from "../../domain/entity/user";
import { UserRepository } from "../../domain/repository/user-repository";
import { UserMapper } from "./mappers/user-mapper";
 
export class UserRepositoryDataBase implements UserRepository{
    constructor(private prismaClient: PrismaClient){}
    async create(user: User): Promise<User> {
        const userPrisma = await this.prismaClient.user.create({
          data:{
            id:user.id,
            createdAt: user.createdAt,
          }
        })
        return new User({
            id:userPrisma.id,
            createdAt: userPrisma.createdAt
          })
    }
   async findById(id: string): Promise<User | undefined> {
      const userPrisma = await this.prismaClient.user.findUnique({
        where:{
          id:id
        }
      })

      if(!userPrisma) {
        return undefined 
      }else{
      return new User({
        id:userPrisma.id,
        createdAt: userPrisma.createdAt
      })
    }
    }
 
    async findAll(): Promise<User[]> {
      const usersPrisma = await this.prismaClient.user.findMany();
      const users = usersPrisma.map(UserMapper.invoceMapper) 
      return users;
    }
}