Add comments to Prisma Schema and GraphQL server (#162)
* Lowercase all relations in prisma/graphql schema * Add Comments data model and graphql schema * Make comments availalble on the api through resolvers and guard them * Update front graphql schema * Fix PR
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
import { Resolver, Args, Mutation } from '@nestjs/graphql';
|
||||
import { UseGuards } from '@nestjs/common';
|
||||
import { JwtAuthGuard } from 'src/auth/guards/jwt.auth.guard';
|
||||
import { PrismaService } from 'src/database/prisma.service';
|
||||
import { Workspace } from '../@generated/workspace/workspace.model';
|
||||
import { AuthWorkspace } from './decorators/auth-workspace.decorator';
|
||||
import { CreateOneCommentArgs } from '../@generated/comment/create-one-comment.args';
|
||||
import { Comment } from '../@generated/comment/comment.model';
|
||||
import { CreateOneCommentGuard } from './guards/create-one-comment.guard';
|
||||
|
||||
@UseGuards(JwtAuthGuard)
|
||||
@Resolver(() => Comment)
|
||||
export class CommentResolver {
|
||||
constructor(private readonly prismaService: PrismaService) {}
|
||||
|
||||
@UseGuards(CreateOneCommentGuard)
|
||||
@Mutation(() => Comment, {
|
||||
nullable: false,
|
||||
})
|
||||
async createOneComment(
|
||||
@Args() args: CreateOneCommentArgs,
|
||||
@AuthWorkspace() workspace: Workspace,
|
||||
): Promise<Comment> {
|
||||
return this.prismaService.comment.create({
|
||||
data: {
|
||||
...args.data,
|
||||
...{ workspace: { connect: { id: workspace.id } } },
|
||||
},
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user