Created
December 11, 2021 20:36
-
-
Save kevinvdburgt/2e6e16c47c8aa814969b5a34b502f42b to your computer and use it in GitHub Desktop.
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
// modules/example/interfaces/listing.interface.ts | |
export interface ListingInterface { | |
names: string[]; | |
} | |
// modules/example/dtos/listing.dto.ts | |
export class ListingPayloadDto implements ListingInterface { | |
// class-validator validations | |
// @nestjs/swagger decorators | |
readonly names!: string[]; | |
} | |
// modules/example/services/example.service.ts | |
@Injectable() | |
export class ExampleService { | |
async list(data: ListingInterface): Promise<string> { | |
return data.names.join(`\n`); | |
} | |
} | |
// modules/example/controllers/example.controller.ts | |
@Controller('example') | |
export class ExampleController { | |
constructor(private readonly exampleService: ExampleService) {} | |
@Post() | |
async list(@Body() payload: ListingPayloadDto): Promise<string> { | |
return await this.exampleService.list(payload); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment