/
githubmirror
/
nest
Обзор
Документация
Войти
/
githubmirror
/
nest
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
sample/22-graphql-prisma/src/posts/posts.service.ts
48 строк
1007 B
Tony133
sample(): upgrade sample 22-graphql-prisma
10 июл 2022, 16:43
10 июл 2022, 16:43
1d2cc84
Код
Авторство
О чём код?
import { Injectable } from '@nestjs/common'; import { Post } from '@prisma/client'; import { NewPost, UpdatePost } from 'src/graphql.schema'; import { PrismaService } from '../prisma/prisma.service'; @Injectable() export class PostsService { constructor(private prisma: PrismaService) {} async findOne(id: string): Promise<Post | null> { return this.prisma.post.findUnique({ where: { id, }, }); } async findAll(): Promise<Post[]> { return this.prisma.post.findMany({}); } async create(input: NewPost): Promise<Post> { return this.prisma.post.create({ data: input, }); } async update(params: UpdatePost): Promise<Post> { const { id, ...params_without_id } = params; return this.prisma.post.update({ where: { id, }, data: { ...params_without_id, }, }); } async delete(id: string): Promise<Post> { return this.prisma.post.delete({ where: { id, }, }); } }