import {Injectable} from "@nestjs/common"; import {PrismaService} from "../../prisma/prisma.service"; import {Post, Prisma} from "../generated/prisma/client"; import {_toNum} from "./helper"; @Injectable() export class PgPostService { constructor(private prisma: PrismaService) { } async post(postWhereUniqueInput: Prisma.PostWhereUniqueInput): Promise { return this.prisma.post.findUnique({ where: postWhereUniqueInput, }); } async getById(id: number): Promise { return this.post({id}) } async createPost(data: Prisma.PostCreateInput): Promise { if(_toNum(process.env.X_NEWS_ALLOW_SAVE_POST_CONTENT) != 1) { console.error('Not allow save ..'); // @ts-ignore return { id: 0 }; } return this.prisma.post.create({ data, }); } async updatePost(id, data: Prisma.PostUpdateInput): Promise { return this.prisma.post.update({ data, where: { id } }); } }