import { Injectable } from '@nestjs/common' import { Pick } from '@prisma/client/runtime/client' import { Theater } from '@prisma/generated/client' import { PrismaService } from '@/infra/prisma/prisma.service' import { TheaterEntity } from '@/modules/theater/domain/entities/theater.entity' import { TheaterRepositoryPort } from '../../domain/ports/theater.repository.port' @Injectable() export class TheaterPrismaRepository implements TheaterRepositoryPort { public constructor(private readonly prismaService: PrismaService) {} public async create( data: Pick ): Promise { const t = await this.prismaService.theater.create({ data }) return this.toEntity(t) } public async findAll(): Promise { const items = await this.prismaService.theater.findMany({ orderBy: { name: 'asc' } }) return items.map(t => this.toEntity(t)) } public async findById( id: TheaterEntity['id'] ): Promise { const theater = await this.prismaService.theater.findUnique({ where: { id } }) return theater ? this.toEntity(theater) : null } private toEntity(theater: Theater): TheaterEntity { return new TheaterEntity( theater.id, theater.name, theater.address, theater.createdAt, theater.updatedAt ) } }