diff --git a/server/src/auth/auth.service.ts b/server/src/auth/auth.service.ts index f5a74ba..9f6add2 100644 --- a/server/src/auth/auth.service.ts +++ b/server/src/auth/auth.service.ts @@ -17,7 +17,7 @@ export class AuthService { username: string, password: string ): Promise { - const user = await this.userService.findOne({ + const user = await this.userService.user({ where: { username }, }); if (user && (await this.passwordService.compare(password, user.password))) { diff --git a/server/src/auth/jwt/base/jwt.strategy.base.ts b/server/src/auth/jwt/base/jwt.strategy.base.ts index 3bbc919..26da6a7 100644 --- a/server/src/auth/jwt/base/jwt.strategy.base.ts +++ b/server/src/auth/jwt/base/jwt.strategy.base.ts @@ -22,7 +22,7 @@ export class JwtStrategyBase async validate(payload: UserInfo): Promise { const { username } = payload; - const user = await this.userService.findOne({ + const user = await this.userService.user({ where: { username }, }); if (!user) { diff --git a/server/src/author/author.service.ts b/server/src/author/author.service.ts index 1011f7a..5641ac3 100644 --- a/server/src/author/author.service.ts +++ b/server/src/author/author.service.ts @@ -18,7 +18,7 @@ export class AuthorService extends AuthorServiceBase { // Set Slug on creation const name = [args.data.firstName, args.data.lastName].join(" "); args.data.slug = slugify(name, SLUGGIFY_OPTIONS); - return super.create(args); + return super.createAuthor(args); } async update( @@ -28,6 +28,6 @@ export class AuthorService extends AuthorServiceBase { if (args.data.slug === null) { delete args.data.slug; } - return super.update(args); + return super.updateAuthor(args); } } diff --git a/server/src/author/base/author.controller.base.spec.ts b/server/src/author/base/author.controller.base.spec.ts index ba78f29..d4b07f6 100644 --- a/server/src/author/base/author.controller.base.spec.ts +++ b/server/src/author/base/author.controller.base.spec.ts @@ -61,11 +61,11 @@ const FIND_ONE_RESULT = { }; const service = { - create() { + createAuthor() { return CREATE_RESULT; }, - findMany: () => FIND_MANY_RESULT, - findOne: ({ where }: { where: { id: string } }) => { + authors: () => FIND_MANY_RESULT, + author: ({ where }: { where: { id: string } }) => { switch (where.id) { case existingId: return FIND_ONE_RESULT; diff --git a/server/src/author/base/author.controller.base.ts b/server/src/author/base/author.controller.base.ts index 5e4db52..a2d48c3 100644 --- a/server/src/author/base/author.controller.base.ts +++ b/server/src/author/base/author.controller.base.ts @@ -22,12 +22,11 @@ import { AuthorService } from "../author.service"; import { AclValidateRequestInterceptor } from "../../interceptors/aclValidateRequest.interceptor"; import { Public } from "../../decorators/public.decorator"; import { AuthorCreateInput } from "./AuthorCreateInput"; -import { AuthorWhereInput } from "./AuthorWhereInput"; -import { AuthorWhereUniqueInput } from "./AuthorWhereUniqueInput"; -import { AuthorFindManyArgs } from "./AuthorFindManyArgs"; -import { AuthorUpdateInput } from "./AuthorUpdateInput"; import { Author } from "./Author"; import { Post } from "../../post/base/Post"; +import { AuthorFindManyArgs } from "./AuthorFindManyArgs"; +import { AuthorWhereUniqueInput } from "./AuthorWhereUniqueInput"; +import { AuthorUpdateInput } from "./AuthorUpdateInput"; import { PostFindManyArgs } from "../../post/base/PostFindManyArgs"; import { PostWhereUniqueInput } from "../../post/base/PostWhereUniqueInput"; @swagger.ApiBearerAuth() @@ -48,8 +47,8 @@ export class AuthorControllerBase { @swagger.ApiForbiddenResponse({ type: errors.ForbiddenException, }) - async create(@common.Body() data: AuthorCreateInput): Promise { - return await this.service.create({ + async createAuthor(@common.Body() data: AuthorCreateInput): Promise { + return await this.service.createAuthor({ data: data, select: { createdAt: true, @@ -71,9 +70,9 @@ export class AuthorControllerBase { @swagger.ApiForbiddenResponse({ type: errors.ForbiddenException, }) - async findMany(@common.Req() request: Request): Promise { + async authors(@common.Req() request: Request): Promise { const args = plainToClass(AuthorFindManyArgs, request.query); - return this.service.findMany({ + return this.service.authors({ ...args, select: { createdAt: true, @@ -95,10 +94,10 @@ export class AuthorControllerBase { @swagger.ApiForbiddenResponse({ type: errors.ForbiddenException, }) - async findOne( + async author( @common.Param() params: AuthorWhereUniqueInput ): Promise { - const result = await this.service.findOne({ + const result = await this.service.author({ where: params, select: { createdAt: true, @@ -131,12 +130,12 @@ export class AuthorControllerBase { @swagger.ApiForbiddenResponse({ type: errors.ForbiddenException, }) - async update( + async updateAuthor( @common.Param() params: AuthorWhereUniqueInput, @common.Body() data: AuthorUpdateInput ): Promise { try { - return await this.service.update({ + return await this.service.updateAuthor({ where: params, data: data, select: { @@ -171,11 +170,11 @@ export class AuthorControllerBase { @swagger.ApiForbiddenResponse({ type: errors.ForbiddenException, }) - async delete( + async deleteAuthor( @common.Param() params: AuthorWhereUniqueInput ): Promise { try { - return await this.service.delete({ + return await this.service.deleteAuthor({ where: params, select: { createdAt: true, @@ -201,7 +200,7 @@ export class AuthorControllerBase { @Public() @common.Get("/:id/posts") @ApiNestedQuery(PostFindManyArgs) - async findManyPosts( + async findPosts( @common.Req() request: Request, @common.Param() params: AuthorWhereUniqueInput ): Promise { @@ -251,7 +250,7 @@ export class AuthorControllerBase { connect: body, }, }; - await this.service.update({ + await this.service.updateAuthor({ where: params, data, select: { id: true }, @@ -273,7 +272,7 @@ export class AuthorControllerBase { set: body, }, }; - await this.service.update({ + await this.service.updateAuthor({ where: params, data, select: { id: true }, @@ -295,7 +294,7 @@ export class AuthorControllerBase { disconnect: body, }, }; - await this.service.update({ + await this.service.updateAuthor({ where: params, data, select: { id: true }, diff --git a/server/src/author/base/author.resolver.base.ts b/server/src/author/base/author.resolver.base.ts index 787663c..56af069 100644 --- a/server/src/author/base/author.resolver.base.ts +++ b/server/src/author/base/author.resolver.base.ts @@ -19,13 +19,13 @@ import { GqlDefaultAuthGuard } from "../../auth/gqlDefaultAuth.guard"; import * as common from "@nestjs/common"; import { Public } from "../../decorators/public.decorator"; import { AclValidateRequestInterceptor } from "../../interceptors/aclValidateRequest.interceptor"; -import { CreateAuthorArgs } from "./CreateAuthorArgs"; -import { UpdateAuthorArgs } from "./UpdateAuthorArgs"; -import { DeleteAuthorArgs } from "./DeleteAuthorArgs"; +import { Author } from "./Author"; import { AuthorCountArgs } from "./AuthorCountArgs"; import { AuthorFindManyArgs } from "./AuthorFindManyArgs"; import { AuthorFindUniqueArgs } from "./AuthorFindUniqueArgs"; -import { Author } from "./Author"; +import { CreateAuthorArgs } from "./CreateAuthorArgs"; +import { UpdateAuthorArgs } from "./UpdateAuthorArgs"; +import { DeleteAuthorArgs } from "./DeleteAuthorArgs"; import { PostFindManyArgs } from "../../post/base/PostFindManyArgs"; import { Post } from "../../post/base/Post"; import { AuthorService } from "../author.service"; @@ -51,7 +51,7 @@ export class AuthorResolverBase { @Public() @graphql.Query(() => [Author]) async authors(@graphql.Args() args: AuthorFindManyArgs): Promise { - return this.service.findMany(args); + return this.service.authors(args); } @Public() @@ -59,7 +59,7 @@ export class AuthorResolverBase { async author( @graphql.Args() args: AuthorFindUniqueArgs ): Promise { - const result = await this.service.findOne(args); + const result = await this.service.author(args); if (result === null) { return null; } @@ -74,7 +74,7 @@ export class AuthorResolverBase { possession: "any", }) async createAuthor(@graphql.Args() args: CreateAuthorArgs): Promise { - return await this.service.create({ + return await this.service.createAuthor({ ...args, data: args.data, }); @@ -91,7 +91,7 @@ export class AuthorResolverBase { @graphql.Args() args: UpdateAuthorArgs ): Promise { try { - return await this.service.update({ + return await this.service.updateAuthor({ ...args, data: args.data, }); @@ -115,7 +115,7 @@ export class AuthorResolverBase { @graphql.Args() args: DeleteAuthorArgs ): Promise { try { - return await this.service.delete(args); + return await this.service.deleteAuthor(args); } catch (error) { if (isRecordNotFoundError(error)) { throw new GraphQLError( @@ -128,7 +128,7 @@ export class AuthorResolverBase { @Public() @graphql.ResolveField(() => [Post], { name: "posts" }) - async resolveFieldPosts( + async findPosts( @graphql.Parent() parent: Author, @graphql.Args() args: PostFindManyArgs ): Promise { diff --git a/server/src/author/base/author.service.base.ts b/server/src/author/base/author.service.base.ts index 67c729a..ad3ae34 100644 --- a/server/src/author/base/author.service.base.ts +++ b/server/src/author/base/author.service.base.ts @@ -10,7 +10,12 @@ https://docs.amplication.com/how-to/custom-code ------------------------------------------------------------------------------ */ import { PrismaService } from "../../prisma/prisma.service"; -import { Prisma, Author, Post } from "@prisma/client"; + +import { + Prisma, + Author, // @ts-ignore + Post, +} from "@prisma/client"; export class AuthorServiceBase { constructor(protected readonly prisma: PrismaService) {} @@ -21,27 +26,27 @@ export class AuthorServiceBase { return this.prisma.author.count(args); } - async findMany( + async authors( args: Prisma.SelectSubset ): Promise { return this.prisma.author.findMany(args); } - async findOne( + async author( args: Prisma.SelectSubset ): Promise { return this.prisma.author.findUnique(args); } - async create( + async createAuthor( args: Prisma.SelectSubset ): Promise { return this.prisma.author.create(args); } - async update( + async updateAuthor( args: Prisma.SelectSubset ): Promise { return this.prisma.author.update(args); } - async delete( + async deleteAuthor( args: Prisma.SelectSubset ): Promise { return this.prisma.author.delete(args); diff --git a/server/src/post/base/post.controller.base.spec.ts b/server/src/post/base/post.controller.base.spec.ts index 9e031f7..d0967e9 100644 --- a/server/src/post/base/post.controller.base.spec.ts +++ b/server/src/post/base/post.controller.base.spec.ts @@ -73,11 +73,11 @@ const FIND_ONE_RESULT = { }; const service = { - create() { + createPost() { return CREATE_RESULT; }, - findMany: () => FIND_MANY_RESULT, - findOne: ({ where }: { where: { id: string } }) => { + posts: () => FIND_MANY_RESULT, + post: ({ where }: { where: { id: string } }) => { switch (where.id) { case existingId: return FIND_ONE_RESULT; diff --git a/server/src/post/base/post.controller.base.ts b/server/src/post/base/post.controller.base.ts index 0e2cba6..4bfc958 100644 --- a/server/src/post/base/post.controller.base.ts +++ b/server/src/post/base/post.controller.base.ts @@ -22,11 +22,10 @@ import { PostService } from "../post.service"; import { AclValidateRequestInterceptor } from "../../interceptors/aclValidateRequest.interceptor"; import { Public } from "../../decorators/public.decorator"; import { PostCreateInput } from "./PostCreateInput"; -import { PostWhereInput } from "./PostWhereInput"; -import { PostWhereUniqueInput } from "./PostWhereUniqueInput"; +import { Post } from "./Post"; import { PostFindManyArgs } from "./PostFindManyArgs"; +import { PostWhereUniqueInput } from "./PostWhereUniqueInput"; import { PostUpdateInput } from "./PostUpdateInput"; -import { Post } from "./Post"; import { TagFindManyArgs } from "../../tag/base/TagFindManyArgs"; import { Tag } from "../../tag/base/Tag"; import { TagWhereUniqueInput } from "../../tag/base/TagWhereUniqueInput"; @@ -48,8 +47,8 @@ export class PostControllerBase { @swagger.ApiForbiddenResponse({ type: errors.ForbiddenException, }) - async create(@common.Body() data: PostCreateInput): Promise { - return await this.service.create({ + async createPost(@common.Body() data: PostCreateInput): Promise { + return await this.service.createPost({ data: { ...data, @@ -86,9 +85,9 @@ export class PostControllerBase { @swagger.ApiForbiddenResponse({ type: errors.ForbiddenException, }) - async findMany(@common.Req() request: Request): Promise { + async posts(@common.Req() request: Request): Promise { const args = plainToClass(PostFindManyArgs, request.query); - return this.service.findMany({ + return this.service.posts({ ...args, select: { author: { @@ -119,10 +118,10 @@ export class PostControllerBase { @swagger.ApiForbiddenResponse({ type: errors.ForbiddenException, }) - async findOne( + async post( @common.Param() params: PostWhereUniqueInput ): Promise { - const result = await this.service.findOne({ + const result = await this.service.post({ where: params, select: { author: { @@ -164,12 +163,12 @@ export class PostControllerBase { @swagger.ApiForbiddenResponse({ type: errors.ForbiddenException, }) - async update( + async updatePost( @common.Param() params: PostWhereUniqueInput, @common.Body() data: PostUpdateInput ): Promise { try { - return await this.service.update({ + return await this.service.updatePost({ where: params, data: { ...data, @@ -219,11 +218,11 @@ export class PostControllerBase { @swagger.ApiForbiddenResponse({ type: errors.ForbiddenException, }) - async delete( + async deletePost( @common.Param() params: PostWhereUniqueInput ): Promise { try { - return await this.service.delete({ + return await this.service.deletePost({ where: params, select: { author: { @@ -258,7 +257,7 @@ export class PostControllerBase { @Public() @common.Get("/:id/tags") @ApiNestedQuery(TagFindManyArgs) - async findManyTags( + async findTags( @common.Req() request: Request, @common.Param() params: PostWhereUniqueInput ): Promise { @@ -296,7 +295,7 @@ export class PostControllerBase { connect: body, }, }; - await this.service.update({ + await this.service.updatePost({ where: params, data, select: { id: true }, @@ -318,7 +317,7 @@ export class PostControllerBase { set: body, }, }; - await this.service.update({ + await this.service.updatePost({ where: params, data, select: { id: true }, @@ -340,7 +339,7 @@ export class PostControllerBase { disconnect: body, }, }; - await this.service.update({ + await this.service.updatePost({ where: params, data, select: { id: true }, diff --git a/server/src/post/base/post.resolver.base.ts b/server/src/post/base/post.resolver.base.ts index a938435..e4122da 100644 --- a/server/src/post/base/post.resolver.base.ts +++ b/server/src/post/base/post.resolver.base.ts @@ -19,13 +19,13 @@ import { GqlDefaultAuthGuard } from "../../auth/gqlDefaultAuth.guard"; import * as common from "@nestjs/common"; import { Public } from "../../decorators/public.decorator"; import { AclValidateRequestInterceptor } from "../../interceptors/aclValidateRequest.interceptor"; -import { CreatePostArgs } from "./CreatePostArgs"; -import { UpdatePostArgs } from "./UpdatePostArgs"; -import { DeletePostArgs } from "./DeletePostArgs"; +import { Post } from "./Post"; import { PostCountArgs } from "./PostCountArgs"; import { PostFindManyArgs } from "./PostFindManyArgs"; import { PostFindUniqueArgs } from "./PostFindUniqueArgs"; -import { Post } from "./Post"; +import { CreatePostArgs } from "./CreatePostArgs"; +import { UpdatePostArgs } from "./UpdatePostArgs"; +import { DeletePostArgs } from "./DeletePostArgs"; import { TagFindManyArgs } from "../../tag/base/TagFindManyArgs"; import { Tag } from "../../tag/base/Tag"; import { Author } from "../../author/base/Author"; @@ -52,13 +52,13 @@ export class PostResolverBase { @Public() @graphql.Query(() => [Post]) async posts(@graphql.Args() args: PostFindManyArgs): Promise { - return this.service.findMany(args); + return this.service.posts(args); } @Public() @graphql.Query(() => Post, { nullable: true }) async post(@graphql.Args() args: PostFindUniqueArgs): Promise { - const result = await this.service.findOne(args); + const result = await this.service.post(args); if (result === null) { return null; } @@ -73,7 +73,7 @@ export class PostResolverBase { possession: "any", }) async createPost(@graphql.Args() args: CreatePostArgs): Promise { - return await this.service.create({ + return await this.service.createPost({ ...args, data: { ...args.data, @@ -94,7 +94,7 @@ export class PostResolverBase { }) async updatePost(@graphql.Args() args: UpdatePostArgs): Promise { try { - return await this.service.update({ + return await this.service.updatePost({ ...args, data: { ...args.data, @@ -122,7 +122,7 @@ export class PostResolverBase { }) async deletePost(@graphql.Args() args: DeletePostArgs): Promise { try { - return await this.service.delete(args); + return await this.service.deletePost(args); } catch (error) { if (isRecordNotFoundError(error)) { throw new GraphQLError( @@ -135,7 +135,7 @@ export class PostResolverBase { @Public() @graphql.ResolveField(() => [Tag], { name: "tags" }) - async resolveFieldTags( + async findTags( @graphql.Parent() parent: Post, @graphql.Args() args: TagFindManyArgs ): Promise { @@ -153,9 +153,7 @@ export class PostResolverBase { nullable: true, name: "author", }) - async resolveFieldAuthor( - @graphql.Parent() parent: Post - ): Promise { + async getAuthor(@graphql.Parent() parent: Post): Promise { const result = await this.service.getAuthor(parent.id); if (!result) { diff --git a/server/src/post/base/post.service.base.ts b/server/src/post/base/post.service.base.ts index c5df9b3..4ff5ed1 100644 --- a/server/src/post/base/post.service.base.ts +++ b/server/src/post/base/post.service.base.ts @@ -10,7 +10,13 @@ https://docs.amplication.com/how-to/custom-code ------------------------------------------------------------------------------ */ import { PrismaService } from "../../prisma/prisma.service"; -import { Prisma, Post, Tag, Author } from "@prisma/client"; + +import { + Prisma, + Post, // @ts-ignore + Tag, // @ts-ignore + Author, +} from "@prisma/client"; export class PostServiceBase { constructor(protected readonly prisma: PrismaService) {} @@ -21,27 +27,27 @@ export class PostServiceBase { return this.prisma.post.count(args); } - async findMany( + async posts( args: Prisma.SelectSubset ): Promise { return this.prisma.post.findMany(args); } - async findOne( + async post( args: Prisma.SelectSubset ): Promise { return this.prisma.post.findUnique(args); } - async create( + async createPost( args: Prisma.SelectSubset ): Promise { return this.prisma.post.create(args); } - async update( + async updatePost( args: Prisma.SelectSubset ): Promise { return this.prisma.post.update(args); } - async delete( + async deletePost( args: Prisma.SelectSubset ): Promise { return this.prisma.post.delete(args); diff --git a/server/src/post/post.service.ts b/server/src/post/post.service.ts index d6bb001..47e6afa 100644 --- a/server/src/post/post.service.ts +++ b/server/src/post/post.service.ts @@ -25,7 +25,7 @@ export class PostService extends PostServiceBase { if (args.data.draft === null || args.data.draft === undefined) { args.data.draft = false; } - return super.create(args); + return super.createPost(args); } async update( @@ -43,6 +43,6 @@ export class PostService extends PostServiceBase { if (args.data.draft === null) { delete args.data.draft; } - return super.update(args); + return super.updatePost(args); } } diff --git a/server/src/tag/base/tag.controller.base.spec.ts b/server/src/tag/base/tag.controller.base.spec.ts index d931e8d..61157d1 100644 --- a/server/src/tag/base/tag.controller.base.spec.ts +++ b/server/src/tag/base/tag.controller.base.spec.ts @@ -49,11 +49,11 @@ const FIND_ONE_RESULT = { }; const service = { - create() { + createTag() { return CREATE_RESULT; }, - findMany: () => FIND_MANY_RESULT, - findOne: ({ where }: { where: { id: string } }) => { + tags: () => FIND_MANY_RESULT, + tag: ({ where }: { where: { id: string } }) => { switch (where.id) { case existingId: return FIND_ONE_RESULT; diff --git a/server/src/tag/base/tag.controller.base.ts b/server/src/tag/base/tag.controller.base.ts index aaf9c6e..c190089 100644 --- a/server/src/tag/base/tag.controller.base.ts +++ b/server/src/tag/base/tag.controller.base.ts @@ -22,12 +22,11 @@ import { TagService } from "../tag.service"; import { AclValidateRequestInterceptor } from "../../interceptors/aclValidateRequest.interceptor"; import { Public } from "../../decorators/public.decorator"; import { TagCreateInput } from "./TagCreateInput"; -import { TagWhereInput } from "./TagWhereInput"; -import { TagWhereUniqueInput } from "./TagWhereUniqueInput"; -import { TagFindManyArgs } from "./TagFindManyArgs"; -import { TagUpdateInput } from "./TagUpdateInput"; import { Tag } from "./Tag"; import { Post } from "../../post/base/Post"; +import { TagFindManyArgs } from "./TagFindManyArgs"; +import { TagWhereUniqueInput } from "./TagWhereUniqueInput"; +import { TagUpdateInput } from "./TagUpdateInput"; import { PostFindManyArgs } from "../../post/base/PostFindManyArgs"; import { PostWhereUniqueInput } from "../../post/base/PostWhereUniqueInput"; @swagger.ApiBearerAuth() @@ -48,8 +47,8 @@ export class TagControllerBase { @swagger.ApiForbiddenResponse({ type: errors.ForbiddenException, }) - async create(@common.Body() data: TagCreateInput): Promise { - return await this.service.create({ + async createTag(@common.Body() data: TagCreateInput): Promise { + return await this.service.createTag({ data: data, select: { createdAt: true, @@ -68,9 +67,9 @@ export class TagControllerBase { @swagger.ApiForbiddenResponse({ type: errors.ForbiddenException, }) - async findMany(@common.Req() request: Request): Promise { + async tags(@common.Req() request: Request): Promise { const args = plainToClass(TagFindManyArgs, request.query); - return this.service.findMany({ + return this.service.tags({ ...args, select: { createdAt: true, @@ -89,10 +88,8 @@ export class TagControllerBase { @swagger.ApiForbiddenResponse({ type: errors.ForbiddenException, }) - async findOne( - @common.Param() params: TagWhereUniqueInput - ): Promise { - const result = await this.service.findOne({ + async tag(@common.Param() params: TagWhereUniqueInput): Promise { + const result = await this.service.tag({ where: params, select: { createdAt: true, @@ -122,12 +119,12 @@ export class TagControllerBase { @swagger.ApiForbiddenResponse({ type: errors.ForbiddenException, }) - async update( + async updateTag( @common.Param() params: TagWhereUniqueInput, @common.Body() data: TagUpdateInput ): Promise { try { - return await this.service.update({ + return await this.service.updateTag({ where: params, data: data, select: { @@ -159,11 +156,11 @@ export class TagControllerBase { @swagger.ApiForbiddenResponse({ type: errors.ForbiddenException, }) - async delete( + async deleteTag( @common.Param() params: TagWhereUniqueInput ): Promise { try { - return await this.service.delete({ + return await this.service.deleteTag({ where: params, select: { createdAt: true, @@ -186,7 +183,7 @@ export class TagControllerBase { @Public() @common.Get("/:id/posts") @ApiNestedQuery(PostFindManyArgs) - async findManyPosts( + async findPosts( @common.Req() request: Request, @common.Param() params: TagWhereUniqueInput ): Promise { @@ -236,7 +233,7 @@ export class TagControllerBase { connect: body, }, }; - await this.service.update({ + await this.service.updateTag({ where: params, data, select: { id: true }, @@ -258,7 +255,7 @@ export class TagControllerBase { set: body, }, }; - await this.service.update({ + await this.service.updateTag({ where: params, data, select: { id: true }, @@ -280,7 +277,7 @@ export class TagControllerBase { disconnect: body, }, }; - await this.service.update({ + await this.service.updateTag({ where: params, data, select: { id: true }, diff --git a/server/src/tag/base/tag.resolver.base.ts b/server/src/tag/base/tag.resolver.base.ts index 841f851..1cc327b 100644 --- a/server/src/tag/base/tag.resolver.base.ts +++ b/server/src/tag/base/tag.resolver.base.ts @@ -19,13 +19,13 @@ import { GqlDefaultAuthGuard } from "../../auth/gqlDefaultAuth.guard"; import * as common from "@nestjs/common"; import { Public } from "../../decorators/public.decorator"; import { AclValidateRequestInterceptor } from "../../interceptors/aclValidateRequest.interceptor"; -import { CreateTagArgs } from "./CreateTagArgs"; -import { UpdateTagArgs } from "./UpdateTagArgs"; -import { DeleteTagArgs } from "./DeleteTagArgs"; +import { Tag } from "./Tag"; import { TagCountArgs } from "./TagCountArgs"; import { TagFindManyArgs } from "./TagFindManyArgs"; import { TagFindUniqueArgs } from "./TagFindUniqueArgs"; -import { Tag } from "./Tag"; +import { CreateTagArgs } from "./CreateTagArgs"; +import { UpdateTagArgs } from "./UpdateTagArgs"; +import { DeleteTagArgs } from "./DeleteTagArgs"; import { PostFindManyArgs } from "../../post/base/PostFindManyArgs"; import { Post } from "../../post/base/Post"; import { TagService } from "../tag.service"; @@ -51,13 +51,13 @@ export class TagResolverBase { @Public() @graphql.Query(() => [Tag]) async tags(@graphql.Args() args: TagFindManyArgs): Promise { - return this.service.findMany(args); + return this.service.tags(args); } @Public() @graphql.Query(() => Tag, { nullable: true }) async tag(@graphql.Args() args: TagFindUniqueArgs): Promise { - const result = await this.service.findOne(args); + const result = await this.service.tag(args); if (result === null) { return null; } @@ -72,7 +72,7 @@ export class TagResolverBase { possession: "any", }) async createTag(@graphql.Args() args: CreateTagArgs): Promise { - return await this.service.create({ + return await this.service.createTag({ ...args, data: args.data, }); @@ -87,7 +87,7 @@ export class TagResolverBase { }) async updateTag(@graphql.Args() args: UpdateTagArgs): Promise { try { - return await this.service.update({ + return await this.service.updateTag({ ...args, data: args.data, }); @@ -109,7 +109,7 @@ export class TagResolverBase { }) async deleteTag(@graphql.Args() args: DeleteTagArgs): Promise { try { - return await this.service.delete(args); + return await this.service.deleteTag(args); } catch (error) { if (isRecordNotFoundError(error)) { throw new GraphQLError( @@ -122,7 +122,7 @@ export class TagResolverBase { @Public() @graphql.ResolveField(() => [Post], { name: "posts" }) - async resolveFieldPosts( + async findPosts( @graphql.Parent() parent: Tag, @graphql.Args() args: PostFindManyArgs ): Promise { diff --git a/server/src/tag/base/tag.service.base.ts b/server/src/tag/base/tag.service.base.ts index 5b243b3..971e0df 100644 --- a/server/src/tag/base/tag.service.base.ts +++ b/server/src/tag/base/tag.service.base.ts @@ -10,7 +10,12 @@ https://docs.amplication.com/how-to/custom-code ------------------------------------------------------------------------------ */ import { PrismaService } from "../../prisma/prisma.service"; -import { Prisma, Tag, Post } from "@prisma/client"; + +import { + Prisma, + Tag, // @ts-ignore + Post, +} from "@prisma/client"; export class TagServiceBase { constructor(protected readonly prisma: PrismaService) {} @@ -21,27 +26,27 @@ export class TagServiceBase { return this.prisma.tag.count(args); } - async findMany( + async tags( args: Prisma.SelectSubset ): Promise { return this.prisma.tag.findMany(args); } - async findOne( + async tag( args: Prisma.SelectSubset ): Promise { return this.prisma.tag.findUnique(args); } - async create( + async createTag( args: Prisma.SelectSubset ): Promise { return this.prisma.tag.create(args); } - async update( + async updateTag( args: Prisma.SelectSubset ): Promise { return this.prisma.tag.update(args); } - async delete( + async deleteTag( args: Prisma.SelectSubset ): Promise { return this.prisma.tag.delete(args); diff --git a/server/src/tag/tag.service.ts b/server/src/tag/tag.service.ts index 2b9888d..12a92f6 100644 --- a/server/src/tag/tag.service.ts +++ b/server/src/tag/tag.service.ts @@ -16,7 +16,7 @@ export class TagService extends TagServiceBase { ): Promise { // Set Slug on creation args.data.slug = slugify(args.data.name ?? "", SLUGGIFY_OPTIONS); - return super.create(args); + return super.createTag(args); } async update( @@ -26,6 +26,6 @@ export class TagService extends TagServiceBase { if (args.data.slug === null) { delete args.data.slug; } - return super.update(args); + return super.updateTag(args); } } diff --git a/server/src/user/base/User.ts b/server/src/user/base/User.ts index c314393..a5efa49 100644 --- a/server/src/user/base/User.ts +++ b/server/src/user/base/User.ts @@ -13,7 +13,7 @@ import { ObjectType, Field } from "@nestjs/graphql"; import { ApiProperty } from "@nestjs/swagger"; import { IsDate, IsString, IsOptional } from "class-validator"; import { Type } from "class-transformer"; -import { IsJSONValue } from "@app/custom-validators"; +import { IsJSONValue } from "../../validators"; import { GraphQLJSON } from "graphql-type-json"; import { JsonValue } from "type-fest"; diff --git a/server/src/user/base/UserCreateInput.ts b/server/src/user/base/UserCreateInput.ts index dce8d74..fe5c9df 100644 --- a/server/src/user/base/UserCreateInput.ts +++ b/server/src/user/base/UserCreateInput.ts @@ -12,7 +12,7 @@ https://docs.amplication.com/how-to/custom-code import { InputType, Field } from "@nestjs/graphql"; import { ApiProperty } from "@nestjs/swagger"; import { IsString, IsOptional } from "class-validator"; -import { IsJSONValue } from "@app/custom-validators"; +import { IsJSONValue } from "../../validators"; import { GraphQLJSON } from "graphql-type-json"; import { InputJsonValue } from "../../types"; diff --git a/server/src/user/base/UserUpdateInput.ts b/server/src/user/base/UserUpdateInput.ts index c11b9d5..ead5207 100644 --- a/server/src/user/base/UserUpdateInput.ts +++ b/server/src/user/base/UserUpdateInput.ts @@ -12,7 +12,7 @@ https://docs.amplication.com/how-to/custom-code import { InputType, Field } from "@nestjs/graphql"; import { ApiProperty } from "@nestjs/swagger"; import { IsString, IsOptional } from "class-validator"; -import { IsJSONValue } from "@app/custom-validators"; +import { IsJSONValue } from "../../validators"; import { GraphQLJSON } from "graphql-type-json"; import { InputJsonValue } from "../../types"; diff --git a/server/src/user/base/user.controller.base.spec.ts b/server/src/user/base/user.controller.base.spec.ts index 2a2044a..fb15280 100644 --- a/server/src/user/base/user.controller.base.spec.ts +++ b/server/src/user/base/user.controller.base.spec.ts @@ -57,11 +57,11 @@ const FIND_ONE_RESULT = { }; const service = { - create() { + createUser() { return CREATE_RESULT; }, - findMany: () => FIND_MANY_RESULT, - findOne: ({ where }: { where: { id: string } }) => { + users: () => FIND_MANY_RESULT, + user: ({ where }: { where: { id: string } }) => { switch (where.id) { case existingId: return FIND_ONE_RESULT; diff --git a/server/src/user/base/user.controller.base.ts b/server/src/user/base/user.controller.base.ts index 76bc836..ee0cc6e 100644 --- a/server/src/user/base/user.controller.base.ts +++ b/server/src/user/base/user.controller.base.ts @@ -22,12 +22,12 @@ import { UserService } from "../user.service"; import { AclValidateRequestInterceptor } from "../../interceptors/aclValidateRequest.interceptor"; import { AclFilterResponseInterceptor } from "../../interceptors/aclFilterResponse.interceptor"; import { UserCreateInput } from "./UserCreateInput"; -import { UserWhereInput } from "./UserWhereInput"; -import { UserWhereUniqueInput } from "./UserWhereUniqueInput"; -import { UserFindManyArgs } from "./UserFindManyArgs"; -import { UserUpdateInput } from "./UserUpdateInput"; import { User } from "./User"; import { Post } from "../../post/base/Post"; +import { UserFindManyArgs } from "./UserFindManyArgs"; +import { UserWhereUniqueInput } from "./UserWhereUniqueInput"; +import { UserUpdateInput } from "./UserUpdateInput"; + @swagger.ApiBearerAuth() @common.UseGuards(defaultAuthGuard.DefaultAuthGuard, nestAccessControl.ACGuard) export class UserControllerBase { @@ -46,8 +46,8 @@ export class UserControllerBase { @swagger.ApiForbiddenResponse({ type: errors.ForbiddenException, }) - async create(@common.Body() data: UserCreateInput): Promise { - return await this.service.create({ + async createUser(@common.Body() data: UserCreateInput): Promise { + return await this.service.createUser({ data: data, select: { createdAt: true, @@ -73,9 +73,9 @@ export class UserControllerBase { @swagger.ApiForbiddenResponse({ type: errors.ForbiddenException, }) - async findMany(@common.Req() request: Request): Promise { + async users(@common.Req() request: Request): Promise { const args = plainToClass(UserFindManyArgs, request.query); - return this.service.findMany({ + return this.service.users({ ...args, select: { createdAt: true, @@ -101,10 +101,10 @@ export class UserControllerBase { @swagger.ApiForbiddenResponse({ type: errors.ForbiddenException, }) - async findOne( + async user( @common.Param() params: UserWhereUniqueInput ): Promise { - const result = await this.service.findOne({ + const result = await this.service.user({ where: params, select: { createdAt: true, @@ -136,12 +136,12 @@ export class UserControllerBase { @swagger.ApiForbiddenResponse({ type: errors.ForbiddenException, }) - async update( + async updateUser( @common.Param() params: UserWhereUniqueInput, @common.Body() data: UserUpdateInput ): Promise { try { - return await this.service.update({ + return await this.service.updateUser({ where: params, data: data, select: { @@ -175,11 +175,11 @@ export class UserControllerBase { @swagger.ApiForbiddenResponse({ type: errors.ForbiddenException, }) - async delete( + async deleteUser( @common.Param() params: UserWhereUniqueInput ): Promise { try { - return await this.service.delete({ + return await this.service.deleteUser({ where: params, select: { createdAt: true, diff --git a/server/src/user/base/user.resolver.base.ts b/server/src/user/base/user.resolver.base.ts index 21558be..0c60d95 100644 --- a/server/src/user/base/user.resolver.base.ts +++ b/server/src/user/base/user.resolver.base.ts @@ -19,13 +19,13 @@ import { GqlDefaultAuthGuard } from "../../auth/gqlDefaultAuth.guard"; import * as common from "@nestjs/common"; import { AclFilterResponseInterceptor } from "../../interceptors/aclFilterResponse.interceptor"; import { AclValidateRequestInterceptor } from "../../interceptors/aclValidateRequest.interceptor"; -import { CreateUserArgs } from "./CreateUserArgs"; -import { UpdateUserArgs } from "./UpdateUserArgs"; -import { DeleteUserArgs } from "./DeleteUserArgs"; +import { User } from "./User"; import { UserCountArgs } from "./UserCountArgs"; import { UserFindManyArgs } from "./UserFindManyArgs"; import { UserFindUniqueArgs } from "./UserFindUniqueArgs"; -import { User } from "./User"; +import { CreateUserArgs } from "./CreateUserArgs"; +import { UpdateUserArgs } from "./UpdateUserArgs"; +import { DeleteUserArgs } from "./DeleteUserArgs"; import { UserService } from "../user.service"; @common.UseGuards(GqlDefaultAuthGuard, gqlACGuard.GqlACGuard) @graphql.Resolver(() => User) @@ -58,7 +58,7 @@ export class UserResolverBase { possession: "any", }) async users(@graphql.Args() args: UserFindManyArgs): Promise { - return this.service.findMany(args); + return this.service.users(args); } @common.UseInterceptors(AclFilterResponseInterceptor) @@ -69,7 +69,7 @@ export class UserResolverBase { possession: "own", }) async user(@graphql.Args() args: UserFindUniqueArgs): Promise { - const result = await this.service.findOne(args); + const result = await this.service.user(args); if (result === null) { return null; } @@ -84,7 +84,7 @@ export class UserResolverBase { possession: "any", }) async createUser(@graphql.Args() args: CreateUserArgs): Promise { - return await this.service.create({ + return await this.service.createUser({ ...args, data: args.data, }); @@ -99,7 +99,7 @@ export class UserResolverBase { }) async updateUser(@graphql.Args() args: UpdateUserArgs): Promise { try { - return await this.service.update({ + return await this.service.updateUser({ ...args, data: args.data, }); @@ -121,7 +121,7 @@ export class UserResolverBase { }) async deleteUser(@graphql.Args() args: DeleteUserArgs): Promise { try { - return await this.service.delete(args); + return await this.service.deleteUser(args); } catch (error) { if (isRecordNotFoundError(error)) { throw new GraphQLError( diff --git a/server/src/user/base/user.service.base.ts b/server/src/user/base/user.service.base.ts index 3c9de61..d23387f 100644 --- a/server/src/user/base/user.service.base.ts +++ b/server/src/user/base/user.service.base.ts @@ -26,17 +26,17 @@ export class UserServiceBase { return this.prisma.user.count(args); } - async findMany( + async users( args: Prisma.SelectSubset ): Promise { return this.prisma.user.findMany(args); } - async findOne( + async user( args: Prisma.SelectSubset ): Promise { return this.prisma.user.findUnique(args); } - async create( + async createUser( args: Prisma.SelectSubset ): Promise { return this.prisma.user.create({ @@ -48,7 +48,7 @@ export class UserServiceBase { }, }); } - async update( + async updateUser( args: Prisma.SelectSubset ): Promise { return this.prisma.user.update({ @@ -66,7 +66,7 @@ export class UserServiceBase { }, }); } - async delete( + async deleteUser( args: Prisma.SelectSubset ): Promise { return this.prisma.user.delete(args); diff --git a/server/tsconfig.json b/server/tsconfig.json index f6c463b..707e8cd 100644 --- a/server/tsconfig.json +++ b/server/tsconfig.json @@ -15,10 +15,7 @@ "allowSyntheticDefaultImports": true, "resolveJsonModule": true, "skipLibCheck": true, - "strict": true, - "paths": { - "@app/custom-validators": ["src/validators"] - } + "strict": true }, "include": ["src"] }