import {Injectable} from "@nestjs/common";
import {PrismaService} from "../../prisma/prisma.service";
import {Post, Prisma} from "../generated/prisma/client";

@Injectable()
export class PgPostService {
    constructor(private prisma: PrismaService) {
    }

    async post(postWhereUniqueInput: Prisma.PostWhereUniqueInput): Promise<Post | null> {
        return this.prisma.post.findUnique({
            where: postWhereUniqueInput,
        });
    }

    async createPost(data: Prisma.PostCreateInput): Promise<Post> {
        return this.prisma.post.create({
            data,
        });
    }

    async updatePost(id, data: Prisma.PostUpdateInput): Promise<Post> {
        return this.prisma.post.update({
            data,
            where: {
                id
            }
        });
    }
}
