Last active
March 27, 2023 13:23
-
-
Save GerritRiesch94/044bb0ec75ccfbde3e5c57d021ec6e8a to your computer and use it in GitHub Desktop.
Nest.js Controller Example
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
import { Controller, Get, Param, Query, Res } from '@nestjs/common'; | |
import { AppService } from './app.service'; | |
import { Response } from 'express'; | |
@Controller('api/data') | |
export class AppController { | |
constructor(private readonly appService: AppService) {} | |
@Get(':id') | |
async getData( | |
@Param('id') id: string, | |
@Query('skip') skip: number, | |
@Query('top') top: number, | |
@Res() response: Response, | |
): Promise<void> { | |
// should represent a database service, api call, etc. | |
const data = this.appService.searchForIdAndPaginate(id, skip, top); | |
if (data.length > 0) { | |
response.status(200).send(data); | |
} else { | |
response.status(204).send(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment