Skip to content

Instantly share code, notes, and snippets.

@kevinvdburgt
Created December 11, 2021 20:36
Show Gist options
  • Save kevinvdburgt/2e6e16c47c8aa814969b5a34b502f42b to your computer and use it in GitHub Desktop.
Save kevinvdburgt/2e6e16c47c8aa814969b5a34b502f42b to your computer and use it in GitHub Desktop.
// 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