Skip to content

Commit

Permalink
refactor: ♻️ creating a base DTO class
Browse files Browse the repository at this point in the history
  • Loading branch information
zhumeisongsong committed Dec 9, 2024
1 parent 7ee3959 commit 83df7bb
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 14 deletions.
14 changes: 14 additions & 0 deletions libs/tasks/interface-adapters/src/lib/dto/base-task.dto.ts
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;
}
}
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;
}
}
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;
}
}

0 comments on commit 83df7bb

Please sign in to comment.