@nest-arch/tui 0.2.0 → 0.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (52) hide show
  1. package/README.md +7 -0
  2. package/dist/cli.js +1 -1
  3. package/dist/{constants-BbJ71cex.js → constants-DBtqeoTh.js} +1 -1
  4. package/dist/index.js +97 -79
  5. package/dist/templates/base/.env.example.hbs +36 -0
  6. package/dist/templates/base/.env.hbs +8 -1
  7. package/dist/templates/base/README.md.hbs +1 -1
  8. package/dist/templates/base/pnpm-workspace.yaml.hbs +9 -0
  9. package/dist/templates/base/src/app.module.ts.hbs +21 -1
  10. package/dist/templates/base/src/database/db.module.ts.hbs +2 -4
  11. package/dist/templates/base/src/main.ts.hbs +11 -1
  12. package/dist/templates/extras/swagger/create-docs.ts.hbs +81 -25
  13. package/dist/templates/feature/graphql/src/graphql/dto/create-todo.input.ts.hbs +13 -0
  14. package/dist/templates/feature/graphql/src/graphql/dto/update-todo.input.ts.hbs +8 -0
  15. package/dist/templates/feature/graphql/src/graphql/graphql.module.ts.hbs +33 -0
  16. package/dist/templates/feature/graphql/src/graphql/models/base.model.ts.hbs +13 -0
  17. package/dist/templates/feature/graphql/src/graphql/models/pagination.model.ts.hbs +27 -0
  18. package/dist/templates/feature/graphql/src/graphql/models/todo.model.ts.hbs +23 -0
  19. package/dist/templates/feature/graphql/src/graphql/models/user.model.ts.hbs +34 -0
  20. package/dist/templates/feature/graphql/src/graphql/orm/drizzle/drizzle-graphql.module.ts.hbs +42 -0
  21. package/dist/templates/feature/graphql/src/graphql/orm/typeorm/typeorm-graphql-relations.helper.ts.hbs +23 -0
  22. package/dist/templates/feature/graphql/src/graphql/resolvers/base.resolver.ts.hbs +50 -0
  23. package/dist/templates/feature/graphql/src/graphql/resolvers/todo.resolver.ts.hbs +126 -0
  24. package/dist/templates/feature/rest/todo-example/src/api/todo/dto/create-todo.dto.ts.hbs +13 -0
  25. package/dist/templates/feature/rest/todo-example/src/api/todo/dto/update-todo.dto.ts.hbs +13 -0
  26. package/dist/templates/feature/rest/todo-example/src/api/todo/todo.controller.ts.hbs +171 -0
  27. package/dist/templates/feature/rest/todo-example/src/api/todo/todo.module.ts.hbs +24 -0
  28. package/dist/templates/feature/rest/todo-example/src/api/todo/todo.router.ts.hbs +76 -0
  29. package/dist/templates/feature/rest/todo-example/src/api/todo/todo.service.ts.hbs +145 -0
  30. package/dist/templates/monorepo/apps/api-gateway/src/app.module.ts.hbs +21 -1
  31. package/dist/templates/monorepo/apps/api-gateway/src/main.ts.hbs +62 -54
  32. package/dist/templates/monorepo/feature/graphql/src/graphql/dto/create-todo.input.ts.hbs +13 -0
  33. package/dist/templates/monorepo/feature/graphql/src/graphql/dto/update-todo.input.ts.hbs +8 -0
  34. package/dist/templates/monorepo/feature/graphql/src/graphql/graphql.module.ts.hbs +33 -0
  35. package/dist/templates/monorepo/feature/graphql/src/graphql/models/base.model.ts.hbs +13 -0
  36. package/dist/templates/monorepo/feature/graphql/src/graphql/models/todo.model.ts.hbs +23 -0
  37. package/dist/templates/monorepo/feature/graphql/src/graphql/models/user.model.ts.hbs +34 -0
  38. package/dist/templates/monorepo/feature/graphql/src/graphql/orm/drizzle/drizzle-graphql.module.ts.hbs +16 -0
  39. package/dist/templates/monorepo/feature/graphql/src/graphql/orm/prisma/prisma-graphql.service.ts.hbs +9 -0
  40. package/dist/templates/monorepo/feature/graphql/src/graphql/orm/typeorm/typeorm-graphql-relations.helper.ts.hbs +23 -0
  41. package/dist/templates/monorepo/feature/graphql/src/graphql/resolvers/todo.resolver.ts.hbs +122 -0
  42. package/dist/templates/monorepo/packages/env/src/api-gateway.ts.hbs +10 -0
  43. package/dist/templates/monorepo/root/README.md.hbs +1 -1
  44. package/dist/templates/monorepo/root/pnpm-workspace.yaml.hbs +9 -0
  45. package/dist/templates/single-project/architecture/nest-api/.env.hbs +25 -1
  46. package/dist/templates/single-project/architecture/nest-api/pnpm-workspace.yaml.hbs +9 -0
  47. package/dist/templates/single-project/architecture/nest-api/src/main.ts.hbs +67 -55
  48. package/dist/templates/single-project/architecture/nest-gateway/src/main.ts.hbs +62 -54
  49. package/dist/templates/single-project/architecture/nest-microservice/.env.hbs +3 -0
  50. package/dist/templates/single-project/architecture/nest-microservice/src/main.ts.hbs +62 -54
  51. package/dist/templates/single-project/shared/config/env.ts.hbs +10 -0
  52. package/package.json +4 -4
