chore: refacto NestJS in modules (#308)

* chore: wip refacto in modules

* fix: rollback port

* fix: jwt guard in wrong folder

* chore: rename folder exception-filter in filters

* fix: tests are running

* fix: excessive stack depth comparing types

* fix: auth issue

* chore: move createUser in UserService

* fix: test

* fix: guards

* fix: jwt guard don't handle falsy user
This commit is contained in:
Jérémy M
2023-06-16 10:38:11 +02:00
committed by GitHub
parent 5921c7f11d
commit 2cd081234f
1084 changed files with 2251 additions and 758 deletions

View File

@ -0,0 +1,73 @@
import { Resolver, Args, Mutation, Query } from '@nestjs/graphql';
import { UseGuards } from '@nestjs/common';
import { JwtAuthGuard } from 'src/guards/jwt.auth.guard';
import { Workspace } from '../../../core/@generated/workspace/workspace.model';
import { AuthWorkspace } from '../../../decorators/auth-workspace.decorator';
import { CommentThread } from '../../../core/@generated/comment-thread/comment-thread.model';
import { CreateOneCommentThreadArgs } from '../../../core/@generated/comment-thread/create-one-comment-thread.args';
import { CreateOneCommentThreadGuard } from '../../../guards/create-one-comment-thread.guard';
import { FindManyCommentThreadArgs } from '../../../core/@generated/comment-thread/find-many-comment-thread.args';
import { CommentThreadService } from '../services/comment-thread.service';
import { prepareFindManyArgs } from 'src/utils/prepare-find-many';
import { UpdateOneCommentThreadArgs } from 'src/core/@generated/comment-thread/update-one-comment-thread.args';
import { Prisma } from '@prisma/client';
@UseGuards(JwtAuthGuard)
@Resolver(() => CommentThread)
export class CommentThreadResolver {
constructor(private readonly commentThreadService: CommentThreadService) {}
@UseGuards(CreateOneCommentThreadGuard)
@Mutation(() => CommentThread, {
nullable: false,
})
async createOneCommentThread(
@Args() args: CreateOneCommentThreadArgs,
@AuthWorkspace() workspace: Workspace,
): Promise<CommentThread> {
const newCommentData = args.data.comments?.createMany?.data
? args.data.comments?.createMany?.data?.map((comment) => ({
...comment,
...{ workspaceId: workspace.id },
}))
: [];
const createdCommentThread = await this.commentThreadService.create({
data: {
...args.data,
...{ comments: { createMany: { data: newCommentData } } },
...{ workspace: { connect: { id: workspace.id } } },
},
});
return createdCommentThread;
}
@Mutation(() => CommentThread, {
nullable: false,
})
async updateOneCommentThread(
@Args() args: UpdateOneCommentThreadArgs,
): Promise<CommentThread> {
const updatedCommentThread = await this.commentThreadService.update(
args satisfies UpdateOneCommentThreadArgs as Prisma.CommentThreadUpdateArgs,
);
return updatedCommentThread;
}
@Query(() => [CommentThread])
async findManyCommentThreads(
@Args() args: FindManyCommentThreadArgs,
@AuthWorkspace() workspace: Workspace,
) {
const preparedArgs = prepareFindManyArgs<FindManyCommentThreadArgs>(
args,
workspace,
);
const result = await this.commentThreadService.findMany(preparedArgs);
return result;
}
}