forked from nestjs/nest
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathposts.service.ts
More file actions
executable file
·48 lines (41 loc) · 1007 Bytes
/
Copy pathposts.service.ts
File metadata and controls
executable file
·48 lines (41 loc) · 1007 Bytes
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
42
43
44
45
46
47
48
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,
},
});
}
}