Skip to content

Commit

Permalink
Merge pull request #84 from amplication/amplication-amplication-blog
Browse files Browse the repository at this point in the history
chore(Amplication): Update Generated Code
  • Loading branch information
yuval-hazaz authored Dec 20, 2023
2 parents a0e95b4 + 31740c6 commit 70e3f15
Show file tree
Hide file tree
Showing 25 changed files with 167 additions and 161 deletions.
2 changes: 1 addition & 1 deletion server/src/auth/auth.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export class AuthService {
username: string,
password: string
): Promise<UserInfo | null> {
const user = await this.userService.findOne({
const user = await this.userService.user({
where: { username },
});
if (user && (await this.passwordService.compare(password, user.password))) {
Expand Down
2 changes: 1 addition & 1 deletion server/src/auth/jwt/base/jwt.strategy.base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export class JwtStrategyBase

async validate(payload: UserInfo): Promise<UserInfo> {
const { username } = payload;
const user = await this.userService.findOne({
const user = await this.userService.user({
where: { username },
});
if (!user) {
Expand Down
4 changes: 2 additions & 2 deletions server/src/author/author.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<T>(args);
return super.createAuthor<T>(args);
}

async update<T extends Prisma.AuthorUpdateArgs>(
Expand All @@ -28,6 +28,6 @@ export class AuthorService extends AuthorServiceBase {
if (args.data.slug === null) {
delete args.data.slug;
}
return super.update<T>(args);
return super.updateAuthor<T>(args);
}
}
6 changes: 3 additions & 3 deletions server/src/author/base/author.controller.base.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
35 changes: 17 additions & 18 deletions server/src/author/base/author.controller.base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -48,8 +47,8 @@ export class AuthorControllerBase {
@swagger.ApiForbiddenResponse({
type: errors.ForbiddenException,
})
async create(@common.Body() data: AuthorCreateInput): Promise<Author> {
return await this.service.create({
async createAuthor(@common.Body() data: AuthorCreateInput): Promise<Author> {
return await this.service.createAuthor({
data: data,
select: {
createdAt: true,
Expand All @@ -71,9 +70,9 @@ export class AuthorControllerBase {
@swagger.ApiForbiddenResponse({
type: errors.ForbiddenException,
})
async findMany(@common.Req() request: Request): Promise<Author[]> {
async authors(@common.Req() request: Request): Promise<Author[]> {
const args = plainToClass(AuthorFindManyArgs, request.query);
return this.service.findMany({
return this.service.authors({
...args,
select: {
createdAt: true,
Expand All @@ -95,10 +94,10 @@ export class AuthorControllerBase {
@swagger.ApiForbiddenResponse({
type: errors.ForbiddenException,
})
async findOne(
async author(
@common.Param() params: AuthorWhereUniqueInput
): Promise<Author | null> {
const result = await this.service.findOne({
const result = await this.service.author({
where: params,
select: {
createdAt: true,
Expand Down Expand Up @@ -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<Author | null> {
try {
return await this.service.update({
return await this.service.updateAuthor({
where: params,
data: data,
select: {
Expand Down Expand Up @@ -171,11 +170,11 @@ export class AuthorControllerBase {
@swagger.ApiForbiddenResponse({
type: errors.ForbiddenException,
})
async delete(
async deleteAuthor(
@common.Param() params: AuthorWhereUniqueInput
): Promise<Author | null> {
try {
return await this.service.delete({
return await this.service.deleteAuthor({
where: params,
select: {
createdAt: true,
Expand All @@ -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<Post[]> {
Expand Down Expand Up @@ -251,7 +250,7 @@ export class AuthorControllerBase {
connect: body,
},
};
await this.service.update({
await this.service.updateAuthor({
where: params,
data,
select: { id: true },
Expand All @@ -273,7 +272,7 @@ export class AuthorControllerBase {
set: body,
},
};
await this.service.update({
await this.service.updateAuthor({
where: params,
data,
select: { id: true },
Expand All @@ -295,7 +294,7 @@ export class AuthorControllerBase {
disconnect: body,
},
};
await this.service.update({
await this.service.updateAuthor({
where: params,
data,
select: { id: true },
Expand Down
20 changes: 10 additions & 10 deletions server/src/author/base/author.resolver.base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -51,15 +51,15 @@ export class AuthorResolverBase {
@Public()
@graphql.Query(() => [Author])
async authors(@graphql.Args() args: AuthorFindManyArgs): Promise<Author[]> {
return this.service.findMany(args);
return this.service.authors(args);
}

@Public()
@graphql.Query(() => Author, { nullable: true })
async author(
@graphql.Args() args: AuthorFindUniqueArgs
): Promise<Author | null> {
const result = await this.service.findOne(args);
const result = await this.service.author(args);
if (result === null) {
return null;
}
Expand All @@ -74,7 +74,7 @@ export class AuthorResolverBase {
possession: "any",
})
async createAuthor(@graphql.Args() args: CreateAuthorArgs): Promise<Author> {
return await this.service.create({
return await this.service.createAuthor({
...args,
data: args.data,
});
Expand All @@ -91,7 +91,7 @@ export class AuthorResolverBase {
@graphql.Args() args: UpdateAuthorArgs
): Promise<Author | null> {
try {
return await this.service.update({
return await this.service.updateAuthor({
...args,
data: args.data,
});
Expand All @@ -115,7 +115,7 @@ export class AuthorResolverBase {
@graphql.Args() args: DeleteAuthorArgs
): Promise<Author | null> {
try {
return await this.service.delete(args);
return await this.service.deleteAuthor(args);
} catch (error) {
if (isRecordNotFoundError(error)) {
throw new GraphQLError(
Expand All @@ -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<Post[]> {
Expand Down
17 changes: 11 additions & 6 deletions server/src/author/base/author.service.base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {}
Expand All @@ -21,27 +26,27 @@ export class AuthorServiceBase {
return this.prisma.author.count(args);
}

async findMany<T extends Prisma.AuthorFindManyArgs>(
async authors<T extends Prisma.AuthorFindManyArgs>(
args: Prisma.SelectSubset<T, Prisma.AuthorFindManyArgs>
): Promise<Author[]> {
return this.prisma.author.findMany(args);
}
async findOne<T extends Prisma.AuthorFindUniqueArgs>(
async author<T extends Prisma.AuthorFindUniqueArgs>(
args: Prisma.SelectSubset<T, Prisma.AuthorFindUniqueArgs>
): Promise<Author | null> {
return this.prisma.author.findUnique(args);
}
async create<T extends Prisma.AuthorCreateArgs>(
async createAuthor<T extends Prisma.AuthorCreateArgs>(
args: Prisma.SelectSubset<T, Prisma.AuthorCreateArgs>
): Promise<Author> {
return this.prisma.author.create<T>(args);
}
async update<T extends Prisma.AuthorUpdateArgs>(
async updateAuthor<T extends Prisma.AuthorUpdateArgs>(
args: Prisma.SelectSubset<T, Prisma.AuthorUpdateArgs>
): Promise<Author> {
return this.prisma.author.update<T>(args);
}
async delete<T extends Prisma.AuthorDeleteArgs>(
async deleteAuthor<T extends Prisma.AuthorDeleteArgs>(
args: Prisma.SelectSubset<T, Prisma.AuthorDeleteArgs>
): Promise<Author> {
return this.prisma.author.delete(args);
Expand Down
6 changes: 3 additions & 3 deletions server/src/post/base/post.controller.base.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Loading

0 comments on commit 70e3f15

Please sign in to comment.