-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: ♻️ creating a base DTO class
- Loading branch information
1 parent
7ee3959
commit 83df7bb
Showing
3 changed files
with
27 additions
and
14 deletions.
There are no files selected for viewing
14 changes: 14 additions & 0 deletions
14
libs/tasks/interface-adapters/src/lib/dto/base-task.dto.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { Field, InputType } from "@nestjs/graphql"; | ||
import { IsNotEmpty, IsUUID } from "class-validator"; | ||
|
||
@InputType({ isAbstract: true }) | ||
export abstract class BaseTaskDto { | ||
@Field(() => String) | ||
@IsNotEmpty() | ||
@IsUUID() | ||
id: string; | ||
|
||
constructor(id: string) { | ||
this.id = id; | ||
} | ||
} |
14 changes: 6 additions & 8 deletions
14
libs/tasks/interface-adapters/src/lib/dto/create-user-task.dto.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,16 @@ | ||
import { Field, InputType } from '@nestjs/graphql'; | ||
import { IsNotEmpty, IsUUID } from 'class-validator'; | ||
|
||
@InputType() | ||
export class CreateUserTaskDto { | ||
@Field(() => String) | ||
@IsNotEmpty() | ||
@IsUUID() | ||
id: string; | ||
import { BaseTaskDto } from './base-task.dto'; | ||
|
||
@InputType({ description: 'Input type for creating a new user task' }) | ||
export class CreateUserTaskDto extends BaseTaskDto { | ||
@Field(() => Date) | ||
createdAt: Date; | ||
@IsNotEmpty() | ||
createdAt: Date = new Date(); | ||
|
||
constructor(id: string, createdAt: Date) { | ||
this.id = id; | ||
super(id); | ||
this.createdAt = createdAt; | ||
} | ||
} |
13 changes: 7 additions & 6 deletions
13
libs/tasks/interface-adapters/src/lib/dto/update-user-task.dto.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,16 @@ | ||
import { Field, InputType } from '@nestjs/graphql'; | ||
import { IsNotEmpty } from 'class-validator'; | ||
|
||
@InputType() | ||
export class UpdateUserTaskDto { | ||
@Field(() => String) | ||
id: string; | ||
import { BaseTaskDto } from './base-task.dto'; | ||
|
||
@InputType({ description: 'Input type for updating a user task' }) | ||
export class UpdateUserTaskDto extends BaseTaskDto { | ||
@Field(() => Date) | ||
updatedAt: Date; | ||
@IsNotEmpty() | ||
updatedAt: Date = new Date(); | ||
|
||
constructor(id: string, updatedAt: Date) { | ||
this.id = id; | ||
super(id); | ||
this.updatedAt = updatedAt; | ||
} | ||
} |