@@ -0,0 +1,126 @@
1
+ {{#if (and hasAuth hasDatabase)}}
2
+ import { UseGuards } from "@nestjs/common";
3
+ {{/if}}
4
+ import { Args, Mutation, Query, Resolver } from "@nestjs/graphql";
5
+ import { CreateTodoInput } from "../dto/create-todo.input.js";
6
+ import { UpdateTodoInput } from "../dto/update-todo.input.js";
7
+ {{#if isMonorepo}}
8
+ import { DbService } from "@repo/db";
9
+ {{else}}
10
+ import { DbService } from "../database/db.service.js";
11
+ {{/if}}
12
+ {{#if useTypeorm}}
13
+ import { GraphRelationBuilder } from "typeorm-relations-graphql";
14
+ import { GraphQLResolveInfo } from "graphql";
15
+ {{/if}}
16
+ {{#if useDrizzle}}
17
+ import * as schema from "../database/orm/drizzle/schema.js";
18
+ {{/if}}
19
+ {{#if (and hasAuth hasDatabase)}}
20
+ import { Todo } from "../models/todo.model.js";
21
+ import { UserEntity } from "../../auth/decorators/index.js";
22
+ import { GqlAuthGuard } from "../../auth/guards/gql-auth.guard.js";
23
+ {{/if}}
24
+
25
+ @Resolver({{#if (and hasAuth hasDatabase)}}{{"("}}() => Todo){{/if}})
26
+ export class TodoResolver {
27
+ constructor(private readonly db: DbService) {}
28
+
29
+ @Query(() => String)
30
+ hello(): string {
31
+ return "Hello GraphQL!";
32
+ }{{#if hasDatabase}}
33
+
34
+ @Query(() => [Todo])
35
+ todos({{#if useTypeorm}}info: GraphQLResolveInfo{{/if}}): Promise<Todo[]> {
36
+ {{#if useTypeorm}}
37
+ const builder = new GraphRelationBuilder(this.db.getDataSource());
38
+ const relations = builder.buildForQuery(Todo, info, "todos");
39
+ return this.db.getRepository(Todo).find({ relations });
40
+ {{else if usePrisma}}
41
+ return this.db.prisma.todo.findMany();
42
+ {{else if useDrizzle}}
43
+ return this.db.select().from(schema.todos);
44
+ {{else}}
45
+ return [];
46
+ {{/if}}
47
+ }
48
+
49
+ @Mutation(() => Todo)
50
+ {{#if (and hasAuth hasDatabase)}}
51
+ @UseGuards(GqlAuthGuard)
52
+ {{/if}}
53
+ createTodo(
54
+ @Args("input") input: CreateTodoInput{{#if (and hasAuth hasDatabase)}},
55
+ @UserEntity() user: { id: string }{{/if}}{{#if useTypeorm}}, info: GraphQLResolveInfo{{/if}}
56
+ ): Promise<Todo> {
57
+ {{#if useTypeorm}}
58
+ const entity = this.db.getRepository(Todo).create(input);
59
+ const saved = await this.db.getRepository(Todo).save(entity);
60
+ const builder = new GraphRelationBuilder(this.db.getDataSource());
61
+ const relations = builder.buildForQuery(Todo, info, "createTodo");
62
+ return this.db.getRepository(Todo).findOneOrFail({
63
+ where: { id: saved.id },
64
+ relations,
65
+ });
66
+ {{else if usePrisma}}
67
+ return this.db.prisma.todo.create({
68
+ data: { ...input{{#if (and hasAuth hasDatabase)}}, authorId: user.id{{/if}} },
69
+ });
70
+ {{else if useDrizzle}}
71
+ const [todo] = await this.db.insert(schema.todos).values(input).returning();
72
+ return todo;
73
+ {{else}}
74
+ return { id: "1", ...input };
75
+ {{/if}}
76
+ }
77
+
78
+ @Mutation(() => Todo)
79
+ {{#if (and hasAuth hasDatabase)}}
80
+ @UseGuards(GqlAuthGuard)
81
+ {{/if}}
82
+ updateTodo(
83
+ @Args("input") input: UpdateTodoInput{{#if useTypeorm}}, info: GraphQLResolveInfo{{/if}}
84
+ ): Promise<Todo> {
85
+ const { id, ...data } = input;
86
+ {{#if useTypeorm}}
87
+ await this.db.getRepository(Todo).update(id, data);
88
+ const builder = new GraphRelationBuilder(this.db.getDataSource());
89
+ const relations = builder.buildForQuery(Todo, info, "updateTodo");
90
+ return this.db.getRepository(Todo).findOneOrFail({
91
+ where: { id },
92
+ relations,
93
+ });
94
+ {{else if usePrisma}}
95
+ return this.db.prisma.todo.update({ where: { id }, data });
96
+ {{else if useDrizzle}}
97
+ const [todo] = await this.db
98
+ .update(schema.todos)
99
+ .set(data)
100
+ .where(eq(schema.todos.id, id))
101
+ .returning();
102
+ return todo;
103
+ {{else}}
104
+ return { id, ...data };
105
+ {{/if}}
106
+ }
107
+
108
+ @Mutation(() => Boolean)
109
+ {{#if (and hasAuth hasDatabase)}}
110
+ @UseGuards(GqlAuthGuard)
111
+ {{/if}}
112
+ async deleteTodo(@Args("id") id: string): Promise<boolean> {
113
+ {{#if useTypeorm}}
114
+ const result = await this.db.getRepository(Todo).delete(id);
115
+ return (result.affected ?? 0) > 0;
116
+ {{else if usePrisma}}
117
+ await this.db.prisma.todo.delete({ where: { id } });
118
+ return true;
119
+ {{else if useDrizzle}}
120
+ await this.db.delete(schema.todos).where(eq(schema.todos.id, id));
121
+ return true;
122
+ {{else}}
123
+ return true;
124
+ {{/if}}
125
+ }{{/if}}
126
+ }
@@ -0,0 +1,13 @@
1
+ import { z } from "zod";
2
+
3
+ export class CreateTodoDto {
4
+ static schema = z.object({
5
+ completed: z.boolean().default(false),
6
+ description: z.string().optional(),
7
+ title: z.string().min(1),
8
+ });
9
+
10
+ title: string;
11
+ description?: string;
12
+ completed: boolean;
13
+ }
@@ -0,0 +1,13 @@
1
+ import { z } from "zod";
2
+
3
+ export class UpdateTodoDto {
4
+ static schema = z.object({
5
+ completed: z.boolean().optional(),
6
+ description: z.string().optional(),
7
+ title: z.string().min(1).optional(),
8
+ });
9
+
10
+ title?: string;
11
+ description?: string;
12
+ completed?: boolean;
13
+ }
@@ -0,0 +1,171 @@
1
+ import {
2
+ Body,
3
+ Controller,
4
+ Delete,
5
+ Get,
6
+ Param,
7
+ Post,
8
+ Put,
9
+ {{#if (and isPassportAuth hasDatabase)}}
10
+ UseGuards,
11
+ {{/if}}
12
+ } from "@nestjs/common";
13
+ {{#if swagger}}
14
+ import {
15
+ ApiCreatedResponse,
16
+ ApiOkResponse,
17
+ ApiOperation,
18
+ ApiTags,
19
+ ApiUnauthorizedResponse,
20
+ } from "@nestjs/swagger";
21
+ {{/if}}
22
+ {{#if isPassportAuth}}
23
+ import {
24
+ ApiBearerAuth,
25
+ } from "@nestjs/swagger";
26
+ {{/if}}
27
+ {{#if (and isBetterAuth hasDatabase)}}
28
+ import { Session } from "@thallesp/nestjs-better-auth";
29
+ import type { UserSession } from "../../auth/auth.js";
30
+ {{/if}}
31
+ {{#if (and isPassportAuth hasDatabase)}}
32
+ import { RestAuthGuard } from "../../auth/guards/rest-auth.guard.js";
33
+ import { CurrentUser } from "../../auth/decorators/current-user.decorator.js";
34
+ {{/if}}
35
+ import { TodoService } from "./todo.service.js";
36
+ import { CreateTodoDto } from "./dto/create-todo.dto.js";
37
+ import { UpdateTodoDto } from "./dto/update-todo.dto.js";
38
+
39
+ {{#if swagger}}
40
+ @ApiTags("Todos")
41
+ {{/if}}
42
+ @Controller("todos")
43
+ {{#if (and isPassportAuth hasDatabase)}}
44
+ @UseGuards(RestAuthGuard)
45
+ {{/if}}
46
+ export class TodoController {
47
+ constructor(private readonly todoService: TodoService) {}
48
+
49
+ @Get()
50
+ {{#if swagger}}
51
+ {{#if (or isPassportAuth)}}
52
+ @ApiBearerAuth()
53
+ {{/if}}
54
+ @ApiOperation({ summary: "/api/todos" })
55
+ @ApiOkResponse({ description: "Returns all todos" })
56
+ {{#if (or isPassportAuth isBetterAuth)}}
57
+ @ApiUnauthorizedResponse({ description: "Unauthorized" })
58
+ {{/if}}
59
+ {{/if}}
60
+ {{#if (and isPassportAuth hasDatabase)}}
61
+ findAll(@CurrentUser() user: { id: string }) {
62
+ return this.todoService.findAll(user.id);
63
+ }
64
+ {{else if (and isBetterAuth hasDatabase)}}
65
+ findAll(@Session() session: UserSession) {
66
+ return this.todoService.findAll(session.user.id);
67
+ }
68
+ {{else}}
69
+ findAll() {
70
+ return this.todoService.findAll();
71
+ }
72
+ {{/if}}
73
+
74
+ @Post()
75
+ {{#if swagger}}
76
+ {{#if (or isPassportAuth)}}
77
+ @ApiBearerAuth()
78
+ {{/if}}
79
+ @ApiOperation({ summary: "/api/todos" })
80
+ @ApiCreatedResponse({ description: "Todo created successfully" })
81
+ {{#if (or isPassportAuth isBetterAuth)}}
82
+ @ApiUnauthorizedResponse({ description: "Unauthorized" })
83
+ {{/if}}
84
+ {{/if}}
85
+ {{#if (and isPassportAuth hasDatabase)}}
86
+ create(
87
+ @Body({ schema: CreateTodoDto.schema }) input: CreateTodoDto,
88
+ @CurrentUser() user: { id: string }
89
+ ) {
90
+ return this.todoService.create(input, user.id);
91
+ }
92
+ {{else if (and isBetterAuth hasDatabase)}}
93
+ create(
94
+ @Body({ schema: CreateTodoDto.schema }) input: CreateTodoDto,
95
+ @Session() session: UserSession
96
+ ) {
97
+ return this.todoService.create(input, session.user.id);
98
+ }
99
+ {{else}}
100
+ create(@Body({ schema: CreateTodoDto.schema }) input: CreateTodoDto) {
101
+ return this.todoService.create(input);
102
+ }
103
+ {{/if}}
104
+
105
+ @Put(":id")
106
+ {{#if swagger}}
107
+ {{#if (or isPassportAuth)}}
108
+ @ApiBearerAuth()
109
+ {{/if}}
110
+ @ApiOperation({ summary: "/api/todos/{id}" })
111
+ @ApiOkResponse({ description: "Todo updated successfully" })
112
+ {{#if (or isPassportAuth isBetterAuth)}}
113
+ @ApiUnauthorizedResponse({ description: "Unauthorized" })
114
+ {{/if}}
115
+ {{/if}}
116
+ {{#if (and isPassportAuth hasDatabase)}}
117
+ update(
118
+ @Param("id") id: string,
119
+ @Body({ schema: UpdateTodoDto.schema }) input: UpdateTodoDto,
120
+ @CurrentUser() user: { id: string }
121
+ ) {
122
+ return this.todoService.update(id, input, user.id);
123
+ }
124
+ {{else if (and isBetterAuth hasDatabase)}}
125
+ update(
126
+ @Param("id") id: string,
127
+ @Body({ schema: UpdateTodoDto.schema }) input: UpdateTodoDto,
128
+ @Session() session: UserSession
129
+ ) {
130
+ return this.todoService.update(id, input, session.user.id);
131
+ }
132
+ {{else}}
133
+ update(
134
+ @Param("id") id: string,
135
+ @Body({ schema: UpdateTodoDto.schema }) input: UpdateTodoDto
136
+ ) {
137
+ return this.todoService.update(id, input);
138
+ }
139
+ {{/if}}
140
+
141
+ @Delete(":id")
142
+ {{#if swagger}}
143
+ {{#if (or isPassportAuth)}}
144
+ @ApiBearerAuth()
145
+ {{/if}}
146
+ @ApiOperation({ summary: "/api/todos/{id}" })
147
+ @ApiOkResponse({ description: "Todo deleted successfully" })
148
+ {{#if (or isPassportAuth isBetterAuth)}}
149
+ @ApiUnauthorizedResponse({ description: "Unauthorized" })
150
+ {{/if}}
151
+ {{/if}}
152
+ {{#if (and isPassportAuth hasDatabase)}}
153
+ async delete(
154
+ @Param("id") id: string,
155
+ @CurrentUser() user: { id: string }
156
+ ) {
157
+ return this.todoService.delete(id, user.id);
158
+ }
159
+ {{else if (and isBetterAuth hasDatabase)}}
160
+ async delete(
161
+ @Param("id") id: string,
162
+ @Session() session: UserSession
163
+ ) {
164
+ return this.todoService.delete(id, session.user.id);
165
+ }
166
+ {{else}}
167
+ async delete(@Param("id") id: string) {
168
+ return this.todoService.delete(id);
169
+ }
170
+ {{/if}}
171
+ }
@@ -0,0 +1,24 @@
1
+ import { Module } from "@nestjs/common";
2
+ {{#if hasRest}}
3
+ import { TodoController } from "./todo.controller.js";
4
+ {{/if}}
5
+ import { TodoService } from "./todo.service.js";
6
+ {{#unless hasRest}}
7
+ import { TodoRouter } from "./todo.router.js";
8
+ {{/unless}}
9
+
10
+ @Module({
11
+ {{#if hasRest}}
12
+ controllers: [TodoController],
13
+ {{/if}}
14
+ providers: [
15
+ TodoService,
16
+ {{#unless hasRest}}
17
+ TodoRouter,
18
+ {{/unless}}
19
+ ],
20
+ {{#if hasRest}}
21
+ exports: [TodoService],
22
+ {{/if}}
23
+ })
24
+ export class TodoModule {}
@@ -0,0 +1,76 @@
1
+ {{#if hasTrpc}}
2
+ import { Router, Query, Mutation, Ctx, Input } from "nestjs-trpc";
3
+ import z from "zod";
4
+ {{#if hasTrpcAndAuth}}
5
+ import type { UserSession } from "../../auth/auth.js";
6
+ import { AuthTRPCMiddleware } from "../../libs/middlewares/auth.trpc.middleware.js";
7
+ import type { InnerContext } from "../../libs/trpc/inner.context.js";
8
+ {{/if}}
9
+ import { TodoService } from "./todo.service.js";
10
+ import { CreateTodoDto } from "./dto/create-todo.dto.js";
11
+ import { UpdateTodoDto } from "./dto/update-todo.dto.js";
12
+
13
+ const todoSchema = z.object({
14
+ id: z.string(),
15
+ title: z.string(),
16
+ description: z.string().nullable().optional(),
17
+ completed: z.boolean(),
18
+ authorId: z.string().nullable().optional(),
19
+ });
20
+
21
+ const updateTodoInput = z.object({
22
+ id: z.string(),
23
+ data: UpdateTodoDto.schema,
24
+ });
25
+
26
+ @Router({ alias: "todoRouter" })
27
+ export class TodoRouter {
28
+ constructor(private readonly todoService: TodoService) {}
29
+
30
+ {{#if hasTrpcAndAuth}}
31
+ @Query({ output: z.array(todoSchema) })
32
+ @UseMiddlewares(AuthTRPCMiddleware)
33
+ findAll(@Ctx() ctx: InnerContext) {
34
+ return this.todoService.findAll(ctx.session!.user.id);
35
+ }
36
+
37
+ @Mutation({ input: CreateTodoDto.schema, output: todoSchema })
38
+ @UseMiddlewares(AuthTRPCMiddleware)
39
+ create(@Ctx() ctx: InnerContext, @Input() input: CreateTodoDto) {
40
+ return this.todoService.create(input, ctx.session!.user.id);
41
+ }
42
+
43
+ @Mutation({ input: updateTodoInput, output: todoSchema })
44
+ @UseMiddlewares(AuthTRPCMiddleware)
45
+ update(@Ctx() ctx: InnerContext, @Input() input: { id: string; data: UpdateTodoDto }) {
46
+ return this.todoService.update(input.id, input.data, ctx.session!.user.id);
47
+ }
48
+
49
+ @Mutation({ input: z.object({ id: z.string() }) })
50
+ @UseMiddlewares(AuthTRPCMiddleware)
51
+ delete(@Ctx() ctx: InnerContext, @Input() input: { id: string }) {
52
+ return this.todoService.delete(input.id, ctx.session!.user.id);
53
+ }
54
+ {{else}}
55
+ @Query({ output: z.array(todoSchema) })
56
+ findAll() {
57
+ return this.todoService.findAll();
58
+ }
59
+
60
+ @Mutation({ input: CreateTodoDto.schema, output: todoSchema })
61
+ create(@Input() input: CreateTodoDto) {
62
+ return this.todoService.create(input);
63
+ }
64
+
65
+ @Mutation({ input: updateTodoInput, output: todoSchema })
66
+ update(@Input() input: { id: string; data: UpdateTodoDto }) {
67
+ return this.todoService.update(input.id, input.data);
68
+ }
69
+
70
+ @Mutation({ input: z.object({ id: z.string() }) })
71
+ delete(@Input() input: { id: string }) {
72
+ return this.todoService.delete(input.id);
73
+ }
74
+ {{/if}}
75
+ }
76
+ {{/if}}
@@ -0,0 +1,145 @@
1
+ import { Injectable } from "@nestjs/common";
2
+ {{#if hasDatabase}}
3
+ {{#if isMonorepo}}
4
+ import { DbService } from "@repo/db";
5
+ {{else}}
6
+ import { DbService } from "../../database/db.service.js";
7
+ {{/if}}
8
+ {{#if useDrizzle}}
9
+ import * as schema from "../../database/orm/drizzle/schema.js";
10
+ import { eq } from "drizzle-orm";
11
+ {{/if}}
12
+ {{#if useTypeorm}}
13
+ import { Todo } from "../../database/entities/todo.entity.js";
14
+ {{/if}}
15
+ {{/if}}
16
+ import { CreateTodoDto } from "./dto/create-todo.dto.js";
17
+ import { UpdateTodoDto } from "./dto/update-todo.dto.js";
18
+
19
+ @Injectable()
20
+ export class TodoService {
21
+ {{#if hasDatabase}}
22
+ constructor(private readonly db: DbService) {}
23
+ {{else}}
24
+ private todos: Array<{
25
+ completed: boolean;
26
+ description?: string;
27
+ id: string;
28
+ title: string;
29
+ }> = [];
30
+ private nextId = 1;
31
+ {{/if}}
32
+
33
+ {{#if hasDatabase}}
34
+ {{#if hasAuth}}
35
+ findAll(authorId: string) {
36
+ {{#if usePrisma}}
37
+ return this.db.prisma.todo.findMany({ where: { authorId } });
38
+ {{else if useTypeorm}}
39
+ return this.db.getRepository(Todo).find({ where: { authorId } });
40
+ {{else if useDrizzle}}
41
+ return this.db.select().from(schema.todos).where(eq(schema.todos.authorId, authorId));
42
+ {{/if}}
43
+ }
44
+
45
+ create(input: CreateTodoDto, authorId: string) {
46
+ {{#if usePrisma}}
47
+ return this.db.prisma.todo.create({ data: { ...input, authorId } });
48
+ {{else if useTypeorm}}
49
+ return this.db.getRepository(Todo).save(this.db.getRepository(Todo).create({ ...input, authorId }));
50
+ {{else if useDrizzle}}
51
+ return this.db.insert(schema.todos).values({ ...input, authorId }).returning();
52
+ {{/if}}
53
+ }
54
+
55
+ update(id: string, input: UpdateTodoDto, authorId: string) {
56
+ {{#if usePrisma}}
57
+ return this.db.prisma.todo.update({ data: input, where: { authorId, id } });
58
+ {{else if useTypeorm}}
59
+ return this.db.getRepository(Todo).update({ authorId, id }, input);
60
+ {{else if useDrizzle}}
61
+ return this.db.update(schema.todos).set(input).where(eq(schema.todos.authorId, authorId) && eq(schema.todos.id, id)).returning();
62
+ {{/if}}
63
+ }
64
+
65
+ async delete(id: string, authorId: string) {
66
+ {{#if usePrisma}}
67
+ await this.db.prisma.todo.delete({ where: { authorId, id } });
68
+ {{else if useTypeorm}}
69
+ await this.db.getRepository(Todo).delete({ authorId, id });
70
+ {{else if useDrizzle}}
71
+ await this.db.delete(schema.todos).where(eq(schema.todos.authorId, authorId) && eq(schema.todos.id, id));
72
+ {{/if}}
73
+ return { message: "Todo deleted successfully" };
74
+ }
75
+ {{else}}
76
+ findAll() {
77
+ {{#if usePrisma}}
78
+ return this.db.prisma.todo.findMany();
79
+ {{else if useTypeorm}}
80
+ return this.db.getRepository(Todo).find();
81
+ {{else if useDrizzle}}
82
+ return this.db.select().from(schema.todos);
83
+ {{/if}}
84
+ }
85
+
86
+ create(input: CreateTodoDto) {
87
+ {{#if usePrisma}}
88
+ return this.db.prisma.todo.create({ data: input });
89
+ {{else if useTypeorm}}
90
+ return this.db.getRepository(Todo).save(this.db.getRepository(Todo).create(input));
91
+ {{else if useDrizzle}}
92
+ return this.db.insert(schema.todos).values(input).returning();
93
+ {{/if}}
94
+ }
95
+
96
+ update(id: string, input: UpdateTodoDto) {
97
+ {{#if usePrisma}}
98
+ return this.db.prisma.todo.update({ data: input, where: { id } });
99
+ {{else if useTypeorm}}
100
+ return this.db.getRepository(Todo).update(id, input);
101
+ {{else if useDrizzle}}
102
+ return this.db.update(schema.todos).set(input).where(eq(schema.todos.id, id)).returning();
103
+ {{/if}}
104
+ }
105
+
106
+ async delete(id: string) {
107
+ {{#if usePrisma}}
108
+ await this.db.prisma.todo.delete({ where: { id } });
109
+ {{else if useTypeorm}}
110
+ await this.db.getRepository(Todo).delete(id);
111
+ {{else if useDrizzle}}
112
+ await this.db.delete(schema.todos).where(eq(schema.todos.id, id));
113
+ {{/if}}
114
+ return { message: "Todo deleted successfully" };
115
+ }
116
+ {{/if}}
117
+ {{else}}
118
+ findAll() {
119
+ return [...this.todos];
120
+ }
121
+
122
+ create(input: CreateTodoDto) {
123
+ const todo = { id: String(this.nextId++), ...input };
124
+ this.todos.push(todo);
125
+ return todo;
126
+ }
127
+
128
+ update(id: string, input: UpdateTodoDto) {
129
+ const todo = this.todos.find((t) => t.id === id);
130
+ if (!todo) {
131
+ return { message: "Todo not found" };
132
+ }
133
+ Object.assign(todo, input);
134
+ return todo;
135
+ }
136
+
137
+ async delete(id: string) {
138
+ const index = this.todos.findIndex((t) => t.id === id);
139
+ if (index >= 0) {
140
+ this.todos.splice(index, 1);
141
+ }
142
+ return { message: "Todo deleted successfully" };
143
+ }
144
+ {{/if}}
145
+ }
@@ -6,6 +6,9 @@ import { env } from "./config/env.js";
6
6
  {{#if (or (eq auth "better-auth") (eq auth "better-auth:stateless"))}}
7
7
  import { AuthModule } from "./auth/auth.module.js";
8
8
  {{/if}}
9
+ {{#if hasGraphql}}
10
+ import { GraphqlAppModule } from "./graphql/graphql.module.js";
11
+ {{/if}}
9
12
  {{#if hasTrpc}}
10
13
  import { TRPCModule } from "nestjs-trpc";
11
14
  import { AppRouterClass as AppRouter } from "./app.router.js";
@@ -17,10 +20,18 @@ import { AuthTRPCMiddleware } from "./libs/middlewares/auth.trpc.middleware.js";
17
20
  {{/if}}
18
21
 
19
22
  import { AppController } from "./app.controller.js";
23
+ {{#if (and hasTodoExample (or hasRest hasTrpc))}}
24
+ import { TodoModule } from "./api/todo/todo.module.js";
25
+ {{/if}}
26
+ {{#if (and hasTrpc hasTodoExample hasRest)}}
27
+ import { TodoRouter } from "./api/todo/todo.router.js";
28
+ {{/if}}
20
29
  import { AppService } from "./app.service.js";
21
30
 
22
31
  @Module({
23
- controllers: [AppController],
32
+ controllers: [
33
+ AppController,
34
+ ],
24
35
  imports: [
25
36
  {{#if (or hasDatabase hasOrm)}}
26
37
  DbModule.forRoot({
@@ -33,12 +44,18 @@ import { AppService } from "./app.service.js";
33
44
  {{#if (or (eq auth "better-auth") (eq auth "better-auth:stateless"))}}
34
45
  AuthModule,
35
46
  {{/if}}
47
+ {{#if hasGraphql}}
48
+ GraphqlAppModule,
49
+ {{/if}}
36
50
  {{#if hasTrpc}}
37
51
  TRPCModule.forRoot({
38
52
  context: AppContext,
39
53
  onError: AppErrorHandler,
40
54
  }),
41
55
  {{/if}}
56
+ {{#if (and hasTodoExample (or hasRest hasTrpc))}}
57
+ TodoModule,
58
+ {{/if}}
42
59
  ],
43
60
  providers: [
44
61
  AppService,
@@ -49,6 +66,9 @@ import { AppService } from "./app.service.js";
49
66
  AppContext,
50
67
  AppErrorHandler,
51
68
  AppRouter,
69
+ {{#if (and hasTrpc hasTodoExample hasRest)}}
70
+ TodoRouter,
71
+ {{/if}}
52
72
  {{/if}}
53
73
  ],
54
74
  })