diff --git a/libs/tasks/interface-adapters/src/index.ts b/libs/tasks/interface-adapters/src/index.ts index a6214aa..c92ed5c 100644 --- a/libs/tasks/interface-adapters/src/index.ts +++ b/libs/tasks/interface-adapters/src/index.ts @@ -1 +1 @@ -export * from './lib/tasks-interface-adapters'; +export * from './lib/tasks.module'; \ No newline at end of file diff --git a/libs/tasks/interface-adapters/src/lib/dto/create-user-task.dto.spec.ts b/libs/tasks/interface-adapters/src/lib/dto/create-user-task.dto.spec.ts new file mode 100644 index 0000000..099aa9b --- /dev/null +++ b/libs/tasks/interface-adapters/src/lib/dto/create-user-task.dto.spec.ts @@ -0,0 +1,14 @@ +import { CreateUserTaskDto } from './create-user-task.dto'; + +describe('CreateUserTaskDto', () => { + it('should create a CreateUserTaskDto instance', () => { + const id = '123'; + const createdAt = new Date(); + + const dto = new CreateUserTaskDto(id, createdAt); + + expect(dto).toBeDefined(); + expect(dto.id).toBe(id); + expect(dto.createdAt).toBe(createdAt); + }); +}); diff --git a/libs/tasks/interface-adapters/src/lib/dto/create-user-task.dto.ts b/libs/tasks/interface-adapters/src/lib/dto/create-user-task.dto.ts new file mode 100644 index 0000000..6534969 --- /dev/null +++ b/libs/tasks/interface-adapters/src/lib/dto/create-user-task.dto.ts @@ -0,0 +1,15 @@ +import { Field, InputType } from '@nestjs/graphql'; + +@InputType() +export class CreateUserTaskDto { + @Field(() => String) + id: string; + + @Field(() => Date) + createdAt: Date; + + constructor(id: string, createdAt: Date) { + this.id = id; + this.createdAt = createdAt; + } +} diff --git a/libs/tasks/interface-adapters/src/lib/dto/task.dto.spec.ts b/libs/tasks/interface-adapters/src/lib/dto/task.dto.spec.ts new file mode 100644 index 0000000..cd748dc --- /dev/null +++ b/libs/tasks/interface-adapters/src/lib/dto/task.dto.spec.ts @@ -0,0 +1,29 @@ +import { TaskDto } from './task.dto'; + +describe('TaskDto', () => { + it('should create a TaskDto instance', () => { + const id = '123'; + const title = 'Test Task'; + const description = 'Test Description'; + const categories = ['category1', 'category2']; + + const dto = new TaskDto(id, title, description, categories); + + expect(dto).toBeDefined(); + expect(dto.id).toBe(id); + expect(dto.title).toBe(title); + expect(dto.description).toBe(description); + expect(dto.categories).toEqual(categories); + }); + + it('should allow null description', () => { + const id = '123'; + const title = 'Test Task'; + const description = null; + const categories = ['category1']; + + const dto = new TaskDto(id, title, description, categories); + + expect(dto.description).toBeNull(); + }); +}); diff --git a/libs/tasks/interface-adapters/src/lib/dto/task.dto.ts b/libs/tasks/interface-adapters/src/lib/dto/task.dto.ts new file mode 100644 index 0000000..a997573 --- /dev/null +++ b/libs/tasks/interface-adapters/src/lib/dto/task.dto.ts @@ -0,0 +1,30 @@ +import { Field, ID, ObjectType } from '@nestjs/graphql'; +import { IsOptional } from 'class-validator'; + +@ObjectType() +export class TaskDto { + @Field(() => ID) + id: string; + + @Field() + title: string; + + @Field(() => String, { nullable: true }) + @IsOptional() + description: string | null; + + @Field(() => [String]) + categories: string[]; + + constructor( + id: string, + title: string, + description: string | null, + categories: string[], + ) { + this.id = id; + this.title = title; + this.description = description; + this.categories = categories; + } +} diff --git a/libs/tasks/interface-adapters/src/lib/dto/update-user-task.dto.spec.ts b/libs/tasks/interface-adapters/src/lib/dto/update-user-task.dto.spec.ts new file mode 100644 index 0000000..2019dd1 --- /dev/null +++ b/libs/tasks/interface-adapters/src/lib/dto/update-user-task.dto.spec.ts @@ -0,0 +1,14 @@ +import { UpdateUserTaskDto } from './update-user-task.dto'; + +describe('UpdateUserTaskDto', () => { + it('should create an UpdateUserTaskDto instance', () => { + const id = '123'; + const updatedAt = new Date(); + + const dto = new UpdateUserTaskDto(id, updatedAt); + + expect(dto).toBeDefined(); + expect(dto.id).toBe(id); + expect(dto.updatedAt).toBe(updatedAt); + }); +}); diff --git a/libs/tasks/interface-adapters/src/lib/dto/update-user-task.dto.ts b/libs/tasks/interface-adapters/src/lib/dto/update-user-task.dto.ts new file mode 100644 index 0000000..1be5004 --- /dev/null +++ b/libs/tasks/interface-adapters/src/lib/dto/update-user-task.dto.ts @@ -0,0 +1,15 @@ +import { Field, InputType } from '@nestjs/graphql'; + +@InputType() +export class UpdateUserTaskDto { + @Field(() => String) + id: string; + + @Field(() => Date) + updatedAt: Date; + + constructor(id: string, updatedAt: Date) { + this.id = id; + this.updatedAt = updatedAt; + } +} diff --git a/libs/tasks/interface-adapters/src/lib/resolver/tasks.resolver.spec.ts b/libs/tasks/interface-adapters/src/lib/resolver/tasks.resolver.spec.ts new file mode 100644 index 0000000..22f80b3 --- /dev/null +++ b/libs/tasks/interface-adapters/src/lib/resolver/tasks.resolver.spec.ts @@ -0,0 +1,32 @@ +import { Args, Mutation, Query, Resolver } from '@nestjs/graphql'; +import { TasksService } from '@tasks/application'; + +import { TaskDto } from '../dto/task.dto'; +import { CreateUserTaskDto } from '../dto/create-user-task.dto'; +import { UpdateUserTaskDto } from '../dto/update-user-task.dto'; + +@Resolver(() => TaskDto) +export class TasksResolver { + constructor(private tasksService: TasksService) {} + + @Query(() => TaskDto, { nullable: true }) + async getTasks(): Promise { + return this.tasksService.findAll(); + } + + @Mutation(() => String) + async createUserTasks( + @Args('userId') userId: string, + @Args('tasks') tasks: CreateUserTaskDto[], + ): Promise { + return this.tasksService.createUserTasks(userId, tasks); + } + + @Mutation(() => String) + async updateUserTasks( + @Args('userId') userId: string, + @Args('userTasks') userTasks: UpdateUserTaskDto[], + ): Promise { + return this.tasksService.updateUserTasks(userId, userTasks); + } +} diff --git a/libs/tasks/interface-adapters/src/lib/resolver/tasks.resolver.ts b/libs/tasks/interface-adapters/src/lib/resolver/tasks.resolver.ts new file mode 100644 index 0000000..22f80b3 --- /dev/null +++ b/libs/tasks/interface-adapters/src/lib/resolver/tasks.resolver.ts @@ -0,0 +1,32 @@ +import { Args, Mutation, Query, Resolver } from '@nestjs/graphql'; +import { TasksService } from '@tasks/application'; + +import { TaskDto } from '../dto/task.dto'; +import { CreateUserTaskDto } from '../dto/create-user-task.dto'; +import { UpdateUserTaskDto } from '../dto/update-user-task.dto'; + +@Resolver(() => TaskDto) +export class TasksResolver { + constructor(private tasksService: TasksService) {} + + @Query(() => TaskDto, { nullable: true }) + async getTasks(): Promise { + return this.tasksService.findAll(); + } + + @Mutation(() => String) + async createUserTasks( + @Args('userId') userId: string, + @Args('tasks') tasks: CreateUserTaskDto[], + ): Promise { + return this.tasksService.createUserTasks(userId, tasks); + } + + @Mutation(() => String) + async updateUserTasks( + @Args('userId') userId: string, + @Args('userTasks') userTasks: UpdateUserTaskDto[], + ): Promise { + return this.tasksService.updateUserTasks(userId, userTasks); + } +} diff --git a/libs/tasks/interface-adapters/src/lib/tasks-interface-adapters.spec.ts b/libs/tasks/interface-adapters/src/lib/tasks-interface-adapters.spec.ts deleted file mode 100644 index a33f1f3..0000000 --- a/libs/tasks/interface-adapters/src/lib/tasks-interface-adapters.spec.ts +++ /dev/null @@ -1,7 +0,0 @@ -import { tasksInterfaceAdapters } from './tasks-interface-adapters'; - -describe('tasksInterfaceAdapters', () => { - it('should work', () => { - expect(tasksInterfaceAdapters()).toEqual('tasks-interface-adapters'); - }); -}); diff --git a/libs/tasks/interface-adapters/src/lib/tasks-interface-adapters.ts b/libs/tasks/interface-adapters/src/lib/tasks-interface-adapters.ts deleted file mode 100644 index 91f284e..0000000 --- a/libs/tasks/interface-adapters/src/lib/tasks-interface-adapters.ts +++ /dev/null @@ -1,3 +0,0 @@ -export function tasksInterfaceAdapters(): string { - return 'tasks-interface-adapters'; -} diff --git a/libs/tasks/interface-adapters/src/lib/tasks.module.ts b/libs/tasks/interface-adapters/src/lib/tasks.module.ts new file mode 100644 index 0000000..8121d73 --- /dev/null +++ b/libs/tasks/interface-adapters/src/lib/tasks.module.ts @@ -0,0 +1,11 @@ +import { Module } from '@nestjs/common'; +import { TasksService } from '@tasks/application'; + +import { TasksResolver } from './resolver/tasks.resolver'; + +@Module({ + imports: [], + providers: [TasksResolver, TasksService], + exports: [TasksService], +}) +export class TasksModule {}